eZ Publish  [4.0]
ezxmlinputhandler.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZXMLInputHandler class
00004 //
00005 // Created on: <06-Nov-2002 15:10:02 wy>
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 ezxmlinputhandler.php
00032 */
00033 
00034 /*!
00035   \class eZXMLInputHandler ezxmlinputhandler.php
00036   \ingroup eZDatatype
00037   \brief The class eZXMLInputHandler does
00038 
00039 */
00040 
00041 //include_once( 'kernel/classes/datatypes/ezurl/ezurl.php' );
00042 
00043 class eZXMLInputHandler
00044 {
00045     /*!
00046      Constructor
00047     */
00048     function eZXMLInputHandler( $xmlData, $aliasedType, $contentObjectAttribute )
00049     {
00050         $this->XMLData = $xmlData;
00051         $this->ContentObjectAttribute = $contentObjectAttribute;
00052         $this->AliasedType = $aliasedType;
00053         $this->AliasedHandler = null;
00054     }
00055 
00056     /*!
00057      \return an array with attribute names.
00058     */
00059     function attributes()
00060     {
00061         return array( 'input_xml',
00062                       'aliased_type',
00063                       'aliased_handler',
00064                       'edit_template_name',
00065                       'information_template_name' );
00066     }
00067 
00068     /*!
00069      \return true if the attribute \a $name exists.
00070     */
00071     function hasAttribute( $name )
00072     {
00073         return in_array( $name, $this->attributes() );
00074     }
00075 
00076     /*!
00077      \return the value of the attribute \a $name if it exists, if not returns \c null.
00078     */
00079     function attribute( $name )
00080     {
00081         switch ( $name )
00082         {
00083             case 'input_xml':
00084             {
00085                 return $this->inputXML();
00086             } break;
00087             case 'edit_template_name':
00088             {
00089                 return $this->editTemplateName();
00090             }break;
00091             case 'information_template_name':
00092             {
00093                 return $this->informationTemplateName();
00094             }break;
00095             case 'aliased_type':
00096             {
00097                 return $this->AliasedType;
00098             }break;
00099             case 'aliased_handler':
00100             {
00101                 if ( $this->AliasedType !== false and
00102                      $this->AliasedHandler === null )
00103                 {
00104                     $this->AliasedHandler = eZXMLText::inputHandler( $this->XMLData,
00105                                                                      $this->AliasedType,
00106                                                                      false,
00107                                                                      $this->ContentObjectAttribute );
00108                 }
00109                 return $this->AliasedHandler;
00110             }break;
00111             default:
00112             {
00113                 eZDebug::writeError( "Attribute '$name' does not exist", 'eZXMLInputHandler::attribute' );
00114                 return null;
00115             }break;
00116         }
00117     }
00118 
00119     /*!
00120      \return the template name for this input handler, includes the edit suffix if any.
00121     */
00122     function editTemplateName()
00123     {
00124         $name = 'ezxmltext';
00125         $suffix = $this->editTemplateSuffix( $this->ContentObjectAttribute );
00126         if ( $suffix !== false )
00127         {
00128             $name .= '_' . $suffix;
00129         }
00130         return $name;
00131     }
00132 
00133     /*!
00134      \return the template name for this input handler, includes the information suffix if any.
00135     */
00136     function informationTemplateName()
00137     {
00138         $name = 'ezxmltext';
00139         $suffix = $this->informationTemplateSuffix( $this->ContentObjectAttribute );
00140         if ( $suffix !== false )
00141         {
00142             $name .= '_' . $suffix;
00143         }
00144         return $name;
00145     }
00146 
00147     /*!
00148      \pure
00149      Handles custom actions for input handler.
00150      \note Default does nothing, reimplement to check actions.
00151     */
00152     function customObjectAttributeHTTPAction( $http, $action, $contentObjectAttribute )
00153     {
00154     }
00155 
00156     /*!
00157      \virtual
00158      \return true if the input handler is considered valid, if not the handler will not be used.
00159      \note Default returns true
00160     */
00161     function isValid()
00162     {
00163         return true;
00164     }
00165 
00166     /*!
00167      \pure
00168      \return the suffix for the attribute template, if false it is ignored.
00169     */
00170     function editTemplateSuffix( &$contentobjectAttribute )
00171     {
00172         return false;
00173     }
00174 
00175     /*!
00176      \pure
00177      \return the suffix for the attribute template, if false it is ignored.
00178     */
00179     function informationTemplateSuffix( &$contentobjectAttribute )
00180     {
00181         return false;
00182     }
00183 
00184     /*!
00185      \return the xml data as text.
00186     */
00187     function xmlData()
00188     {
00189         return $this->XMLData;
00190     }
00191 
00192     /*!
00193      \pure
00194      Validates user input and returns whether it can be used or not.
00195     */
00196     function validateInput( $http, $base, $contentObjectAttribute )
00197     {
00198         return eZInputValidator::STATE_INVALID;
00199     }
00200 
00201     /*!
00202      \pure
00203      Converts text input \a $text into an XML structure and returns it.
00204      \return an array where index 0 is the xml structure and index 1 is a message.
00205     */
00206     function convertInput( $text )
00207     {
00208         return null;
00209     }
00210 
00211     /*!
00212      \pure
00213      Returns the text representation of the XML structure, implement this to turn
00214      XML back into user input.
00215     */
00216     function inputXML()
00217     {
00218         return null;
00219     }
00220 
00221     /// \privatesection
00222     /// Contains the XML data as text
00223     public $XMLData;
00224     public $AliasedType;
00225     public $AliasedHandler;
00226     public $ContentObjectAttribute;
00227 }
00228 
00229 ?>