From: <nma...@us...> - 2006-04-05 19:48:08
|
Revision: 48 Author: nmarkgraf Date: 2006-04-05 12:47:43 -0700 (Wed, 05 Apr 2006) ViewCVS: http://svn.sourceforge.net/opendocumentphp/?rev=48&view=rev Log Message: ----------- More refactoring: - Deleted AllInclude.inc, OpenDocumentObjectAbstract and OpenDocumentAbstract. They are no longer needed. - Added a new test case for the MimeTypes class. Modified Paths: -------------- poc/src/OpenDocumentFactory.php poc/src/OpenDocumentFactoryTest.php poc/src/OpenDocumentPackage.php poc/src/content/Content.php poc/src/util/AbstractDocument.php poc/src/util/MimeTypes.php Added Paths: ----------- poc/src/util/MimeTypesTest.php Removed Paths: ------------- poc/src/AllInclude.inc poc/src/OpenDocumentAbstract.php poc/src/OpenDocumentObjectAbstract.php Deleted: poc/src/AllInclude.inc =================================================================== --- poc/src/AllInclude.inc 2006-04-05 15:52:08 UTC (rev 47) +++ poc/src/AllInclude.inc 2006-04-05 19:47:43 UTC (rev 48) @@ -1,38 +0,0 @@ -<?php -/** - * AllInclude include file - * - * I hope this is a temporay solution to the massiv require_once problem, - * but Axel is working on this, I hope. - * - * $Id$ - * - * @license GNU General Public License - * @copyright Copyright © 2006, Norman Markgraf, Alex Latchford, et al. - * @author Norman Markgraf <nma...@us...> - * @version $Revision$ - * @package OpenDocument - * - * @since 0.4.3 - */ - -// Our own stuff: -require_once( "OpenDocument.php" ); -require_once( "OpenDocumentAbstract.php" ); -require_once( "OpenDocumentObjectAbstract.php" ); -require_once( "OpenDocumentSingle.php" ); -require_once( "OpenDocumentPackage.php" ); -require_once( "styles/Style.php" ); -require_once( "styles/Styles.php" ); -require_once( "content/Content.php" ); -require_once( "meta/Meta.php" ); -require_once( "manifest/Manifest.php" ); -require_once( "content/Body.php" ); -require_once( "content/BodyText.php" ); -require_once( "content/BodyTable.php" ); -require_once( "styles/FontFaceDeclaration.php" ); -// Non-PEAR and not our stuff: -require_once( "others/ZipFile.php" ); -// PEAR stuff: -require_once( "Log.php" ); -?> \ No newline at end of file Deleted: poc/src/OpenDocumentAbstract.php =================================================================== --- poc/src/OpenDocumentAbstract.php 2006-04-05 15:52:08 UTC (rev 47) +++ poc/src/OpenDocumentAbstract.php 2006-04-05 19:47:43 UTC (rev 48) @@ -1,156 +0,0 @@ -<?php -/** - * OpenDocumentAbstract Class - * (C) by Norman Markgraf in 2006 - * - * OpenDocumentAbstract is the basic class for all OpenDocument classes - * - * $Id$ - * - * @license GNU General Public License - * @copyright Copyright © 2006, Norman Markgraf, Alex Latchford, et al. - * @author Norman Markgraf <nma...@us...> - * @version $Revision$ - * @package OpenDocument - * - * @since 0.3.0 - */ - -require_once( "util/ReleaseInformation.php" ); - -class OpenDocumentAbstract { - - /** - * Copyright notice for this package. - */ - const Copyright = "(C) in 2006 by Norman Markgraf, Alex Latchford, et al."; - - /** - * Name of this package. - */ - const PackageName = "OpenDocumentPHP"; - - /** - * Default mime type is set to a text document. - */ - const defaultMimeType = "application/vnd.oasis.opendocument.text"; - - /** - * The PEAR::Log logger - * - * @access protected - * @since 0.4.0 - */ - protected $logger; - - /** - * The mime type of the document - * - * @access protected - * @since 0.4.0 - */ - protected $mimetype; - - /** - * This is the storage for all OpenDocument objects - * - * @access protected - * @since 0.3.0 - */ - protected $DocumentObjects; - - /** - * This construtor will set the mimetype of this document and start logging. - * - * Therefor this line is included in this constructor: - * <code> - * $this->logger = &Log::factory( "null", "", "OpenDocument" ); - * </code> - * - * @param string $mimetype The mime type of this document. - * @access public - * @since 0.3.0 - */ - public function __construct( $mimetype = 0 ) { - $this->logger = &Log::factory( "null", "", "OpenDocument" ); - $this->logger->debug( "Constructing OpenDocumentAbstract." ); - - // make an array for all the Document Objects. - $this->DocumentObjects = array(); - - if (!empty($mimetype)) { - $this->mimetype = $mimetype; - } - } - - /** - * - * @access public - * @since 0.3.0 - */ - public function __destruct() { - $this->logger->debug( "OpenDocumentAbstract destructed." ); - $this->logger->close(); - } - - /** - * Returns revision information - * - * @return string Revision information. - * @access public - * @final - * @since 0.4.0 - */ - final public function getRevision() { - $Revision = ""; - return "(".substr("$Revision$",-2).")".ReleaseInformation::Revision; - } - - /** - * Returns release and revision information. - * - * @return string Release and revision information. - * @access public - * @final - * @since 0.4.0 - */ - final public function getRelease() { - return ReleaseInformation::Release.".".ReleaseInformation::Revision; - } - - /** - * Returns some informations about this package, release and copyright. - * - * @return string Package name, release and copyright. - * @access public - * @final - * @since 0.4.0 - */ - final public function getPackageInformation() { - return self::PackageName . " " . $this->getRelease() . " " . self::Copyright; - } - - /** - * - * @access public - * @final - * @since 0.4.0 - */ - final public function attachObserverToLogger( $observer ) { - $this->logger->attach( $observer ); - } - - /** - * Returns the setted mime type of this document. - * - * @return string Current mime type of this document. - * @access public - * @final - * @since 0.4.0 - */ - final public function getMimeType() { - return $this->mimetype; - } - -} -?> \ No newline at end of file Modified: poc/src/OpenDocumentFactory.php =================================================================== --- poc/src/OpenDocumentFactory.php 2006-04-05 15:52:08 UTC (rev 47) +++ poc/src/OpenDocumentFactory.php 2006-04-05 19:47:43 UTC (rev 48) @@ -13,36 +13,18 @@ * @since 0.4.0 */ -include_once ( "AllInclude.inc" ); - +require_once( "OpenDocument.php" ); +require_once( "OpenDocumentSingle.php" ); +require_once( "OpenDocumentPackage.php" ); +require_once( "util/MimeTypes.php" ); /** - * - * @author Alex Latchford <yaw...@us...> - * - * @since 0.4.1 - */ - /* -function __autoload($class_name) { - // There is no "void" class, so we must ignore it - if ($class_name != "void" ) { - // Classes in subdirectories have '_' instead of '/' or '\\' in their names. - require_once( strtr ( $class_name, "_", "/" ) . ".php" ); - } -} -*/ - -/** * The main factory class of OpenDocumentPHP * * This is the main factory class for OpenDocumentPHP. You can use like this: * <code> * <?php - * $SingleDoc = OpenDocumentFactory::createOpenDocument( - * "test.odc", "", true, "application/vnd.oasis.opendocument.calc" - * ); - * $PackageDoc = OpenDocumentFactory::createOpenDocument( - * "test.odt", "", false - * ); + * $SingleDoc = OpenDocumentFactory::createOpenDocument( true, "application/vnd.oasis.opendocument.image" ); + * $PackageDoc = OpenDocumentFactory::createOpenDocument( false ); * ?> * </code> * @@ -52,7 +34,6 @@ * @since 0.4.0 */ final class OpenDocumentFactory { - const defaultMimeType = "application/vnd.oasis.opendocument.text"; /** * Creates an OpenDocument. * @@ -68,11 +49,11 @@ * * @since 0.4.0 */ - static public function createOpenDocument( $documentName, $documentPath=0, $singleDocument = TRUE, $mimeType=self::defaultMimeType ) { + static public function createOpenDocument( $singleDocument = TRUE, $mimeType=MimeTypes::defaultMimeType ) { if ( $singleDocument ) { return new OpenDocumentSingle( $mimeType ); } else { - return new OpenDocumentPackage( $documentName, $documentPath, $mimeType ); + return new OpenDocumentPackage( $mimeType ); } } Modified: poc/src/OpenDocumentFactoryTest.php =================================================================== --- poc/src/OpenDocumentFactoryTest.php 2006-04-05 15:52:08 UTC (rev 47) +++ poc/src/OpenDocumentFactoryTest.php 2006-04-05 19:47:43 UTC (rev 48) @@ -20,7 +20,7 @@ class OpenDocumentFactoryTest extends PHPUnit2_Framework_TestCase { function testFactoryForSingleDocument() { - $OD = OpenDocumentFactory::createOpenDocument( "test.odf", "", true ); + $OD = OpenDocumentFactory::createOpenDocument( true ); $this->assertNotNull( $OD ); $this->assertType( "OpenDocumentSingle", $OD ); @@ -28,20 +28,21 @@ unset( $OD ); } + function testFactoryForMimetypeInSingleDocumentDefault() { + $OD = OpenDocumentFactory::createOpenDocument( true ); + $mimetype = $OD->getMimeType(); + $this->assertEquals( "application/vnd.oasis.opendocument.text", $OD->getMimeType(), "Default mimetype not set correctly (was:".$mimetype.")." ); + } + function testFactoryForMimetypeInSingleDocument() { - $OD = OpenDocumentFactory::createOpenDocument( "test.odf", "", true ); + $ODA = OpenDocumentFactory::createOpenDocument( true, "TestMimeType" ); + $mimetype = $ODA->getMimeType(); + $this->assertEquals( "TestMimeType", $ODA->getMimeType(), "Default mimetype not set correctly (was:".$mimetype.")." ); - $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 ); + $OD = OpenDocumentFactory::createOpenDocument( false ); $this->assertNotNull( $OD ); $this->assertType( "OpenDocumentPackage", $OD ); @@ -49,16 +50,16 @@ unset( $OD ); } + function testFactoryForMimetypeInPackageDocumentDefault() { + $OD = OpenDocumentFactory::createOpenDocument( false ); + $mimetype = $OD->getMimeType(); + $this->assertEquals( "application/vnd.oasis.opendocument.text", $OD->getMimeType(), "Default mimetype not set correctly (was:".$mimetype.")." ); + } + 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 ); + $ODA = OpenDocumentFactory::createOpenDocument( false, "TestMimeType" ); + $mimetype = $ODA->getMimeType(); + $this->assertEquals( "TestMimeType", $ODA->getMimeType(), "Default mimetype not set correctly (was:".$mimetype.")." ); } Deleted: poc/src/OpenDocumentObjectAbstract.php =================================================================== --- poc/src/OpenDocumentObjectAbstract.php 2006-04-05 15:52:08 UTC (rev 47) +++ poc/src/OpenDocumentObjectAbstract.php 2006-04-05 19:47:43 UTC (rev 48) @@ -1,74 +0,0 @@ -<?php -/** - * OpenDocumentObjectAbstract Class - * - * $Id$ - * - * @license GNU General Public License - * @copyright Copyright © 2006, Norman Markgraf, et al. - * @author Norman Markgraf <nma...@us...> - * @version $Revision$ - * @package OpenDocument - * @since 0.4.0 - */ - -require_once( "OpenDocumentAbstract.php" ); - -class OpenDocumentObjectAbstract extends OpenDocumentAbstract { - - /** - * @access protected - */ - protected $dom; - - /** - * @access protected - */ - protected $isCommited; - - /** - * - * @access public - * - * @since 0.4.0 - */ - public function __construct( $mimetype = 0 ) { - parent::__construct( $mimetype ); - $this->logger->debug( "Constructing OpenDocumentObjectAbstract." ); - $this->isCommited = false; - } - - /** - * - * @access public - * - * @since 0.4.0 - */ - public function __destruct() { - $this->logger->debug( "OpenDocumentObjectAbstract destructed." ); - parent::__destruct(); - } - /** - * - * @return DOMDocument - * @access public - * - * @since 0.4.0 - */ - public function get() { - return $this->dom; - } - - /** - * - * @access public - * - * @since 0.4.0 - */ - public function save( $filename ) { - $tmp =& $this->dom; - - $tmp->save( $filename ); - } -} -?> \ No newline at end of file Modified: poc/src/OpenDocumentPackage.php =================================================================== --- poc/src/OpenDocumentPackage.php 2006-04-05 15:52:08 UTC (rev 47) +++ poc/src/OpenDocumentPackage.php 2006-04-05 19:47:43 UTC (rev 48) @@ -17,16 +17,18 @@ */ require_once( "meta/Meta.php" ); require_once( "settings/Settings.php" ); +require_once( "content/Content.php" ); +require_once( "styles/Styles.php" ); +require_once( "content/Body.php" ); require_once( "content/Scripts.php" ); +require_once( "styles/AutomaticStyles.php" ); +require_once( "styles/AutomaticStylesSplitter.php" ); require_once( "styles/FontFaceDeclaration.php" ); require_once( "styles/FontFaceDeclSplitter.php" ); require_once( "styles/Style.php" ); -require_once( "styles/AutomaticStyles.php" ); require_once( "styles/MasterStyles.php" ); -require_once( "content/Body.php" ); -require_once( "OpenDocumentAbstract.php" ); require_once( "util/AbstractDocument.php" ); - +require_once( "util/MimeTypes.php" ); require_once( "others/ZipFile.php" ); class OpenDocumentPackage extends AbstractDocument implements OpenDocument { @@ -35,28 +37,19 @@ private $packagetmp; private $zip; private $isCommited; - // - public $tmp = "c:/TEMP/"; - public $path = ""; /** * * @access public * @since 0.4.0 */ - public function __construct( $documentName=0, $documentPath=0, $mimetype="application/vnd.oasis.opendocument.text" ) { + public function __construct( $mimetype=MimeTypes::Text ) { parent::__construct( $mimetype ); $this->isCommited = false; $this->zip = new ZipFile(); - if ( !empty( $documentName ) ) { - $this->setPackageName( $documentName ); - if ( !empty( $documentPath ) ) { - $this->path = $documentPath; - } - } $this->Manifest = new Manifest( $this->getMimeType() ); $this->Meta = new Meta(); Modified: poc/src/content/Content.php =================================================================== --- poc/src/content/Content.php 2006-04-05 15:52:08 UTC (rev 47) +++ poc/src/content/Content.php 2006-04-05 19:47:43 UTC (rev 48) @@ -17,7 +17,6 @@ require_once( "styles/FontFaceDeclaration.php" ); require_once( "styles/AutomaticStyles.php" ); require_once( "content/Body.php" ); -require_once( "OpenDocumentObjectAbstract.php" ); require_once( "util/NameSpaces.php" ); class Content { Modified: poc/src/util/AbstractDocument.php =================================================================== --- poc/src/util/AbstractDocument.php 2006-04-05 15:52:08 UTC (rev 47) +++ poc/src/util/AbstractDocument.php 2006-04-05 19:47:43 UTC (rev 48) @@ -89,9 +89,6 @@ * @since 0.4.7 */ public function __construct( $mimetype = 0 ) { - $this->logger = &Log::factory( "null", "", "OpenDocument" ); - $this->logger->debug( "Constructing AbstractDocument." ); - $this->mimetype = $mimetype; } @@ -101,8 +98,6 @@ * @since 0.3.0 */ public function __destruct() { - $this->logger->debug( "AbstractDocument destructed." ); - $this->logger->close(); } Modified: poc/src/util/MimeTypes.php =================================================================== --- poc/src/util/MimeTypes.php 2006-04-05 15:52:08 UTC (rev 47) +++ poc/src/util/MimeTypes.php 2006-04-05 19:47:43 UTC (rev 48) @@ -1,7 +1,25 @@ <?php /** - * NameSpaces Class + * MimeTypes Class * + * <b>Mimtype -> file suffix</b> + * vnd.oasis.opendocument.text -> .odt + * vnd.oasis.opendocument.text-template -> .ott + * vnd.oasis.opendocument.text-master -> .otm + * vnd.oasis.opendocument.text-web -> .oth + * vnd.oasis.opendocument.spreadsheet -> .ods + * vnd.oasis.opendocument.spreadsheet-template -> .ots + * vnd.oasis.opendocument.graphics -> .odg + * vnd.oasis.opendocument.graphics-template -> .otg + * vnd.oasis.opendocument.presentation -> .odp + * vnd.oasis.opendocument.presentation-template -> .otp + * vnd.oasis.opendocument.image -> .odi + * vnd.oasis.opendocument.image-template -> .oti + * vnd.oasis.opendocument.formula -> .odf + * vnd.oasis.opendocument.formula-template -> .otf + * vnd.oasis.opendocument.chart -> .odc + * vnd.oasis.opendocument.chart-template -> .otc + * * $Id$ * * @license GNU General Public License @@ -13,10 +31,108 @@ * @since 0.4.7 */ -class MimeTypes { - const Text = "application/vnd.oasis.opendocument.text"; - const Calc = "application/vnd.oasis.opendocument.calc"; - const defaultMimeType = "application/vnd.oasis.opendocument.text"; +class MimeTypes { + /** + * Mime type for texts + * @since 0.4.7 + */ + const Text = "application/vnd.oasis.opendocument.text"; + + /** + * Mime type for text templates + * @since 0.4.7 + */ + const TextTemplate = "application/vnd.oasis.opendocument.text-template"; + + /** + * Mime type for text master files + * @since 0.4.7 + */ + const TextMaster = "application/vnd.oasis.opendocument.text-master"; + + /** + * Mime type for text web + * @since 0.4.7 + */ + const TextWeb = "application/vnd.oasis.opendocument.text-web"; + + /** + * Mime type for spreadsheets + * @since 0.4.7 + */ + const Spreadsheet = "application/vnd.oasis.opendocument.spreadsheet"; + + /** + * Mime type for spreadsheets templates + * @since 0.4.7 + */ + const SpreadsheetTemplate = "application/vnd.oasis.opendocument.spreadsheet-template"; + + /** + * Mime type for graphics + * @since 0.4.7 + */ + const Graphics = "application/vnd.oasis.opendocument.graphics"; + + /** + * Mime type for graphics templates + * @since 0.4.7 + */ + const GraphicsTemplate = "application/vnd.oasis.opendocument.graphics-template"; + + /** + * Mime type for presentations + * @since 0.4.7 + */ + const Presentation = "application/vnd.oasis.opendocument.presentation"; + + /** + * Mime type for presentation templates + * @since 0.4.7 + */ + const PresentationTemplate = "application/vnd.oasis.opendocument.presentation-template"; + + /** + * Mime type for images + * @since 0.4.7 + */ + const Image = "application/vnd.oasis.opendocument.image"; + + /** + * Mime type for images templates + * @since 0.4.7 + */ + const ImageTemplate = "application/vnd.oasis.opendocument.image-template"; + + /** + * Mime type for formulars + * @since 0.4.7 + */ + const Formula = "application/vnd.oasis.opendocument.formula"; + + /** + * Mime type for formular templates + * @since 0.4.7 + */ + const FormulaTemplate = "application/vnd.oasis.opendocument.formula-template"; + + /** + * Mime type for charts + * @since 0.4.7 + */ + const Chart = "application/vnd.oasis.opendocument.chart"; + + /** + * Mime type for chart templates + * @since 0.4.7 + */ + const ChartTemplate = "application/vnd.oasis.opendocument.chart-template"; + + /** + * Default mime type is set to text + * @since 0.4.7 + */ + const defaultMimeType = "application/vnd.oasis.opendocument.text"; } ?> \ No newline at end of file Added: poc/src/util/MimeTypesTest.php =================================================================== --- poc/src/util/MimeTypesTest.php (rev 0) +++ poc/src/util/MimeTypesTest.php 2006-04-05 19:47:43 UTC (rev 48) @@ -0,0 +1,62 @@ +<?php +/** + * TestCase for MimeTypes class + * + * $Id$ + * + * @copyright Copyright © 2006, Norman Markgraf, et al. + * @license GNU General Public License + * @author Norman Markgraf <nma...@us...> + * @version $Revision$ + * @package OpenDocument + * @subpackage UnitTest + * @since 0.4.7 + */ + +require_once "PHPUnit2/Framework/TestCase.php"; +require_once "util/MimeTypes.php"; + +class MimeTypesTest extends PHPUnit2_Framework_TestCase { + const Text = "application/vnd.oasis.opendocument.text"; + const TextTemplate = "application/vnd.oasis.opendocument.text-template"; + const TextMaster = "application/vnd.oasis.opendocument.text-master"; + const TextWeb = "application/vnd.oasis.opendocument.text-web"; + const Spreadsheet = "application/vnd.oasis.opendocument.spreadsheet"; + const SpreadsheetTemplate = "application/vnd.oasis.opendocument.spreadsheet-template"; + const Graphics = "application/vnd.oasis.opendocument.graphics"; + const GraphicsTemplate = "application/vnd.oasis.opendocument.graphics-template"; + const Presentation = "application/vnd.oasis.opendocument.presentation"; + const PresentationTemplate = "application/vnd.oasis.opendocument.presentation-template"; + const Image = "application/vnd.oasis.opendocument.image"; + const ImageTemplate = "application/vnd.oasis.opendocument.image-template"; + const Formula = "application/vnd.oasis.opendocument.formula"; + const FormulaTemplate = "application/vnd.oasis.opendocument.formula-template"; + const Chart = "application/vnd.oasis.opendocument.chart"; + const ChartTemplate = "application/vnd.oasis.opendocument.chart-template"; + const defaultMimeType = "application/vnd.oasis.opendocument.text"; + + /** + * This test will check all mime types. + * @since 0.4.7 + */ + function testMimeTypes() { + $this->assertEquals( MimeTypes::Text, self::Text ); + $this->assertEquals( MimeTypes::TextTemplate, self::TextTemplate ); + $this->assertEquals( MimeTypes::TextMaster, self::TextMaster ); + $this->assertEquals( MimeTypes::TextWeb, self::TextWeb ); + $this->assertEquals( MimeTypes::Spreadsheet, self::Spreadsheet ); + $this->assertEquals( MimeTypes::SpreadsheetTemplate, self::SpreadsheetTemplate ); + $this->assertEquals( MimeTypes::Graphics, self::Graphics ); + $this->assertEquals( MimeTypes::GraphicsTemplate, self::GraphicsTemplate ); + $this->assertEquals( MimeTypes::Presentation, self::Presentation ); + $this->assertEquals( MimeTypes::PresentationTemplate, self::PresentationTemplate ); + $this->assertEquals( MimeTypes::Image, self::Image ); + $this->assertEquals( MimeTypes::ImageTemplate, self::ImageTemplate ); + $this->assertEquals( MimeTypes::Formula, self::Formula ); + $this->assertEquals( MimeTypes::FormulaTemplate, self::FormulaTemplate ); + $this->assertEquals( MimeTypes::Chart, self::Chart ); + $this->assertEquals( MimeTypes::ChartTemplate, self::ChartTemplate ); + $this->assertEquals( MimeTypes::defaultMimeType, self::defaultMimeType ); + } +} +?> \ No newline at end of file Property changes on: poc/src/util/MimeTypesTest.php ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |