eZ Publish  [4.0]
ezxmltext.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZXMLText class
00004 //
00005 // Created on: <28-Jan-2003 12:56:49 bf>
00006 //
00007 // ## BEGIN COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00008 // SOFTWARE NAME: eZ Publish
00009 // SOFTWARE RELEASE: 4.0.x
00010 // COPYRIGHT NOTICE: Copyright (C) 1999-2008 eZ Systems AS
00011 // SOFTWARE LICENSE: GNU General Public License v2.0
00012 // NOTICE: >
00013 //   This program is free software; you can redistribute it and/or
00014 //   modify it under the terms of version 2.0  of the GNU General
00015 //   Public License as published by the Free Software Foundation.
00016 //
00017 //   This program is distributed in the hope that it will be useful,
00018 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //   GNU General Public License for more details.
00021 //
00022 //   You should have received a copy of version 2.0 of the GNU General
00023 //   Public License along with this program; if not, write to the Free
00024 //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00025 //   MA 02110-1301, USA.
00026 //
00027 //
00028 // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ##
00029 //
00030 
00031 /*! \file ezxmltext.php
00032 */
00033 
00034 /*!
00035   \class eZXMLText ezxmltext.php
00036   \ingroup eZDatatype
00037   \brief The class eZXMLText handles XML text data type instances
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                 $dom = new DOMDocument( '1.0', 'utf-8' );
00105                 if ( !$this->XMLData )
00106                 {
00107                     return $isEmpty;
00108                 }
00109                 $success = $dom->loadXML( $this->XMLData );
00110                 if ( $success )
00111                 {
00112                     $sectionNode = $dom->documentElement;
00113 
00114                     if ( $sectionNode->childNodes->length > 0 )
00115                     {
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     /// \static
00132     static 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     /// \static
00165     static 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     /// \static
00198     static 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             {
00219                 eZDebug::writeError( "Could not instantiate class '$class', it is not defined",
00220                                      'eZXMLText::fetchHandler' );
00221             }
00222 
00223             if ( !$handlerValid and
00224                  $out['type'] != $out['original-type'] and
00225                  isset( $definition['alias-group'] ) and
00226                  isset( $definition['alias-variable'] ) )
00227             {
00228                 unset( $definition['alias-group'] );
00229                 unset( $definition['alias-variable'] );
00230                 if ( eZExtension::findExtensionType( $definition,
00231                                                      $out ) )
00232                 {
00233                     $filePath = $out['found-file-path'];
00234                     include_once( $filePath );
00235                     $class = $out['type'] . $classSuffix;
00236                     $handlerValid = false;
00237                     if( class_exists( $class ) )
00238                     {
00239                         $handler = new $class( $xmlData, false, $contentObjectAttribute );
00240                         if ( $handler->isValid() )
00241                             $handlerValid = true;
00242                     }
00243                     else
00244                     {
00245                         eZDebug::writeError( "Could not instantiate class '$class', it is not defined",
00246                                              'eZXMLText::fetchHandler' );
00247                     }
00248 
00249                     if ( !$handlerValid )
00250                     {
00251                         $handler = null;
00252                     }
00253                 }
00254             }
00255         }
00256         return $handler;
00257     }
00258 
00259     /// Contains the XML data
00260     public $XMLData;
00261 
00262     public $XMLInputHandler;
00263     public $XMLOutputHandler;
00264     public $XMLAttributeID;
00265     public $ContentObjectAttribute;
00266 }
00267 
00268 ?>