|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZXMLText class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package kernel 00009 */ 00010 00011 /*! 00012 \class eZXMLText ezxmltext.php 00013 \ingroup eZDatatype 00014 \brief The class eZXMLText handles XML text data type instances 00015 00016 */ 00017 00018 class eZXMLText 00019 { 00020 function eZXMLText( $xmlData, $contentObjectAttribute ) 00021 { 00022 $this->XMLData = $xmlData; 00023 $this->ContentObjectAttribute = $contentObjectAttribute; 00024 $this->XMLInputHandler = null; 00025 $this->XMLOutputHandler = null; 00026 $this->PDFOutputHandler = null; 00027 } 00028 00029 function attributes() 00030 { 00031 return array( 'input', 00032 'output', 00033 'pdf_output', 00034 'xml_data', 00035 'is_empty' ); 00036 } 00037 00038 function hasAttribute( $name ) 00039 { 00040 return in_array( $name, $this->attributes() ); 00041 } 00042 00043 function attribute( $name ) 00044 { 00045 switch ( $name ) 00046 { 00047 case 'input' : 00048 { 00049 if ( $this->XMLInputHandler === null ) 00050 { 00051 $this->XMLInputHandler = $this->inputHandler( $this->XMLData, false, true, $this->ContentObjectAttribute ); 00052 } 00053 return $this->XMLInputHandler; 00054 }break; 00055 00056 case 'output' : 00057 { 00058 if ( $this->XMLOutputHandler === null ) 00059 { 00060 $this->XMLOutputHandler = $this->outputHandler( $this->XMLData, false, true, $this->ContentObjectAttribute ); 00061 } 00062 return $this->XMLOutputHandler; 00063 }break; 00064 00065 case 'pdf_output' : 00066 { 00067 if ( $this->PDFOutputHandler === null ) 00068 { 00069 $this->PDFOutputHandler = $this->outputHandler( $this->XMLData, 'ezpdf', true, $this->ContentObjectAttribute ); 00070 } 00071 return $this->PDFOutputHandler; 00072 }break; 00073 00074 case 'xml_data' : 00075 { 00076 return $this->XMLData; 00077 }break; 00078 00079 case 'is_empty' : 00080 { 00081 $isEmpty = true; 00082 $dom = new DOMDocument( '1.0', 'utf-8' ); 00083 if ( !$this->XMLData ) 00084 { 00085 return $isEmpty; 00086 } 00087 $success = $dom->loadXML( $this->XMLData ); 00088 if ( $success ) 00089 { 00090 $sectionNode = $dom->documentElement; 00091 00092 if ( $sectionNode->childNodes->length > 0 ) 00093 { 00094 $isEmpty = false; 00095 } 00096 } 00097 return $isEmpty; 00098 }break; 00099 00100 default: 00101 { 00102 eZDebug::writeError( "Attribute '$name' does not exist", __METHOD__ ); 00103 $retValue = null; 00104 return $retValue; 00105 }break; 00106 } 00107 } 00108 00109 /// \static 00110 static function inputHandler( &$xmlData, $type = false, $useAlias = true, $contentObjectAttribute = false ) 00111 { 00112 $optionArray = array( 'iniFile' => 'ezxml.ini', 00113 'iniSection' => 'InputSettings', 00114 'iniVariable' => 'HandlerClass', 00115 'callMethod' => 'isValid', 00116 'handlerParams' => array( $xmlData, 00117 $type, 00118 $contentObjectAttribute ), 00119 'aliasVariable' => ( $useAlias ? 'AliasClasses' : null ), 00120 'aliasOptionalIndex' => ( $type ? $type : null ) ); 00121 00122 $options = new ezpExtensionOptions( $optionArray ); 00123 00124 $inputHandler = eZExtension::getHandlerClass( $options ); 00125 00126 if ( $inputHandler === null || $inputHandler === false ) 00127 { 00128 $inputHandler = new eZSimplifiedXMLInput( $xmlData, false, $contentObjectAttribute ); 00129 } 00130 return $inputHandler; 00131 } 00132 00133 /// \static 00134 static function outputHandler( &$xmlData, $type = false, $useAlias = true, $contentObjectAttribute = false ) 00135 { 00136 $optionArray = array( 'iniFile' => 'ezxml.ini', 00137 'iniSection' => 'OutputSettings', 00138 'iniVariable' => 'HandlerClass', 00139 'callMethod' => 'isValid', 00140 'handlerParams' => array( $xmlData, 00141 $type, 00142 $contentObjectAttribute ), 00143 'aliasVariable' => ( $useAlias ? 'AliasClasses' : null ), 00144 'aliasOptionalIndex' => ( $type ? $type : null ) ); 00145 00146 $options = new ezpExtensionOptions( $optionArray ); 00147 00148 $outputHandler = eZExtension::getHandlerClass( $options ); 00149 00150 if ( $outputHandler === null || $outputHandler === false ) 00151 { 00152 $outputHandler = new eZXHTMLXMLOutput( $xmlData, false, $contentObjectAttribute ); 00153 } 00154 return $outputHandler; 00155 } 00156 00157 /// Contains the XML data 00158 public $XMLData; 00159 00160 public $XMLInputHandler; 00161 public $XMLOutputHandler; 00162 protected $PDFOutputHandler; 00163 public $XMLAttributeID; 00164 public $ContentObjectAttribute; 00165 } 00166 00167 ?>