Author: ks
Date: Thu Jul 12 22:44:58 2007
New Revision: 5714
Log:
- Added some class prototypes.
Added:
experimental/Document/src/
experimental/Document/src/convbase.php
experimental/Document/src/conversion.php
experimental/Document/src/exceptions/
experimental/Document/src/parser.php
experimental/Document/src/parsers/
experimental/Document/src/schemas/
experimental/Document/src/transformer.php
experimental/Document/src/transformers/
experimental/Document/src/validator.php
experimental/Document/src/writer.php
experimental/Document/src/writers/
experimental/Document/src/xslt/
Added: experimental/Document/src/convbase.php
==============================================================================
--- experimental/Document/src/convbase.php (added)
+++ experimental/Document/src/convbase.php [iso-8859-1] Thu Jul 12 22:44:58 2007
@@ -1,0 +1,25 @@
+<?php
+/**
+ * File containing the ezcDocConverterBase class
+ *
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+
+abstract class ezcDocConverterBase
+{
+ const TEXT = 1;
+ const DOM = 2;
+ const FILE = 3;
+
+ protected $sourceDataType;
+ protected $destDataType;
+
+ public function convert( $source, $dest = null );
+
+}
+
+?>
Added: experimental/Document/src/conversion.php
==============================================================================
--- experimental/Document/src/conversion.php (added)
+++ experimental/Document/src/conversion.php [iso-8859-1] Thu Jul 12 22:44:58
2007
@@ -1,0 +1,97 @@
+<?php
+/**
+ * File containing the ezcDocConversion class
+ *
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+*
+* ezcDocConversion class is a wrapper around real converter classes.
+* It keeps information about available formats and possible transformation
+* ways and cares about choosing a way to transform from any user's input
+* format to any output format.
+*
+* Often direct conversion is impossible and some intermediate formats are
needed.
+* A sequence of all intermediate formats and corresponding conversion classes
is
+* called "conversion chain". Sometimes there could be more then one chain, in
this
+* case a shorter one is choosen automatically. But if you want to alter this,
its
+* possible to use getConversionChains() function to get all the chains and
+* useChain() to select one of them.
+*
+* This class also cares about input/output data types, which can be text, DOM
and file,
+* and converts data (parses/dumps XML and reads/writes files) when it is
necessary.
+* Not all the data can be converted to another type directly (for example
plain text
+* formats can't be converted to DOM), in this case a error is thrown.
+*/
+
+
+class ezcDocConversion
+{
+ // moved to ezcDocConverterBase
+ //const TEXT = 1;
+ //const DOM = 2;
+ //const FILE = 3;
+
+ /**
+ * List of available formats
+ */
+ private $availableFormats = array( 'oehtmlinput', 'oehtml', 'ezxmltext',
'docbook', 'xhtml', 'xhtmlbody' );
+
+ /**
+ * List of available converter classes
+ */
+ private $availableConverters = array( 'oehtmlinput' => array( 'oehtml' =>
'ezcParserOe' ),
+ 'oehtml' => array( 'ezxmltext' =>
'ezcTransformOeEzp' ),
+ 'ezxmltext' => array( 'docbook' =>
'ezcTransformEzpDocbook',
+ 'xhtml' =>
'ezcTransformEzpXhtml',
+ 'xhtmlbody' =>
'ezcWriteEzpXhtml' ) );
+ /**
+ * Sets source format, data type is TEXT, DOM or FILE
+ */
+ public function setSourceFormat( $formatName, $dataType = null )
+ {
+ }
+
+ /**
+ * Sets destination format, data type is TEXT, DOM or FILE
+ */
+ public function setDestFormat( $formatName, $dataType = null )
+ {
+ }
+
+ /**
+ * Main conversion function, returns the result of conversion
+ * Second parameter is needed only when the output format is a file,
+ * and contains a path to the output file.
+ *
+ * @return the converted document in the requested format,
+ * which can be a text string, DOM document or a file path.
+ *
+ */
+ public function convert( $source, $dest = null )
+ {
+ }
+
+ /**
+ * @return An array of conversion chains:
+ * array( array( string => string, ... ), ... )
+ *
+ * example for converting 'oehtmlinput' to 'ezxmltext':
+ *
+ * array( array( 'oehtml' => 'ezcParseOe', 'ezxmltext' =>
ezcTransformOeEzp' ) )
+ */
+ public function getConversionChains()
+ {
+ }
+
+ public function useChain( $chainID )
+ {
+ }
+
+}
+
+?>
Added: experimental/Document/src/parser.php
==============================================================================
--- experimental/Document/src/parser.php (added)
+++ experimental/Document/src/parser.php [iso-8859-1] Thu Jul 12 22:44:58 2007
@@ -1,0 +1,50 @@
+<?php
+/**
+ * File containing the ezcDocParser class
+ *
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * ezcDocParser class performs a parsing of the input text and presents
+ * it as a DOM tree.
+ *
+ * This is not an implementation of a real context-free parser.
+ * There is an assumption that input language is XML-like, i.e. consists
+ * of elements that have their opening and ending parts and some
+ * content between them (that may contain another elements).
+ *
+ * Sometimes it's hard or impossible to formalize input in these terms,
+ * so some special algorithms or custom element handlers will be used
+ * in this case.
+ *
+ */
+
+abstract class ezcDocParser extends ezcDocConverterBase
+{
+
+ /**
+ *
+ * Example grammar for wikipedia.
+ * (Just an idea, far from being complete.)
+ *
+ * $elements = array( 'h1' => array( 'begin' => '=',
+ * 'end' => '=",
+ * ... ),
+ * 'link' => array( 'begin' =>
'\[([^\]\s]+)\s?([^\]]*)?\]',
+ * 'end' => '',
+ * ... ) );
+ *
+ * the link's inner sub-expressions are attribute's values.
+ *
+ */
+ protected $elements;
+
+ $sourceDataType = TEXT;
+ $destDataType = DOM;
+}
+
+?>
Added: experimental/Document/src/transformer.php
==============================================================================
--- experimental/Document/src/transformer.php (added)
+++ experimental/Document/src/transformer.php [iso-8859-1] Thu Jul 12 22:44:58
2007
@@ -1,0 +1,84 @@
+<?php
+/**
+ * File containing the ezcDocTransformer class
+ *
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ *
+ * ezcDocTransformer transforms a given DOM tree by calling element handlers
+ * specified in derived classes. Attributes are converted using simple rules.
+ *
+ * The main function walks around the tree from bottom to the top and
+ * it contains 3 hooks where handlers are called.
+ * Each element can have 3 handlers which are functions of the derived class.
+ * (see transform() function for details)
+ *
+ */
+
+abstract class ezcDocTransformer extends ezcDocConverterBase
+{
+
+ /**
+ * Attribute conversion rules:
+ *
+ * $convertAttributes = array( 'element1' => array( 'attribute1' =>
'new-name1',
+ * 'attribute2' => false ),
+ * ... );
+ *
+ * attribute1 is renamed and attribute2 is removed in this example.
+ *
+ */
+ protected $convertAttributes;
+
+ /** Conversion function
+ * @return output string
+ */
+ public function convert( $source )
+ {
+ //...
+ return $doc;
+ }
+
+ /** Main walk-tree recursive function.
+ */
+ protected function transform( $element, &$handlersData )
+ {
+ // call of the 1st element's handler
+ $this->initHandler( $element, &$handlersData );
+
+ // process children
+ $child = $element->firstChild;
+ do
+ {
+ $this->transform( $child, &$handlersData );
+ $child = $element->nextSibiling;
+
+ }while( $child );
+
+ // call of the 2nd element's handler
+ $this->structHandler( $element, &$handlersData );
+
+ // Element is check against document schema
+ // If there are errors one of next actions is taken depending on
+ // $errorLevel paramater:
+ // - error exception is thrown
+ // - error fixed automatically (wrong elements are removed)
+ //
+ $this->checkElement( $element );
+
+ // call of the 3rd element's handler
+ $this->finalHandler( $element, &$handlersData );
+ }
+
+ protected $errorLevel;
+
+ $sourceDataType = DOM;
+ $destDataType = DOM;
+}
+
+?>
Added: experimental/Document/src/validator.php
==============================================================================
--- experimental/Document/src/validator.php (added)
+++ experimental/Document/src/validator.php [iso-8859-1] Thu Jul 12 22:44:58
2007
@@ -1,0 +1,71 @@
+<?php
+/**
+ * File containing the ezcDocValidator class
+ *
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * ezcDocValidator is used to validate a document or a separate element
+ * against it's schema.
+ *
+ * This class uses RelaxNG schema format as the input, then transforms it
+ * to the inner format for fast processing.
+ *
+ * (cache to a file?? use cache component?)
+ *
+ * The idea for fast validation is using regular expressions and strings.
+ * Here is an example:
+ *
+ * <element name="elem1">
+ * <zeroOrMore>
+ * <element name="elem2">
+ * ...
+ * </element>
+ * </zeroOrMore>
+ * <element name="elem3">
+ * ...
+ * </element>
+ * </element>
+ *
+ * This RelaxNG schema for the element's content can be presented with regexp:
+ *
+ * '#(elem2)*elem3#'
+ *
+ * Validated document element's children can be also presented with a string,
+ * like 'elem2elem2elem3' for instance, which is validated with this regexp.
+ *
+ * The same goes for attributes.
+ */
+
+class ezcDocValidator
+{
+ __construct( $formatName, $schemaFile )
+ {
+
+ }
+
+ /**
+ * Internal presentation of the schema for fast validation.
+ *
+ * $schema = array( 'elem1' => array( 'children' => '(elem2)*elem3',
+ * 'attrs' => ...,
+ * ... ),
+ * ... );
+ *
+ */
+ private $schema;
+
+ public validateElement( $element )
+ {
+ }
+
+ public validateDocument( $document )
+ {
+ }
+}
+
+?>
Added: experimental/Document/src/writer.php
==============================================================================
--- experimental/Document/src/writer.php (added)
+++ experimental/Document/src/writer.php [iso-8859-1] Thu Jul 12 22:44:58 2007
@@ -1,0 +1,71 @@
+<?php
+/**
+ * File containing the ezcDocWriter class
+ *
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * ezcDocWriter class performs an output of the given document tree in the text
+ * format using simple internal templating system. Also it cares about text
+ * indenting to show the structure of the document.
+ *
+ * Exact templates for element output and helper formatting functions are set
+ * in derived classes.
+ *
+ * ezcDocWriterTemplate class is implemented in the DocumentTemplateTieIn
+ * component. It extends this class to use Template component for elements
+ * output.
+ *
+ */
+
+abstract class ezcDocWriter extends ezcDocConverterBase
+{
+
+ /**
+ * Rules for elements output, specified in derived classes
+ *
+ * $elementsOutput = array( 'element1' => array( 'startTag' =>
'<element1$>'.
+ * 'endTag' =>
"</element1>\n",
+ * 'attribute1' => '
attr1="$"',
+ * 'attribute2' => '
attr2="$"' ... ),
+ * ... );
+ *
+ * '$' sign is replaced with attributes string in tag's start or end
template,
+ * and with attributes' values in attributes templates.
+ *
+ * (There should also be a possibility to set default view)
+ *
+ */
+ protected $elementsOutput;
+
+ /**
+ * String to use for indentations
+ */
+ protected $indentString;
+
+ /** Conversion function
+ * @return output text string
+ */
+ public function convert( $source )
+ {
+ //...
+ return $text;
+ }
+
+ /** Main walk-tree recursive function.
+ * @return string part
+ */
+ protected function elementOutput( $element )
+ {
+
+ }
+
+ $sourceDataType = DOM;
+ $destDataType = TEXT;
+}
+
+?>
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components