00001 <?php
00002
00007 class HTMLPurifier_ConfigSchema_Builder_Xml extends XMLWriter
00008 {
00009
00010 protected $interchange;
00011
00012 protected function writeHTMLDiv($html) {
00013 $this->startElement('div');
00014
00015 $purifier = HTMLPurifier::getInstance();
00016 $html = $purifier->purify($html);
00017 $this->writeAttribute('xmlns', 'http:
00018 $this->writeRaw($html);
00019
00020 $this->endElement();
00021 }
00022
00023 protected function export($var) {
00024 if ($var === array()) return 'array()';
00025 return var_export($var, true);
00026 }
00027
00028 public function build($interchange) {
00029
00030 $this->interchange = $interchange;
00031
00032 $this->setIndent(true);
00033 $this->startDocument('1.0', 'UTF-8');
00034 $this->startElement('configdoc');
00035 $this->writeElement('title', $interchange->name);
00036
00037 foreach ($interchange->namespaces as $namespace) {
00038 $this->buildNamespace($namespace);
00039 }
00040
00041 $this->endElement();
00042 $this->flush();
00043 }
00044
00045 public function buildNamespace($namespace) {
00046 $this->startElement('namespace');
00047 $this->writeAttribute('id', $namespace->namespace);
00048
00049 $this->writeElement('name', $namespace->namespace);
00050 $this->startElement('description');
00051 $this->writeHTMLDiv($namespace->description);
00052 $this->endElement();
00053
00054 foreach ($this->interchange->directives as $directive) {
00055 if ($directive->id->namespace !== $namespace->namespace) continue;
00056 $this->buildDirective($directive);
00057 }
00058
00059 $this->endElement();
00060 }
00061
00062 public function buildDirective($directive) {
00063 $this->startElement('directive');
00064 $this->writeAttribute('id', $directive->id->toString());
00065
00066 $this->writeElement('name', $directive->id->directive);
00067
00068 $this->startElement('aliases');
00069 foreach ($directive->aliases as $alias) $this->writeElement('alias', $alias->toString());
00070 $this->endElement();
00071
00072 $this->startElement('constraints');
00073 if ($directive->version) $this->writeElement('version', $directive->version);
00074 $this->startElement('type');
00075 if ($directive->typeAllowsNull) $this->writeAttribute('allow-null', 'yes');
00076 $this->text($directive->type);
00077 $this->endElement();
00078 if ($directive->allowed) {
00079 $this->startElement('allowed');
00080 foreach ($directive->allowed as $value => $x) $this->writeElement('value', $value);
00081 $this->endElement();
00082 }
00083 $this->writeElement('default', $this->export($directive->default));
00084 $this->writeAttribute('xml:space', 'preserve');
00085 if ($directive->external) {
00086 $this->startElement('external');
00087 foreach ($directive->external as $project) $this->writeElement('project', $project);
00088 $this->endElement();
00089 }
00090 $this->endElement();
00091
00092 if ($directive->deprecatedVersion) {
00093 $this->startElement('deprecated');
00094 $this->writeElement('version', $directive->deprecatedVersion);
00095 $this->writeElement('use', $directive->deprecatedUse->toString());
00096 $this->endElement();
00097 }
00098
00099 $this->startElement('description');
00100 $this->writeHTMLDiv($directive->description);
00101 $this->endElement();
00102
00103 $this->endElement();
00104 }
00105
00106 }