From c113f43440dcb24cfb1392366ea36a32ccd9e3e4 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Mon, 28 May 2007 02:41:01 +0000 Subject: [PATCH] Add basic structure for ConfigDoc namespace, begin moving things over. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1103 48356398-32a2-884e-a903-53898d9a118a --- configdoc/generate.php | 116 +---------------- configdoc/library/ConfigDoc.auto.php | 10 ++ configdoc/library/ConfigDoc.php | 13 ++ configdoc/library/ConfigDoc/XMLSerializer.php | 10 ++ .../ConfigDoc/XMLSerializer/ConfigSchema.php | 118 ++++++++++++++++++ .../library/ConfigDoc/XMLSerializer/Types.php | 27 ++++ 6 files changed, 183 insertions(+), 111 deletions(-) create mode 100644 configdoc/library/ConfigDoc.auto.php create mode 100644 configdoc/library/ConfigDoc.php create mode 100644 configdoc/library/ConfigDoc/XMLSerializer.php create mode 100644 configdoc/library/ConfigDoc/XMLSerializer/ConfigSchema.php create mode 100644 configdoc/library/ConfigDoc/XMLSerializer/Types.php diff --git a/configdoc/generate.php b/configdoc/generate.php index d01878b8..328394ee 100644 --- a/configdoc/generate.php +++ b/configdoc/generate.php @@ -30,7 +30,7 @@ error_reporting(E_ALL); // Include HTML Purifier library require_once '../library/HTMLPurifier.auto.php'; - +require_once 'library/ConfigDoc.auto.php'; // --------------------------------------------------------------------------- // Setup convenience functions @@ -67,122 +67,16 @@ $purifier = new HTMLPurifier(); // --------------------------------------------------------------------------- // Generate types.xml, a document describing the constraint "type" -$types_document = new DOMDocument('1.0', 'UTF-8'); -$types_root = $types_document->createElement('types'); -$types_document->appendChild($types_root); -$types_document->formatOutput = true; -foreach ($schema->types as $name => $expanded_name) { - $types_type = $types_document->createElement('type', $expanded_name); - $types_type->setAttribute('id', $name); - $types_root->appendChild($types_type); -} +$types_serializer = new ConfigDoc_XMLSerializer_Types(); +$types_document = $types_serializer->serialize($schema); $types_document->save('types.xml'); // --------------------------------------------------------------------------- // Generate configdoc.xml, a document documenting configuration directives -$dom_document = new DOMDocument('1.0', 'UTF-8'); -$dom_root = $dom_document->createElement('configdoc'); -$dom_document->appendChild($dom_root); -$dom_document->formatOutput = true; - -// add the name of the application -$dom_root->appendChild($dom_document->createElement('title', 'HTML Purifier')); - -/* -TODO for XML format: -- create a definition (DTD or other) once interface stabilizes -*/ - -foreach($schema->info as $namespace_name => $namespace_info) { - - $dom_namespace = $dom_document->createElement('namespace'); - $dom_root->appendChild($dom_namespace); - - $dom_namespace->setAttribute('id', $namespace_name); - $dom_namespace->appendChild( - $dom_document->createElement('name', $namespace_name) - ); - $dom_namespace_description = $dom_document->createElement('description'); - $dom_namespace->appendChild($dom_namespace_description); - appendHTMLDiv($dom_document, $dom_namespace_description, - $schema->info_namespace[$namespace_name]->description); - - foreach ($namespace_info as $name => $info) { - - if ($info->class == 'alias') continue; - - $dom_directive = $dom_document->createElement('directive'); - $dom_namespace->appendChild($dom_directive); - - $dom_directive->setAttribute('id', $namespace_name . '.' . $name); - $dom_directive->appendChild( - $dom_document->createElement('name', $name) - ); - - $dom_constraints = $dom_document->createElement('constraints'); - $dom_directive->appendChild($dom_constraints); - - $dom_type = $dom_document->createElement('type', $info->type); - if ($info->allow_null) { - $dom_type->setAttribute('allow-null', 'yes'); - } - $dom_constraints->appendChild($dom_type); - - if ($info->allowed !== true) { - $dom_allowed = $dom_document->createElement('allowed'); - $dom_constraints->appendChild($dom_allowed); - foreach ($info->allowed as $allowed => $bool) { - $dom_allowed->appendChild( - $dom_document->createElement('value', $allowed) - ); - } - } - - $raw_default = $schema->defaults[$namespace_name][$name]; - if (is_bool($raw_default)) { - $default = $raw_default ? 'true' : 'false'; - } elseif (is_string($raw_default)) { - $default = "\"$raw_default\""; - } elseif (is_null($raw_default)) { - $default = 'null'; - } else { - $default = print_r( - $schema->defaults[$namespace_name][$name], true - ); - } - - $dom_default = $dom_document->createElement('default', $default); - - // remove this once we get a DTD - $dom_default->setAttribute('xml:space', 'preserve'); - - $dom_constraints->appendChild($dom_default); - - $dom_descriptions = $dom_document->createElement('descriptions'); - $dom_directive->appendChild($dom_descriptions); - - foreach ($info->descriptions as $file => $file_descriptions) { - foreach ($file_descriptions as $line => $description) { - $dom_description = $dom_document->createElement('description'); - // hack - if (!defined('HTMLPURIFIER_CUSTOM_SCHEMA')) { - $dom_description->setAttribute('file', $file); - $dom_description->setAttribute('line', $line); - } - appendHTMLDiv($dom_document, $dom_description, $description); - $dom_descriptions->appendChild($dom_description); - } - } - - } - -} - -// print_r($dom_document->saveXML()); - -// save a copy of the raw XML +$schema_serializer = new ConfigDoc_XMLSerializer_ConfigSchema(); +$dom_document = $schema_serializer->serialize($schema); $dom_document->save('configdoc.xml'); diff --git a/configdoc/library/ConfigDoc.auto.php b/configdoc/library/ConfigDoc.auto.php new file mode 100644 index 00000000..8dbe120b --- /dev/null +++ b/configdoc/library/ConfigDoc.auto.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/configdoc/library/ConfigDoc.php b/configdoc/library/ConfigDoc.php new file mode 100644 index 00000000..26ad6c27 --- /dev/null +++ b/configdoc/library/ConfigDoc.php @@ -0,0 +1,13 @@ + \ No newline at end of file diff --git a/configdoc/library/ConfigDoc/XMLSerializer.php b/configdoc/library/ConfigDoc/XMLSerializer.php new file mode 100644 index 00000000..288cb8ad --- /dev/null +++ b/configdoc/library/ConfigDoc/XMLSerializer.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/configdoc/library/ConfigDoc/XMLSerializer/ConfigSchema.php b/configdoc/library/ConfigDoc/XMLSerializer/ConfigSchema.php new file mode 100644 index 00000000..0aac4aa0 --- /dev/null +++ b/configdoc/library/ConfigDoc/XMLSerializer/ConfigSchema.php @@ -0,0 +1,118 @@ +createElement('configdoc'); + $dom_document->appendChild($dom_root); + $dom_document->formatOutput = true; + + // add the name of the application + $dom_root->appendChild($dom_document->createElement('title', 'HTML Purifier')); + + /* + TODO for XML format: + - create a definition (DTD or other) once interface stabilizes + */ + + foreach($schema->info as $namespace_name => $namespace_info) { + + $dom_namespace = $dom_document->createElement('namespace'); + $dom_root->appendChild($dom_namespace); + + $dom_namespace->setAttribute('id', $namespace_name); + $dom_namespace->appendChild( + $dom_document->createElement('name', $namespace_name) + ); + $dom_namespace_description = $dom_document->createElement('description'); + $dom_namespace->appendChild($dom_namespace_description); + appendHTMLDiv($dom_document, $dom_namespace_description, + $schema->info_namespace[$namespace_name]->description); + + foreach ($namespace_info as $name => $info) { + + if ($info->class == 'alias') continue; + + $dom_directive = $dom_document->createElement('directive'); + $dom_namespace->appendChild($dom_directive); + + $dom_directive->setAttribute('id', $namespace_name . '.' . $name); + $dom_directive->appendChild( + $dom_document->createElement('name', $name) + ); + + $dom_constraints = $dom_document->createElement('constraints'); + $dom_directive->appendChild($dom_constraints); + + $dom_type = $dom_document->createElement('type', $info->type); + if ($info->allow_null) { + $dom_type->setAttribute('allow-null', 'yes'); + } + $dom_constraints->appendChild($dom_type); + + if ($info->allowed !== true) { + $dom_allowed = $dom_document->createElement('allowed'); + $dom_constraints->appendChild($dom_allowed); + foreach ($info->allowed as $allowed => $bool) { + $dom_allowed->appendChild( + $dom_document->createElement('value', $allowed) + ); + } + } + + $raw_default = $schema->defaults[$namespace_name][$name]; + if (is_bool($raw_default)) { + $default = $raw_default ? 'true' : 'false'; + } elseif (is_string($raw_default)) { + $default = "\"$raw_default\""; + } elseif (is_null($raw_default)) { + $default = 'null'; + } else { + $default = print_r( + $schema->defaults[$namespace_name][$name], true + ); + } + + $dom_default = $dom_document->createElement('default', $default); + + // remove this once we get a DTD + $dom_default->setAttribute('xml:space', 'preserve'); + + $dom_constraints->appendChild($dom_default); + + $dom_descriptions = $dom_document->createElement('descriptions'); + $dom_directive->appendChild($dom_descriptions); + + foreach ($info->descriptions as $file => $file_descriptions) { + foreach ($file_descriptions as $line => $description) { + $dom_description = $dom_document->createElement('description'); + // hack + if (!defined('HTMLPURIFIER_CUSTOM_SCHEMA')) { + $dom_description->setAttribute('file', $file); + $dom_description->setAttribute('line', $line); + } + appendHTMLDiv($dom_document, $dom_description, $description); + $dom_descriptions->appendChild($dom_description); + } + } + + } + + } + + return $dom_document; + + } + +} + +?> \ No newline at end of file diff --git a/configdoc/library/ConfigDoc/XMLSerializer/Types.php b/configdoc/library/ConfigDoc/XMLSerializer/Types.php new file mode 100644 index 00000000..abbb4f6a --- /dev/null +++ b/configdoc/library/ConfigDoc/XMLSerializer/Types.php @@ -0,0 +1,27 @@ +createElement('types'); + $types_document->appendChild($types_root); + $types_document->formatOutput = true; + foreach ($schema->types as $name => $expanded_name) { + $types_type = $types_document->createElement('type', $expanded_name); + $types_type->setAttribute('id', $name); + $types_root->appendChild($types_type); + } + return $types_document; + } + +} + +?> \ No newline at end of file