Author: ks
Date: Fri Sep 21 17:51:29 2007
New Revision: 6236
Log:
- Code fixes, restructure, added comments.
Added:
experimental/Document/design/class_diagram.png (with props)
experimental/Document/docs/html2docbook_static.php
experimental/Document/src/interfaces/document.php
experimental/Document/tests/
experimental/Document/tests/convert_xhtml.php
experimental/Document/tests/files/
experimental/Document/tests/files/docbook_sample.xml
experimental/Document/tests/files/xhtml_sample.xml
experimental/Document/tests/suite.php
Removed:
experimental/Document/src/document.php
experimental/Document/src/tests/
Modified:
experimental/Document/src/converters/xhtml_docbook.php
experimental/Document/src/document_autoload.php
experimental/Document/src/document_binary.php
experimental/Document/src/document_text.php
experimental/Document/src/document_xml.php
experimental/Document/src/interfaces/converter.php
experimental/Document/src/output.php
experimental/Document/src/parser.php
experimental/Document/src/validator.php
Added: experimental/Document/design/class_diagram.png
==============================================================================
Binary file - no diff available.
Propchange: experimental/Document/design/class_diagram.png
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: experimental/Document/docs/html2docbook_static.php
==============================================================================
--- experimental/Document/docs/html2docbook_static.php (added)
+++ experimental/Document/docs/html2docbook_static.php [iso-8859-1] Fri Sep 21
17:51:29 2007
@@ -1,0 +1,39 @@
+<?php
+require_once 'html2docbook_autoload.php';
+
+$xhtml = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>Test document</title>
+</head>
+<body>
+<h1>Header 1</h1>
+<p>
+Para 1
+</p>
+<h2>Header 1.1</h2>
+<p>
+Para 2
+</p>
+<ul>
+ <li>
+ <p>
+ List item 1 para 1
+ </p>
+ <p>
+ List item 1 para 2
+ </p>
+ </li>
+ <li>List item 2</li>
+ <li>List item 2 line 1<br/>line 2</li>
+</ul>
+</body>
+</html>';
+
+$docXhtml = new ezcDocumentXML( 'xhtml', $xhtml );
+$docDocbook = ezcDocumentXhtmlToDocbook::convert( $docXhtml );
+$result = $docDocbook->getXML();
+
+echo "Docbook:\n" . $result;
+
+?>
Modified: experimental/Document/src/converters/xhtml_docbook.php
==============================================================================
--- experimental/Document/src/converters/xhtml_docbook.php [iso-8859-1]
(original)
+++ experimental/Document/src/converters/xhtml_docbook.php [iso-8859-1] Fri Sep
21 17:51:29 2007
@@ -15,27 +15,58 @@
class ezcDocumentXhtmlToDocbook implements ezcDocumentConverter
{
+ /**
+ * XSLT stylesheet
+ *
+ * @var DOMDocument
+ */
+ static private $xslt = null;
+
+ /**
+ * XSLT processor
+ *
+ * @var XSLTProcessor
+ */
+ static private $proc = null;
+
+ /**
+ * Various conversion parameters
+ *
+ * @var mixed
+ */
+ private $parameters = array();
+
+ /**
+ * Constructs new converter
+ */
public function __construct( $parameters = array() )
{
- $this->xslt = new DOMDocument;
- $this->xslt->load( '../src/converters/xhtml_docbook.xsl' );
-
- $this->proc = new XSLTProcessor;
- $this->proc->importStyleSheet( $this->xslt );
-
$this->parameters = $parameters;
}
- public function convert( ezcDocument $doc )
+ /**
+ * Returns converted document
+ *
+ * @return ezcDocumentXML
+ */
+ static public function convert( ezcDocument $doc, $parameters = array() )
{
- $resultDOM = $this->proc->transformToDoc( $doc->getDOM() );
+ if ( !ezcDocumentXhtmlToDocbook::$proc )
+ {
+ if ( !ezcDocumentXhtmlToDocbook::$xslt )
+ {
+ ezcDocumentXhtmlToDocbook::$xslt = new DOMDocument;
+ ezcDocumentXhtmlToDocbook::$xslt->load(
'Document/src/converters/xhtml_docbook.xsl' );
+ }
+ ezcDocumentXhtmlToDocbook::$proc = new XSLTProcessor;
+ ezcDocumentXhtmlToDocbook::$proc->importStyleSheet(
ezcDocumentXhtmlToDocbook::$xslt );
+ }
+
+ $resultDOM = ezcDocumentXhtmlToDocbook::$proc->transformToDoc(
$doc->getDOM() );
$resultDoc = new ezcDocumentXML( 'docbook', $resultDOM );
return $resultDoc;
}
- private $xslt;
- private $proc;
- private $parameters;
}
?>
Modified: experimental/Document/src/document_autoload.php
==============================================================================
--- experimental/Document/src/document_autoload.php [iso-8859-1] (original)
+++ experimental/Document/src/document_autoload.php [iso-8859-1] Fri Sep 21
17:51:29 2007
@@ -10,11 +10,14 @@
*/
return array(
+ 'ezcDocument' => 'Document/interfaces/document.php',
+ 'ezcDocumentConverter' => 'Document/interfaces/converter.php',
+ 'ezcDocumentBinary' => 'Document/document_binary.php',
+ 'ezcDocumentOutput' => 'Document/output.php',
+ 'ezcDocumentParser' => 'Document/parser.php',
+ 'ezcDocumentText' => 'Document/document_text.php',
+ 'ezcDocumentValidator' => 'Document/validator.php',
+ 'ezcDocumentXML' => 'Document/document_xml.php',
'ezcDocumentXhtmlToDocbook' => 'Document/converters/xhtml_docbook.php',
- 'ezcDocumentText' => 'Document/document_text.php',
- 'ezcDocumentXML' => 'Document/document_xml.php',
- 'ezcDocumentBinary' => 'Document/document_binary.php',
- 'ezcDocument' => 'Document/document.php',
- 'ezcDocumentConverter' => 'Document/interfaces/converter.php',
);
?>
Modified: experimental/Document/src/document_binary.php
==============================================================================
--- experimental/Document/src/document_binary.php [iso-8859-1] (original)
+++ experimental/Document/src/document_binary.php [iso-8859-1] Fri Sep 21
17:51:29 2007
@@ -1,51 +1,43 @@
<?php
/**
- * File containing the ezcDocument class
+ * File containing the ezcDocumentXML 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
*
- * A base class for document format handlers.
+ * A binary document class.
*
*/
-class ezcDocumentBinary implements ezcDocument
+class ezcDocumentBinary extends ezcDocument
{
- __construct( $formatName, $filePath )
+ /**
+ * A file where the document is stored
+ */
+ private $fileName = null;
+
+ /**
+ * Constructs a binary document
+ */
+ public function __construct( $formatName, $filePath )
{
- $this->formatName = $filePath;
+ $this->fileName = $filePath;
$this->formatName = $formatName;
}
- public function getDOM()
- {
-
- }
- public function getXML()
- {
-
- }
- public function getText()
- {
- // throw exception
- }
-
+ /**
+ * Returns name of the file where the document is stored
+ *
+ * @return string
+ */
public function getFileName()
{
- // throw exception
+ return $this->fileName;
}
-
- public function getFormatName()
- {
-
- }
-
- private $filePath;
- private $formatName;
}
?>
Modified: experimental/Document/src/document_text.php
==============================================================================
--- experimental/Document/src/document_text.php [iso-8859-1] (original)
+++ experimental/Document/src/document_text.php [iso-8859-1] Fri Sep 21
17:51:29 2007
@@ -1,51 +1,42 @@
<?php
/**
- * File containing the ezcDocument class
+ * File containing the ezcDocumentText 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
*
- * A base class for document format handlers.
+ * A class for text documents.
*
*/
-
class ezcDocumentText extends ezcDocument
{
+ /**
+ * Text of the document
+ */
+ private $text = null;
+
+ /**
+ * Constructs a document in some text format.
+ */
public function __construct( $formatName, $text )
{
$this->Text = $text;
$this->formatName = $formatName;
}
- public function getDOM()
- {
- // throw exception
- }
- public function getXML()
- {
- // throw exception
- }
+ /**
+ * Returns current document in text format
+ *
+ * @return string
+ */
public function getText()
{
return $Text;
}
-
- public function getFileName()
- {
- // throw exception
- }
-
- public function getFormatName()
- {
-
- }
-
- private $Text = null;
- private $formatName;
}
?>
Modified: experimental/Document/src/document_xml.php
==============================================================================
--- experimental/Document/src/document_xml.php [iso-8859-1] (original)
+++ experimental/Document/src/document_xml.php [iso-8859-1] Fri Sep 21 17:51:29
2007
@@ -1,69 +1,74 @@
<?php
/**
- * File containing the ezcDocument class
+ * File containing the ezcDocumentXML 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
*
- * A base class for document format handlers.
+ * A text document class.
*
*/
-
class ezcDocumentXML extends ezcDocument
{
+ /**
+ * DOM tree representation of the current document
+ */
+ private $DOM = null;
+
+ /**
+ * XML representation of the current document
+ */
+ private $XML = null;
+
+ /**
+ * Constructs a document in some XML format.
+ */
public function __construct( $formatName, $data )
{
- if ( get_class( $data ) == 'DOMDocument' )
+ if ( $data instanceof DOMDocument )
{
$this->DOM = $data;
}
else
{
- $this->xml = $data;
+ $this->XML = $data;
}
$this->formatName = $formatName;
}
+ /**
+ * Returns current document in DOM format
+ *
+ * @return DOMDocument
+ */
public function getDOM()
{
if ( !$this->DOM )
{
$this->DOM = new DOMDocument;
- $this->DOM->loadXML( $this->xml );
+ $this->DOM->loadXML( $this->XML );
}
return $this->DOM;
}
+
+ /**
+ * Returns current document in XML format
+ *
+ * @return string
+ */
public function getXML()
{
- if ( !$this->xml )
- $this->xml = $this->DOM->saveXML();
+ if ( !$this->XML )
+ $this->XML = $this->DOM->saveXML();
- return $this->xml;
+ return $this->XML;
}
- public function getText()
- {
- // throw exception
- }
-
- public function getFileName()
- {
- // throw exception
- }
-
- public function getFormatName()
- {
-
- }
-
- private $DOM = null;
- private $xml = null;
- private $formatName;
}
?>
Modified: experimental/Document/src/interfaces/converter.php
==============================================================================
--- experimental/Document/src/interfaces/converter.php [iso-8859-1] (original)
+++ experimental/Document/src/interfaces/converter.php [iso-8859-1] Fri Sep 21
17:51:29 2007
@@ -15,7 +15,7 @@
interface ezcDocumentConverter
{
- public function convert( ezcDocument $doc );
+ static public function convert( ezcDocument $doc, $parameters = array() );
}
?>
Added: experimental/Document/src/interfaces/document.php
==============================================================================
--- experimental/Document/src/interfaces/document.php (added)
+++ experimental/Document/src/interfaces/document.php [iso-8859-1] Fri Sep 21
17:51:29 2007
@@ -1,0 +1,75 @@
+<?php
+
+/**
+ * File containing the ezcDocument 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
+ *
+ * A base class for document type handlers.
+ *
+ */
+
+
+abstract class ezcDocument
+{
+ /**
+ * Returns current document in DOM format
+ * Should be implemented in derived class
+ *
+ * @return DOMDocument
+ */
+ public function getDOM()
+ {
+ // throw exception
+ }
+
+ /**
+ * Returns current document in XML format
+ * Should be implemented in derived class
+ *
+ * @return string
+ */
+ public function getXML()
+ {
+ // throw exception
+ }
+
+ /**
+ * Returns current document in text format
+ * Should be implemented in derived class
+ *
+ * @return string
+ */
+ public function getText()
+ {
+ // throw exception
+ }
+
+ /**
+ * Returns name of the file where the document is stored
+ * Should be implemented in derived class
+ *
+ * @return string
+ */
+ public function getFileName()
+ {
+ // throw exception
+ }
+
+ /**
+ * Returns name of the document format
+ *
+ * @return string
+ */
+ public function getFormatName()
+ {
+ return $this->formatName;
+ }
+
+ private $formatName;
+}
+
+?>
Modified: experimental/Document/src/output.php
==============================================================================
--- experimental/Document/src/output.php [iso-8859-1] (original)
+++ experimental/Document/src/output.php [iso-8859-1] Fri Sep 21 17:51:29 2007
@@ -22,7 +22,7 @@
*
*/
-abstract class ezcDocOutput
+abstract class ezcDocumentOutput
{
/**
@@ -63,9 +63,6 @@
{
}
-
- $sourceDataType = DOM;
- $destDataType = TEXT;
}
?>
Modified: experimental/Document/src/parser.php
==============================================================================
--- experimental/Document/src/parser.php [iso-8859-1] (original)
+++ experimental/Document/src/parser.php [iso-8859-1] Fri Sep 21 17:51:29 2007
@@ -23,7 +23,7 @@
*
*/
-abstract class ezcDocParser extends ezcDocConverterBase
+abstract class ezcDocumentParser
{
/**
@@ -43,8 +43,6 @@
*/
protected $elements;
- $sourceDataType = TEXT;
- $destDataType = DOM;
}
?>
Modified: experimental/Document/src/validator.php
==============================================================================
--- experimental/Document/src/validator.php [iso-8859-1] (original)
+++ experimental/Document/src/validator.php [iso-8859-1] Fri Sep 21 17:51:29
2007
@@ -40,9 +40,9 @@
* The same goes for attributes.
*/
-class ezcDocValidator
+class ezcDocumentValidator
{
- __construct( $formatName, $schemaFile )
+ public function __construct( $formatName, $schemaFile )
{
}
@@ -58,11 +58,11 @@
*/
private $schema;
- public validateElement( $element )
+ public function validateElement( $element )
{
}
- public validateDocument( $document )
+ public function validateDocument( $document )
{
}
}
Added: experimental/Document/tests/convert_xhtml.php
==============================================================================
--- experimental/Document/tests/convert_xhtml.php (added)
+++ experimental/Document/tests/convert_xhtml.php [iso-8859-1] Fri Sep 21
17:51:29 2007
@@ -1,0 +1,39 @@
+<?php
+/**
+ * ezcDocTestConvertXhtmlDocbook
+ *
+ * @package Document
+ * @version //autogen//
+ * @subpackage Tests
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Test suite for class.
+ *
+ * @package Document
+ * @subpackage Tests
+ */
+class ezcDocumentConvertXhtmlTest extends ezcTestCase
+{
+ public function testDocumentXHtmlToDocbook()
+ {
+ $xhtml = file_get_contents( 'Document/tests/files/xhtml_sample.xml' );
+ $docbook = file_get_contents(
'Document/tests/files/docbook_sample.xml' );
+
+ $docXhtml = new ezcDocumentXML( 'xhtml', $xhtml );
+ $converter = new ezcDocumentXhtmlToDocbook;
+ $docDocbook = $converter->convert( $docXhtml );
+ $result = $docDocbook->getXML();
+
+ self::assertEquals( $docbook, $result, 'Converting XHTML to DocBook
failed.' );
+
+ }
+
+ public static function suite()
+ {
+ return new PHPUnit_Framework_TestSuite( "ezcDocumentConvertXhtmlTest"
);
+ }
+}
+?>
Added: experimental/Document/tests/files/docbook_sample.xml
==============================================================================
--- experimental/Document/tests/files/docbook_sample.xml (added)
+++ experimental/Document/tests/files/docbook_sample.xml [iso-8859-1] Fri Sep
21 17:51:29 2007
@@ -1,0 +1,10 @@
+<?xml version="1.0"?>
+<section><title>Header 1</title><para>
+Para 1
+</para><para>
+Para 2
+</para><itemizedlist><listitem><para>
+ List item 1 para 1
+ </para><para>
+ List item 1 para 2
+ </para></listitem><listitem><para>List item
2</para></listitem><listitem><para>List item 2 line 1line
2</para></listitem></itemizedlist></section>
Added: experimental/Document/tests/files/xhtml_sample.xml
==============================================================================
--- experimental/Document/tests/files/xhtml_sample.xml (added)
+++ experimental/Document/tests/files/xhtml_sample.xml [iso-8859-1] Fri Sep 21
17:51:29 2007
@@ -1,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>Test document</title>
+</head>
+<body>
+<h1>Header 1</h1>
+<p>
+Para 1
+</p>
+<h2>Header 1.1</h2>
+<p>
+Para 2
+</p>
+<ul>
+ <li>
+ <p>
+ List item 1 para 1
+ </p>
+ <p>
+ List item 1 para 2
+ </p>
+ </li>
+ <li>List item 2</li>
+ <li>List item 2 line 1<br/>line 2</li>
+</ul>
+</body>
+</html>
Added: experimental/Document/tests/suite.php
==============================================================================
--- experimental/Document/tests/suite.php (added)
+++ experimental/Document/tests/suite.php [iso-8859-1] Fri Sep 21 17:51:29 2007
@@ -1,0 +1,35 @@
+<?php
+
+/**
+ * File containing the ezcDocument 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
+ *
+ * A base class for document type handlers.
+ *
+ */
+
+/**
+* Requires conversion test suites.
+*/
+require_once 'convert_xhtml.php';
+
+
+class ezcDocumentSuite extends PHPUnit_Framework_TestSuite
+{
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setName( "Document" );
+ $this->addTest( ezcDocumentConvertXhtmlTest::suite() );
+ }
+
+ public static function suite()
+ {
+ return new ezcDocumentSuite( "ezcDocumentSuite" );
+ }
+}
+?>
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components