dmBridge PHP API
DMAPIDocumentationController.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 DMAPIDocumentationController extends DMAbstractController {
00014 
00015    public function index() {
00016       // load main documentation XML file
00017       $dxml = new DMDOMDocument("1.0", "utf-8");
00018       $dxml->load(dirname(__FILE__) . "/../../includes/doc/1/index.xml");
00019 
00020       // append XML fragments from module documentation files
00021       $mm = DMModuleManager::getInstance();
00022       foreach ($mm->getEnabledModules() as $module) {
00023          $module_dxml = $module->getHTTPAPIDocumentation();
00024          if (!$module_dxml) {
00025             continue;
00026          }
00027          $module_dxp = new DOMXPath($module_dxml);
00028          foreach ($dxml->documentElement->getElementsByTagName("category")
00029                as $main_cat) {
00030             $main_cat_name = $main_cat->getAttribute("name");
00031             $matching_module_methods = $module_dxp->query(
00032                   sprintf("//category[@name = '%s']/apiMethod",
00033                         $main_cat_name));
00034             foreach ($matching_module_methods as $method_node) {
00035                $new_node = $dxml->importNode($method_node, true);
00036                $main_cat->appendChild($new_node);
00037             }
00038          }
00039       }
00040 
00041       // apply XSL stylesheet
00042       $dxsl = new DOMDocument();
00043       $dxsl->load(dirname(__FILE__) . "/../../includes/doc/1/default.xsl",
00044             LIBXML_NOCDATA);
00045       $xslt = new XSLTProcessor();
00046       $xslt->importStylesheet($dxsl);
00047       $uri = DMHTTPRequest::getCurrent()->getURI();
00048       $uri->setFragment(null);
00049       $uri->setQueryString(null);
00050       $uri->setExtension(null);
00051       $uri->setParams(null);
00052       $xslt->setParameter(null, "dmBridgeURI", $uri);
00053       $doc = $xslt->transformToDoc($dxml);
00054 
00055       // append CSS stylesheet
00056       $style = $doc->createElement("link");
00057       $style->setAttribute("rel", "stylesheet");
00058       $style->setAttribute("href",
00059             dirname($_SERVER['PHP_SELF']) . "/includes/doc/1/default.css");
00060       $dxp = new DOMXPath($doc);
00061       $result = $dxp->query("//html/head");
00062       $result->item(0)->appendChild($style);
00063 
00064       $response = new DMHTTPResponse();
00065       $rep = new DMHTTPRepresentation();
00066       $rep->setMediaType(new DMMediaType("text", "html"));
00067       $doc->formatOutput = true;
00068       $rep->setBody('<!DOCTYPE html>' . $doc->saveHTML());
00069       $response->setRepresentation($rep);
00070       $response->send();
00071       die;
00072    }
00073 
00074 }
 All Data Structures Functions Variables