Author: ks
Date: Tue Nov 20 13:56:07 2007
New Revision: 6774

Log:
- Added custom tags support in ezp3->ezp4 converter.
- Added ezp32ezp4.php to examples.
- Fixed some minor stuff.

Added:
    experimental/Document/docs/example_autoload.php
    experimental/Document/docs/ezp32ezp4.php
Removed:
    experimental/Document/docs/html2docbook_autoload.php
Modified:
    experimental/Document/design/class_diagram.png
    experimental/Document/docs/html2docbook.php
    experimental/Document/src/converters/ezp3_ezp4.php
    experimental/Document/src/converters/ezp3_ezp4.xsl
    experimental/Document/src/converters/xhtml_docbook.php
    experimental/Document/src/converters/xhtml_docbook.xsl
    experimental/Document/src/document_autoload.php
    experimental/Document/tests/files/ezp3_sample.xml

Modified: experimental/Document/design/class_diagram.png
==============================================================================
Binary files - no diff available.

Added: experimental/Document/docs/example_autoload.php
==============================================================================
--- experimental/Document/docs/example_autoload.php (added)
+++ experimental/Document/docs/example_autoload.php [iso-8859-1] Tue Nov 20 
13:56:07 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/docs/ezp32ezp4.php
==============================================================================
--- experimental/Document/docs/ezp32ezp4.php (added)
+++ experimental/Document/docs/ezp32ezp4.php [iso-8859-1] Tue Nov 20 13:56:07 
2007
@@ -1,0 +1,23 @@
+<?php
+require_once 'example_autoload.php';
+
+if ( count( $argc ) < 1 || count( $argc ) > 2 )
+{
+  echo "\nUsage: ezp32ezp4 <ezp3 xml filename> [<ezp4 xml filename>]\n";
+  die();
+}
+
+$ezp3 = file_get_contents( $argv[1] );
+
+$docEzp3 = new ezcDocumentXML( 'ezp4', $ezp3 );
+
+$converter = new ezcDocumentEzp3ToEzp4( array( 'inline_custom_tags' => array( 
'sub', 'sup', 'strike' ) ) );
+$docEzp4 = $converter->convert( $docEzp3 );
+$result = $docEzp4->getXML();
+
+if ( isset( $argv[2] ) )
+    file_put_contents( $argv[2], $result );
+else
+    echo "Docbook:\n" . $result;
+
+?>

Modified: experimental/Document/docs/html2docbook.php
==============================================================================
--- experimental/Document/docs/html2docbook.php [iso-8859-1] (original)
+++ experimental/Document/docs/html2docbook.php [iso-8859-1] Tue Nov 20 
13:56:07 2007
@@ -1,5 +1,5 @@
 <?php
-require_once 'html2docbook_autoload.php';
+require_once 'example_autoload.php';
 
 if ( count( $argc ) < 1 || count( $argc ) > 2 )
 {

Modified: experimental/Document/src/converters/ezp3_ezp4.php
==============================================================================
--- experimental/Document/src/converters/ezp3_ezp4.php [iso-8859-1] (original)
+++ experimental/Document/src/converters/ezp3_ezp4.php [iso-8859-1] Tue Nov 20 
13:56:07 2007
@@ -1,14 +1,12 @@
 <?php
 
 /**
- * File containing the ezcDocument class
+ * File containing the ezcDocumentEzp3ToEzp4 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.
  *
  */
 
@@ -37,11 +35,29 @@
     private $parameters = array();
 
     /**
+     * XPath sting to select all inline custom tags by 'name' attribute
+     * Used in XSLT.
+     *
+     * @var string
+     */
+    static private $inlineCustomTags = '';
+
+    /**
      * Constructs new converter
+     *
+     * @param $parameters 
      */
     public function __construct( $parameters = array() )
     {
         $this->parameters = $parameters;
+
+        if ( isset( $this->parameters['inline_custom_tags'] ) )
+        foreach( $this->parameters['inline_custom_tags'] as $key=>$tagname )
+        {
+            ezcDocumentEzp3ToEzp4::$inlineCustomTags .= "@name = '$tagname'";
+            if ( $key != count( $parameters['inline_custom_tags'] ) - 1 )
+                ezcDocumentEzp3ToEzp4::$inlineCustomTags .= ' or ';
+        }
     }
 
     /**
@@ -51,22 +67,28 @@
      */
     static public function convert( ezcDocument $doc, $parameters = array() )
     {
-        if ( !ezcDocumentXhtmlToDocbook::$proc )
+        if ( !ezcDocumentEzp3ToEzp4::$proc )
         {
-            if ( !ezcDocumentXhtmlToDocbook::$xslt )
+            if ( !ezcDocumentEzp3ToEzp4::$xslt )
             {
-                ezcDocumentXhtmlToDocbook::$xslt = new DOMDocument;
-                ezcDocumentXhtmlToDocbook::$xslt->load( dirname( __FILE__ ) . 
'/../converters/ezp3_ezp4.xsl' );
+                ezcDocumentEzp3ToEzp4::$xslt = new DOMDocument;
+                ezcDocumentEzp3ToEzp4::$xslt->load( dirname( __FILE__ ) . 
'/../converters/ezp3_ezp4.xsl' );
             }
-            ezcDocumentXhtmlToDocbook::$proc = new XSLTProcessor;
-            ezcDocumentXhtmlToDocbook::$proc->importStyleSheet( 
ezcDocumentXhtmlToDocbook::$xslt );
+            ezcDocumentEzp3ToEzp4::$proc = new XSLTProcessor;
+            ezcDocumentEzp3ToEzp4::$proc->importStyleSheet( 
ezcDocumentEzp3ToEzp4::$xslt );
+            ezcDocumentEzp3ToEzp4::$proc->registerPHPFunctions();
         }
 
         // XSLT transformation
-        $resultDOM = ezcDocumentXhtmlToDocbook::$proc->transformToDoc( 
$doc->getDOM() );
+        $resultDOM = ezcDocumentEzp3ToEzp4::$proc->transformToDoc( 
$doc->getDOM() );
 
-        $resultDoc = new ezcDocumentXML( 'docbook', $resultDOM);
+        $resultDoc = new ezcDocumentXML( 'ezp4', $resultDOM);
         return $resultDoc;
+    }
+    
+    static public function getInlineCustomTags()
+    {
+        return ezcDocumentEzp3ToEzp4::$inlineCustomTags;
     }
 
 }

Modified: experimental/Document/src/converters/ezp3_ezp4.xsl
==============================================================================
--- experimental/Document/src/converters/ezp3_ezp4.xsl [iso-8859-1] (original)
+++ experimental/Document/src/converters/ezp3_ezp4.xsl [iso-8859-1] Tue Nov 20 
13:56:07 2007
@@ -3,7 +3,8 @@
                 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";               
  
                 xmlns:set="http://exslt.org/sets";
                 xmlns:dyn="http://exslt.org/dynamic";
-                extension-element-prefixes="set dyn"
+                xmlns:php="http://php.net/xsl";
+                extension-element-prefixes="set dyn php"
                 exclude-result-prefixes="xsl">
 
 <xsl:output method="xml" indent="yes" />
@@ -39,7 +40,7 @@
 </xsl:template>
 
 <!-- A common template for inline tags -->
-<xsl:template 
match="line|strong|emphasize|embed-inline|custom-inline|anchor|link|text()" 
mode="common">
+<xsl:template name="inline_common" 
match="line|strong|emphasize|embed-inline|anchor|link|text()" mode="common">
  <xsl:choose>
    <!-- If a parent is paragraph -->
    <xsl:when test="boolean(parent::paragraph)">
@@ -73,15 +74,35 @@
  </p>
 </xsl:template>
  
-<!-- Specific templates for block tags -->
+<!-- Common template for block tags -->
 <xsl:template match="embed|table|tr|td|th|ol|ul|li|literal|custom" 
mode='common'>
+ <xsl:choose>
+  <xsl:when test="name() = 'custom' and 
dyn:evaluate(php:function('ezcDocumentEzp3ToEzp4::getInlineCustomTags'))">
+   <xsl:call-template name='inline_common'/>
+  </xsl:when>
+  <xsl:when test="name() = 'embed'">
+   <xsl:apply-templates mode="special" select="."/>
+  </xsl:when>
+  <xsl:otherwise>
+   <xsl:copy>
+    <xsl:copy-of select="@*" />
+    <xsl:apply-templates/>
+   </xsl:copy>
+  </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Specific templates for tags -->
+<xsl:template match='embed|embed-inline' mode='special'>
  <xsl:copy>
-  <xsl:copy-of select="@*" />
-  <xsl:apply-templates/>
+    <xsl:copy-of select="@*[name() != 'href']" />
+    <xsl:attribute name='src'>
+     <xsl:value-of select='@href'/>
+    </xsl:attribute>
+    <xsl:apply-templates/>
  </xsl:copy>
 </xsl:template>
 
-<!-- Specific templates for inline tags -->
 <xsl:template match="line" mode="special">
    <xsl:apply-templates mode="common"/>
    <xsl:variable name="nextname" select="name(following-sibling::node()[1])" />
@@ -89,13 +110,6 @@
                  and ($nextname != 'embed') and ($nextname != 'table') and 
($nextname != 'ol') and ($nextname != 'ul') and ($nextname != 'literal') and 
($nextname != 'custom')">
     <br />
    </xsl:if>
-</xsl:template>
-
-<xsl:template match="strong|emphasize" mode="special">
- <xsl:copy>
-  <xsl:copy-of select="@*" />
-  <xsl:apply-templates/>
- </xsl:copy>
 </xsl:template>
 
 <xsl:template match="link" mode="special">
@@ -106,7 +120,18 @@
 </xsl:template>
 
 <xsl:template match="text()" mode="special">
- <xsl:copy-of select="."/>
+ <xsl:choose>
+  <xsl:when test="normalize-space(.) = ''"></xsl:when>
+  <xsl:otherwise><xsl:copy/></xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- For all other inline tags -->
+<xsl:template match="strong|emphasize|anchor|custom" mode="special">
+ <xsl:copy>
+  <xsl:copy-of select="@*" />
+  <xsl:apply-templates/>
+ </xsl:copy>
 </xsl:template>
 
 </xsl:stylesheet>

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] Tue Nov 
20 13:56:07 2007
@@ -1,14 +1,12 @@
 <?php
 
 /**
- * File containing the ezcDocument class
+ * File containing the ezcDocumentXhtmlToDocbook 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.
  *
  */
 

Modified: experimental/Document/src/converters/xhtml_docbook.xsl
==============================================================================
--- experimental/Document/src/converters/xhtml_docbook.xsl [iso-8859-1] 
(original)
+++ experimental/Document/src/converters/xhtml_docbook.xsl [iso-8859-1] Tue Nov 
20 13:56:07 2007
@@ -13,8 +13,8 @@
             doctype-public="-//OASIS//DTD Simplified DocBook XML V1.0//EN"
             
doctype-system="http://www.oasis-open.org/docbook/xml/simple/1.0/sdocbook.dtd"/>
             
-<xsl:param name="filename"></xsl:param> 
-<xsl:param name="prefix">wb</xsl:param>
+<!--<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 -->

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] Tue Nov 20 
13:56:07 2007
@@ -13,6 +13,7 @@
     'ezcDocument'               => 'Document/interfaces/document.php',
     'ezcDocumentConverter'      => 'Document/interfaces/converter.php',
     'ezcDocumentBinary'         => 'Document/document_binary.php',
+    'ezcDocumentEzp3ToEzp4'     => 'Document/converters/ezp3_ezp4.php',
     'ezcDocumentOutput'         => 'Document/output.php',
     'ezcDocumentParser'         => 'Document/parser.php',
     'ezcDocumentText'           => 'Document/document_text.php',

Modified: experimental/Document/tests/files/ezp3_sample.xml
==============================================================================
--- experimental/Document/tests/files/ezp3_sample.xml [iso-8859-1] (original)
+++ experimental/Document/tests/files/ezp3_sample.xml [iso-8859-1] Tue Nov 20 
13:56:07 2007
@@ -3,7 +3,7 @@
     <section>
         <header>Header 1</header>
         <paragraph class="pRed">abc
-            <strong>def</strong><embed 
src="eznode://123"/>ghi<strong>jkl</strong></paragraph>
+            <strong>def</strong><embed 
href="eznode://123"/>ghi<strong>jkl</strong></paragraph>
         <section>
             <header>Header 1.1</header>
             <paragraph>Text 1.1</paragraph>
@@ -12,6 +12,17 @@
     <section>
         <header>Header 2</header>
         <paragraph><line>line 1</line><line>line 2</line></paragraph>
+        <paragraph>Inline custom tag:<custom name='sub'/> Block custom 
tag:<custom name='factbox'/></paragraph>
+        <paragraph>Embed inline:<embed-inline href="eznode://123"/> Embed 
block: <embed href="eznode://123"/></paragraph>
+        <paragraph><anchor name='self'/><link 
href='#self'>linked</link></paragraph>
+        <paragraph><ol>
+        <li><ul>
+            <li><paragraph>element 1.1</paragraph></li>
+            <li><paragraph>element 1.2</paragraph></li>
+            </ul>
+        </li>
+        <li><paragraph>element 2</paragraph></li>
+        </ol></paragraph>
     </section>
 </section>
 


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to