eZ Publish  [4.0]
ezdiff.php
Go to the documentation of this file.
00001 <?php
00002 //
00003 // Definition of eZDiff class
00004 //
00005 // <creation-tag>
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 ezdiff.php
00032   Diff functionality
00033 */
00034 
00035 require_once( 'lib/ezutils/classes/ezdebug.php' );
00036 
00037 /*!
00038   \class eZDiff ezdiff.php
00039   \ingroup eZDiff
00040   \brief eZDiff provides an access point the diff system
00041 
00042   The eZDiff class is responsible for accessing and loading the correct
00043   diff engine when a datatype makes a call to eZDiff library.
00044 */
00045 class eZDiff
00046 {
00047     /*!
00048       Instantiates the eZDiff object
00049       \param $diffEngineType The type of diff engine to initialize at start
00050     */
00051     function eZDiff( $diffEngineType = false )
00052     {
00053         if ( $diffEngineType )
00054         {
00055             $this->DiffEngine = $diffEngineType;
00056             eZDebug::writeNotice( "Diff engine type: " . $diffEngineType, 'eZDiff' );
00057         }
00058     }
00059 
00060     /*!
00061       \public
00062       Set the diff engine to be used for diffing.
00063       \param $diffEngineType The type of diff engine to intitialize
00064     */
00065     function setDiffEngineType( $diffEngineType )
00066     {
00067         if ( isset( $diffEngineType ) )
00068         {
00069             $this->DiffEngine = $diffEngineType;
00070             eZDebug::writeNotice( "Changing diff engine to type: " . $diffEngineType, 'eZDiff' );
00071         }
00072     }
00073 
00074     /*!
00075       \public
00076       \return The diff engine type used in this instance.
00077     */
00078     function getDiffEngineType()
00079     {
00080         return $this->DiffEngine;
00081     }
00082 
00083     /*!
00084       \public
00085       \return Internal id of engine type given in \a $typeString
00086     */
00087     function engineType( $typeString )
00088     {
00089         switch ( $typeString )
00090         {
00091             case 'text':
00092             {
00093                 return $this->DIFF_TYPE['text'];
00094             }break;
00095 
00096             case 'xml':
00097             {
00098                 return $this->DIFF_TYPE['xml'];
00099             }break;
00100 
00101             case 'container':
00102             {
00103                 return $this->DIFF_TYPE['container'];
00104             }break;
00105         }
00106     }
00107 
00108     /*!
00109       \public
00110       Returns diff engine of \a $type
00111     */
00112     function initDiffEngine()
00113     {
00114         //include_once( 'lib/ezdiff/classes/ezdiffengine.php' );
00115 
00116         if ( !$diffEngine = $this->DiffEngineInstance )
00117         {
00118             switch( $this->DiffEngine )
00119             {
00120                 case '0': //Text
00121                 {
00122                     //include_once( 'lib/ezdiff/classes/ezdifftextengine.php' );
00123                     $this->DiffEngineInstance = new eZDiffTextEngine();
00124                 }break;
00125 
00126                 case '1': //XML
00127                 {
00128                     //include_once( 'lib/ezdiff/classes/ezdiffxmltextengine.php' );
00129                     $this->DiffEngineInstance = new eZDiffXMLTextEngine();
00130                 }break;
00131 
00132                 case '2': //ObjectContainer
00133                 {
00134                     //include_once( 'lib/ezdiff/classes/ezdiffcontainerobjectengine.php' );
00135                     $this->DiffEngineInstance = new eZDiffContainerObjectEngine();
00136                 }
00137             }
00138         }
00139     }
00140 
00141     /*!
00142       \public
00143       Perform a diff operation on the provided set of data. A valid
00144       diff engine have to be specified, before this can be run.
00145 
00146       \return An eZDiffContent object with the detected changes
00147     */
00148     function &diff( $fromData, $toData)
00149     {
00150         if ( !$this->DiffEngineInstance )
00151             return null;
00152 
00153         $differ =& $this->DiffEngineInstance;
00154         $diffObject = $differ->createDifferenceObject( $fromData, $toData );
00155         return $diffObject;
00156     }
00157 
00158     ///\privatesection
00159     /// Variable holding the diff engine type
00160     public $DiffEngine;
00161 
00162     /// The instance of the diff engine class
00163     public $DiffEngineInstance;
00164 
00165     /// The allowed input on which to diff
00166     public $DIFF_TYPE = array( 'text' => 0,
00167                             'xml' => 1,
00168                             'container' => 2 );
00169 }
00170 
00171 ?>