dmBridge PHP API
DMXMLRepresentationTransformerV1.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00013 class DMXMLRepresentationTransformerV1 extends DMXMLRepresentationTransformer
00014 implements DMHTTPAPIRepresentationTransformer {
00015 
00019    protected $version = 1;
00020 
00021 
00025    public function nullResponse() {
00026       $this->dxml->documentElement->appendChild(
00027          $this->dxml->createElement("querySeconds", $this->getQSeconds()));
00028       return $this->output();
00029    }
00030 
00036    public function transformCollection(DMCollection $col) {
00037       $this->addSchema("collection_view");
00038       $colnode = $this->dxml->createElement("dmCollection");
00039       $this->dxml->documentElement->appendChild($colnode);
00040       // alias
00041       $colnode->setAttribute("alias", $col->getAlias());
00042       // title
00043       $colnode->appendChild(
00044          $this->dxml->createElement("name",
00045             DMString::xmlentities($col->getName()))
00046       );
00047       // # of objects
00048       $colnode->appendChild(
00049          $this->dxml->createElement("numObjects",
00050             DMString::xmlentities($col->getNumObjects())));
00051       $this->dxml->documentElement->appendChild($colnode);
00052       // overview page
00053       if ($col->getOverviewURI()) {
00054          $overview = $this->dxml->createElement("overview");
00055          $overview->setAttribute("xlink:href", $col->getOverviewURI());
00056          $colnode->appendChild($overview);
00057       }
00058       // description
00059       if ($col->getDescription()) {
00060          $desc = $this->dxml->createElement("description",
00061                $col->getDescription());
00062          $colnode->appendChild($desc);
00063       }
00064       // image
00065       if ($col->getImage512URI()) {
00066          $img = $this->dxml->createElement("image512");
00067          $img->setAttribute("xlink:href", $col->getImage512URI());
00068          $colnode->appendChild($img);
00069       }
00070       // fields
00071       $fields = $this->dxml->createElement("fields");
00072       foreach ($col->getFields() as $f) {
00073          if ($f->isHidden()) {
00074             continue;
00075          }
00076          $field = $this->dxml->createElement("dmField");
00077          $field->setAttribute("nick", $f->getNick());
00078          $field->setAttribute("name", $f->getName());
00079          $field->setAttribute("isControlled", (int) $f->isControlled());
00080          $field->setAttribute("isSearchable", (int) $f->isSearchable());
00081          $field->setAttribute("dc", $f->getDCNick());
00082          $field->setAttribute("type", $f->getType());
00083          $fields->appendChild($field);
00084       }
00085       $colnode->appendChild($fields);
00086       return $this->output();
00087    }
00088 
00094    public function transformCollections(array $collections) {
00095       $this->addSchema('collections_list');
00096       foreach ($collections as $c) {
00097          if (!$c instanceof DMCollection) {
00098             continue;
00099          }
00100          $colnode = $this->dxml->createElement('dmCollection');
00101          // alias
00102          $colnode->setAttribute('alias', $c->getAlias());
00103 
00104          // URI
00105          $colnode->setAttribute('xlink:type', 'simple');
00106          $colnode->setAttribute('xlink:href',
00107                $c->getURI(DMBridgeComponent::HTTPAPI));
00108 
00109          // title
00110          $colnode->appendChild(
00111             $this->dxml->createElement('name',
00112                DMString::xmlentities($c->getName())));
00113          // # of objects
00114          $colnode->appendChild(
00115             $this->dxml->createElement('numObjects',
00116                DMString::xmlentities($c->getNumObjects())));
00117          $this->dxml->documentElement->appendChild($colnode);
00118       }
00119       return $this->output();
00120    }
00121 
00127    public function transformComment(DMComment $comment) {
00128       $this->addSchema('comment_view');
00129       // object
00130       $object = $this->dxml->createElement('dmObject');
00131       $object->setAttribute('alias',
00132             $comment->getObject()->getCollection()->getAlias());
00133       $object->setAttribute('pointer', $comment->getObject()->getPtr());
00134       $object->setAttribute('xlink:type', 'simple');
00135       $object->setAttribute('xlink:href',
00136             $comment->getObject()->getURI(DMBridgeComponent::HTTPAPI));
00137 
00138       // comment
00139       $cnode = $this->dxml->createElement('dmComment');
00140       // id
00141       $cnode->setAttribute('id', $comment->getID());
00142       // timestamp
00143       $cnode->setAttribute('timestamp', $comment->getTimestamp()->asISO8601());
00144 
00145       // poster
00146       $poster = $this->dxml->createElement('poster');
00147       $poster->appendChild(
00148          $this->dxml->createElement('name',
00149                DMString::xmlentities($comment->getName())));
00150       $poster->appendChild(
00151          $this->dxml->createElement('email',
00152                DMString::xmlentities($comment->getEmail())));
00153       $cnode->appendChild($poster);
00154       // text
00155       $cnode->appendChild(
00156          $this->dxml->createElement('body',
00157                DMString::xmlentities($comment->getValue())));
00158       $object->appendChild($cnode);
00159       $this->dxml->documentElement->appendChild($object);
00160       return $this->output();
00161    }
00162 
00171    public function transformComments(array $comments, $page, $rpp, $total) {
00172       $this->addSchema('comments_list');
00173       $node = $this->dxml->createElement('comments');
00174       $node->setAttribute('page', $page);
00175       $node->setAttribute('perPage', $rpp);
00176       $node->setAttribute('numPages', ceil($total / $rpp));
00177       $node->setAttribute('total', $total);
00178       foreach ($comments as $c) {
00179          $cnode = $this->dxml->createElement('dmComment');
00180          $cnode->setAttribute('id', $c->getID());
00181          $cnode->setAttribute('xlink:type', 'simple');
00182          $cnode->setAttribute('xlink:href',
00183                $c->getURI(DMBridgeComponent::HTTPAPI));
00184          $node->appendChild($cnode);
00185       }
00186       $this->dxml->documentElement->appendChild($node);
00187       return $this->output();
00188    }
00189 
00195    public function transformException(Exception $ex) {
00196       self::__construct(); // clear any xml that has been generated up til now
00197       $this->addSchema('exception');
00198       $node = $this->dxml->createElement('dmException');
00199       // message
00200       $node->appendChild(
00201          $this->dxml->createElement('message',
00202             DMString::xmlentities($ex->getMessage())));
00203       if (DMConfigIni::getInstance()->getString("dmbridge.debug_mode")) {
00204          $node->setAttribute('type', get_class($ex));
00205          // stack trace
00206          $node->appendChild(
00207             $this->dxml->createElement('stackTrace',
00208                DMString::xmlentities($ex->getTraceAsString())));
00209       }
00210       $doc = $this->dxml->createElement('documentation');
00211       $doc->setAttribute('xlink:type', 'simple');
00212       $doc->setAttribute('xlink:href',
00213          DMInternalURI::getURIWithParams("api/1/doc", array(), "html"));
00214       $node->appendChild($doc);
00215 
00216       $this->dxml->documentElement->appendChild($node);
00217       return $this->output();
00218    }
00219 
00225    public function transformObject(DMObject $obj) {
00226       $this->addSchema('object_view');
00227       $objnode = $this->dxml->createElement('dmObject');
00228       // alias
00229       $objnode->setAttribute('alias', $obj->getCollection()->getAlias());
00230       // pointer
00231       $objnode->setAttribute('pointer', $obj->getPtr());
00232       // created
00233       $objnode->setAttribute('created', $obj->getDateCreated()->asISO8601());
00234       // last updated
00235       $objnode->setAttribute('lastUpdated', $obj->getDateUpdated()->asISO8601());
00236       // is compound
00237       $objnode->setAttribute('isCompound', (int) $obj->isCompound());
00238 
00239       // compound object page & title
00240       if ($obj->getParent()) {
00241          $objnode->setAttribute('page', $obj->getPage());
00242          $objnode->setAttribute('title', $obj->getTitle());
00243       }
00244 
00245       // web template
00246       $node = $this->dxml->createElement('webTemplate');
00247       $node->setAttribute('xlink:type', 'simple');
00248       $node->setAttribute('xlink:href', $obj->getReferenceURL());
00249       $objnode->appendChild($node);
00250 
00251       // file
00252       $node = $this->dxml->createElement('file');
00253       $node->setAttribute('xlink:type', 'simple');
00254       $node->setAttribute('xlink:href', $obj->getFileURL());
00255       $node->appendChild(
00256          $this->dxml->createElement('filename',
00257             DMString::xmlentities($obj->getFilename())));
00258       $node->appendChild(
00259          $this->dxml->createElement("mimeType",
00260             DMString::xmlentities($obj->getMediaType())));
00261       $node->appendChild(
00262          $this->dxml->createElement('height', (int) $obj->getHeight()));
00263       $node->appendChild(
00264          $this->dxml->createElement('width', (int) $obj->getWidth()));
00265       $objnode->appendChild($node);
00266 
00267       // image
00268       $node = $this->dxml->createElement('image');
00269       $node->setAttribute('generator',
00270             rtrim(DMHTTPRequest::getCurrent()->getURI()->getAbsoluteHostURI(), "/")
00271                . DMConfigIni::getInstance()->getString(
00272                      "contentdm.getimage_exe.path"));
00273       $sm = $this->dxml->createElement('small');
00274       $med = $this->dxml->createElement('medium');
00275       $lg = $this->dxml->createElement('large');
00276       $sm->setAttribute('xlink:type', 'simple');
00277       $med->setAttribute('xlink:type', 'simple');
00278       $lg->setAttribute('xlink:type', 'simple');
00279       $sm->setAttribute('xlink:href', $obj->getImageURL(300, 300));
00280       $med->setAttribute('xlink:href', $obj->getImageURL(600, 600));
00281       $lg->setAttribute('xlink:href', $obj->getImageURL(900, 900));
00282       $node->appendChild($sm);
00283       $node->appendChild($med);
00284       $node->appendChild($lg);
00285       $objnode->appendChild($node);
00286 
00287       // thumbnail
00288       $node = $this->dxml->createElement('thumbnail');
00289       $node->setAttribute('xlink:type', 'simple');
00290       $node->setAttribute('xlink:href', $obj->getThumbnailURL());
00291       $objnode->appendChild($node);
00292 
00293       // rating
00294       $ds = DMDataStoreFactory::getDataStore();
00295       $rating = $this->dxml->createElement('rating');
00296       $rating->setAttribute('numRatings',
00297             (int) $ds->getNumRatingsForObject($obj));
00298       $rating->setAttribute('average',
00299             DMString::xmlentities($obj->getRating(100)));
00300       $objnode->appendChild($rating);
00301 
00302       // parent
00303       $parent = $this->dxml->createElement('parent');
00304       if ($obj->getParent()) {
00305          $parent->setAttribute('alias',
00306                $obj->getParent()->getCollection()->getAlias());
00307          $parent->setAttribute('pointer', $obj->getParent()->getPtr());
00308          $parent->setAttribute('xlink:type', 'simple');
00309          $parent->setAttribute('xlink:href',
00310                $obj->getParent()->getURI(DMBridgeComponent::HTTPAPI));
00311       }
00312       $objnode->appendChild($parent);
00313 
00314       // children
00315       $children = $this->dxml->createElement('children');
00316       foreach ($obj->getChildren() as $c) {
00317          $child = $this->dxml->createElement('dmObject');
00318          $child->setAttribute('pointer', $c->getPtr());
00319          $child->setAttribute('xlink:type', 'simple');
00320          $child->setAttribute('xlink:href',
00321                $c->getURI(DMBridgeComponent::HTTPAPI));
00322          $title = $this->dxml->createElement('title',
00323             DMString::xmlentities($c->getTitle()));
00324          $thumb = $this->dxml->createElement('thumbnail');
00325          $thumb->setAttribute('xlink:href', $c->getThumbnailURL());
00326          $child->appendChild($title);
00327          $child->appendChild($thumb);
00328          $children->appendChild($child);
00329       }
00330       $objnode->appendChild($children);
00331 
00332       // metadata
00333       $metadata = $this->dxml->createElement('metadata');
00334       foreach ($obj->getMetadata() as $f) {
00335          if (strlen($f->getValue()) < 1 || $f->isHidden()) {
00336             continue;
00337          }
00338          $node = $metadata->appendChild(
00339             $this->dxml->createElement(
00340                'field', DMString::xmlentities($f->getValue())));
00341          $node->setAttribute('nick', DMString::xmlentities($f->getNick()));
00342          $node->setAttribute('name', DMString::xmlentities($f->getName()));
00343          $node->setAttribute('dc', DMString::xmlentities($f->getDCNick()));
00344          $node->setAttribute('controlled', $f->isControlled() ? 1 : 0);
00345          $node->setAttribute('searchable', $f->isSearchable() ? 1 : 0);
00346       }
00347       $objnode->appendChild($metadata);
00348 
00349       // tags
00350       $tq = new DMTagQuery($ds);
00351       $tq->addObject($obj);
00352       $tq->setApproved(1);
00353       $tags = $this->dxml->createElement('tags');
00354       foreach ($tq->getSearchResultsAsObjects() as $t) {
00355          $tag = $this->dxml->createElement('dmTag',
00356             DMString::xmlentities($t->getValue()));
00357          $tag->setAttribute('id', $t->getID());
00358          $tag->setAttribute('xlink:type', 'simple');
00359          $tag->setAttribute('xlink:href',
00360                $t->getURI(DMBridgeComponent::HTTPAPI));
00361          $tags->appendChild($tag);
00362       }
00363       $objnode->appendChild($tags);
00364 
00365       // comments
00366       $comments = $this->dxml->createElement('comments');
00367       foreach (DMDataStoreFactory::getDataStore()
00368             ->getApprovedCommentsForObject($obj, 1, 1000) as $c) {
00369          $comment = $this->dxml->createElement('dmComment');
00370          $comment->setAttribute('id', $c->getID());
00371          $comment->setAttribute('xlink:type', 'simple');
00372          $comment->setAttribute('xlink:href',
00373                $c->getURI(DMBridgeComponent::HTTPAPI));
00374          $comments->appendChild($comment);
00375       }
00376       $objnode->appendChild($comments);
00377 
00378       $this->dxml->documentElement->appendChild($objnode);
00379       return $this->output();
00380    }
00381 
00389    public function transformObjectComments(DMObject $obj, $page, $rpp) {
00390       $this->addSchema('object_comments');
00391       $comments = DMDataStoreFactory::getDataStore()
00392          ->getApprovedCommentsForObject($obj, $page, $rpp);
00393       $onode = $this->dxml->createElement('dmObject');
00394       $onode->setAttribute('alias', $obj->getCollection()->getAlias());
00395       $onode->setAttribute('pointer', $obj->getPtr());
00396       $onode->setAttribute('xlink:type', 'simple');
00397       $onode->setAttribute('xlink:href',
00398             $obj->getURI(DMBridgeComponent::HTTPAPI));
00399       foreach ($comments as $c) {
00400          if (!$c instanceof DMComment) {
00401             continue;
00402          }
00403          $cnode = $this->dxml->createElement('dmComment');
00404          // id
00405          $cnode->setAttribute('id', $c->getID());
00406          $cnode->setAttribute('xlink:type', 'simple');
00407          $cnode->setAttribute('xlink:href',
00408                $c->getURI(DMBridgeComponent::HTTPAPI));
00409          // timestamp
00410          $cnode->setAttribute('timestamp', $c->getTimestamp()->asISO8601());
00411          // poster
00412          $poster = $this->dxml->createElement('poster');
00413          $poster->appendChild(
00414             $this->dxml->createElement('name',
00415                DMString::xmlentities($c->getName())));
00416          $poster->appendChild(
00417             $this->dxml->createElement('email',
00418                DMString::xmlentities($c->getEmail())));
00419          $cnode->appendChild($poster);
00420          // text
00421          $cnode->appendChild(
00422             $this->dxml->createElement(
00423                'body', DMString::xmlentities($c->getValue())));
00424          $onode->appendChild($cnode);
00425 
00426       }
00427       $this->dxml->documentElement->appendChild($onode);
00428       return $this->output();
00429    }
00430 
00436    public function transformObjectRating(DMObject $obj) {
00437       $this->addSchema('object_rating');
00438       $ds = DMDataStoreFactory::getDataStore();
00439 
00440       $onode = $this->dxml->createElement('dmObject');
00441       $onode->setAttribute('alias', $obj->getCollection()->getAlias());
00442       $onode->setAttribute('pointer', $obj->getPtr());
00443       $onode->setAttribute('xlink:type', 'simple');
00444       $onode->setAttribute('xlink:href',
00445             $obj->getURI(DMBridgeComponent::HTTPAPI));
00446 
00447       $rnode = $this->dxml->createElement('rating');
00448       $rnode->setAttribute('numRatings', $ds->getNumRatingsForObject($obj));
00449       $rnode->setAttribute('average', $obj->getRating());
00450       $onode->appendChild($rnode);
00451       $this->dxml->documentElement->appendChild($onode);
00452       return $this->output();
00453    }
00454 
00460    public function transformObjectTags(DMObject $obj) {
00461       $this->addSchema('object_tags');
00462 
00463       $onode = $this->dxml->createElement('dmObject');
00464       $onode->setAttribute('alias', $obj->getCollection()->getAlias());
00465       $onode->setAttribute('pointer', $obj->getPtr());
00466       $onode->setAttribute('xlink:type', 'simple');
00467       $onode->setAttribute('xlink:href',
00468             $obj->getURI(DMBridgeComponent::HTTPAPI));
00469 
00470       $ds = DMDataStoreFactory::getDataStore();
00471       $tq = new DMTagQuery($ds);
00472       $tq->addObject($obj);
00473       $tq->setApproved(1);
00474       $tags = $this->dxml->createElement('tags');
00475       foreach ($tq->getSearchResultsAsObjects() as $t) {
00476          $tag = $this->dxml->createElement('dmTag',
00477             DMString::xmlentities($t->getValue()));
00478          $tag->setAttribute('xlink:type', 'simple');
00479          $tag->setAttribute('xlink:href',
00480                $t->getURI(DMBridgeComponent::HTTPAPI));
00481          $tags->appendChild($tag);
00482       }
00483       $onode->appendChild($tags);
00484 
00485       $this->dxml->documentElement->appendChild($onode);
00486       return $this->output();
00487    }
00488 
00494    public function transformRatings(DMObjectQuery $q) {
00495       $this->addSchema('objects_list_ratings');
00496 
00497       // results
00498       $results = $this->dxml->createElement('results');
00499       $results->setAttribute('perPage', $q->getNumResultsPerPage());
00500       $results->setAttribute('total', $q->getNumResults());
00501 
00502       foreach ($q->getSearchResults() as $obj) {
00503          $objnode = $this->dxml->createElement('dmObject');
00504          $objnode->setAttribute('alias', $obj->getCollection()->getAlias());
00505          $objnode->setAttribute('pointer', $obj->getPtr());
00506          $objnode->setAttribute('xlink:type', 'simple');
00507          $objnode->setAttribute('xlink:href',
00508                $obj->getURI(DMBridgeComponent::HTTPAPI));
00509          $objnode->appendChild(
00510                $this->dxml->createElement("rating", $obj->getRating()));
00511          $results->appendChild($objnode);
00512       }
00513       $this->dxml->documentElement->appendChild($results);
00514 
00515       return $this->output();
00516    }
00517 
00523    public function transformResults(DMObjectQuery $q) {
00524       $this->addSchema('objects_list');
00525       // suggestion
00526       if ($q->getSuggestion()) {
00527          $sugnode = $this->dxml->createElement('suggestion',
00528                $q->getSuggestion());
00529          $this->dxml->documentElement->appendChild($sugnode);
00530       }
00531 
00532       // results
00533       $results = $this->dxml->createElement('results');
00534       $results->setAttribute('page', $q->getPage());
00535       $results->setAttribute('perPage', $q->getNumResultsPerPage());
00536       $results->setAttribute('numPages', $q->getNumPages());
00537       $results->setAttribute('total', $q->getNumResults());
00538 
00539       foreach ($q->getSearchResults() as $obj) {
00540          $objnode = $this->dxml->createElement('dmObject');
00541          $objnode->setAttribute('alias', $obj->getCollection()->getAlias());
00542          $objnode->setAttribute('pointer', $obj->getPtr());
00543          $objnode->setAttribute('xlink:type', 'simple');
00544          $objnode->setAttribute('xlink:href',
00545                $obj->getURI(DMBridgeComponent::HTTPAPI));
00546          $results->appendChild($objnode);
00547       }
00548       $this->dxml->documentElement->appendChild($results);
00549 
00550       // facets
00551       $facets = $this->dxml->createElement('facets');
00552       foreach ($q->getFacetTerms() as $f) {
00553          $fnode = $this->dxml->createElement('dmFacetTerm',
00554             DMString::xmlentities($f->getField()->getValue()));
00555          $fnode->setAttribute('field', $f->getField()->getNick());
00556          $fnode->setAttribute('name', $f->getField()->getName());
00557          $fnode->setAttribute('count', $f->getCount());
00558          $fnode->setAttribute('xlink:type', 'simple');
00559          $fnode->setAttribute('xlink:href',
00560                $f->getURI(DMBridgeComponent::HTTPAPI));
00561          $facets->appendChild($fnode);
00562       }
00563       $this->dxml->documentElement->appendChild($facets);
00564 
00565       return $this->output();
00566    }
00567 
00572    public function transformStatus() {
00573       $this->addSchema('status');
00574       $root = $this->dxml->createElement('dmStatus');
00575 
00576       // institution
00577       $node = $this->dxml->createElement('institution');
00578       $node->appendChild(
00579          $this->dxml->createElement('name',
00580             DMString::xmlentities(
00581                   DMConfigXML::getInstance()->getInstitutionName())));
00582       $root->appendChild($node);
00583 
00584       // comments
00585       $node = $this->dxml->createElement('comments');
00586       $node->setAttribute('areAvailable',
00587             (int) DMConfigXML::getInstance()->isCommentingEnabled());
00588       $node->setAttribute('areModerated',
00589             (int) DMConfigXML::getInstance()->isCommentModerationEnabled());
00590       $root->appendChild($node);
00591 
00592       // tags
00593       $node = $this->dxml->createElement('tags');
00594       $node->setAttribute('areAvailable',
00595             (int) DMConfigXML::getInstance()->isTaggingEnabled());
00596       $node->setAttribute('areModerated',
00597             (int) DMConfigXML::getInstance()->isTagModerationEnabled());
00598       $root->appendChild($node);
00599 
00600       // ratings
00601       $node = $this->dxml->createElement('ratings');
00602       $node->setAttribute('areAvailable',
00603             (int) DMConfigXML::getInstance()->isRatingEnabled());
00604       $root->appendChild($node);
00605 
00606       // version
00607       $version = $this->dxml->createElement('version',
00608          DMConfigXML::getInstance()->getVersion());
00609       $root->appendChild($version);
00610 
00611       // version sequence
00612       $seq = $this->dxml->createElement('versionSequence',
00613          DMConfigXML::getInstance()->getVersionSequence());
00614       $root->appendChild($seq);
00615 
00616       $this->dxml->documentElement->appendChild($root);
00617       return $this->output();
00618    }
00619 
00625    public function transformTag(DMTag $tag) {
00626       $this->addSchema('tag_view');
00627       $node = $this->dxml->createElement('dmTag',
00628          DMString::xmlentities($tag->getValue()));
00629       $node->setAttribute('id', $tag->getID());
00630       $node->setAttribute('timestamp', $tag->getTimestamp()->asISO8601());
00631 
00632       $obj = $this->dxml->createElement('dmObject');
00633       $obj->setAttribute('alias', $tag->getObject()->getCollection()->getAlias());
00634       $obj->setAttribute('pointer', $tag->getObject()->getPtr());
00635       $obj->setAttribute('xlink:type', 'simple');
00636       $obj->setAttribute('xlink:href',
00637             $tag->getObject()->getURI(DMBridgeComponent::HTTPAPI));
00638 
00639       $obj->appendChild($node);
00640       $this->dxml->documentElement->appendChild($obj);
00641       return $this->output();
00642    }
00643 
00652    public function transformTagCounts(array $tags, $page, $rpp, $total) {
00653       $this->addSchema("tag_counts");
00654 
00655       $tnode = $this->dxml->createElement("tags");
00656       $tnode->setAttribute("page", $page);
00657       $tnode->setAttribute("perPage", $rpp);
00658       $tnode->setAttribute("numPages", ceil($total / $rpp));
00659       $tnode->setAttribute("total", $total);
00660       foreach ($tags as $value => $count) {
00661          $node = $this->dxml->createElement("dmTag",
00662             DMString::xmlentities($value));
00663          $node->setAttribute("count", $count);
00664          $tnode->appendChild($node);
00665       }
00666       $this->dxml->documentElement->appendChild($tnode);
00667       return $this->output();
00668    }
00669 
00674    public function transformVocabularyFrequencies(array $freqs) {
00675       $this->addSchema('vocabulary_frequency');
00676       $vnode = $this->dxml->createElement('vocabulary');
00677       foreach ($freqs as $term => $count) {
00678          $node = $this->dxml->createElement('term',
00679             DMString::xmlentities($term));
00680          $node->setAttribute('count', $count);
00681          $vnode->appendChild($node);
00682       }
00683       $this->dxml->documentElement->appendChild($vnode);
00684       return $this->output();
00685    }
00686 
00691    public function transformVocabularySuggestions(array $words) {
00692       $this->addSchema('vocabulary_suggestions');
00693       $s = $this->dxml->createElement('vocabulary');
00694       foreach ($words as $word) {
00695          $s->appendChild(
00696             $this->dxml->createElement('term',
00697                   DMString::xmlentities($word)));
00698       }
00699       $this->dxml->documentElement->appendChild($s);
00700       return $this->output();
00701    }
00702 
00703 }
 All Data Structures Functions Variables