|
From: <yaw...@us...> - 2006-03-08 23:15:33
|
Revision: 8 Author: yawnster Date: 2006-03-08 15:15:08 -0800 (Wed, 08 Mar 2006) ViewCVS: http://svn.sourceforge.net/opendocumentphp/?rev=8&view=rev Log Message: ----------- - Restructured class inclusion, it now uses __autoload() to do this automatically. - Now using a single file extension, (.php), this was done to help the __autoload() function, please check your Inbox for documentation on this. - Built in a UI to TestOutput.php to select Document Type - Removed all traces of .php3-5 extensions from the build.xml file. Modified Paths: -------------- poc/build.xml Added Paths: ----------- poc/src/OpenDocument.php poc/src/OpenDocumentAbstract.php poc/src/OpenDocumentContent.php poc/src/OpenDocumentContentBody.php poc/src/OpenDocumentContentBodyText.php poc/src/OpenDocumentFactory.php poc/src/OpenDocumentFactoryTest.php poc/src/OpenDocumentManifest.php poc/src/OpenDocumentManifestTest.php poc/src/OpenDocumentMeta.php poc/src/OpenDocumentMetaTest.php poc/src/OpenDocumentObjectAbstract.php poc/src/OpenDocumentPackage.php poc/src/OpenDocumentSingle.php poc/src/OpenDocumentStyle.php poc/src/TestOutput.php poc/src/ZipFile.php Modified: poc/build.xml =================================================================== --- poc/build.xml 2006-03-08 10:31:35 UTC (rev 7) +++ poc/build.xml 2006-03-08 23:15:08 UTC (rev 8) @@ -22,11 +22,7 @@ <coverage-setup database="reports/coverage.db"> <fileset dir="src"> <include name="**/*.php"/> - <include name="**/*.php3"/> - <include name="**/*.php5"/> <exclude name="**/*Test.php"/> - <exclude name="**/*Test.php3"/> - <exclude name="**/*Test.php5"/> </fileset> </coverage-setup> @@ -36,8 +32,6 @@ <batchtest> <fileset dir="src"> <include name="**/*Test.php"/> - <include name="**/*Test.php3"/> - <include name="**/*Test.php5"/> </fileset> </batchtest> </phpunit2> @@ -57,8 +51,6 @@ <batchtest> <fileset dir="src"> <include name="**/*Test.php"/> - <include name="**/*Test.php5"/> - <include name="**/*Test.php3"/> </fileset> </batchtest> </phpunit2> Added: poc/src/OpenDocument.php =================================================================== --- poc/src/OpenDocument.php (rev 0) +++ poc/src/OpenDocument.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,34 @@ +<?php +/** + * OpenDocument interface + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 5 $ + * @package OpenDocument + * + * $Id: OpenDocument.php5 5 2006-03-07 08:16:08Z nmarkgraf $ + */ +interface OpenDocument { + /** + * get the whole OpenDocument as string. + */ + public function get(); + + public function getMeta(); + + public function getContent(); + + public function getStyle(); + + /** + * get mimetype of the document + * + * @return string Mimetype of the document + */ + public function getMimeType(); + + // public function getSetting(); +} + +?> \ No newline at end of file Added: poc/src/OpenDocumentAbstract.php =================================================================== --- poc/src/OpenDocumentAbstract.php (rev 0) +++ poc/src/OpenDocumentAbstract.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,77 @@ +<?php +/** + * OpenDocumentAbstract Class + * (C) by Norman Markgraf in 2006 + * + * OpenDocumentAbstract is the basic class for all OpenDocument classes + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 6 $ + * @package OpenDocument + * + * $Id: OpenDocumentAbstract.php5 6 2006-03-08 09:19:19Z nmarkgraf $ + */ + +class OpenDocumentAbstract { + /** + * + */ + const Revision = "ALPHA"; + const Release = "0.4.1"; + const Copyright = "(C) in 2006 by Norman Markgraf published under GPL 2.0"; + const PackageName = "OpenDocumentPHP"; + + protected $logger; + + protected $mimetype; + + /** + * This is the storage for all OpenDocument objects + */ + protected $DocumentObjects; + + public function __construct( $mimetype = 0 ) { + $this->logger = &Log::factory( "null", "", "OpenDocument" ); + //$this->logger = &Log::factory( "file", "d:/PHP/OpenDocumentPHP.log", "OpenDocument" ); + $this->logger->debug( "Constructing OpenDocumentAbstract." ); + + $this->DocumentObjects = array(); + + if (!empty($mimetype)) { + $this->mimetype = $mimetype; + } + } + + /** + * + */ + public function __destruct() { + $this->logger->debug( "OpenDocumentAbstract destructed." ); + $this->logger->close(); + } + + final public function getRevision() { + return self::Revision; + } + + final public function getRelease() { + return self::Release.".".self::Revision; + } + + final public function getPackageInformation() { + return self::PackageName . " " . $this->getRelease() . " " . self::Copyright; + } + + final public function attachObserverToLogger( $observer ) { + $this->logger->attach( $observer ); + } + + final public function getMimeType() { + return $this->mimetype; + } + + +} + +?> \ No newline at end of file Added: poc/src/OpenDocumentContent.php =================================================================== --- poc/src/OpenDocumentContent.php (rev 0) +++ poc/src/OpenDocumentContent.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,128 @@ +<?php +/** + * OpenDocumentContent Class + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 6 $ + * @package OpenDocument + * + * $Id: OpenDocumentContent.php5 6 2006-03-08 09:19:19Z nmarkgraf $ + */ + +class OpenDocumentContent extends OpenDocumentObjectAbstract { + + private $root; + private $meta; + private $FontFaceDecl; + private $body; + private $text; + + /**I + * + */ + public function __construct( $dom=0 ) { + parent::__construct(); + $this->logger->debug( "Constructing OpenDocumentContent." ); + if (empty($dom)) { + // this is part of a package document + $this->dom = new DOMDocument( "1.0", "utf-8" ); + $this->dom->formatOutput = true; + + $this->root = $this->dom->createElementNS( self::NS_OFFICE, "office:document-content" ); + $this->root->setAttributeNS( self::NS_OFFICE, "office:version", "1.0" ); + + $this->content = $this->dom; + } else { + // this is part of a single document + $this->dom = $dom; + $this->content = $this->dom; + $this->root = $this->dom->createElementNS( self::NS_OFFICE, "office:content" ); + } + $this->FontFaceDecl = $this->dom->createElementNS( self::NS_OFFICE, "office:font-face-decl" ); + $this->body = new OpenDocumentContentBody( $this->dom ); +/* + $this->body = $this->dom->createElementNS( self::NS_OFFICE, "office:body" ); + $this->text = $this->dom->createElementNS( self::NS_OFFICE, "office:text" ); +*/ + + } + + /** + * + */ + public function __destruct() { + unset( $this->dom ); + unset( $this->root ); + unset( $this->meta ); + unset( $this->FontFaceDecl ); + } + + public function addNoScript() { + $this->root->appendChild( $this->dom->createElementNS( self::NS_OFFICE, "office:script" ) ); + } + + public function addFontFace( $name, $fontFamily ) { + $font = $this->dom->createElementNS( self::NS_STYLE, "style:font-face" ); + $font->setAttributeNS( self::NS_STYLE, "style:name", $name ); + $font->setAttributeNS( self::NS_SVG, "svg:font-family", $fontFamily ); + $this->FontFaceDecl->appendChild( $font ); + unset( $font ); + } + + public function addAutomaticStyles() { + + } + + public function addNoAutomaticStyles() { + $this->root->appendChild( $this->dom->createElementNS( self::NS_OFFICE, "office:automatics-sytles" ) ); + } + + +/* + <text:sequence-decls> + <text:sequence-decl text:display-outline-level="0" text:name="Illustration"/> + <text:sequence-decl text:display-outline-level="0" text:name="Table"/> + <text:sequence-decl text:display-outline-level="0" text:name="Text"/> + <text:sequence-decl text:display-outline-level="0" text:name="Drawing"/> + </text:sequence-decls> + +*/ + + public function getBody() { + return $this->body; + } + + + /** + * + */ + public function commit() { + $this->root->appendChild( $this->FontFaceDecl ); + // $this->body->appendChild( $this->text ); + $this->root->appendChild( $this->body->get() ); + $this->content->appendChild( $this->root ); + $this->dom->normalize(); + $this->isCommited = true; + } + + /** + * @return + */ + final public function get() { + if (!$this->isCommited) { + $this->commit(); + } + return $this->dom; + } + + /** + * + */ + final public function save( $filename ) { + $this->get()->save( $filename ); + } + +} + +?> \ No newline at end of file Added: poc/src/OpenDocumentContentBody.php =================================================================== --- poc/src/OpenDocumentContentBody.php (rev 0) +++ poc/src/OpenDocumentContentBody.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,76 @@ +<?php +/** + * OpenDocumentContentBody Class + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 2 $ + * @package OpenDocument.Content.Body + * @since POC 0.5 + * + * $Id: OpenDocumentContent.php5 2 2006-02-28 13:10:42Z nmarkgraf $ + */ + +class OpenDocumentContentBody extends OpenDocumentObjectAbstract { + + private $DomFragment; + private $body; + + private $Fragments; + + public function __construct( $dom ) { + parent::__construct(); + $this->logger->debug( "Constructing OpenDocumentContentBody." ); + + $this->dom = $dom; + $this->BodyFragment = $this->dom->createDocumentFragment(); + $this->body = $this->dom->createElementNS( self::NS_OFFICE, "office:body" ); + $this->Fragments = array(); + } + + public function commit() { + $this->logger->debug( "OpenDocumentContentBody->commit()" ); + foreach( $this->Fragments as $namespace => $class ) { + $tmp = $class->get(); + if (!empty( $tmp )) { + $this->BodyFragment->appendChild( $class->get() ); + } + } + if (!empty( $this->BodyFragment )) { + $this->body->appendChild( $this->BodyFragment ); + } + $this->isCommited = true; + } + + private function getByNamespace( $NS, $class ) { + $this->logger->debug( "OpenDocumentContentBody->getByNamespace(\"".$NS."\", \"".$class."\")" ); + if (!array_key_exists( $NS, $this->Fragments ) ) { + $this->Fragments[ $NS ] = new $class( $this->dom ); + } + return $this->Fragments[ $NS ]; + } + + public function getText() { + $this->logger->debug( "OpenDocumentContentBody->getText()" ); + return $this->getByNamespace( self::NS_TEXT, "OpenDocumentContentBodyText" ); + } + + public function getTable() { + $this->logger->debug( "OpenDocumentContentBody->getTable()" ); + return $this->getByNamespace( self::NS_TABLE, "OpenDocumentContentBodyTable" ); + } + + /** + * @return DOMDocumentFragment body fragment + */ + final public function get() { + $this->logger->debug( "OpenDocumentContentBody->get()" ); + if (!$this->isCommited) { + $this->commit(); + } + return $this->body; + } + +} + +?> \ No newline at end of file Added: poc/src/OpenDocumentContentBodyText.php =================================================================== --- poc/src/OpenDocumentContentBodyText.php (rev 0) +++ poc/src/OpenDocumentContentBodyText.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,78 @@ +<?php +/** + * OpenDocumentContentBodyText Class + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 2 $ + * @package OpenDocument.Content.Body.Text + * @since POC 0.5 + * + * $Id: OpenDocumentContent.php5 2 2006-02-28 13:10:42Z nmarkgraf $ + */ + +class OpenDocumentContentBodyText extends OpenDocumentObjectAbstract { + + public function __construct( $dom ) { + parent::__construct(); + $this->logger->debug( "Constructing OpenDocumentContentBodyText." ); + + $this->dom = $dom; + $this->text = $this->dom->createElementNS( self::NS_OFFICE, "office:text" ); + } + + public function commit() { + $this->logger->debug( "OpenDocumentContentBodyText->commit()" ); + $this->isCommited = true; + } + + public function getTextParagraph( $styleName, $parText=0 ) { + $this->logger->debug( "OpenDocumentContentBodyText->getTextParagraph(\"".$styleName."\",\"".$parText."\")" ); + if (empty($parText)) { + $par = $this->dom->createElementNS( self::NS_TEXT, "text:p" ); + } else { + $par = $this->dom->createElementNS( self::NS_TEXT, "text:p", $parText ); + } + $par->setAttributeNS( self::NS_STYLE, "style:name", $styleName ); + return $par; + } + + public function addToText( $Node ) { + $this->logger->debug( "OpenDocumentContentBodyText->addToText()" ); + $this->text->appendChild( $Node ); + } + + public function getTextHeading( $styleName, $headText=0 ) { + $this->logger->debug( "OpenDocumentContentBodyText->getTextHeading()" ); + if (empty($headText)) { + $head = $this->dom->createElementNS( self::NS_TEXT, "text:h" ); + } else { + $head = $this->dom->createElementNS( self::NS_TEXT, "text:h", $headText ); + } + $head->setAttributeNS( self::NS_STYLE, "style:name", $styleName ); + return $head; + } + + public function addNoForms() { + $this->logger->debug( "OpenDocumentContentBodyText->addNoForms()" ); + $forms = $this->dom->createElementNS( self::NS_OFFICE, "office:forms" ); + + $forms->setAttributeNS( self::NS_FORM, "form:automatic-focus", "false" ); + $forms->setAttributeNS( self::NS_FORM, "form:apply-design-mode", "false" ); + + $this->text->appendChild( $forms ); + unset( $forms ); + } + + /** + * @return DOMDocumentFragment body fragment + */ + final public function get() { + $this->logger->debug( "OpenDocumentContentBodyText->get()" ); + if (!$this->isCommited) { + $this->commit(); + } + return $this->text; + } +} +?> \ No newline at end of file Added: poc/src/OpenDocumentFactory.php =================================================================== --- poc/src/OpenDocumentFactory.php (rev 0) +++ poc/src/OpenDocumentFactory.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,38 @@ +<?php +/** + * OpenDocumentFactoy Class + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 7 $ + * @package OpenDocument + * + * $Id: OpenDocumentFactory.php5 7 2006-03-08 10:31:35Z nmarkgraf $ + */ + +function __autoload($class_name) { + if($class_name != 'Log_null') + { + require_once("$class_name.php"); + } +} + +class OpenDocumentFactory { + +/** + * Creates a OpenDocument. + * + * @return OpenDocument + */ + static public function createOpenDocument( $documentName, $documentPath=0, $singleDocument = TRUE, $mimeType="application/vnd.oasis.opendocument.text" ) { + if ( $singleDocument ) { + return new OpenDocumentSingle( $mimeType ); + return 0; + } else { + return new OpenDocumentPackage( $documentName, $documentPath, $mimeType ); + } + } + +} + +?> \ No newline at end of file Added: poc/src/OpenDocumentFactoryTest.php =================================================================== --- poc/src/OpenDocumentFactoryTest.php (rev 0) +++ poc/src/OpenDocumentFactoryTest.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,78 @@ +<?php +/** + * OpenDocumentFactoyTest Class + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 4 $ + * @package OpenDocumentTest + * + * $Id: OpenDocumentFactory.php5 4 2006-03-06 15:15:30Z nmarkgraf $ + */ +require_once "PHPUnit2/Framework/TestCase.php"; +require_once( "OpenDocumentFactory.php" ); +require_once( "OpenDocumentSingle.php" ); +require_once( "OpenDocumentPackage.php" ); + +class OpenDocumentFactoryTest extends PHPUnit2_Framework_TestCase { + + function testFactoryForSingleDocument() { + $OD = OpenDocumentFactory::createOpenDocument( "test.odf", "", true ); + $this->assertNotNull( $OD ); + + $this->assertType( "OpenDocumentSingle", $OD ); + + unset( $OD ); + } + + function testFactoryForMimetypeInSingleDocument() { + $OD = OpenDocumentFactory::createOpenDocument( "test.odf", "", true ); + + $this->assertEquals( "application/vnd.oasis.opendocument.text", $OD->getMimeType(), "Default mimetype not set correctly." ); + + $ODA = OpenDocumentFactory::createOpenDocument( "test.odf", "", true, "TestMimeType" ); + $this->assertEquals( "TestMimeType", $ODA->getMimeType(), "Default mimetype not set correctly." ); + + unset( $OD ); + unset( $ODA ); + } + + function testFactoryForPackageDocument() { + $OD = OpenDocumentFactory::createOpenDocument( "test.odf", "", false ); + $this->assertNotNull( $OD ); + + $this->assertType( "OpenDocumentPackage", $OD ); + + unset( $OD ); + } + + function testFactoryForMimetypeInPackageDocument() { + $OD = OpenDocumentFactory::createOpenDocument( "test.odf", "", false ); + + $this->assertEquals( "application/vnd.oasis.opendocument.text", $OD->getMimeType(), "Default mimetype not set correctly." ); + + $ODA = OpenDocumentFactory::createOpenDocument( "test.odf", "", false, "TestMimeType" ); + $this->assertEquals( "TestMimeType", $ODA->getMimeType(), "Default mimetype not set correctly." ); + + unset( $OD ); + unset( $ODA ); + } + + +/** + * Creates a OpenDocument. + * + * @return OpenDocument + static public function createOpenDocument( $documentName, $documentPath=0, $singleDocument = TRUE, $mimeType="application/vnd.oasis.opendocument.text" ) { + if ( $singleDocument ) { + return new OpenDocumentSingle( $mimeType ); + return 0; + } else { + return new OpenDocumentPackage( $documentName, $documentPath, $mimeType ); + } + } + */ + +} + +?> \ No newline at end of file Added: poc/src/OpenDocumentManifest.php =================================================================== --- poc/src/OpenDocumentManifest.php (rev 0) +++ poc/src/OpenDocumentManifest.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,125 @@ +<?php +/** + * OpenDocumentManifest.php + * + * Release information: + * 0.1 - 0.3 : 17/21-Feb-2006 (nm) Initial programmings + * 0.4 : 22-Feb-2006 (nm) Declared <c>getManifest<c> as deprecated. + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 5 $ + * @package OpenDocument + * + * $Id: OpenDocumentManifest.php5 5 2006-03-07 08:16:08Z nmarkgraf $ + */ + +class OpenDocumentManifest extends OpenDocumentObjectAbstract { + const odmPUBLIC = "-//OpenOffice.org//DTD Manifest 1.0//EN"; + const odmSYSTEM = "Manifest.dtd"; + const odmROOT = "manifest:manifest"; + + private $root; + + /** + * + */ + public function __construct( $mimetype = "application/vnd.oasis.opendocument.text" ) { + parent::__construct( $mimetype ); + $this->createManifestDOM(); + } + + /** + * + */ + public function __destruct() { + unset( $dom ); + unset( $root ); + unset( $mimetype ); + } + + /** + * + * @access private + */ + final private function createManifestDOM() { + $impl = new DOMImplementation; + + $dtd = $impl->createDocumentType( self::odmROOT, self::odmPUBLIC, self::odmSYSTEM ); + + $this->dom = $impl->createDocument( "", "", $dtd ); + $this->dom->encoding = "UTF-8"; + $this->dom->formatOutput = true; + + $this->root = $this->dom->createElementNS( self::NS_MANIFEST, self::odmROOT ); + + $node = $this->dom->createElementNS( self::NS_MANIFEST, "manifest:file-entry" ); + $node->setAttributeNS( self::NS_MANIFEST, "manifest:media-type", $this->mimetype ); + $node->setAttributeNS( self::NS_MANIFEST, "manifest:full-path", "/" ); + + $this->root->appendChild( $node ); + + unset( $impl ); + unset( $dtd ); + unset( $node ); + } + + /** + * + */ + final public function addEntryToManifest( $fullpath, $mimetype, $size=-1, $encrypt=0 ) { + $node = $this->dom->createElementNS( self::NS_MANIFEST, "manifest:file-entry" ); + $node->setAttributeNS( self::NS_MANIFEST, "manifest:mediatype", $mimetype ); + $node->setAttributeNS( self::NS_MANIFEST, "manifest:full-path", $filename ); + if ( $size >= 0 ) { + $node->setAttributeNS( self::NS_MANIFEST, "manifest:size", $size ); + } + if (!empty($encrypt)) { + $node->appendChild( $encrypt ); + } + $this->root->appendChild( $node ); + unset( $node ); + } + + /** + * + */ + final public function createEncryptionData( ) { + return $this->dom->createElmentNS( self::NS_MANIFEST, "manifest:encryption-data" ); + } + + /** + * Returns the whole OpenDocument Manifest as DOM. + * + * @access public + * + * @return DOM manifest as DOM. + */ + final public function get() { + $this->dom->appendChild( $this->root ); + $this->dom->normalize(); + return $this->dom; + } + + /** + * Same as <c>get<c>! + * + * @deprecated + */ + final public function getManifest() { + return $this->get(); + } + + /** + * Save the whole OpenDocument Manifest in a file + * + * @access public + * + * @param string name of file + */ + final public function save( $filename ) { + $this->get()->save( $filename ); + } +} + +?> \ No newline at end of file Added: poc/src/OpenDocumentManifestTest.php =================================================================== --- poc/src/OpenDocumentManifestTest.php (rev 0) +++ poc/src/OpenDocumentManifestTest.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,31 @@ +<?php +/** + * Test Class for OpenDocumentManifest + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 3 $ + * @package OpenDocumentUnitTest + * + * $Id: OpenDocumentManifestTest.php5 3 2006-03-04 20:33:26Z nmarkgraf $ + */ +require_once "PHPUnit2/Framework/TestCase.php"; +require_once "OpenDocumentManifest.php"; + +class OpenDocumentManifestTest extends PHPUnit2_Framework_TestCase { + + function testConstrution() { + + $ODM = new OpenDocumentManifest(); + + $this->assertNotNull( $ODM, "Error constructing OpenDocumentManifest without a given mimetype." ); + + $ODMMT = new OpenDocumentManifest( "alternateMimeType" ); + + $this->assertNotNull( $ODMMT, "Error constructing OpenDocumentManifest with a given mimetype." ); + + } + +} + +?> \ No newline at end of file Added: poc/src/OpenDocumentMeta.php =================================================================== --- poc/src/OpenDocumentMeta.php (rev 0) +++ poc/src/OpenDocumentMeta.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,220 @@ +<?php +/** + * OpenDocumentMeta Class + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 3 $ + * @package OpenDocument + * + * $Id: OpenDocumentMeta.php5 3 2006-03-04 20:33:26Z nmarkgraf $ + */ + +class OpenDocumentMeta extends OpenDocumentObjectAbstract { + + private $root; + private $meta; + + /** + * + */ + public function __construct( $dom=0 ) { + parent::__construct(); + + $this->logger->debug( "Constructing OpenDocumentMeta." ); + + if (empty($dom)) { + // this is part of a package document + $this->dom = new DOMDocument( "1.0", "utf-8" ); + $this->dom->formatOutput = true; + + $node = $this->dom->createElementNS( self::NS_OFFICE, "office:document-meta" ); + $node->setAttributeNS( self::NS_OFFICE, "office:version", "1.0" ); + + $this->dom->appendChild( $node ); + $this->meta = $node; + unset( $node ); + } else { + // this is part of a single document + $this->dom = $dom; + $this->meta = $this->dom; + } + $this->root = $this->dom->createElementNS( self::NS_OFFICE, "office:meta" ); + } + + /** + * + */ + public function __destruct() { + unset( $dom ); + unset( $root ); + unset( $meta ); + + $this->logger->debug( "OpenDocumentMeta destructed." ); + + parent::__destruct(); + } + + public function load( $filename ) { + $tmpDom = new DOMDocument(); + + if($tmpDom->load( $filename ) === false) { + trigger_error( 'Could not parse XML contents in OpenDocument file' ); + $this->logger->crit( "Could not parse XML contents in OpenDocument file" ); + return false; + } + + $OFFICE_PREFIX = $tmpDom->getElementsByTagNameNS( self::NS_OFFICE, "*").item( 0 )->prefix; + + // Figgure out if file is part of a package or a single document; + $isSingleDoc = (count($tmpDom->getElementsByTagNameNS( self::NS_OFFICE, $OFFICE_PREFIX.":document-meta" ))==0); + if ($isSingleDoc) { + $this->dom = $tmpDoc; + $this->meta = $tmpDoc; + } else { + $this->dom = $tmpDoc; + $this->meta = $tmtDoc->getElementsByTageNameNS( self::NS_OFFICE, $OFFICE_PREFIX.":document-meta").item( 0 ); + } + + $this->root = $this->dom->getElementsByTageNameNS( self::NS_OFFICE, $OFFICE_PREFIX.":meta").item( 0 ); + + return true; + } + + /** + * + */ + public function addDublinCore( $dc, $value) { + $this->logger->debug( "OpenDocumentMeta->addDublinCore: ". $value ."." ); + $node = $this->dom->createElementNS( self::NS_DC, "dc:".$dc, $value ); + $this->root->appendChild( $node ); + unset( $node ); + } + + /** + * + */ + public function getDublicCore( $dc ) { + $retValue = ""; + $nodelist = $this->dom->getElementsByTagNameNS( self::NS_DC, $dc ); + if ($nodelist->length == 1) { + $retValue = $nodelist->item( 0 )->nodeValue; + } + unset( $nodelist ); + $this->logger->debug( "OpenDocumentMeta->getDublinCore: ". $retValue ."." ); + return $retValue; + } + + /** + * + */ + public function addGenerator( $generator ) { + $lgenerator = ""; + + if (empty($generator)) { + $lgenerator = "OpenDocmentPHP/".$this->getRelease(); + } else { + $lgenerator = $generator; + } + + $this->logger->debug( "OpenDocumentMeta->addGenerator: ". $lgenerator ."." ); + + $node = $this->dom->createElementNS( self::NS_META, "meta:generator", $lgenerator ); + + $this->root->appendChild( $node ); + + unset( $lgenerator ); + } + + /** + * + */ + public function getGenerator() { + $retValue = ""; + + $nodelist = $this->dom->getElementsByTagNameNS( self::NS_META, "generator" ); + + if ($nodelist->length == 1) { + $retValue = $nodelist->item( 0 )->nodeValue; + } + unset( $nodelist ); + $this->logger->debug( "OpenDocumentMeta->getGenerator: ". $retValue ."." ); + return $retValue; + } + + /** + * + */ + public function addInitialCreator( $initialCreator ) { + $this->logger->debug( "OpenDocumentMeta->addInitialCreator: ". $initialCreator ."." ); + $node = $this->dom->createElementNS( self::NS_META, "meta:initial-creator", $initialCreator ); + $this->root->appendChild( $node ); + } + + /** + * + */ + public function getInitialCreator() { + $retValue = ""; + $nodelist = $this->dom->getElementsByTagNameNS( self::NS_META, "initial-creator" ); + if ($nodelist->length == 1) { + $retValue = $nodelist->item( 0 )->nodeValue; + } +// unset( $nodelist ); + $this->logger->debug( "OpenDocumentMeta->getInitialCreator: ". $retValue ."." ); + return $retValue; + } + + /** + * + */ + public function addUserDefinedMetadata( $name, $type, $value ) { + $node = $this->dom->createElementNS( self::NS_META, "meta:user-defined" ); + $node->setAttributeNS( self::NS_META, "meta:name", $name ); + if ( !empty( $type ) ) { + $node->setAttributeNS( self::NS_META, "meta:type", $type ); + } + if ( !empty( $value ) ) { + $node->setAttributeNS( self::NS_META, "meta:value", $value ); + } + $this->root->appendChild( $node ); + unset( $node ); + } + + /** + * + */ + public function commit() { + $this->meta->appendChild( $this->root ); + $this->dom->normalize(); + $this->isCommited = true; + $this->logger->debug( "OpenDocumentMeta->commit()." ); + } + + /** + * @depricated + */ + final public function getMeta() { + return $this->get(); + } + + /** + * @return + */ + final public function get() { + if (!$this->isCommited) { + $this->commit(); + } + $this->logger->debug( "OpenDocumentMeta->get()." ); + return $this->dom; + } + + /** + * + */ + final public function save( $filename ) { + $this->logger->debug( "OpenDocumentMeta->save(". $filename .")." ); + $this->get()->save( $filename ); + } + +} \ No newline at end of file Added: poc/src/OpenDocumentMetaTest.php =================================================================== --- poc/src/OpenDocumentMetaTest.php (rev 0) +++ poc/src/OpenDocumentMetaTest.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,129 @@ +<?php +/** + * Test class for OpenDocumentMeta + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 3 $ + * @package OpenDocumentUnitTest + * + * $Id: OpenDocumentMetaTest.php5 3 2006-03-04 20:33:26Z nmarkgraf $ + */ +require_once "PHPUnit2/Framework/TestCase.php"; +require_once "OpenDocumentMeta.php"; + + class OpenDocumentMetaTest extends PHPUnit2_Framework_TestCase + { + /** + * namespace OpenDocument office + */ + const NS_OFFICE = "urn:oasis:names:tc:opendocument:xmlns:office:1.0"; + /** + * namespace Dublin Core + */ + const NS_DC = "http://purl.org/dc/elements/1.1"; + + public function testConstructWithoutDom(){ + $ODM = new OpenDocumentMeta(); + + $this->assertNotNull( $ODM ); + + $resultDom = $ODM->get(); + $this->assertNotNull($resultDom, "No result." ); + //$this->assertType(new DOMC$resultDom, new DOMDocument(), "Result is not for type DOMDocument!" ); + + $xpath = new DOMXPath( $resultDom ); + $xpath->registerNamespace( "office", self::NS_OFFICE ); + + // test for right root tag + $query = "/office:document-meta"; + $entries = $xpath->query( $query ); + $this->assertEquals( 1, $entries->length, "Wrong root tag." ); + + // test for right version + $query = '/office:document-meta[@office:version="1.0"]'; + $entries = $xpath->query( $query ); + $this->assertEquals( 1, $entries->length, "Wrong document version." ); + + // test for right body tag + $query = "/office:document-meta/office:meta"; + $entries = $xpath->query( $query ); + $this->assertEquals( 1, $entries->length, "Wrong meta tag" ); + + unset( $ODM ); + unset( $resultDom ); + unset( $query ); + unset( $entries ); + } + + public function testConstructWithDom(){ + $testDom = new DOMDocument(); + + $ODM = new OpenDocumentMeta( $testDom ); + $this->assertNotNull( $ODM ); + + $resultDom = $ODM->get(); + $this->assertNotNull($resultDom, "No result." ); + //$this->assertType($resultDom, new DOMDocument(), "Result is not for type DOMDocument!" ); + + $xpath = new DOMXPath( $resultDom ); + $xpath->registerNamespace( "office", self::NS_OFFICE ); + + + // test for right root tag + $query = "/office:meta"; + $entries = $xpath->query( $query ); + $this->assertEquals( 1, $entries->length, "Wrong meta tag" ); + + unset( $ODM ); + unset( $resultDom ); + unset( $query ); + unset( $entries ); + } + + public function testAddGetDublinCore() { + $ODM = new OpenDocumentMeta(); + + $this->assertNotNull( $ODM ); + + $this->assertEquals( "", $ODM->getDublicCore( "xxx" ), "Returned Dublin Core should be empty, was not." ); + + $ODM->addDublinCore( "peek", "poke"); + $ODM->commit(); + + $this->assertEquals( "poke", $ODM->getDublicCore( "peek"), "Dublin Core entry was not correctly returned." ); + unset( $ODM ); + } + + public function testAddGetGenerator() { + $ODM = new OpenDocumentMeta(); + + $this->assertNotNull( $ODM ); + + $this->assertEquals( "", $ODM->getGenerator(), "Generator should be empty, was not." ); + + $ODM->addGenerator( "TEST" ); + $ODM->commit(); + + $this->assertEquals( "TEST", $ODM->getGenerator(), "Generator was not correctly returned. (".$ODM->getGenerator().")" ); + + unset( $ODM ); + } + + public function testAddGetInitialCreator() { + $ODM = new OpenDocumentMeta(); + + $this->assertNotNull( $ODM ); + + $this->assertEquals( "", $ODM->getInitialCreator(), "InitialCreator should be empty, was not." ); + + $ODM->addInitialCreator( "InitCreator" ); + $ODM->commit(); + + $this->assertEquals( "InitCreator", $ODM->getInitialCreator(), "InitialCreator was not correctly returned." ); + + unset( $ODM ); + } + + + } \ No newline at end of file Added: poc/src/OpenDocumentObjectAbstract.php =================================================================== --- poc/src/OpenDocumentObjectAbstract.php (rev 0) +++ poc/src/OpenDocumentObjectAbstract.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,115 @@ +<?php +/** + * OpenDocumentObjectAbstract Class + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 6 $ + * @package OpenDocument + * + * $Id: OpenDocumentObjectAbstract.php5 6 2006-03-08 09:19:19Z nmarkgraf $ + */ + +class OpenDocumentObjectAbstract extends OpenDocumentAbstract { + + /** + * namespace Dublin Core + */ + const NS_DC = "http://purl.org/dc/elements/1.1"; + + /** + * namespace OpenDocument meta + */ + const NS_META = "urn:oasis:names:tc:opendocument:xmlns:meta:1.0"; + + /** + * namespace OpenDocument office + */ + const NS_OFFICE = "urn:oasis:names:tc:opendocument:xmlns:office:1.0"; + + /** + * namespace OpenDocument manifest + */ + const NS_MANIFEST = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"; + + /** + * namespace OpenDocument style + */ + const NS_STYLE = "urn:oasis:names:tc:opendocument:xmlns:style:1.0"; + + /** + * namespace OpenDocument svg + */ + const NS_SVG = "urn:oasis:names:tc:openedocument:xmlsns:svg-compartible:1.0"; + + /** + * namespace OpenDocument fo (formation objects) + */ + const NS_FO = "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compartible:1.0"; + + /** + * namespace OpenDocument text + */ + const NS_TEXT = "urn:oasis:names:tc:opendocument:xmlns:text:1.0"; + + /** + * namespace OpenDocument draw + */ + const NS_DRAW = "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"; + + /** + * namespace OpenDocument table + */ + const NS_TABLE = "urn:oasis:names:tc:opendocument:xmlns:table:1.0"; + + /** + * namespace OpenDocument number + */ + const NS_NUMBER = "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"; + + /** + * namespace OpenDocument chart + */ + const NS_CHART = "urn:oasis:names:tc:opendocument:xmlns:chart:1.0"; + + /** + * namespace OpenDocument form + */ + const NS_FORM = "urn:oasis:names:tc:opendocument:xmlns:form:1.0"; + + + protected $dom; + + protected $isCommited; + + /** + * + */ + public function __construct( $mimetype = 0 ) { + parent::__construct( $mimetype ); + $this->logger->debug( "Constructing OpenDocumentObjectAbstract." ); + $this->isCommited = false; + } + + /** + * + */ + public function __destruct() { + $this->logger->debug( "OpenDocumentObjectAbstract destructed." ); + parent::__destruct(); + } + + public function get() { + return $this->dom; + } + + /** + * + */ + public function save( $filename ) { + $tmp =& $this->dom; + + $tmp->save( $filename ); + } +} +?> \ No newline at end of file Added: poc/src/OpenDocumentPackage.php =================================================================== --- poc/src/OpenDocumentPackage.php (rev 0) +++ poc/src/OpenDocumentPackage.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,233 @@ +<?php +/** + * OpenDocumentPackage Class + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 5 $ + * @package OpenDocument + * + * $Id: OpenDocumentPackage.php5 5 2006-03-07 08:16:08Z nmarkgraf $ + */ + +class OpenDocumentPackage extends OpenDocumentAbstract implements OpenDocument { + private $manifest; + private $packagename; + private $packagetmp; + private $zip; + private $isCommited; + // + public $tmp = "c:/TEMP/"; + public $path = ""; + + /** + * + */ + public function __construct( $documentName=0, $documentPath=0, $mimetype="application/vnd.oasis.opendocument.text" ) { + parent::__construct( $mimetype ); + + $this->logger->debug( "Constructing OpenDocumentPackage." ); + + $this->isCommited = false; + + $this->logger->debug( "Generating ZipFile object." ); + $this->zip = new ZipFile; + $this->logger->debug( "Generating OpenDocumentManifest with mimetype \"".$this->getMimeType()."\"." ); + $this->manifest = new OpenDocumentManifest( $this->getMimeType() ); + + if ( !empty( $documentName ) ) { + $this->setPackageName( $documentName ); + if ( !empty( $documentPath ) ) { + $this->path = $documentPath; + } + } + } + + /** + * + */ + public function __destruct() { + $this->logger->debug( "Destructing OpenDocumentPackage." ); + $this->removeTmpPackage(); + + unset( $this->manifest ); + unset( $this->packagename ); + unset( $this->packagetmp ); + unset( $this->tmp ); + unset( $this->path ); + + $this->logger->debug( "OpenDocumentPackage destructed." ); + + parent::__destruct(); + } + + /** + * + */ + public function createPackage() { + //$this->compartibility->makeDir( $this->packagetmp ); + } + + /** + * + */ + private function writeDOMToPackage( $fullpath, $dom ) { + //$dom->save( str_replace( "\\", "/", $this->packagetmp . $fullpath) ); + $tmp = str_replace( "\\", "/", $fullpath ); + + $this->logger->debug( "Write DOM to package, use fullpath \"" . $tmp . "\"." ); + $this->zip->addFile( $dom->saveXML(), $tmp ); + + unset( $tmp ); + } + + /** + * + */ + public function writeZIPFile( $data, $alt=0 ) { + if (empty($alt)) { + $tmp = $this->path . $this->packagename; + } else { + $tmp = $alt; + } + clearstatcache(); + + $this->logger->debug( "OpenDocumentPackage->writeZIPFile: Write zip file to \"". $tmp ."\"" ); + + if ( file_exists( $tmp ) ) { + $this->logger->warning( "OpenDocumentPackage->writeZIPFile: Found old file \"". $tmp ."\", so I remove it first!" ); + unlink( $tmp ); + } + $handle = fopen( $tmp, "wb" ); + fputs( $handle, $data ); + fclose( $handle ); + unset( $tmp ); + } + + /** + * + */ + private function removeTmpPackage() { + // $this->compartibility->removeDir( $this->packagetmp ); + } + + /** + * + */ + private function makeSubDir( $path ) { + //$this->compartibility->makeDir( $this->packagetmp . $this->compartibility->sep . $path ); + } + + /** + * + */ + public function setPackageName( $filename ) { + global $logger; + $this->logger->debug( "OpenDocumentPackage->setPackageName(" . $filename . ")." ); + $this->packagename = $filename; + //$this->packagetmp = $this->tmp . $filename . ".tmp" . $this->compartibility->sep; + $this->packagetmp = $this->tmp . $filename . ".tmp/"; + $this->logger->debug( "OpenDocumentPackage->set packagetmp to \"" . $this->packagetmp . "\" ..." ); + } + + /** + * + */ + public function getPackageName() { + return $this->packagename; + } + + /** + * + */ + public function addManifest( $manifest ) { + $this->logger->debug( "OpenDocumentPackage->addManifest(...)." ); + $this->manifest = $manifest; + } + + + /** + * + */ + public function addImage( $fullpath, $origimage, $mimetype ) { + $this->copyFileToPackage( $origimage, $fullpath ); + $this->makeSubDir( "Pictures" ); + $this->manifest->addEntryToManifest( $fullpath, $mimetype ); + } + + /** + * + */ + public function addXMLDocument( $fullpath, $dom, $mimetype="text/xml" ) { + $this->logger->info( "OpenDocumentPackage->addXMLDocument(" . $fullpath . ") with mimetype '" . $mimetype . "' to package '". $this->packagetmp . "'" ); + + $this->manifest->addEntryToManifest( $fullpath, $mimetype ); + $this->writeDOMToPackage( $fullpath, $dom ); + } + + private function commit() { + $this->logger->debug( "OpenDocumentPackage->commit()." ); + foreach($this->DocumentObjects as $key => $docObj) { + $this->logger->debug( "OpenDocumentPackage->commit: found \"" . $key . "\" in DocumentObjects array." ); + switch ($key) { + case "meta" : + $this->addXMLDocument( "meta.xml", $docObj->get() ); + break; + case "style" : + $this->addXMLDocument( "style.xml", $docObj->get() ); + break; + case "content" : + $this->addXMLDocument( "content.xml", $docObj->get() ); + break; +/* + case "settings" : + $this->addXMLDocument( "settings.xml", $dom ); + break; +*/ + } + } + + $this->writeDOMToPackage( "META-INF/manifest.xml" , $this->manifest->getManifest() ); + $this->logger->debug( "OpenDocumentPackage->commit: Write mimetype \"". $this->getMimeType()."\" to file \"mimetype\"..." ); + $this->zip->addFile( $this->getMimeType(), "mimetype" ); + $this->logger->debug( "OpenDocumentPackage->commit: Commited package named \"" . $this->packagename . "\"..." ); + + $this->isCommited = true; + } + + public function get() { + if (!($this->isCommited)) { + $this->commit(); + } + $this->logger->debug( "OpenDocumentPackage->get()" ); + return $this->zip->file(); + } + + public function save( $altFilename=0 ) { + $this->writeZIPFile( $this->get() ); + } + + public function getMeta() { + if (!array_key_exists ( "meta", $this->DocumentObjects) ) { + $this->DocumentObjects[ "meta" ] = new OpenDocumentMeta(); + } + return $this->DocumentObjects[ "meta" ]; + } + + public function getContent() { + if (!array_key_exists ( "content", $this->DocumentObjects) ) { + $this->DocumentObjects[ "content" ] = new OpenDocumentContent(); + } + return $this->DocumentObjects[ "content" ]; + } + + public function getStyle() { + if (!array_key_exists ( "style", $this->DocumentObjects) ) { + $this->DocumentObjects[ "style" ] = new OpenDocumentStyle(); + } + return $this->DocumentObjects[ "style" ]; + } + +} + +?> \ No newline at end of file Added: poc/src/OpenDocumentSingle.php =================================================================== --- poc/src/OpenDocumentSingle.php (rev 0) +++ poc/src/OpenDocumentSingle.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,99 @@ +<?php +/** + * OpenDocumentSingle Class + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 3 $ + * @package OpenDocument + * + * $Id: OpenDocumentPackage.php5 3 2006-03-04 20:33:26Z nmarkgraf $ + */ + +class OpenDocumentSingle extends OpenDocumentAbstract implements OpenDocument { + private $isCommited; + private $dom; + + /** + * + */ + public function __construct( $mimetype = "application/vnd.oasis.opendocument.text" ) { + parent::__construct( $mimetype ); + + $this->logger->debug( "Constructing OpenDocumentSingle." ); + + $this->isCommited = false; + + $this->dom = new DOMDocument( "1.0", "utf-8" ); + } + + /** + * + */ + public function __destruct() { + $this->logger->debug( "OpenDocumentSingle destructed." ); + + parent::__destruct(); + } + + /** + * + */ + public function addImage( $fullpath, $origimage, $mimetype ) { + $this->copyFileToPackage( $origimage, $fullpath ); + $this->makeSubDir( "Pictures" ); + $this->manifest->addEntryToManifest( $fullpath, $mimetype ); + } + + /** + * + */ + public function addXMLDocument( $fullpath, $domFrag, $mimetype="text/xml" ) { + $this->logger->info( "OpenDocumentSingle->addXMLDocument(" . $fullpath . ") with mimetype '" . $mimetype . "' to package '". $this->packagetmp . "'" ); + $this->dom->appendChild( $domFrag ); + } + + private function commit() { + $this->logger->debug( "OpenDocumentSingle->commit()" ); + foreach( $this->DocumentObjects as $key => $class) { + $class->commit(); + } + $this->isCommited = true; + } + + public function get() { + if (!($this->isCommited)) { + $this->commit(); + } + $this->logger->debug( "OpenDocumentSingle->get()" ); + return $this->dom->saveXML(); + } + + public function save( $altFilename=0 ) { + $this->writeZIPFile( $this->get() ); + } + + public function getMeta() { + if (!array_key_exists ( "meta", $this->DocumentObjects) ) { + $this->DocumentObjects[ "meta" ] = new OpenDocumentMeta( $this->dom ); + } + return $this->DocumentObjects[ "meta" ]; + } + + public function getContent() { + if (!array_key_exists ( "content", $this->DocumentObjects) ) { + $this->DocumentObjects[ "content" ] = new OpenDocumentContent( $this->dom ); + } + return $this->DocumentObjects[ "content" ]; + } + + public function getStyle() { + if (!array_key_exists ( "style", $this->DocumentObjects) ) { + $this->DocumentObjects[ "style" ] = new OpenDocumentStyle( $this->dom ); + } + return $this->DocumentObjects[ "style" ]; + } + +} + +?> \ No newline at end of file Added: poc/src/OpenDocumentStyle.php =================================================================== --- poc/src/OpenDocumentStyle.php (rev 0) +++ poc/src/OpenDocumentStyle.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,164 @@ +<?php +/** + * OpenDocumentStyle Class + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 2 $ + * @package OpenDocument + * + * $Id: OpenDocumentStyle.php5 2 2006-02-28 13:10:42Z nmarkgraf $ + */ + +class OpenDocumentStyle extends OpenDocumentObjectAbstract { + + private $root; + private $style; + private $FontFaceDecl; + private $Styles; + private $DefaultStyles; + /** + * + */ + public function __construct( $dom=0 ) { + parent::__construct(); + + if (empty($dom)) { + // this is part of a package document + $this->dom = new DOMDocument( "1.0", "utf-8" ); + $this->dom->formatOutput = true; + + $this->root = $this->dom->createElementNS( self::NS_OFFICE, "office:document-styles" ); + $this->root->setAttributeNS( self::NS_OFFICE, "office:version", "1.0" ); + + $this->style = $this->dom; + } else { + // this is part of a single document + $this->dom = $dom; + $this->style = $this->dom; + $this->root = $this->dom->createElementNS( self::NS_OFFICE, "office:style" ); + } + $this->FontFaceDecl = $this->dom->createElementNS( self::NS_OFFICE, "office:font-face-decl" ); + $this->Styles = array(); + $this->DefaultStyles = array(); + } + + /** + * + */ + public function __destruct() { + unset( $this->dom ); + unset( $this->root ); + unset( $this->style ); + } + + public function addFontFace( $name, $fontFamily, $genericFamily=0, $fontPitch=0, $fontCharset=0 ) { + $font = $this->dom->createElementNS( self::NS_STYLE, "style:font-face" ); + $font->setAttributeNS( self::NS_STYLE, "style:name", $name ); + $font->setAttributeNS( self::NS_SVG, "svg:font-family", $fontFamily ); + if (!empty($genericFamily)) { + $font->setAttributeNS( self::NS_STYLE, "style:font-family-genric", $genericFamily ); + } + if (!empty($fontPitch)) { + $font->setAttributeNS( self::NS_STYLE, "style:font-pitch", $fontPitch ); + } + if (!empty($fontCharset)) { + $font->setAttributeNS( self::NS_STYLE, "style:font-charset", $fontCharset ); + } + $this->FontFaceDecl->appendChild( $font ); + unset( $font ); + } + + public function getDom() { + return $this->dom; + } + + /** + * + * common family names: graphic, paragraph, table, table-row + */ + public function getDefaultStyle( $family=0 ) { + if (!empty($gamily) && array_key_exists($family, $this->DefaultStyles) ) { + return $this->DefaultStyles[$name]; + } else { + $node = $this->dom->createElementNS( self::NS_STYLE, "style:default-style" ); + if (!empty($family)) { + $node->setAttributeNS( self::NS_STYLE, "style:family", $family ); + } + return $node; + } + } + /** + * + * common family names: graphic, paragraph, table, table-row + */ + public function addDefaultStyle( $DefaultStyle, $family=0 ) { + if (empty($family)) { + $this->DefaultStyles[] = $DefaultStyle; + } else { + $this->DefaultStyles[$name] = $DefaultStyle; + } + } + + public function getStyle( $name ) { + if (array_key_exists($name, $this->Styles) ) { + return $this->Styles[$name]; + } else { + $node = $this->dom->createElementNS( self::NS_STYLE, "style:style" ); + $node->setAttributeNS( self::NS_STYLE, "style:name", $name ); + return $node; + } + } + + public function addStyle( $Style, $name=0 ) { + if (empty($name)) { + $this->Styles[] = $Style; + } else { + $this->Styles[$name] = $Style; + } + } + + + /** + * + */ + public function commit() { + $this->root->appendChild( $this->FontFaceDecl ); + $styleStyle = $this->dom->createElementNS( self::NS_OFFICE, "office:style" ); + + // Add all DefaultStyles + foreach( $this->DefaultStyles as $aDefaultStyle) { + $styleStyle->appendChild( $aDefaultStyle ); + } + + // Add all Styles + foreach( $this->Styles as $aStyle) { + $styleStyle->appendChild( $aStyle ); + } + $this->root->appendChild( $styleStyle ); + + $this->style->appendChild( $this->root ); + $this->dom->normalize(); + $this->isCommited = true; + } + + /** + * @return + */ + final public function get() { + if (!$this->isCommited) { + $this->commit(); + } + return $this->dom; + } + + /** + * + */ + final public function save( $filename ) { + $this->get()->save( $filename ); + } + +} + +?> \ No newline at end of file Added: poc/src/TestOutput.php =================================================================== --- poc/src/TestOutput.php (rev 0) +++ poc/src/TestOutput.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,195 @@ +<?php +/** + * SampleClass produces a little OpenDocument and send it to the client + * + * @copyright GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision: 6 $ + * @package OpenDocument.Samples + * + * $Id: TestOutput.php5 6 2006-03-08 09:19:19Z nmarkgraf $ + */ + +require_once( "OpenDocumentFactory.php" ); +require_once( "Log/observer.php" ); + +class TestOutput { + + private $logger; + + function __construct() { + /* ***TO DO *** This raises a warning ... + // $conf = array( "mode" => 0600 ); + $this->logger = &Log_observer::factory( "file", "D:/PHP/OpenDocument.log", "OpenDocument", $conf ); + $this->logger = &Log_observer::factory( "console", "", "OpenDocument" ); + */ + + /* + Console output: + $this->logger = &Log_observer::factory( "console", "", "OpenDocument" ); + + File output: + $this->logger = &Log_observer::factory( "file", "OpenDocument.log", "OpenDocument" ); + */ + } + + function makeMeta( $meta ) { + $meta->addDublinCore( "title", "This is a test!" ); + $meta->addDublinCore( "creator", "Norman Markgraf" ); + $meta->addDublinCore( "language", "en-EN" ); + $meta->addGenerator( "" ); + $meta->addInitialCreator( "Norman Markgraf" ); + } + + function makeContent( $content ) { + $content->addNoScript(); + + $content->addFontFace( "Test", "Tahoma" ); + + $content->addNoAutomaticStyles(); + + $text = $content->getBody()->getText(); + + $text->addNoForms(); + + $text->addToText( $text->getTextHeading( "Heading", "The first step" ) ); + $text->addToText( $text->getTextParagraph( "Paragraph", "This is a little test!" ) ); + } + + function makeStyle( $style ) { + $NS_STYLE = "urn:oasis:names:tc:opendocument:xmlns:style:1.0"; + $NS_FO = "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compartible:1.0"; + + $style->addFontFace( "Test", "Tahoma" ); + + // Set default style + $defStyle = $style->getDefaultStyle( "paragraph" ); + + $defProp = $style->getDom()->createElementNS( $NS_STYLE, "style:paragraph-properties" ); + $defProp->setAttributeNS( $NS_FO, "fo:hypenation-ladder-count", "no-limit" ); + $defProp->setAttributeNS( $NS_STYLE, "style:text-autospace", "ideograph-alpha" ); + $defProp->setAttributeNS( $NS_STYLE, "style:punctuation-wrap", "hanging" ); + $defProp->setAttributeNS( $NS_STYLE, "style:line-break", "strict" ); + $defProp->setAttributeNS( $NS_STYLE, "style:tab-stop-distance", "1.251cm" ); + $defProp->setAttributeNS( $NS_STYLE, "style:writeing-mode", "page" ); + $defStyle->appendChild( $defProp ); + + $defProp = $style->getDom()->createElementNS( $NS_STYLE, "style:text-properties" ); + $defProp->setAttributeNS( $NS_FO, "fo:font-size", "12pt" ); + $defProp->setAttributeNS( $NS_FO, "fo:language", "de" ); + $defProp->setAttributeNS( $NS_FO, "fo:country", "DE" ); + $defProp->setAttributeNS( $NS_FO, "fo:hyphenate", "false" ); + $defProp->setAttributeNS( $NS_FO, "fo:hypenation-remain-char-count", "2" ); + $defProp->setAttributeNS( $NS_FO, "fo:hypenation-push-char-count", "2" ); + $defProp->setAttributeNS( $NS_STYLE, "style:use-window-font-color", "true" ); + $defProp->setAttributeNS( $NS_STYLE, "style:font-name", "Times New Roman" ); + $defProp->setAttributeNS( $NS_STYLE, "style:font-name-asian", "Arial Unicode MS" ); + $defProp->setAttributeNS( $NS_STYLE, "style:font-size-asian", "12pt" ); + $defProp->setAttributeNS( $NS_STYLE, "style:language-asian", "none" ); + $defProp->setAttributeNS( $NS_STYLE, "style:country-asian", "none" ); + $defProp->setAttributeNS( $NS_STYLE, "style:font-name-complex", "Tahoma" ); + $defProp->setAttributeNS( $NS_STYLE, "style:font-site-complex", "12pt" ); + $defProp->setAttributeNS( $NS_STYLE, "style:language-complex", "none" ); + $defProp->setAttributeNS( $NS_STYLE, "style:country-complex", "none" ); + $defStyle->appendChild( $defProp ); + + $style->addDefaultStyle( $defStyle ); + + //Set a style + $aStyle = $style->getStyle( "Paragraph" ); + $aStyle->setAttributeNS ( $NS_STYLE, "style:family", "paragraph" ); + $aStyle->setAttributeNS ( $NS_STYLE, "style:class", "text" ); + + $style->addStyle( $aStyle, "Paragraph" ); + + //Set a style + $aStyle = $style->getStyle( "Heading" ); + $aStyle->setAttributeNS ( $NS_STYLE, "style:family", "paragraph" ); + $aStyle->setAttributeNS ( $NS_STYLE, "style:class", "text" ); + + $aStyleProp = $style->getDom()->createElementNS( $NS_STYLE, "style:paragraph-properties" ); + $aStyleProp->setAttributeNS ( $NS_FO, "fo:margin-top", "0.423cm" ); + $aStyleProp->setAttributeNS ( $NS_FO, "fo:margin-bottom", "0.212cm" ); + $aStyleProp->setAttributeNS ( $NS_FO, "fo:keep-with-next", "always" ); + $aStyle->appendChild( $aStyleProp ); + + $aStyleProp = $style->getDom()->createElementNS( $NS_STYLE, "style:text-properties" ); + $aStyleProp->setAttributeNS ( $NS_FO, "fo:font-size", "20pt" ); + $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-name", "Arial" ); + $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-name-asian", "MS Mincho" ); + $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-size-asian", "20pt" ); + $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-name-complex", "Tahoma1" ); + $aStyleProp->setAttributeNS ( $NS_STYLE, "style:font-size-complex", "20pt" ); + $aStyle->appendChild( $aStyleProp ); + + $style->addStyle( $aStyle, "Paragraph" ); + } + + function run($SingleDocument) { + if (!function_exists('gzencode')) { + $out = "<p>You have to enable zlib at compile time of your PHP! "; + $out .= "use <emph>--with-zlib=[DIR]</emph> at the <emph>configure</emph> "; + $out .= "procedure</p>"; + echo $out; + return; + } + + $DocumentName = "test.odt"; + + //header( "Content-type: application/odt" ); + //header( "Content-Disposition: attachment; filename=".$DocumentName ); + + + // Get a OpenDocument object from the factory: + + if(isset($SingleDocument)) + { + $TestDoc = OpenDocumentFactory::createOpenDocument( + $DocumentName, + "D:/PHP/OpenDocument/", + $SingleDocument + ); + + /* + $TestDoc->attachObserverToLogger( $this->logger ); + */ + + $this->makeMeta( $TestDoc->getMeta() ); + $this->makeStyle( $TestDoc->getStyle() ); + $this->makeContent( $TestDoc->getContent() ); + + echo $TestDoc->get(); + + //$TestDoc->save(); + } + + + } +} + +if(isset($_POST['SingleDocument'])) +{ + $SingleDocument = $_POST['SingleDocument']; + $TestOutput = new TestOutput(); + $TestOutput->run($SingleDocument); +} + + + +?> + +<html> +<head> +<title>TestOutput File!</title> +</head> +<body> +<form method="POST" action=""> + <fieldset> + <legend>Document Type:</legend> + Single <input type="radio" name="SingleDocument" value="TRUE" checked="checked" /> + Package <input type="radio" name="SingleDocument" value="FALSE" /><br /> + <input type="submit" value="Submit!" /> + </fieldset> +</form> +</body> +</html> Added: poc/src/ZipFile.php =================================================================== --- poc/src/ZipFile.php (rev 0) +++ poc/src/ZipFile.php 2006-03-08 23:15:08 UTC (rev 8) @@ -0,0 +1,184 @@ +<?php +/** + * Zip file creation class. + * Makes zip files. + * + * Based on : + * + * http://www.zend.com/codex.php?id=535&single=1 + * By Eric Mueller <er...@th...> + * + * http://www.zend.com/codex.php?id=470&single=1 + * by Denis125 <web...@at...> + * + * a patch from Peter Listiak <ml...@us...> for last modified + * date and time of the compressed file + * + * Official ZIP file format: http://www.pkware.com/appnote.txt + * + * @access public + */ +class ZipFile +{ + /** + * Array to store compressed data + * + * @var array $datasec + */ + var $datasec = array(); + + /** + * Central directory + * + * @var array $ctrl_dir + */ + var $ctrl_dir = array(); + + /** + * End of central directory record + * + * @var string $eof_ctrl_dir + */ + var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00"; + + /** + * Last offset position + * + * @var integer $old_offset + */ + var $old_offset = 0; + + + /** + * Converts an Unix timestamp to a four byte DOS date and time format (date + * in high two bytes, time in low two bytes allowing magnitude comparison). + * + * @param integer the current Unix timestamp + * + * @return integer the current date in a four byte DOS format + * + * @access private + */ + function unix2DosTime($unixtime = 0) { + $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime); + + ... [truncated message content] |