Author: ks
Date: Tue Sep 18 22:41:54 2007
New Revision: 6193
Log:
- The draft of XHTML to Docbook conversion with a working sample.
Added:
experimental/Document/docs/
experimental/Document/docs/html2docbook.php
experimental/Document/docs/html2docbook_autoload.php
experimental/Document/src/converters/
experimental/Document/src/converters/xhtml_docbook.php
experimental/Document/src/converters/xhtml_docbook.xsl
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/tests/
experimental/Document/src/tests/convert_xhtml_docbook.php
experimental/Document/src/tests/suite.php
experimental/Document/src/tests/sysinfo_test.php
Removed:
experimental/Document/src/transform_xslt.php
Modified:
experimental/Document/design/design.txt
experimental/Document/src/document.php
Modified: experimental/Document/design/design.txt
==============================================================================
--- experimental/Document/design/design.txt [iso-8859-1] (original)
+++ experimental/Document/design/design.txt [iso-8859-1] Tue Sep 18 22:41:54
2007
@@ -71,25 +71,9 @@
Transforming XML
----------------
-The component supports 2 ways of transforming DOM documents:
-1) Using XSLT stylesheet. In this case the converter is derived from
- ezcDocConverterBase class and applies XSLT stylesheets to the document using
- PHP XSL extension.
-2) Using ezcDocTransformer class. In this case the converter is derived from
- ezcDocTransformer class.
-
-ezcDocTransformer class provides the interface to process the document.
-It's principle is completely different from XSL and it assumes that the result
-of transformations is the same document, but with diffrent schema.
-It's main function walks around the document's tree and calls callback handlers
-for elements. Derived classes contain control arrays and elements' handlers.
+XML documents are transformed using XSLT stylesheets and XSL extension for PHP.
+Transformations are done with ezcDocXSLTTransformer class.
-Element's handler can pass information to next processed element's handler.
-This makes it possible to handle complex transformations that evolve many
-elements. For instance the handler of "text" element "knows" that it is needed
-to have <p> element as a parent. It creates new <p> element and passes it
-to the next element's handler by reference. So if the next element is a text,
-it will have a new parent element to be attached to.
Parsing text/XML
----------------
@@ -152,4 +136,25 @@
Validated document element's children can be also presented with a string,
like 'elem2elem2elem3' for instance, which is validated with this regexp.
-The similar process used for attributes.
+The similar process used for attributes.
+
+
+Examples
+========
+
+Converting Format1 to Format2
+-----------------------------
+
+$docFormat1 = new ezcDocumentText( $text, 'format1' );
+$converter1 = new ezcDocFormat1ToInternal( $parameters1 );
+$docInternal = $converter1->convert( $docFormat1 );
+$converter2 = new ezcDocInternalToFormat2( $parameters2 );
+$docFormat2 = $converter2->convert( $docInternal );
+$result = $docFormat2->getText();
+
+/// The same with static functions:
+
+$docFormat1 = new ezcDocumentText( $text, 'format1' );
+$docInternal = ezcDocFormat1ToInternal::convert( $docFormat1, $parameters1 );
+$docFormat2 = ezcDocInternalToFormat2::convert( $docInternal, $parameters2 );
+$result = $docFormat2->getText();
Added: experimental/Document/docs/html2docbook.php
==============================================================================
--- experimental/Document/docs/html2docbook.php (added)
+++ experimental/Document/docs/html2docbook.php [iso-8859-1] Tue Sep 18
22:41:54 2007
@@ -1,0 +1,41 @@
+<?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 );
+
+$converter = new ezcDocumentXhtmlToDocbook;
+$docDocbook = $converter->convert( $docXhtml );
+$result = $docDocbook->getXML();
+
+echo "Docbook:\n" . $result;
+
+?>
Added: experimental/Document/docs/html2docbook_autoload.php
==============================================================================
--- experimental/Document/docs/html2docbook_autoload.php (added)
+++ experimental/Document/docs/html2docbook_autoload.php [iso-8859-1] Tue Sep
18 22:41:54 2007
@@ -1,0 +1,20 @@
+<?php
+$dir = dirname( __FILE__ );
+$dirParts = explode( '/', $dir );
+switch ( $dirParts[count( $dirParts ) - 3] )
+{
+ case 'doc': require_once 'ezc/Base/base.php'; break; // pear
+ case 'trunk': require_once "$dir/../../Base/src/base.php"; break; // svn
+ default: require_once "$dir/../../Base/src/base.php"; break; // bundle
+}
+
+/**
+ * Autoload ezc classes
+ *
+ * @param string $className
+ */
+function __autoload( $className )
+{
+ ezcBase::autoload( $className );
+}
+?>
Added: experimental/Document/src/converters/xhtml_docbook.php
==============================================================================
--- experimental/Document/src/converters/xhtml_docbook.php (added)
+++ experimental/Document/src/converters/xhtml_docbook.php [iso-8859-1] Tue Sep
18 22:41:54 2007
@@ -1,0 +1,41 @@
+<?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 format handlers.
+ *
+ */
+
+
+class ezcDocumentXhtmlToDocbook implements ezcDocumentConverter
+{
+ 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 )
+ {
+ $resultDOM = $this->proc->transformToDoc( $doc->getDOM() );
+ $resultDoc = new ezcDocumentXML( 'docbook', $resultDOM );
+ return $resultDoc;
+ }
+
+ private $xslt;
+ private $proc;
+ private $parameters;
+}
+
+?>
Added: experimental/Document/src/converters/xhtml_docbook.xsl
==============================================================================
--- experimental/Document/src/converters/xhtml_docbook.xsl (added)
+++ experimental/Document/src/converters/xhtml_docbook.xsl [iso-8859-1] Tue Sep
18 22:41:54 2007
@@ -1,0 +1,545 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:fo="http://www.w3.org/1999/XSL/Format"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns:saxon="http://icl.com/saxon"
+ exclude-result-prefixes="xsl fo html saxon">
+
+<xsl:output method="xml" indent="no"/>
+<xsl:param name="filename"></xsl:param>
+<xsl:param name="prefix">wb</xsl:param>
+<xsl:param name="graphics_location">file:///path/to/graphics/</xsl:param>
+
+<!-- Main block-level conversions -->
+<xsl:template match="html:html">
+ <xsl:apply-templates select="html:body"/>
+</xsl:template>
+
+<!-- This template converts each HTML file encountered into a DocBook
+ section. For a title, it selects the first h1 element -->
+<xsl:template match="html:body">
+ <section>
+ <xsl:if test="$filename != ''">
+ <xsl:attribute name="id">
+ <xsl:value-of select="$prefix"/>
+ <xsl:text>_</xsl:text>
+ <xsl:value-of select="translate($filename,' ()','__')"/>
+ </xsl:attribute>
+ </xsl:if>
+ <title>
+ <xsl:value-of select=".//html:h1[1]
+ |.//html:h2[1]
+ |.//html:h3[1]"/>
+ </title>
+ <xsl:apply-templates select="*"/>
+ </section>
+</xsl:template>
+
+<!-- This template matches on all HTML header items and makes them into
+ bridgeheads. It attempts to assign an ID to each bridgehead by looking
+ for a named anchor as a child of the header or as the immediate preceding
+ or following sibling -->
+<xsl:template match="html:h1
+ |html:h2
+ |html:h3
+ |html:h4
+ |html:h5
+ |html:h6">
+ <bridgehead>
+ <xsl:choose>
+ <xsl:when test="count(html:a/@name)">
+ <xsl:attribute name="id">
+ <xsl:value-of select="html:a/@name"/>
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:when test="preceding-sibling::* = preceding-sibling::html:[EMAIL
PROTECTED] != '']">
+ <xsl:attribute name="id">
+ <xsl:value-of select="concat($prefix,preceding-sibling::html:a[1]/@name)"/>
+ </xsl:attribute>
+ </xsl:when>
+ <xsl:when test="following-sibling::* = following-sibling::html:[EMAIL
PROTECTED] != '']">
+ <xsl:attribute name="id">
+ <xsl:value-of select="concat($prefix,following-sibling::html:a[1]/@name)"/>
+ </xsl:attribute>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:apply-templates/>
+ </bridgehead>
+</xsl:template>
+
+<!-- These templates perform one-to-one conversions of HTML elements into
+ DocBook elements -->
+<xsl:template match="html:p">
+<!-- if the paragraph has no text (perhaps only a child <img>), don't
+ make it a para -->
+ <xsl:choose>
+ <xsl:when test="normalize-space(.) = ''">
+ <xsl:apply-templates/>
+ </xsl:when>
+ <xsl:otherwise>
+ <para>
+ <xsl:apply-templates/>
+ </para>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+<xsl:template match="html:pre">
+ <programlisting>
+ <xsl:apply-templates/>
+ </programlisting>
+</xsl:template>
+
+<!-- Hyperlinks -->
+<xsl:template match="html:a[contains(@href,'http://')]" priority="1.5">
+ <ulink>
+ <xsl:attribute name="url">
+ <xsl:value-of select="normalize-space(@href)"/>
+ </xsl:attribute>
+ <xsl:apply-templates/>
+ </ulink>
+</xsl:template>
+<xsl:template match="html:a[contains(@href,'ftp://')]" priority="1.5">
+ <ulink>
+ <xsl:attribute name="url">
+ <xsl:value-of select="normalize-space(@href)"/>
+ </xsl:attribute>
+ <xsl:apply-templates/>
+ </ulink>
+</xsl:template>
+
+<xsl:template match="html:a[contains(@href,'#')]" priority="0.6">
+ <xref>
+ <xsl:attribute name="linkend">
+ <xsl:call-template name="make_id">
+ <xsl:with-param name="string" select="substring-after(@href,'#')"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </xref>
+</xsl:template>
+<xsl:template match="html:[EMAIL PROTECTED] != '']" priority="0.6">
+ <anchor>
+ <xsl:attribute name="id">
+ <xsl:call-template name="make_id">
+ <xsl:with-param name="string" select="@name"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ <xsl:apply-templates/>
+ </anchor>
+</xsl:template>
+
+<xsl:template match="html:[EMAIL PROTECTED] != '']">
+ <xref>
+ <xsl:attribute name="linkend">
+ <xsl:value-of select="$prefix"/>
+ <xsl:text>_</xsl:text>
+ <xsl:call-template name="make_id">
+ <xsl:with-param name="string" select="@href"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </xref>
+</xsl:template>
+
+<!-- Need to come up with good template for converting filenames into ID's -->
+<xsl:template name="make_id">
+ <xsl:param name="string" select="''"/>
+ <xsl:variable name="fixedname">
+ <xsl:call-template name="get_filename">
+ <xsl:with-param name="path" select="translate($string,' \()','_/_')"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="contains($fixedname,'.htm')">
+ <xsl:value-of select="substring-before($fixedname,'.htm')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$fixedname"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="string.subst">
+ <xsl:param name="string" select="''"/>
+ <xsl:param name="substitute" select="''"/>
+ <xsl:param name="with" select="''"/>
+ <xsl:choose>
+ <xsl:when test="contains($string,$substitute)">
+ <xsl:variable name="pre" select="substring-before($string,$substitute)"/>
+ <xsl:variable name="post" select="substring-after($string,$substitute)"/>
+ <xsl:call-template name="string.subst">
+ <xsl:with-param name="string" select="concat($pre,$with,$post)"/>
+ <xsl:with-param name="substitute" select="$substitute"/>
+ <xsl:with-param name="with" select="$with"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$string"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Images -->
+<!-- Images and image maps -->
+<xsl:template match="html:img">
+ <xsl:variable name="tag_name">
+ <xsl:choose>
+ <xsl:when test="boolean(parent::html:p) and
+ boolean(normalize-space(parent::html:p/text()))">
+ <xsl:text>inlinemediaobject</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>mediaobject</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:element name="{$tag_name}">
+ <imageobject>
+ <xsl:call-template name="process.image"/>
+ </imageobject>
+ </xsl:element>
+</xsl:template>
+
+<xsl:template name="process.image">
+ <imagedata>
+<xsl:attribute name="fileref">
+ <xsl:call-template name="make_absolute">
+ <xsl:with-param name="filename" select="@src"/>
+ </xsl:call-template>
+</xsl:attribute>
+<xsl:if test="@height != ''">
+ <xsl:attribute name="depth">
+ <xsl:value-of select="@height"/>
+ </xsl:attribute>
+</xsl:if>
+<xsl:if test="@width != ''">
+ <xsl:attribute name="width">
+ <xsl:value-of select="@width"/>
+ </xsl:attribute>
+</xsl:if>
+ </imagedata>
+</xsl:template>
+
+<xsl:template name="make_absolute">
+ <xsl:param name="filename"/>
+ <xsl:variable name="name_only">
+ <xsl:call-template name="get_filename">
+ <xsl:with-param name="path" select="$filename"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:value-of select="$graphics_location"/><xsl:value-of select="$name_only"/>
+</xsl:template>
+
+<xsl:template match="html:ul[count(*) = 0]">
+ <xsl:message>Matched</xsl:message>
+ <blockquote>
+ <xsl:apply-templates/>
+ </blockquote>
+</xsl:template>
+
+<xsl:template name="get_filename">
+ <xsl:param name="path"/>
+ <xsl:choose>
+ <xsl:when test="contains($path,'/')">
+ <xsl:call-template name="get_filename">
+ <xsl:with-param name="path" select="substring-after($path,'/')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$path"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- LIST ELEMENTS -->
+<xsl:template match="html:ul">
+ <itemizedlist>
+ <xsl:apply-templates/>
+ </itemizedlist>
+</xsl:template>
+
+<xsl:template match="html:ol">
+ <orderedlist>
+ <xsl:apply-templates/>
+ </orderedlist>
+</xsl:template>
+
+<!-- This template makes a DocBook variablelist out of an HTML definition list
-->
+<xsl:template match="html:dl">
+ <variablelist>
+ <xsl:for-each select="html:dt">
+ <varlistentry>
+ <term>
+ <xsl:apply-templates/>
+ </term>
+ <listitem>
+ <xsl:apply-templates select="following-sibling::html:dd[1]"/>
+ </listitem>
+ </varlistentry>
+ </xsl:for-each>
+ </variablelist>
+</xsl:template>
+
+<xsl:template match="html:dd">
+ <xsl:choose>
+ <xsl:when test="boolean(html:p)">
+ <xsl:apply-templates/>
+ </xsl:when>
+ <xsl:otherwise>
+ <para>
+ <xsl:apply-templates/>
+ </para>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="html:li">
+ <listitem>
+ <xsl:choose>
+ <xsl:when test="count(html:p) = 0">
+ <para>
+ <xsl:apply-templates/>
+ </para>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </listitem>
+</xsl:template>
+
+<xsl:template match="*">
+ <xsl:message>No template for <xsl:value-of select="name()"/>
+ </xsl:message>
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="@*">
+ <xsl:message>No template for <xsl:value-of select="name()"/>
+ </xsl:message>
+ <xsl:apply-templates/>
+</xsl:template>
+
+<!-- inline formatting -->
+<xsl:template match="html:b">
+ <emphasis role="bold">
+ <xsl:apply-templates/>
+ </emphasis>
+</xsl:template>
+<xsl:template match="html:i">
+ <emphasis>
+ <xsl:apply-templates/>
+ </emphasis>
+</xsl:template>
+<xsl:template match="html:u">
+ <citetitle>
+ <xsl:apply-templates/>
+ </citetitle>
+</xsl:template>
+<xsl:template match="html:tt">
+ <literal>
+ <xsl:apply-templates/>
+ </literal>
+</xsl:template>
+
+<!-- Ignored elements -->
+<xsl:template match="html:hr"/>
+<xsl:template match="html:h1[1]|html:h2[1]|html:h3[1]" priority="1"/>
+<xsl:template match="html:br"/>
+<xsl:template match="html:p[normalize-space(.) = '' and count(*) = 0]"/>
+<xsl:template match="text()">
+ <xsl:choose>
+ <xsl:when test="normalize-space(.) = ''"></xsl:when>
+ <xsl:otherwise><xsl:copy/></xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Workbench Hacks -->
+<xsl:template match="html:div[contains(@style,'margin-left: 2em')]">
+ <blockquote><para>
+ <xsl:apply-templates/></para>
+ </blockquote>
+</xsl:template>
+
+<xsl:template match="html:[EMAIL PROTECTED] != ''
+ and not(boolean(ancestor::html:p|ancestor::html:li))]"
+ priority="1">
+ <para>
+ <xref>
+ <xsl:attribute name="linkend">
+ <xsl:value-of select="$prefix"/>
+ <xsl:text>_</xsl:text>
+ <xsl:call-template name="make_id">
+ <xsl:with-param name="string" select="@href"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </xref>
+ </para>
+</xsl:template>
+
+<xsl:template match="html:a[contains(@href,'#')
+ and not(boolean(ancestor::html:p|ancestor::html:li))]"
+ priority="1.1">
+ <para>
+ <xref>
+ <xsl:attribute name="linkend">
+ <xsl:value-of select="$prefix"/>
+ <xsl:text>_</xsl:text>
+ <xsl:call-template name="make_id">
+ <xsl:with-param name="string" select="substring-after(@href,'#')"/>
+ </xsl:call-template>
+ </xsl:attribute>
+ </xref>
+ </para>
+</xsl:template>
+
+<!-- Table conversion -->
+<xsl:template match="html:table">
+<!-- <xsl:variable name="column_count"
+
select="saxon:max(.//html:tr,saxon:expression('count(html:td)'))"/> -->
+ <xsl:variable name="column_count">
+ <xsl:call-template name="count_columns">
+ <xsl:with-param name="table" select="."/>
+ </xsl:call-template>
+ </xsl:variable>
+ <informaltable>
+ <tgroup>
+ <xsl:attribute name="cols">
+ <xsl:value-of select="$column_count"/>
+ </xsl:attribute>
+ <xsl:call-template name="generate-colspecs">
+ <xsl:with-param name="count" select="$column_count"/>
+ </xsl:call-template>
+ <thead>
+ <xsl:apply-templates select="html:tr[1]"/>
+ </thead>
+ <tbody>
+ <xsl:apply-templates select="html:tr[position() != 1]"/>
+ </tbody>
+ </tgroup>
+ </informaltable>
+</xsl:template>
+
+<xsl:template name="generate-colspecs">
+ <xsl:param name="count" select="0"/>
+ <xsl:param name="number" select="1"/>
+ <xsl:choose>
+ <xsl:when test="$count < $number"/>
+ <xsl:otherwise>
+ <colspec>
+ <xsl:attribute name="colnum">
+ <xsl:value-of select="$number"/>
+ </xsl:attribute>
+ <xsl:attribute name="colname">
+ <xsl:value-of select="concat('col',$number)"/>
+ </xsl:attribute>
+ </colspec>
+ <xsl:call-template name="generate-colspecs">
+ <xsl:with-param name="count" select="$count"/>
+ <xsl:with-param name="number" select="$number + 1"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="html:tr">
+ <row>
+ <xsl:apply-templates/>
+ </row>
+</xsl:template>
+
+<xsl:template match="html:th|html:td">
+ <xsl:variable name="position" select="count(preceding-sibling::*) + 1"/>
+ <entry>
+ <xsl:if test="@colspan > 1">
+ <xsl:attribute name="namest">
+ <xsl:value-of select="concat('col',$position)"/>
+ </xsl:attribute>
+ <xsl:attribute name="nameend">
+ <xsl:value-of select="concat('col',$position + number(@colspan) - 1)"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:if test="@rowspan > 1">
+ <xsl:attribute name="morerows">
+ <xsl:value-of select="number(@rowspan) - 1"/>
+ </xsl:attribute>
+ </xsl:if>
+ <xsl:apply-templates/>
+ </entry>
+</xsl:template>
+
+<xsl:template match="html:td_null">
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template name="count_columns">
+ <xsl:param name="table" select="."/>
+ <xsl:param name="row" select="$table/html:tr[1]"/>
+ <xsl:param name="max" select="0"/>
+ <xsl:choose>
+ <xsl:when test="local-name($table) != 'table'">
+ <xsl:message>Attempting to count columns on a non-table
element</xsl:message>
+ </xsl:when>
+ <xsl:when test="local-name($row) != 'tr'">
+ <xsl:message>Row parameter is not a valid row</xsl:message>
+ </xsl:when>
+ <xsl:otherwise>
+ <!-- Count cells in the current row -->
+ <xsl:variable name="current_count">
+ <xsl:call-template name="count_cells">
+ <xsl:with-param name="cell" select="$row/html:td[1]|$row/html:th[1]"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <!-- Check for the maximum value of $current_count and $max -->
+ <xsl:variable name="new_max">
+ <xsl:choose>
+ <xsl:when test="$current_count > $max">
+ <xsl:value-of select="number($current_count)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="number($max)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <!-- If this is the last row, return $max, otherwise continue -->
+ <xsl:choose>
+ <xsl:when test="count($row/following-sibling::html:tr) = 0">
+ <xsl:value-of select="$new_max"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="count_columns">
+ <xsl:with-param name="table" select="$table"/>
+ <xsl:with-param name="row" select="$row/following-sibling::html:tr"/>
+ <xsl:with-param name="max" select="$new_max"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template name="count_cells">
+ <xsl:param name="cell"/>
+ <xsl:param name="count" select="0"/>
+ <xsl:variable name="new_count">
+ <xsl:choose>
+ <xsl:when test="$cell/@colspan > 1">
+ <xsl:value-of select="number($cell/@colspan) + number($count)"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="number('1') + number($count)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="count($cell/following-sibling::*) > 0">
+ <xsl:call-template name="count_cells">
+ <xsl:with-param name="cell"
+ select="$cell/following-sibling::*[1]"/>
+ <xsl:with-param name="count" select="$new_count"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$new_count"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
Modified: experimental/Document/src/document.php
==============================================================================
--- experimental/Document/src/document.php [iso-8859-1] (original)
+++ experimental/Document/src/document.php [iso-8859-1] Tue Sep 18 22:41:54 2007
@@ -8,38 +8,30 @@
* @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 base class for document type handlers.
*
*/
-class ezcDocument
+abstract class ezcDocument
{
- /**
- * Factory methods to create a document object from simple data types
- * \return document object
- */
- public static function createFromDOM( $dom );
- public static function createFromXML( $xml );
- public static function createFromText( $text );
- public static function createFromFile( $filename );
-
/**
* Functions to get current focument in various datatypes
*/
- public function getDOM();
- public function getXML();
- public function getText();
- public function getFileName();
+ abstract public function getDOM();
+ abstract public function getXML();
+ abstract public function getText();
+ abstract public function getFileName();
- private $DOM = null;
- private $XML = null;
- private $Text = null;
- private $FileName = null;
+ abstract public function getFormatName();
- // Name of the class that contains conversion defenitions for this format.
- // If null, then only the default registry is used.
- private $registry = null;
+ private $formatName;
+
+ private $DOM;
+ private $XML;
+ private $Text;
+ private $FileName;
+
}
?>
Added: experimental/Document/src/document_autoload.php
==============================================================================
--- experimental/Document/src/document_autoload.php (added)
+++ experimental/Document/src/document_autoload.php [iso-8859-1] Tue Sep 18
22:41:54 2007
@@ -1,0 +1,20 @@
+<?php
+/**
+ * Autoloader definition for the Document component.
+ *
+ * @copyright Copyright (C) 2005-2007 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package Document
+ */
+
+return array(
+ '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',
+);
+?>
Added: experimental/Document/src/document_binary.php
==============================================================================
--- experimental/Document/src/document_binary.php (added)
+++ experimental/Document/src/document_binary.php [iso-8859-1] Tue Sep 18
22:41:54 2007
@@ -1,0 +1,51 @@
+<?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 format handlers.
+ *
+ */
+
+
+class ezcDocumentBinary implements ezcDocument
+{
+ __construct( $formatName, $filePath )
+ {
+ $this->formatName = $filePath;
+ $this->formatName = $formatName;
+ }
+
+ public function getDOM()
+ {
+
+ }
+ public function getXML()
+ {
+
+ }
+ public function getText()
+ {
+ // throw exception
+ }
+
+ public function getFileName()
+ {
+ // throw exception
+ }
+
+ public function getFormatName()
+ {
+
+ }
+
+ private $filePath;
+ private $formatName;
+}
+
+?>
Added: experimental/Document/src/document_text.php
==============================================================================
--- experimental/Document/src/document_text.php (added)
+++ experimental/Document/src/document_text.php [iso-8859-1] Tue Sep 18
22:41:54 2007
@@ -1,0 +1,51 @@
+<?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 format handlers.
+ *
+ */
+
+
+class ezcDocumentText extends ezcDocument
+{
+ public function __construct( $formatName, $text )
+ {
+ $this->Text = $text;
+ $this->formatName = $formatName;
+ }
+
+ public function getDOM()
+ {
+ // throw exception
+ }
+ public function getXML()
+ {
+ // throw exception
+ }
+ public function getText()
+ {
+ return $Text;
+ }
+
+ public function getFileName()
+ {
+ // throw exception
+ }
+
+ public function getFormatName()
+ {
+
+ }
+
+ private $Text = null;
+ private $formatName;
+}
+
+?>
Added: experimental/Document/src/document_xml.php
==============================================================================
--- experimental/Document/src/document_xml.php (added)
+++ experimental/Document/src/document_xml.php [iso-8859-1] Tue Sep 18 22:41:54
2007
@@ -1,0 +1,69 @@
+<?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 format handlers.
+ *
+ */
+
+
+class ezcDocumentXML extends ezcDocument
+{
+ public function __construct( $formatName, $data )
+ {
+ if ( get_class( $data ) == 'DOMDocument' )
+ {
+ $this->DOM = $data;
+ }
+ else
+ {
+ $this->xml = $data;
+ }
+
+ $this->formatName = $formatName;
+ }
+
+ public function getDOM()
+ {
+ if ( !$this->DOM )
+ {
+ $this->DOM = new DOMDocument;
+ $this->DOM->loadXML( $this->xml );
+ }
+
+ return $this->DOM;
+ }
+ public function getXML()
+ {
+ if ( !$this->xml )
+ $this->xml = $this->DOM->saveXML();
+
+ return $this->xml;
+ }
+ public function getText()
+ {
+ // throw exception
+ }
+
+ public function getFileName()
+ {
+ // throw exception
+ }
+
+ public function getFormatName()
+ {
+
+ }
+
+ private $DOM = null;
+ private $xml = null;
+ private $formatName;
+}
+
+?>
Added: experimental/Document/src/interfaces/converter.php
==============================================================================
--- experimental/Document/src/interfaces/converter.php (added)
+++ experimental/Document/src/interfaces/converter.php [iso-8859-1] Tue Sep 18
22:41:54 2007
@@ -1,0 +1,21 @@
+<?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.
+ *
+ */
+
+
+interface ezcDocumentConverter
+{
+ public function convert( ezcDocument $doc );
+}
+
+?>
Added: experimental/Document/src/tests/convert_xhtml_docbook.php
==============================================================================
--- experimental/Document/src/tests/convert_xhtml_docbook.php (added)
+++ experimental/Document/src/tests/convert_xhtml_docbook.php [iso-8859-1] Tue
Sep 18 22:41:54 2007
@@ -1,0 +1,88 @@
+<?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 ezcDocTestConvertXhtml extends ezcTestCase
+{
+ public function testDocXHtmlToDocbook()
+ {
+ $xhtml = '<html>
+<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>
+<p>
+
+</p>
+</body>
+<html>';
+
+ $docXhtml = new ezcDocumentText( 'xhtml', $xhtml );
+ $converter = new ezcDocXhtmlToDocbook;
+ $docDocbook = $converter->convert( $docXhtml );
+ $result = $docDocbook->getText();
+
+ self::assertEquals( '<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook
V4.1//EN">
+
+<article>
+<articleinfo>
+<title></title>
+</articleinfo>
+
+<sect1><title>Header 1</title>
+<para>Para 1</para>
+<sect2><title>Header 1.1</title>
+<para>Para 2</para>
+<itemizedlist>
+<listitem>
+<para>List item 1 para 1</para>
+<para>List item 1 para 2</para>
+</listitem>
+<listitem>List item 2</listitem>
+<listitem>List item 2 line 1line 2</listitem>
+</itemizedlist>
+<para> </para>
+</sect2></sect1></article>',
+
+ $result,
+ 'Converting XHTML to DocBook failed.'
+ );
+
+ }
+
+ public static function suite()
+ {
+ return new PHPUnit_Framework_TestSuite( "ezcDocTestConvertXhtml" );
+ }
+}
+?>
Added: experimental/Document/src/tests/suite.php
==============================================================================
--- experimental/Document/src/tests/suite.php (added)
+++ experimental/Document/src/tests/suite.php [iso-8859-1] Tue Sep 18 22:41:54
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_docbook.php';
+
+
+class ezcDocumentSuite extends PHPUnit_Framework_TestSuite
+{
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setName( "Document" );
+ $this->addTest( ezcDocTestConvertXhtml::suite() );
+ }
+
+ public static function suite()
+ {
+ return new ezcDocumentSuite( "ezcDocumentSuite" );
+ }
+}
+?>
Added: experimental/Document/src/tests/sysinfo_test.php
==============================================================================
--- experimental/Document/src/tests/sysinfo_test.php (added)
+++ experimental/Document/src/tests/sysinfo_test.php [iso-8859-1] Tue Sep 18
22:41:54 2007
@@ -1,0 +1,262 @@
+<?php
+/**
+ * ezcSystemInfoTest
+ *
+ * @package SystemInformation
+ * @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 SystemInformation
+ * @subpackage Tests
+ */
+class ezcSystemInfoTest extends ezcTestCase
+{
+ public function testSystemInfoCpuCountTest()
+ {
+ $info = ezcSystemInfo::getInstance();
+ $cpuCount = $info->cpuCount;
+ if ( !is_int( $cpuCount ) || $cpuCount <= 0 )
+ {
+ self::fail( 'Amount of CPUs was not determined correctly' );
+ }
+ }
+
+ public function testSystemInfoCpuTypeTest()
+ {
+ $info = ezcSystemInfo::getInstance();
+ $cpuType = $info->cpuType;
+ $haveCpuVendor = preg_match( '/AMD|Intel|Cyrix/', $cpuType ) ? true :
false;
+
+ if ( !is_string( $cpuType ) || $cpuType=='' || !$haveCpuVendor )
+ {
+ self::fail( 'CPU type was not determined correctly' );
+ }
+ }
+
+ public function testSystemInfoCpuSpeedTest()
+ {
+ $info = ezcSystemInfo::getInstance();
+ $cpuSpeed = $info->cpuSpeed;
+
+ if ( !is_float($cpuSpeed) || $cpuSpeed <= 0 )
+ {
+ self::fail( 'CPU speed was not determined correctly' );
+ }
+ }
+
+ public function testSystemInfoOsNameTest()
+ {
+ $info = ezcSystemInfo::getInstance();
+ $osName = $info->osName;
+
+ $haveOsName = preg_match( '/Linux|FreeBSD|Windows|Mac/', $osName ) ?
true : false;
+
+ if ( !$haveOsName )
+ {
+ self::fail( 'OS name was not determined correctly' );
+ }
+ }
+
+ public function testSystemInfoOsTypeTest()
+ {
+ $info = ezcSystemInfo::getInstance();
+ $osType = $info->osType;
+
+ $haveOsType = preg_match( '/unix|win32|mac/', $osType ) ? true : false;
+
+ if ( !$haveOsType )
+ {
+ self::fail( 'OS type was not determined correctly' );
+ }
+ }
+
+ public function testSystemInfoMemorySizeTest()
+ {
+ $info = ezcSystemInfo::getInstance();
+ $memorySize = $info->memorySize;
+
+ if ( substr( php_uname( 's' ), 0, 7 ) == 'Windows' &&
!ezcBaseFeatures::hasExtensionSupport( "win32ps" ) )
+ {
+ // scanning of Total Physical memory not implemented for Windows
+ // without php_win32ps.dll extention installed
+ if ( $memorySize != null )
+ {
+ self::fail( 'OS memory size should be null in Windows when
win32ps extention is not installed in PHP' );
+ }
+ return;
+ }
+
+ if ( !is_int( $memorySize ) || $memorySize == 0 || $memorySize % 1024
!= 0 )
+ {
+ self::fail( 'OS memory size was not determined correctly' );
+ }
+ }
+
+ public function testSystemInfoFileSystemTypeTest()
+ {
+ $info = ezcSystemInfo::getInstance();
+ $fileSystemType = $info->fileSystemType;
+
+ $haveFileSysType = preg_match( '/unix|win32/', $fileSystemType ) ?
true : false;
+ if ( !$haveFileSysType )
+ {
+ self::fail( 'File System type was not determined correctly' );
+ }
+ }
+
+ public function testSystemInfoLineSeparatorTest()
+ {
+ $info = ezcSystemInfo::getInstance();
+ $lineSeparator = $info->lineSeparator;
+
+ if ( $lineSeparator != "\n" && $lineSeparator != "\r\n" &&
$lineSeparator != "\r" )
+ {
+ self::fail( 'Line separator was not determined correctly' );
+ }
+ }
+
+ public function testSystemInfoBackupFileNameTest()
+ {
+ $info = ezcSystemInfo::getInstance();
+ $backupFileName = $info->backupFileName;
+
+ if ( $backupFileName != "~" && $backupFileName != ".bak" )
+ {
+ self::fail( 'Backup file name was not determined correctly' );
+ }
+ }
+
+ public function testSystemInfoPhpVersionTest()
+ {
+ $phpVersion = ezcSystemInfo::phpVersion();
+ $waitVersion = explode( '.', phpVersion() );
+
+ self::assertEquals(
+ $phpVersion,
+ $waitVersion,
+ 'Php version was not determined correctly'
+ );
+ unset( $phpVersion );
+ $info = ezcSystemInfo::getInstance();
+ $phpVersion = $info->phpVersion;
+ self::assertEquals(
+ $phpVersion,
+ $waitVersion,
+ 'Php version was not determined correctly'
+ );
+ }
+
+ public function testSystemInfoIsShellExecutionTest()
+ {
+ $info = ezcSystemInfo::getInstance();
+ $isShellExecution = $info->isShellExecution;
+
+ self::assertEquals(
+ $isShellExecution,
+ true,
+ 'Execution from shell was not determined correctly'
+ );
+
+ unset ( $isShellExecution );
+ $isShellExecution = ezcSystemInfo::isShellExecution();
+ self::assertEquals(
+ $isShellExecution,
+ true,
+ 'Execution from shell was not determined correctly'
+ );
+ }
+
+ public function testSystemInfoPhpAcceleratorTest()
+ {
+ $testSample = null;
+ $info = ezcSystemInfo::getInstance();
+ $accelerator = $info->phpAccelerator;
+
+ if ( isset( $GLOBALS['_PHPA'] ) )
+ {
+ $testSample = new ezcSystemInfoAccelerator(
+ "ionCube PHP Accelerator", // name
+ "http://www.php-accelerator.co.uk", // url
+ $GLOBALS['_PHPA']['ENABLED'], // isEnabled
+ $GLOBALS['_PHPA']['iVERSION'], // version int
+ $GLOBALS['_PHPA']['VERSION'] // version string
+ );
+ self::assertEquals( $accelerator, $testSample, 'PHP Accelerator
not determined correctly' );
+ }
+ else if ( ezcBaseFeatures::hasExtensionSupport( "Turck MMCache" ) )
+ {
+ $testSample = new ezcSystemInfoAccelerator(
+ "Turck MMCache", // name
+ "http://turck-mmcache.sourceforge.net", // url
+ true, // isEnabled
+ false, // version int
+ false // version string
+ );
+ self::assertEquals( $accelerator, $testSample, 'PHP Accelerator
not determined correctly' );
+ }
+ else if ( ezcBaseFeatures::hasExtensionSupport( "eAccelerator" ) )
+ {
+ $testSample = new ezcSystemInfoAccelerator(
+ "eAccelerator", // name
+ "http://sourceforge.net/projects/eaccelerator/", // url
+ true, //
isEnabled
+ false, // version
int
+ phpversion('eAccelerator') // version
string
+ );
+ self::assertEquals( $accelerator, $testSample, 'PHP Accelerator
not determined correctly' );
+ }
+ else if ( ezcBaseFeatures::hasExtensionSupport( "apc" ) )
+ {
+ $testSample = new ezcSystemInfoAccelerator(
+ "APC", // name
+ "http://pecl.php.net/package/APC", // url
+ (ini_get( 'apc.enabled' ) != 0), // isEnabled
+ false, // version int
+ phpversion( 'apc' ) // version string
+ );
+ self::assertEquals( $accelerator, $testSample, 'PHP Accelerator
not determined correctly' );
+ }
+ else if ( ezcBaseFeatures::hasExtensionSupport( "Zend Performance
Suite" ) )
+ {
+ $testSample = new ezcSystemInfoAccelerator(
+ "Zend WinEnabler (Zend Performance Suite)",
// name
+ "http://www.zend.com/store/products/zend-win-enabler.php",
// url
+ true,
// isEnabled
+ false,
// version int
+ false
// version string
+ );
+ self::assertEquals( $accelerator, $testSample, 'PHP Accelerator
not determined correctly' );
+ }
+ else
+ {
+ self::assertEquals( $accelerator, null, 'phpAccelerator() should
return null' );
+ }
+ }
+
+ public function testGetInvalidProperty()
+ {
+ $info = ezcSystemInfo::getInstance();
+ try
+ {
+ $info->no_such_property;
+ $this->fail( 'Expected exception was not thrown' );
+ }
+ catch ( ezcBasePropertyNotFoundException $e )
+ {
+ $expected = "No such property name 'no_such_property'.";
+ $this->assertEquals( $expected, $e->getMessage() );
+ }
+ }
+
+ public static function suite()
+ {
+ return new PHPUnit_Framework_TestSuite( "ezcSystemInfoTest" );
+ }
+}
+?>
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components