00001 <?php 00002 00007 class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter 00008 { 00009 00010 protected $interchange; 00011 private $namespace; 00012 00013 protected function writeHTMLDiv($html) { 00014 $this->startElement('div'); 00015 00016 $purifier = HTMLPurifier::getInstance(); 00017 $html = $purifier->purify($html); 00018 $this->writeAttribute('xmlns', 'http://www.w3.org/1999/xhtml'); 00019 $this->writeRaw($html); 00020 00021 $this->endElement(); // div 00022 } 00023 00024 protected function export($var) { 00025 if ($var === array()) return 'array()'; 00026 return var_export($var, true); 00027 } 00028 00029 public function build($interchange) { 00030 // global access, only use as last resort 00031 $this->interchange = $interchange; 00032 00033 $this->setIndent(true); 00034 $this->startDocument('1.0', 'UTF-8'); 00035 $this->startElement('configdoc'); 00036 $this->writeElement('title', $interchange->name); 00037 00038 foreach ($interchange->directives as $directive) { 00039 $this->buildDirective($directive); 00040 } 00041 00042 if ($this->namespace) $this->endElement(); // namespace 00043 00044 $this->endElement(); // configdoc 00045 $this->flush(); 00046 } 00047 00048 public function buildDirective($directive) { 00049 00050 // Kludge, although I suppose having a notion of a "root namespace" 00051 // certainly makes things look nicer when documentation is built. 00052 // Depends on things being sorted. 00053 if (!$this->namespace || $this->namespace !== $directive->id->getRootNamespace()) { 00054 if ($this->namespace) $this->endElement(); // namespace 00055 $this->namespace = $directive->id->getRootNamespace(); 00056 $this->startElement('namespace'); 00057 $this->writeAttribute('id', $this->namespace); 00058 $this->writeElement('name', $this->namespace); 00059 } 00060 00061 $this->startElement('directive'); 00062 $this->writeAttribute('id', $directive->id->toString()); 00063 00064 $this->writeElement('name', $directive->id->getDirective()); 00065 00066 $this->startElement('aliases'); 00067 foreach ($directive->aliases as $alias) $this->writeElement('alias', $alias->toString()); 00068 $this->endElement(); // aliases 00069 00070 $this->startElement('constraints'); 00071 if ($directive->version) $this->writeElement('version', $directive->version); 00072 $this->startElement('type'); 00073 if ($directive->typeAllowsNull) $this->writeAttribute('allow-null', 'yes'); 00074 $this->text($directive->type); 00075 $this->endElement(); // type 00076 if ($directive->allowed) { 00077 $this->startElement('allowed'); 00078 foreach ($directive->allowed as $value => $x) $this->writeElement('value', $value); 00079 $this->endElement(); // allowed 00080 } 00081 $this->writeElement('default', $this->export($directive->default)); 00082 $this->writeAttribute('xml:space', 'preserve'); 00083 if ($directive->external) { 00084 $this->startElement('external'); 00085 foreach ($directive->external as $project) $this->writeElement('project', $project); 00086 $this->endElement(); 00087 } 00088 $this->endElement(); // constraints 00089 00090 if ($directive->deprecatedVersion) { 00091 $this->startElement('deprecated'); 00092 $this->writeElement('version', $directive->deprecatedVersion); 00093 $this->writeElement('use', $directive->deprecatedUse->toString()); 00094 $this->endElement(); // deprecated 00095 } 00096 00097 $this->startElement('description'); 00098 $this->writeHTMLDiv($directive->description); 00099 $this->endElement(); // description 00100 00101 $this->endElement(); // directive 00102 } 00103 00104 } 00105 00106 // vim: et sw=4 sts=4
| Copyright © 2003 - 2009 MyOOS [Shopsystem]. All rights reserved. MyOOS [Shopsystem] is Free Software released under the GNU/GPL License. Webmaster: info@r23.de (Impressum) |
|
