Example #1
0
 /**
  * Docarate BBCode AST
  *
  * Visit the BBCode abstract syntax tree.
  *
  * @param ezcDocumentBBCodeDocumentNode $ast
  * @return mixed
  */
 public function visit(ezcDocumentBBCodeDocumentNode $ast)
 {
     // Create article from AST
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('article', '-//OASIS//DTD DocBook XML V4.5//EN', 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd');
     $this->document = $imp->createDocument('http://docbook.org/ns/docbook', '', $dtd);
     $this->document->formatOutput = true;
     //        $root = $this->document->createElement( 'article' );
     $root = $this->document->createElementNs('http://docbook.org/ns/docbook', 'article');
     $this->document->appendChild($root);
     // Visit all childs of the AST root node.
     foreach ($ast->nodes as $node) {
         $this->visitNode($root, $node);
     }
     return $this->document;
 }
Example #2
0
 /**
  * If here is already data in the buffer, add a separator before starting the next.
  *
  * @return boolean
  */
 public function visitEnterSelectorSequence()
 {
     if ($this->_current === $this->_dom->documentElement && $this->_current->hasChildNodes()) {
         $this->_current->appendChild($this->_dom->createElementNs($this->_xmlns, 'text'))->appendChild($this->_dom->createCDATASection(', '));
     }
     return $this->start($this->appendElement('selector'));
 }
Example #3
0
 /**
  * Initialize destination document
  *
  * Initialize the structure which the destination document could be build
  * with. This may be an initial DOMDocument with some default elements, or
  * a string, or something else.
  *
  * @return mixed
  */
 protected function initializeDocument()
 {
     $ezxml = new DOMDocument();
     $ezxml->formatOutput = true;
     $root = $ezxml->createElementNs('http://ez.no/namespaces/ezpublish3', 'section');
     $root->setAttribute('xmlns:image', 'http://ez.no/namespaces/ezpublish3/image/');
     $root->setAttribute('xmlns:xhtml', 'http://ez.no/namespaces/ezpublish3/xhtml/');
     $root->setAttribute('xmlns:custom', 'http://ez.no/namespaces/ezpublish3/custom/');
     $ezxml->appendChild($root);
     return $root;
 }
Example #4
0
 /**
  * Docarate RST AST
  *
  * Visit the RST abstract syntax tree.
  *
  * @param ezcDocumentRstDocumentNode $ast
  * @return mixed
  */
 public function visit(ezcDocumentRstDocumentNode $ast)
 {
     parent::visit($ast);
     // Create article from AST
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('html', '-//W3C//DTD XHTML 1.0 Transitional//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd');
     $this->document = $imp->createDocument('http://www.w3.org/1999/xhtml', '', $dtd);
     $root = $this->document->createElementNs('http://www.w3.org/1999/xhtml', 'html');
     $this->document->appendChild($root);
     $this->head = $this->document->createElement('head');
     $root->appendChild($this->head);
     // Append generator
     $generator = $this->document->createElement('meta');
     $generator->setAttribute('name', 'generator');
     $generator->setAttribute('content', 'eZ Components; http://ezcomponents.org');
     $this->head->appendChild($generator);
     // Set content type and encoding
     $type = $this->document->createElement('meta');
     $type->setAttribute('http-equiv', 'Content-Type');
     $type->setAttribute('content', 'text/html; charset=utf-8');
     $this->head->appendChild($type);
     $this->addStylesheets($this->head);
     $body = $this->document->createElement('body');
     $root->appendChild($body);
     // Visit all childs of the AST root node.
     foreach ($ast->nodes as $node) {
         $this->visitNode($body, $node);
     }
     // Visit all footnotes at the document body
     foreach ($this->footnotes as $footnotes) {
         ksort($footnotes);
         $footnoteList = $this->document->createElement('ul');
         $footnoteList->setAttribute('class', 'footnotes');
         $body->appendChild($footnoteList);
         foreach ($footnotes as $footnote) {
             $this->visitFootnote($footnoteList, $footnote);
         }
     }
     // Check that all required elements for a valid XHTML document exist
     if ($this->head->getElementsByTagName('title')->length < 1) {
         $title = $this->document->createElement('title', 'Empty document');
         $this->head->appendChild($title);
     }
     return $this->document;
 }
Example #5
0
 /**
  * Create the order XML.
  *
  * @param array $data
  *   The data array to create the XML from.
  *
  * @return \DOMDocument
  *   The generated XML object.
  */
 protected function createXml(array $data)
 {
     $xml = new \DOMDocument('1.0', 'UTF-8');
     // Add the request root element.
     $request = $xml->createElementNs('http://www.euroscript.com/escaepe/types', 'tns:ClientWoRequest');
     $request->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
     $request->setAttribute('xsi:schemaLocation', 'http://www.euroscript.com/escaepe/types clientOrderRequestTypes.xsd');
     $xml->appendChild($request);
     // Add the data to the request in the XML.
     $this->arrayToXml($data, $request);
     return $xml;
 }
Example #6
0
 /**
  * Retrieve properties defined on the specified resource.
  *
  * Performs a <tt>PROPFIND</tt> request as defined in the
  * {@link http://tools.ietf.org/html/rfc4918#section-9.1 Section 9.1 of RFC-4918}.
  *
  * The following options are available:
  * - <tt>properties</tt>
  * - <tt>depth</tt>
  *
  * @param string $uri
  *            Resource URI
  * @param array $options
  *            Options to apply to the request
  *            
  * @return MultiStatus
  */
 public function propfind($uri, array $options = null)
 {
     $depth = isset($options['depth']) ? (int) $options['depth'] : 0;
     $properties = isset($options['properties']) ? $options['properties'] : array();
     $dom = new \DOMDocument('1.0', 'UTF-8');
     $xPropfind = $dom->createElementNS('DAV:', 'D:propfind');
     if (count($properties) == 0) {
         $xProp = $dom->createElement('D:allprop');
     } else {
         $xProp = $dom->createElement('D:prop');
         $namespaces = array_flip($this->xmlNamespaces);
         foreach ($properties as $property) {
             list($prefix, ) = explode(':', $property, 2);
             if ($prefix !== null && isset($namespaces[$prefix])) {
                 $xProp->setAttributeNS('http://www.w3.org/2000/xmlns/', "xmlns:{$prefix}", $namespaces[$prefix]);
                 $xPropNode = $dom->createElementNs($namespaces[$prefix], $property);
             } else {
                 $xPropNode = $dom->createElement($property);
             }
             $xProp->appendChild($xPropNode);
         }
     }
     $dom->appendChild($xPropfind)->appendChild($xProp);
     $body = $dom->saveXML();
     $request = $this->createRequest('PROPFIND', $uri, array('Content-Type' => 'Content-Type: text/xml; charset="utf-8"', 'Depth' => $depth), $body);
     $response = $this->doRequest($request);
     return $response->getStatusCode() == 207 ? MultiStatus::parse($this, $response->getBody()) : null;
 }
 /**
  * Render the document
  *
  * @param   boolean  $cache   If true, cache the output
  * @param   array    $params  Associative array of attributes
  *
  * @return  The rendered data
  *
  * @since   11.1
  */
 public function render($cache = false, $params = array())
 {
     $xml = new DOMDocument('1.0', 'utf-8');
     if (defined('JDEBUG') && JDEBUG) {
         $xml->formatOutput = true;
     }
     // The OpenSearch Namespace
     $osns = 'http://a9.com/-/spec/opensearch/1.1/';
     // Create the root element
     $elOs = $xml->createElementNs($osns, 'OpenSearchDescription');
     $elShortName = $xml->createElementNs($osns, 'ShortName');
     $elShortName->appendChild($xml->createTextNode(htmlspecialchars($this->_shortName)));
     $elOs->appendChild($elShortName);
     $elDescription = $xml->createElementNs($osns, 'Description');
     $elDescription->appendChild($xml->createTextNode(htmlspecialchars($this->description)));
     $elOs->appendChild($elDescription);
     // Always set the accepted input encoding to UTF-8
     $elInputEncoding = $xml->createElementNs($osns, 'InputEncoding');
     $elInputEncoding->appendChild($xml->createTextNode('UTF-8'));
     $elOs->appendChild($elInputEncoding);
     foreach ($this->_images as $image) {
         $elImage = $xml->createElementNs($osns, 'Image');
         $elImage->setAttribute('type', $image->type);
         $elImage->setAttribute('width', $image->width);
         $elImage->setAttribute('height', $image->height);
         $elImage->appendChild($xml->createTextNode(htmlspecialchars($image->data)));
         $elOs->appendChild($elImage);
     }
     foreach ($this->_urls as $url) {
         $elUrl = $xml->createElementNs($osns, 'Url');
         $elUrl->setAttribute('type', $url->type);
         // Results is the default value so we don't need to add it
         if ($url->rel != 'results') {
             $elUrl->setAttribute('rel', $url->rel);
         }
         $elUrl->setAttribute('template', $url->template);
         $elOs->appendChild($elUrl);
     }
     $xml->appendChild($elOs);
     parent::render();
     return $xml->saveXml();
 }
Example #8
0
 /**
  * @param StdClass $resource
  * @return string
  */
 public function renderXml(StdClass $resource)
 {
     $doc = new DOMDocument("1.0", "utf-8");
     if ($resource->resourceType == "Bundle") {
         // stupid special case
         $root = $doc->createElementNs("http://www.w3.org/2005/Atom", "feed");
         $doc->appendChild($root);
         $this->renderXmlBundle($resource, $doc, $root);
     } else {
         $this->renderXmlRecursive($resource, $doc, $doc);
     }
     if (YII_DEBUG) {
         $doc->formatOutput = true;
     }
     return $doc->saveXML();
 }
Example #9
0
File: odt.php Project: bmdevel/ezc
 /**
  * Build docbook document out of annotated ODT document
  *
  * @param DOMDocument $document
  * @return DOMDocument
  */
 protected function buildDocbookDocument(DOMDocument $document)
 {
     $docbook = new DOMDocument('1.0', 'utf-8');
     $docbook->preserveWhiteSpace = false;
     $docbook->formatOutput = true;
     $root = $docbook->createElementNs('http://docbook.org/ns/docbook', 'article');
     $docbook->appendChild($root);
     $xpath = new DOMXPath($document);
     $xpath->registerNamespace('office', self::NS_ODT_OFFICE);
     // @todo: Process meta data
     $body = $xpath->query('//office:body')->item(0);
     $this->transformToDocbook($body, $root);
     return $docbook;
 }
Example #10
0
 /**
  * Build docbook document out of annotated XHtml document
  *
  * @param DOMDocument $document
  * @return DOMDocument
  */
 protected function buildDocbookDocument(DOMDocument $document)
 {
     $docbook = new DOMDocument('1.0', 'utf-8');
     $docbook->preserveWhiteSpace = false;
     $docbook->formatOutput = true;
     $root = $docbook->createElementNs('http://docbook.org/ns/docbook', 'article');
     $docbook->appendChild($root);
     $xpath = new DOMXPath($document);
     $html = $xpath->query('/*[local-name() = "html"]')->item(0);
     $this->transformToDocbook($html, $root);
     return $docbook;
 }
Example #11
0
 private function renderXmlBundle(StdClass $data, DOMDocument $doc, DOMNode $parent)
 {
     foreach ($data as $name => $value) {
         if ($name == 'resourceType') {
             continue;
         }
         $values = is_array($value) ? $value : array($value);
         foreach ($values as $value) {
             if ($name == 'totalResults') {
                 $el = $doc->createElementNs('http://a9.com/-/spec/opensearch/1.1/', 'os:totalResults');
             } else {
                 $el = $doc->createElement($name);
             }
             switch ($name) {
                 case 'link':
                     // value contains attributes
                 // value contains attributes
                 case 'category':
                     foreach ($value as $attrName => $attrValue) {
                         $el->setAttribute($attrName, $attrValue);
                     }
                     break;
                 case 'title':
                     // value is text content
                 // value is text content
                 case 'id':
                 case 'updated':
                 case 'published':
                 case 'totalResults':
                 case 'name':
                 case 'uri':
                     $el->appendChild($doc->createTextNode($value));
                     $parent->appendChild($el);
                     break;
                 case 'summary':
                     $frag = $doc->createDocumentFragment();
                     $frag->appendXML($value);
                     $el->appendChild($frag);
                     $el->setAttribute('type', 'xhtml');
                     $parent->appendChild($el);
                     break;
                 case 'entry':
                     // recur
                 // recur
                 case 'author':
                     $this->renderXmlBundle($value, $doc, $el);
                     break;
                 case 'content':
                     // yeah, let's get out of here!
                     $el->setAttribute('type', 'text/xml');
                     $this->renderXmlRecursive($value, $doc, $el);
                     break;
                 default:
                     throw new Exception("Unexpected item name found in Bundle: '{$name}'");
             }
             $parent->appendChild($el);
         }
     }
 }