00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class eZXMLText
00042 {
00043 function eZXMLText( &$xmlData, $contentObjectAttribute )
00044 {
00045 $this->XMLData =& $xmlData;
00046 $this->ContentObjectAttribute = $contentObjectAttribute;
00047 $this->XMLInputHandler = null;
00048 $this->XMLOutputHandler = null;
00049 }
00050
00051 function attributes()
00052 {
00053 return array( 'input',
00054 'output',
00055 'pdf_output',
00056 'xml_data',
00057 'is_empty' );
00058 }
00059
00060 function hasAttribute( $name )
00061 {
00062 return in_array( $name, $this->attributes() );
00063 }
00064
00065 function &attribute( $name )
00066 {
00067 switch ( $name )
00068 {
00069 case 'input' :
00070 {
00071 if ( $this->XMLInputHandler === null )
00072 {
00073 $this->XMLInputHandler =& $this->inputHandler( $this->XMLData, false, true, $this->ContentObjectAttribute );
00074 }
00075 return $this->XMLInputHandler;
00076 }break;
00077
00078 case 'output' :
00079 {
00080 if ( $this->XMLOutputHandler === null )
00081 {
00082 $this->XMLOutputHandler =& $this->outputHandler( $this->XMLData, false, true, $this->ContentObjectAttribute );
00083 }
00084 return $this->XMLOutputHandler;
00085 }break;
00086
00087 case 'pdf_output' :
00088 {
00089 if ( $this->XMLOutputHandler === null )
00090 {
00091 $this->XMLOutputHandler =& $this->outputHandler( $this->XMLData, 'ezpdf', true, $this->ContentObjectAttribute );
00092 }
00093 return $this->XMLOutputHandler;
00094 }break;
00095
00096 case 'xml_data' :
00097 {
00098 return $this->XMLData;
00099 }break;
00100
00101 case 'is_empty' :
00102 {
00103 $isEmpty = true;
00104 $xml = new eZXML();
00105 $dom =& $xml->domTree( $this->XMLData, array(), true );
00106 if ( $dom )
00107 {
00108 $node = $dom->get_elements_by_tagname( "section" );
00109
00110 $sectionNode = $node[0];
00111 if ( ( get_class( $sectionNode ) == "ezdomnode" ) or
00112 ( get_class( $sectionNode ) == "domelement" ) )
00113 {
00114 $children = $sectionNode->children();
00115 if ( count( $children ) > 0 )
00116 $isEmpty = false;
00117 }
00118 }
00119 return $isEmpty;
00120 }break;
00121
00122 default:
00123 {
00124 eZDebug::writeError( "Attribute '$name' does not exist", 'eZXMLText::attribute' );
00125 $retValue = null;
00126 return $retValue;
00127 }break;
00128 }
00129 }
00130
00131
00132 function &inputHandler( &$xmlData, $type = false, $useAlias = true, $contentObjectAttribute = false )
00133 {
00134 $inputDefinition = array( 'ini-name' => 'ezxml.ini',
00135 'repository-group' => 'HandlerSettings',
00136 'repository-variable' => 'Repositories',
00137 'extension-group' => 'HandlerSettings',
00138 'extension-variable' => 'ExtensionRepositories',
00139 'type-group' => 'InputSettings',
00140 'type-variable' => 'Handler',
00141 'subdir' => 'input',
00142 'type-directory' => false,
00143 'extension-subdir' => 'ezxmltext/handlers/input',
00144 'suffix-name' => 'xmlinput.php' );
00145 if ( $type !== false )
00146 $inputDefinition['type'] = $type;
00147 if ( $useAlias )
00148 {
00149 $inputDefinition['alias-group'] = 'InputSettings';
00150 $inputDefinition['alias-variable'] = 'Alias';
00151 }
00152 $inputHandler =& eZXMLText::fetchHandler( $inputDefinition,
00153 'XMLInput',
00154 $xmlData,
00155 $contentObjectAttribute );
00156 if ( $inputHandler === null )
00157 {
00158 include_once( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinput.php' );
00159 $inputHandler = new eZSimplifiedXMLInput( $xmlData, false, $contentObjectAttribute );
00160 }
00161 return $inputHandler;
00162 }
00163
00164
00165 function &outputHandler( &$xmlData, $type = false, $useAlias = true, $contentObjectAttribute = false )
00166 {
00167 $outputDefinition = array( 'ini-name' => 'ezxml.ini',
00168 'repository-group' => 'HandlerSettings',
00169 'repository-variable' => 'Repositories',
00170 'extension-group' => 'HandlerSettings',
00171 'extension-variable' => 'ExtensionRepositories',
00172 'type-group' => 'OutputSettings',
00173 'type-variable' => 'Handler',
00174 'subdir' => 'output',
00175 'type-directory' => false,
00176 'extension-subdir' => 'ezxmltext/handlers/output',
00177 'suffix-name' => 'xmloutput.php' );
00178 if ( $type !== false )
00179 $outputDefinition['type'] = $type;
00180 if ( $useAlias )
00181 {
00182 $outputDefinition['alias-group'] = 'OutputSettings';
00183 $outputDefinition['alias-variable'] = 'Alias';
00184 }
00185 $outputHandler = eZXMLText::fetchHandler( $outputDefinition,
00186 'XMLOutput',
00187 $xmlData,
00188 $contentObjectAttribute );
00189 if ( $outputHandler === null )
00190 {
00191 include_once( 'kernel/classes/datatypes/ezxmltext/handlers/output/ezxhtmlxmloutput.php' );
00192 $outputHandler = new eZXHTMLXMLOutput( $xmlData, false, $contentObjectAttribute );
00193 }
00194 return $outputHandler;
00195 }
00196
00197
00198 function &fetchHandler( $definition, $classSuffix, &$xmlData, $contentObjectAttribute )
00199 {
00200 $handler = null;
00201 if ( eZExtension::findExtensionType( $definition,
00202 $out ) )
00203 {
00204 $filePath = $out['found-file-path'];
00205 include_once( $filePath );
00206 $class = $out['type'] . $classSuffix;
00207 $handlerValid = false;
00208 $aliasedType = false;
00209 if ( $out['original-type'] != $out['type'] )
00210 $aliasedType = $out['original-type'];
00211 if( class_exists( $class ) )
00212 {
00213 $handler = new $class( $xmlData, $aliasedType, $contentObjectAttribute );
00214 if ( $handler->isValid() )
00215 $handlerValid = true;
00216 }
00217 else
00218 eZDebug::writeError( "Could not instantiate class '$class', it is not defined",
00219 'eZXMLText::fetchHandler' );
00220 if ( !$handlerValid and
00221 $out['type'] != $out['original-type'] and
00222 isset( $definition['alias-group'] ) and
00223 isset( $definition['alias-variable'] ) )
00224 {
00225 unset( $definition['alias-group'] );
00226 unset( $definition['alias-variable'] );
00227 if ( eZExtension::findExtensionType( $definition,
00228 $out ) )
00229 {
00230 $filePath = $out['found-file-path'];
00231 include_once( $filePath );
00232 $class = $out['type'] . $classSuffix;
00233 $handlerValid = false;
00234 if( class_exists( $class ) )
00235 {
00236 $handler = new $class( $xmlData, false, $contentObjectAttribute );
00237 if ( $handler->isValid() )
00238 $handlerValid = true;
00239 }
00240 else
00241 eZDebug::writeError( "Could not instantiate class '$class', it is not defined",
00242 'eZXMLText::fetchHandler' );
00243 if ( !$handlerValid )
00244 {
00245 $handler = null;
00246 }
00247 }
00248 }
00249 }
00250 return $handler;
00251 }
00252
00253
00254 var $XMLData;
00255
00256 var $XMLInputHandler;
00257 var $XMLOutputHandler;
00258 var $XMLAttributeID;
00259 var $ContentObjectAttribute;
00260 }
00261
00262 ?>