dmBridge PHP API
DMXMLRepresentationTransformer.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 abstract class DMXMLRepresentationTransformer
00014 extends DMAbstractRepresentationTransformer {
00015 
00016    const XMLNS = "http://digital.library.unlv.edu";
00017 
00019    protected $dxml;
00021    protected $pretty_print = false;
00022 
00023 
00024    public function __construct() {
00025       $this->dxml = new DOMDocument("1.0", "utf-8");
00026       $this->dxml->preserveWhiteSpace = false;
00027       $this->reset();
00028    }
00029 
00033    protected function reset() {
00034       $this->dxml->loadXML(
00035          '<dmBridgeResponse xmlns:xlink="http://www.w3.org/1999/xlink"/>');
00036    }
00037 
00041    public final function setPrettyPrint($bool) {
00042       $this->pretty_print = (bool) $bool;
00043    }
00044 
00045    protected function output() {
00046       $this->dxml->documentElement->appendChild(
00047          $this->dxml->createElement("copyright",
00048             DMConfigXML::getInstance()->getFeedCopyright()));
00049       $this->dxml->documentElement->appendChild(
00050          $this->dxml->createElement("querySeconds", $this->getQSeconds()));
00051       if ($this->pretty_print) $this->dxml->formatOutput = true;
00052       $this->dxml->documentElement->setAttribute("version", $this->getVersion());
00053       $return = $this->dxml->saveXML($this->dxml->documentElement);
00054       $this->reset();
00055       return $return;
00056    }
00057 
00063    protected function addSchema($name) {
00064       $uri = clone DMHTTPRequest::getCurrent()->getURI();
00065       $uri->unsetQuery();
00066       $uri->setParams("api/1/schema/xml/" . $name . ".xsd");
00067       $this->addSchemaAtURI($uri);
00068    }
00069 
00073    protected function addSchemaAtURI(DMURI $uri) {
00074       $this->dxml->documentElement->setAttribute(
00075          "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
00076       $this->dxml->documentElement->setAttribute("xmlns", self::XMLNS);
00077       $this->dxml->documentElement->setAttribute("xsi:schemaLocation",
00078          sprintf("%s %s", self::XMLNS, $uri));
00079    }
00080 
00084    public function getVersion() {
00085       return $this->version;
00086    }
00087 
00088 }
 All Data Structures Functions Variables