design_2.txt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. eZ Component: Document, Design
  2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3. :Author: $Author$
  4. :Revision: $Revision$
  5. :Date: $Date$
  6. Design description
  7. ==================
  8. ezcDocument class (abstract)
  9. ----------------------------
  10. This class is the base class for each implemented markup format. The extending
  11. classes are named like 'ezcDocumentHtmlDocument'.
  12. The extending classes implement the required actions to load a file or string
  13. in the respective markup and return an arbitrary structure describing the
  14. document and containing all available markup information. For each document
  15. there will be at least a conversion to the DocBook__ format.
  16. The document classes may implement additional interfaces for direct access to
  17. some converted format, if there are shortcut implementations available, like
  18. the following example shows::
  19. <?php
  20. class ezcDocumentRstDocument extends ezcDocument implements
  21. ezcDocumentHtmlConversion
  22. {
  23. // Required by ezcDocumentHtmlConversion interface
  24. public function getAsHtml()
  25. {
  26. // Use direct conversion using `rst2html.py`
  27. }
  28. }
  29. ?>
  30. Beside loading a document all document classes need to implement save()
  31. method, which returns the document serialized as a string.
  32. ezcDocumentWikiBase class
  33. ^^^^^^^^^^^^^^^^^^^^^^^^^
  34. There may be extensions, like a basic wiki syntax parser, from the document
  35. class, which implement a set of parse helper functions for some set of markup
  36. languages.
  37. ezcDocumentConversion interface
  38. -------------------------------
  39. Interface that defines an abstract conversion class. Real conversion classes
  40. will implement conversion of the given document from one format to another.
  41. The names of that classes follow the pattern:
  42. 'ezcDocumentRstToHtmlConversion'.
  43. The main method of this abstract class, convert(), takes a document of the
  44. first format and returns a document in the other format. Both objects extend
  45. the ezcDocument class::
  46. <?php
  47. abstract class ezcDocumentConversion
  48. {
  49. /**
  50. * @return ezcDocument
  51. */
  52. abstract public function convert( ezcDocument $source );
  53. }
  54. ?>
  55. ezcDocumentXsltConversion
  56. ^^^^^^^^^^^^^^^^^^^^^^^^^
  57. There are a lot of conversions which may just work on the base of an XSLT. For
  58. all those conversions an abstract ezcDocumentXsltConversion class is provided,
  59. which just takes a set of XSLT files to apply to the XML of the source
  60. document and handles the selection of a proper XSLT engine.
  61. ezcDocumentManager
  62. ------------------
  63. The document manager knows about the document parsers to use for each format
  64. and offers a set of static convenient methods to change the used parser for a
  65. document type, or directly create a document from a string or file. The Syntax
  66. for accessing the document manager could look like::
  67. <?php
  68. ezcDocumentManager::setFormat( 'rst', 'myCustomRstDocument' );
  69. $doc = ezcDocumentManager::loadFile( 'rst', '/path/to/my.rst' );
  70. ?>
  71. The document manager initiall knows about all internal formats and has them
  72. registered.
  73. ezcDocumentConversionManager
  74. ----------------------------
  75. This won't be implemented in the first release.
  76. While you may call the conversion directly, the conversion manager has a set
  77. of registered conversion routes and offers you direct access to the document
  78. conversions, like::
  79. <?php
  80. $result = ezcDocumentConversionManager::convert(
  81. 'rst', 'xhtml', '/path/to/my.rst'
  82. );
  83. ?>
  84. There will be an interface to overwrite default conversion routes and add or
  85. change the classes used for some conversion.
  86. Multiple conversions
  87. ^^^^^^^^^^^^^^^^^^^^
  88. There may be multiple conversion implementations for a set of formats. A
  89. conversion from ezp4xml to HTML may not only be done by using an XSLT, but also
  90. using a simple templating enging, based on string replacements, or a
  91. ezcDocumentTemplateTieIn which uses ezcTemplate to convert between the
  92. documents.
  93. ezcDocumentValidation interface
  94. -------------------------------
  95. The document classes may implement the ezcDocumentValidation, which provides
  96. the method validate( $file ), which can be used to validate an input file
  97. before trying to load it.
  98. The XML based formats will usually implement this by checking against a
  99. RelaxNG based document definition.
  100. Algorithms
  101. ==========
  102. Transforming XML
  103. ----------------
  104. XML documents are transformed using XSLT stylesheets and XSL extension for
  105. PHP. Transformations are done with ezcDocXSLTTransformer class. Optionally
  106. the transformations may be done by the xsltrans CLI utility.
  107. Examples
  108. ========
  109. Examples for the usage of the ezcDocument API.
  110. Loading a document
  111. ------------------
  112. ::
  113. $doc = new ezcDocumentRstDocument();
  114. $doc->loadFile( '/path/to/my.rst' );
  115. Validating a set of documents
  116. -----------------------------
  117. ::
  118. $doc = new ezcDocumentXhtmlDocument();
  119. $result_1 = $doc->validate( '/path/to/first.htm' );
  120. $result_2 = $doc->validate( '/path/to/second.htm' );
  121. foreach ( $result_1 as $error )
  122. {
  123. echo "- {$error->msg} in {$error->line} in {$error->file}.\n";
  124. }
  125. Convert between documents
  126. -------------------------
  127. ::
  128. $doc = new ezcDocumentRstDocument();
  129. $doc->loadFile( '/path/to/my.rst' );
  130. $converter = new ezcDocumentRstToHtmlConversion();
  131. $converter->option->literalTag = 'code';
  132. $html = $converter->convert( $doc );
  133. // __toString() will of course be implemented, too.
  134. echo $doc->save();
  135. Using the document manager
  136. --------------------------
  137. ::
  138. ezcDocumentManager::setFormat( 'rst', 'myCustomRstHandler' );
  139. $doc = ezcDocumentManager::loadFile( 'rst', '/path/to/my.rst' );
  140. // All errors in the RST syntax should now be magically fixed.
  141. echo $doc;
  142. ..
  143. Local Variables:
  144. mode: rst
  145. fill-column: 79
  146. End:
  147. vim: et syn=rst tw=79