Copyright (c) 2002, DM Solutions Group Inc.
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
include_once( COMMON."logger/logger.php" );
//global array for the current map file, used in parsing the map file
$aszMapFile = array();
//global size of the map file, so we don't have to use count() all the time
$nLines = 0;
/**
* Class TokenizeMapFile
*
* This class helps the parsing process. Instead of passing
* globals variables, we pass a instance of that class to
* all functions that parse (parseMapFileString, parseValue).
*
*/
class TokenizedMapFile
{
var $m_aszMapFile;
var $m_nIndex;
var $m_nLines;
/*
* TokenizedMapFile
*
* @param $aszMapFile Preprocessed array of token provided by ms_TokenizeMapFile
*/
function TokenizedMapFile($aszMapFile)
{
$this->m_aszMapFile = $aszMapFile;
$this->m_nIndex = 0;
$this->m_nLines = count($this->m_aszMapFile);
}
/**
* getNextToken()
*
* @return Next token from mapfile. Pointer is incremented.
*/
function &getNextToken()
{
// Check if we pass end of array
// if (!isset($this->m_aszMapFile[$this->m_nIndex]))
// return false;
$szToken =& $this->m_aszMapFile[$this->m_nIndex];
// Increment pointer
$this->m_nIndex = $this->m_nIndex + 1;
// If token start by a quote or double quotes
// return the token without them.
if ($szToken[0] == "\"" || $szToken[0] == "'")
{
return substr($szToken, 1, -1);
}
else
{
return $szToken;
}
}
}
/**
* The purpose of this class is to provide a factory for sub-classes of
* BaseObj. It contains an array of the valid object types. To add new
* types, simply add them to the array initialization in the object
* factory and create the new class (as a sub-class of BaseObj please)
*/
class ObjFactory extends Logger
{
/**
* array of supported object types
*/
var $aObjTypes;
/**
* Constructor - initialize the valid object types
*/
function ObjFactory()
{
$this->Logger( "ObjFactory" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering ObjFactory" ); #STRIPED_LOG# */
//implementation
$this->aObjTypes = array( "DOC", "WEB", "REFERENCE", "QUERYMAP", "PROJECTION",
"LEGEND", "SCALEBAR", "LAYER", "CLASS", "FEATURE",
"LABEL", "BITMAPLABEL", "METADATA", "MAP", "JOIN", "SYMBOL",
"POINTS", "SYMBOLSTYLE", "STYLE", "OUTPUTFORMAT", "GRID");
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done ObjFactory" ); #STRIPED_LOG# */
}
/**
* create an object from a name value
*
* @param szName the name of the object to create
*
* @return mixed an instance of a subclass of BaseObj or false
* if the name isn't supported
*/
function createObj( $szName )
{
$mResult = false;
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering createObj($szName)" ); #STRIPED_LOG# */
//implementation
if ( in_array( strtoupper($szName), $this->aObjTypes))
{
$szEval = "\$mResult = new ".ucfirst(strtolower($szName))."Obj();";
/* #STRIPED_LOG# //$this->log( LOG_ALL, "evaluating $szEval" ); #STRIPED_LOG# */
@eval( $szEval );
}
else
{
$this->error( 0,
"unrecognized object $szName, object not created");
}
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done createObj($szName)" ); #STRIPED_LOG# */
return $mResult;
}
}
/**
* The purpose of this class is to provide a factory for sub-classes of
* BaseType. It contains an array of the valid element types. To add new
* types, simply add them to the array initialization in the type
* factory and create the new class (as a sub-class of BaseType please)
*/
class TypeFactory extends Logger
{
/**
* array of supported types
*/
var $aTypes;
/**
* Constructor - initialize the valid types
*/
function TypeFactory()
{
$this->Logger( "TypeFactory" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering TypeFactory" ); #STRIPED_LOG# */
//implementation
$this->aTypes = array( "STRING", "STRINGBLOCK", "COLOR", "DOUBLE",
"INTEGER", "ENUMERATION", "COMPLEXTYPE",
"DIRECTORYNAME", "FILENAME", "EXPRESSION",
"COMBOENUMERATIONINTEGER", "FONTSIZE",
"COMBOENUMERATIONDOUBLE", "SYMBOL", "FONT",
"SHAPEATTR", "SEPARATOR", "METADATAITEM",
"SYMBOLPOINTS", "SYMBOLSTYLE", "FORMATOPTIONITEM");
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done TypeFactory" ); #STRIPED_LOG# */
}
/**
* create a type object from a name value
*
* @param szName the name of the type to create
*
* @return mixed an instance of a subclass of BaseType or false
* if the name isn't supported
*/
function createType( $szName )
{
$mResult = false;
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering createType($szName)" ); #STRIPED_LOG# */
//implementation
if ( in_array( strtoupper($szName), $this->aTypes))
{
$szEval = "\$mResult = new ".ucfirst(strtolower($szName))."Type();";
/* #STRIPED_LOG# //$this->log( LOG_ALL, "evaluating $szEval" ); #STRIPED_LOG# */
@eval( $szEval );
}
else
{
$this->error( 0,
"unrecognized type $szName, type not created");
}
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done =createType($szName)" ); #STRIPED_LOG# */
return $mResult;
}
}
/**
* BaseObj is the base class for all the XxxObj classes and provides the
* common attributes and methods to be used. It is not intended to be
* directly instantiated as each sub-class should implement specific
* parsing, serializing and rendering functions
*
*/
class BaseObj extends Logger
{
/**
* elements of this object that have actually been set
*/
var $maoTypes;
/**
* sub-objects that exist in this object
*/
var $maoObjs;
/*
* array of valid sub-object names
*/
var $maszValidObjs;
/**
* name of the object (set by sub-classes)
*/
var $mszName;
/**
* title of the the object
*/
var $mszTitle;
/**
* index value of this object
*/
var $mszIndex;
/**
* original index of this object when the map file was opened or
* saved. This value can be used for the restore operation
*/
var $mnOriginalIndex;
/**
*
*/
var $mszMultiplicity;
/**
* Comment to display before the object
*/
var $mszComments;
var $mszEndingComments;
/**
* Constructor - initialize instance vars
*
*
*/
function BaseObj( )
{
$bResult = true;
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering BaseObj" ); #STRIPED_LOG# */
//implementation
$this->maoTypes = array();
$this->maoObjs = array();
$this->maszValidObjs = array();
$this->mszIndex = "";
$this->mnOriginalIndex = -1;
$this->mszMultiplicity = 1;
$this->mszComments = "";
$this->mszEndingComments = "";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done BaseObj" ); #STRIPED_LOG# */
return $bResult;
}
/**
* parse this object out of the contents of a array of strings (MapFile
* format) up to the next END and return the remaining elements of the
* string
*
* @param $oTokMapFile Object needed to navigate in mapfile
*
* @return the remaining elements in the array or false if something went
* wrong, in which case look in the global error manager.
*/
function parseMapFileString( &$oTokMapFile )
{
global $gApp;
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "parseMapFileString()" ); #STRIPED_LOG# */
$szComments = "";
// Get next token.
$szToken =& $oTokMapFile->getNextToken();
// If reache en of object or getnext token return an error.
while( strcasecmp($szToken, "end") != 0 && $szToken !== false)
{
if ($szToken === FALSE)
{
//something went terribly wrong
$this->error(0, "error parsing map file");
return false;
}
/* #STRIPED_LOG# //$this->log( LOG_ALL, "processing token ($szToken)"); #STRIPED_LOG# */
if ($szToken[0] == "#")
{
/* #STRIPED_LOG# //$this->log(LOG_ALL, "found a comment"); #STRIPED_LOG# */
$szComments .= "$szToken\n";
}
elseif(strcasecmp($szToken, $this->mszName) == 0)
{
//skip the line
/* #STRIPED_LOG# //$this->log(LOG_ALL, "key matches name, skipping key $szToken"); #STRIPED_LOG# */
$this->mszComments = $szComments;
$szComments = "";
}
elseif(in_array(strtoupper($szToken), $this->maszValidObjs))
{
/* #STRIPED_LOG# //$this->log(LOG_ALL,
// "create Object $szToken"); #STRIPED_LOG# */
$oObj = $gApp->createObj($szToken);
$oObj->mszIndex = $this->mszIndex.
sprintf( "%03d", count($this->maoObjs) );
$oObj->mszComments = $szComments;
$szComments = "";
$bResult = $oObj->parseMapFileString( $oTokMapFile );
if($bResult === false)
{
//something went terribly wrong
$this->error(0, "error parsing map file");
return false;
}
$this->addObj($oObj);
}
elseif(isset($this->maoTypes[strtoupper($szToken)]))
{
//okay, its valid
/* #STRIPED_LOG# //$this->log(LOG_ALL, "create type $szToken"); #STRIPED_LOG# */
$nResult = $this->maoTypes[strtoupper($szToken)]->parseValue( $oTokMapFile );
if($nResult === false)
{
//something went terribly wrong
$this->error(0, "error parsing map file");
return false;
}
$this->maoTypes[strtoupper($szToken)]->mszComments = $szComments;
$szComments = "";
}
else
{
$this->error( 0, "invalid map file entry $szToken in ". $this->mszName);
}
$szToken =& $oTokMapFile->getNextToken();
}
if (strcmp(strtolower($szToken), "end") == 0)
$this->mszEndingComments = $szComments;
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done parseMapFileString" ); #STRIPED_LOG# */
//test for failure
if(strcmp(strtolower($szToken), "end") != 0)
{
$this->error(0,
"premature end of map file processing ".$this->mszName.", final token was $szToken");
return false;
}
else
{
return $szToken;
}
}
/**
* addObj adds/updates the attribute and value pair
*/
function addObj( &$oObj )
{
$bResult = false;
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE,
"entering addObj(".$oObj->mszName.")" ); #STRIPED_LOG# */
//implementation
if (in_array($oObj->mszName, $this->maszValidObjs))
{
/* #STRIPED_LOG# //$this->log(LOG_ALL, "adding object"); #STRIPED_LOG# */
//find the position of the object we are inserting
$nInsertPos = array_search($oObj->mszName, $this->maszValidObjs);
/* #STRIPED_LOG# //$this->log(LOG_ALL, "position of obj is $nInsertPos"); #STRIPED_LOG# */
$bAtEnd = false;
$bValidInsert = true;
$nInsertIdx = count($this->maoObjs);
$nLast = count($this->maoObjs) - 1;
for( $i=0; $i<$nInsertIdx && $bValidInsert; $i++)
{
//find the position of the current object
$oSubObj =& $this->maoObjs[$i];
$nCurPos = array_search($oSubObj->mszName, $this->maszValidObjs);
/* #STRIPED_LOG# //$this->log(LOG_ALL, "position of subobj is $nCurPos"); #STRIPED_LOG# */
if($nCurPos > $nInsertPos)
{
if ($bAtEnd)
{
$nInsertIdx = $i + 1;
}
else
{
$nInsertIdx = $i;
}
break;
}
elseif($nCurPos == $nInsertPos)
{
$bAtEnd = true;
//can check to see if multiples allowed here
if ($oObj->mszMultiplicity != "*")
{
$this->error( 0, "multiple instances of ".
$oObj->mszName." not allowed" );
$bValidInsert = false;
}
}
}
if ($bValidInsert)
{
/* #STRIPED_LOG# //$this->log( LOG_ALL, "insert is valid at position $nInsertIdx of $nLast" ); #STRIPED_LOG# */
///// $nLast = count($this->maoObjs) - 1;
if ($nInsertIdx == 0)
{
//pushing at beginning
/* #STRIPED_LOG# //$this->log(LOG_ALL, "insert at beginning"); #STRIPED_LOG# */
array_unshift($this->maoObjs, $oObj);
}
elseif ( $nInsertIdx <= $nLast )
{
//insert in the middle
/* #STRIPED_LOG# //$this->log(LOG_ALL, "pushing in middle of array" ); #STRIPED_LOG# */
$aoObj = array_slice($this->maoObjs, 0, $nInsertIdx );
array_push( $aoObj, $oObj );
$this->maoObjs = array_merge( $aoObj, array_slice( $this->maoObjs, $nInsertIdx ) );
}
else
{
//pushing on end
/* #STRIPED_LOG# //$this->log(LOG_ALL, "pushing on end of array"); #STRIPED_LOG# */
array_push( $this->maoObjs, $oObj );
}
$this->reIndexObjs();
$bResult = sprintf( "%s%03d", $this->mszIndex,$nInsertIdx );
}
else
{
$bResult = false;
}
}
else
{
/* #STRIPED_LOG# //$this->log(LOG_ALL, "not adding object"); #STRIPED_LOG# */
/* #STRIPED_LOG# //$this->log(LOG_ALL, $this->maszValidObjs); #STRIPED_LOG# */
}
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_QUIET, "done addObj(".$oObj->mszName."), returning $bResult" ); #STRIPED_LOG# */
return $bResult;
}
/**
* Remove Obj
*/
function removeObjByIndex( $szIndex )
{
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering removeObjByIndex( $szIndex )"); #STRIPED_LOG# */
//break the index down into 3 char blocks
$nIndex = intval(substr( $szIndex, 0, 3));
$szNextIndex = substr( $szIndex, 3 );
/* #STRIPED_LOG# //$this->log( LOG_QUIET, "index is $nIndex, next is $szNextIndex"); #STRIPED_LOG# */
if ($szNextIndex == "")
{
array_splice($this->maoObjs, $nIndex, 1);
$this->reIndexObjs();
$nRet = $nIndex-1;
}
else
{
$nRet = $this->maoObjs[$nIndex]->removeObjByIndex($szNextIndex);
}
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done removeObjByIndex()"); #STRIPED_LOG# */
return $nRet;
}
/**
* Promote object
*/
function promoteObjByIndex( $szIndex )
{
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering promoteObjByIndex( $szIndex )"); #STRIPED_LOG# */
$nRet = false;
//break the index down into 3 char blocks
$nIndex = intval(substr( $szIndex, -3));
$oParent = &$this->getObjByIndex(substr($szIndex, 0, -3));
if ($nIndex != 0)
{
$oPrev = $oParent->maoObjs[$nIndex-1];
// must be same type.
if ($oPrev->mszName == $oParent->maoObjs[$nIndex]->mszName)
{
$oParent->maoObjs[$nIndex-1] = $oParent->maoObjs[$nIndex];
$oParent->maoObjs[$nIndex] = $oPrev;
$this->reIndexObjs();
$nRet = $nIndex-1;
}
}
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done promoteObjByIndex()"); #STRIPED_LOG# */
return $nRet;
}
/**
* Demote object
*/
function demoteObjByIndex( $szIndex )
{
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering demoteObjByIndex( $szIndex )"); #STRIPED_LOG# */
$nRet = false;
//break the index down into 3 char blocks
$nIndex = intval(substr( $szIndex, -3));
$oParent = &$this->getObjByIndex(substr($szIndex, 0, -3));
if ($nIndex != count($oParent->maoObjs))
{
$oNext = $oParent->maoObjs[$nIndex+1];
// must be same type.
if ($oNext->mszName == $oParent->maoObjs[$nIndex]->mszName)
{
$oParent->maoObjs[$nIndex+1] = $oParent->maoObjs[$nIndex];
$oParent->maoObjs[$nIndex] = $oNext;
$this->reIndexObjs();
$nRet = $nIndex+1;
}
}
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done demoteObjByIndex()"); #STRIPED_LOG# */
return $nRet;
}
/**
* reindex contained objects and sub-objects
*/
function reIndexObjs( )
{
$nObjs = count($this->maoObjs);
for($i=0;$i<$nObjs;$i++)
{
$this->maoObjs[$i]->mszIndex = $this->mszIndex.
sprintf( "%03d", $i);
$this->maoObjs[$i]->reIndexObjs();
}
}
/**
* set the original index value to the current index value for this
* object and all sub-objects.
*/
function saveIndexes()
{
$this->mnOriginalIndex = $this->mszIndex;
$nObj = count($this->maoObjs);
for ( $i=0; $i<$nObj;$i++)
{
$this->maoObjs[$i]->saveIndexes();
}
}
function getIndex()
{
return $this->mszIndex;
}
function &getObjByIndex( $szIndex )
{
$oObj = false;
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering getObjByIndex( $szIndex )"); #STRIPED_LOG# */
if(trim($szIndex) == "")
{
/* #STRIPED_LOG# //$this->log( LOG_QUIET, "returning $this->mszName"); #STRIPED_LOG# */
$oObj = &$this;
}
else
{
//break the index down into 3 char blocks
$nIndex = intval(substr( $szIndex, 0, 3));
$szNextIndex = substr( $szIndex, 3 );
/* #STRIPED_LOG# //$this->log( LOG_QUIET, "index is $nIndex, next is $szNextIndex"); #STRIPED_LOG# */
return $this->maoObjs[$nIndex]->getObjByIndex($szNextIndex);
}
/* #STRIPED_LOG# //$this->log(LOG_ALL, "returning an object called ".$oObj->mszName); #STRIPED_LOG# */
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done getObjByIndex()"); #STRIPED_LOG# */
return $oObj;
}
/**
* Reset all attribute to empty
*/
function clearObject()
{
foreach($this->maoTypes as $szKey => $oVal)
{
/* #STRIPED_LOG# //$this->log(LOG_ALL, "Clearing $szKey that is set to $oVal"); #STRIPED_LOG# */
$this->maoTypes[$szKey]->setValue("");
}
}
/**
* Set all current object attribute with
* oObj values.
*/
function restoreObject($oObj)
{
// reset this object and copy all type from oObj
foreach($this->maoTypes as $szKey => $oVal)
$this->maoTypes[$szKey] = new BaseType();
foreach($oObj->maoTypes as $oType)
{
$this->addType($oType);
}
$this->reIndexObjs();
}
/**
* addType adds/updates the attribute and value pair
*/
function addType( $oType )
{
$bResult = false;
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE,
"entering addType(".$oType->mszName.")" ); #STRIPED_LOG# */
$this->maoTypes[strtoupper($oType->mszName)] = $oType;
$bResult = true;
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done addType(".$oType->mszName.")" ); #STRIPED_LOG# */
return $bResult;
}
/**
* getType return the type obj for szName
*/
function getType( $szName )
{
$bResult = false;
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE,
"entering getType(".$szName.")" ); #STRIPED_LOG# */
if (isset($this->maoTypes[strtoupper($szName)]))
$bResult = $this->maoTypes[strtoupper($szName)];
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done getType()" ); #STRIPED_LOG# */
return $bResult;
}
/**
* return a string representing this object as an HTML page, every element
* will be rendered as HTML which will include FORM inputs
*/
function renderAsHTML()
{
$szURI = "http://".$_SERVER['HTTP_HOST'].
$_SERVER['PHP_SELF'];
$szResult = "";
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering renderAsHTML" ); #STRIPED_LOG# */
//implementation
//$this->error( 0, "BaseObj doesn't support rendering to HTML :(");
$szResult = "
\n";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done renderAsHTML" ); #STRIPED_LOG# */
return $szResult;
}
function renderAsMapFileString( $szIndent = "" )
{
//this we can do
$szResult = "";
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering renderAsMapFileString" ); #STRIPED_LOG# */
//implementation
if ($this->mszComments != "")
{
$szResult .= str_replace("#", "$szIndent#", $this->mszComments);
}
$szResult .= $szIndent.$this->mszName."\n";
foreach( $this->maoTypes as $oElement )
$szResult .= $oElement->renderAsMapFileString( $szIndent." " );
foreach( $this->maoObjs as $oObj )
$szResult .= $oObj->renderAsMapFileString( $szIndent." " );
if ($this->mszEndingComments != "")
$szResult .= str_replace("#", "$szIndent#", $this->mszEndingComments);
$szResult .= $szIndent."END\n";
/* #STRIPED_LOG# //$this->log( LOG_ALL, "rendering result is:\n$szResult"); #STRIPED_LOG# */
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done renderAsMapFileString" ); #STRIPED_LOG# */
return $szResult;
}
function renderAsTreemenuString( $szLevel = "" )
{
$szResult = "";
/* #STRIPED_LOG# $this->logFuncStart(LOG_VERBOSE,
"entering renderAsTreemenuString($szLevel)"); #STRIPED_LOG# */
$szResult = $szLevel."|images/tree_".strtolower($this->mszName).".gif|@".$this->getIndex()."\n";
foreach( $this->maoObjs as $oObj)
{
if (is_object( $oObj ) )
$szResult .= $oObj->renderAsTreemenuString( $szLevel."." );
}
/* #STRIPED_LOG# $this->logFuncEnd(LOG_ALL,
"done renderAsTreemenuString($szLevel)"); #STRIPED_LOG# */
return $szResult;
}
/**
* return an array of objects and sub-objects
*/
function renderAsTreemenuArray( )
{
$aMe = array();
$aMe["type"] = strtoupper($this->mszName);
$aMe["name"] = "";
if(isset($this->maoTypes['NAME']))
{
$aMe["name"] = $this->maoTypes['NAME']->getValue();
}
$aMe["icon"] = "images/tree_".strtolower($this->mszName).".gif";
$aMe["index"] = $this->getIndex();
$aMe["children"] = array();
foreach( $this->maoObjs as $oObj)
{
if (is_object( $oObj ) )
$aMe["children"][$oObj->getIndex()] = &$oObj->renderAsTreemenuArray( );
}
return $aMe;
}
function processFormVars( $szIndex, $aszFormVars )
{
$bResult = true;
/* #STRIPED_LOG# $this->logFuncStart( LOG_ALL, "entering processFormVars($szIndex, $aszFormVars)" ); #STRIPED_LOG# */
//$this->logFuncStart( LOG_QUIET, "entering processFormVars($szIndex, $aszFormVars)" );
if (trim($szIndex != "") )
{
//process on the next sub-object
$nIndex = intval(substr( $szIndex, 0, 3));
$szNextIndex = substr( $szIndex, 3 );
/* #STRIPED_LOG# //$this->log( LOG_ALL, "index is $nIndex, next is $szNextIndex" ); #STRIPED_LOG# */
/* #STRIPED_LOG# ////$this->log( LOG_ALL, $this->maoObjs ); #STRIPED_LOG# */
//echo $this->maoObjs[$nIndex]->mszName;
//echo count($aszFormVars);
$bResult = $this->maoObjs[$nIndex]->processFormVars($szNextIndex, $aszFormVars);
}
else
{
//process on this obj.
$keys = array_keys($this->maoTypes);
foreach( $keys as $key )
{
$bResult = $this->maoTypes[$key]->processFormVars($aszFormVars);
if (!$bResult)
$this->error( 0, "an error occurred setting the value for ".
$this->maoTypes[$key]->mszName );
}
}
//$this->logFuncEnd( LOG_QUIET, "done processFormVars() : $bResult" );
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done processFormVars() : $bResult" ); #STRIPED_LOG# */
return $bResult;
}
function addNewObject( $szIndex, $szName )
{
global $gApp;
$bResult = true;
/* #STRIPED_LOG# $this->logFuncStart( LOG_ALL, "entering addNewObject( $szIndex, $szName)" ); #STRIPED_LOG# */
if (trim($szIndex != "") )
{
//process on the next sub-object
$nIndex = intval(substr( $szIndex, 0, 3));
$szNextIndex = substr( $szIndex, 3 );
$bResult = $this->maoObjs[$nIndex]->addNewObject($szNextIndex, $szName);
}
else
{
//process on this obj.
if (in_array($szName, $this->maszValidObjs))
{
$oObj = $gApp->createObj($szName);
//add default metadata if available
$oMetaData = $gApp->aValidators["METADATA"];
foreach( $oMetaData->maoTypes as $szKey => $oType )
{
if ($oType->mxValue == $oObj->mszName)
{
/* #STRIPED_LOG# //$this->log( LOG_ALL, "default metadata found ".$oType->mszName." ".$oType->mszTitle ); #STRIPED_LOG# */
if (!isset($oMeta))
{
$oMeta = $gApp->createObj("METADATA");
}
array_push($oMeta->maszMetaData, array( $oType->mszName, $oType->mszTitle ));
}
}
$bResult = $this->addObj( $oObj );
/* #STRIPED_LOG# //$this->log( LOG_ALL, "added new object at index $nIdx"); #STRIPED_LOG# */
if (isset($oMeta))
{
$this->maoObjs[$nIdx]->addObj( $oMeta );
}
}
else
{
$this->error(0, "$szName is an invalid object for ".$this->mszName );
/* #STRIPED_LOG# //$this->log( LOG_QUIET, array_values($this->maszValidObjs) ); #STRIPED_LOG# */
}
}
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done processFormVars() : $bResult" ); #STRIPED_LOG# */
return $bResult;
}
/**
* dump the object contents
*/
function dump( )
{
echo "";
echo "ObjDump for ".$this->mszName." ";
echo "Types: ";
echo "
";
foreach( $this->maoTypes as $key => $obj )
echo "
".$key." => ".$obj->mszName;
echo "
";
echo "Sub Objects: ";
echo "
";
foreach ($this->maoObjs as $key => $obj)
{
echo "
$key => ".$obj->mszName;
$obj->dump();
}
echo "
";
echo "Allowed Objs: ";
echo "
";
foreach($this->maszValidObjs as $key => $obj)
echo "
$key => $obj";
echo "
";
echo "";
}
}
class DocObj extends BaseObj
{
// Dummy obj
}
/**
* A WebObj class
*/
class WebObj extends BaseObj
{
/**
* initialize the class
*/
function WebObj( )
{
$this->BaseObj();
$this->Logger( "WebObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering WebObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "WEB";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done WebObj" ); #STRIPED_LOG# */
}
}
/**
* A SymbolObj class
*/
class SymbolObj extends BaseObj
{
/**
* initialize the class
*/
function SymbolObj( )
{
$this->BaseObj();
$this->Logger( "SymbolObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering SymbolObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "SYMBOL";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done SymbolObj" ); #STRIPED_LOG# */
}
/**
* return a string representing this object as an HTML page, every element
* will be rendered as HTML which will include FORM inputs
*/
function renderAsHTML()
{
//this probably isn't the place to do this.
//automatically add sub-objects for POINTS and STYLE
//if they don't exist
if ( !isset($this->maoObjs["POINTS"]) )
{
$this->addNewObject( "", "POINTS" );
}
if ( !isset($this->maoObjs["SYMBOLSTYLE"]) )
{
$this->addNewObject( "", "SYMBOLSTYLE" );
}
$szURI = "http://".$_SERVER['HTTP_HOST'].
$_SERVER['PHP_SELF'];
$szResult = "";
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering renderAsHTML" ); #STRIPED_LOG# */
//implementation
//$this->error( 0, "BaseObj doesn't support rendering to HTML :(");
$szResult = "\n";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done renderAsHTML" ); #STRIPED_LOG# */
return $szResult;
}
function renderAsTreemenuString( $szLevel = "" )
{
$szResult = "";
/* #STRIPED_LOG# $this->logFuncStart(LOG_VERBOSE,
"entering renderAsTreemenuString($szLevel)"); #STRIPED_LOG# */
$szResult = $szLevel."|images/tree_".strtolower($this->mszName).".gif|@".$this->getIndex()."\n";
/* #STRIPED_LOG# $this->logFuncEnd(LOG_ALL,
"done renderAsTreemenuString($szLevel)"); #STRIPED_LOG# */
return $szResult;
}
function processFormVars( $szIndex, $aszFormVars )
{
$bResult = true;
/* #STRIPED_LOG# $this->logFuncStart( LOG_ALL, "entering processFormVars($szIndex, $aszFormVars)" ); #STRIPED_LOG# */
if (trim($szIndex != "") )
{
//process on the next sub-object
$nIndex = intval(substr( $szIndex, 0, 3));
$szNextIndex = substr( $szIndex, 3 );
/* #STRIPED_LOG# //$this->log( LOG_ALL, "index is $nIndex, next is $szNextIndex" ); #STRIPED_LOG# */
/* #STRIPED_LOG# ////$this->log( LOG_ALL, $this->maoObjs ); #STRIPED_LOG# */
//echo $this->maoObjs[$nIndex]->mszName;
//echo count($aszFormVars);
$bResult = $this->maoObjs[$nIndex]->processFormVars($szNextIndex, $aszFormVars);
}
else
{
//process on this obj.
$keys = array_keys($this->maoTypes);
foreach( $keys as $key )
{
$bResult = $this->maoTypes[$key]->processFormVars($aszFormVars);
if (!$bResult)
$this->error( 0, "an error occurred setting the value for ".
$this->maoTypes[$key]->mszName );
}
//process automatically on sub-objects also
$aszObjKeys = array_keys($this->maoObjs);
foreach( $aszObjKeys as $szObjKey )
{
$aszTypeKeys = array_keys( $this->maoObjs[$szObjKey]->maoTypes );
foreach( $aszTypeKeys as $szTypeKey )
{
$bResult = $this->maoObjs[$szObjKey]->maoTypes[$szTypeKey]->processFormVars($aszFormVars);
if (!$bResult)
$this->error(0, "an error occurred setting the value for ".
$this->maoObjs[$szObjKey]->maoTypes[$szTypeKey]->mszName );
}
}
}
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done processFormVars() : $bResult" ); #STRIPED_LOG# */
return $bResult;
}
}
/**
* A PointsObj class
*/
class PointsObj extends BaseObj
{
/**
* initialize the class
*/
function PointsObj( )
{
$this->BaseObj();
$this->Logger( "PointsObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering PointsObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "POINTS";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done PointsObj" ); #STRIPED_LOG# */
}
/**
* override baseobj implementation because Points are a special case
*
* @param $oTokMapFile Object needed to navigate in mapfile
* @return false if something gone wrong
**/
function parseMapFileString(&$oTokMapFile)
{
/* #STRIPED_LOG# $this->logFuncStart(LOG_VERBOSE, "entering parseMapFileString"); #STRIPED_LOG# */
$szToken =& $oTokMapFile->getNextToken();
while(strcasecmp($szToken, "END") != 0 && $szToken !== FALSE)
{
while (substr($szToken, 0, 1) == "#")
$szToken =& $oTokMapFile->getNextToken();
$this->maoTypes['POINTS']->setValue($this->maoTypes['POINTS']->getValue()." ".$szToken );
//process the next token
$szToken =& $oTokMapFile->getNextToken();
}
/* #STRIPED_LOG# $this->logFuncEnd(LOG_ALL, "done parseMapFileString"); #STRIPED_LOG# */
return $szToken;
}
/**
* override default behaviour because if the contents of POINTS is not
* defined then don't write the object tag
*/
function renderAsMapFileString( $szIndent = "" )
{
//this we can do
$szResult = "";
$szComments = "";
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering renderAsMapFileString" ); #STRIPED_LOG# */
//make sure there's something to put in the POINTS tag, otherwise just return
//an empty string
foreach( $this->maoTypes as $oElement )
$szResult .= $oElement->renderAsMapFileString( $szIndent." " );
if ($szResult != "" )
{
//implementation
if ($this->mszComments != "")
{
$szComments .= str_replace("#", "$szIndent#", $this->mszComments);
}
$szResult = $szComments.$szIndent.$this->mszName."\n".$szResult;
if ($this->mszEndingComments != "")
$szResult .= str_replace("#", "$szIndent#", $this->mszEndingComments);
$szResult .= $szIndent."END\n";
}
/* #STRIPED_LOG# //$this->log( LOG_ALL, "rendering result is:\n$szResult"); #STRIPED_LOG# */
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done renderAsMapFileString" ); #STRIPED_LOG# */
return $szResult;
}
}
/**
* A StyleObj class
*/
class SymbolStyleObj extends BaseObj
{
/**
* initialize the class
*/
function SymbolStyleObj( )
{
$this->BaseObj();
$this->Logger( "SymbolStyleObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering SymbolStyleObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "SYMBOLSTYLE";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done SymbolStyleObj" ); #STRIPED_LOG# */
}
/**
* override baseobj implementation because SymbolStyles are a special case
*
* @param $oTokMapFile Object needed to navigate in mapfile
* @return false if something gone wrong
**/
function parseMapFileString(&$oTokMapFile)
{
/* #STRIPED_LOG# $this->logFuncStart(LOG_VERBOSE, "entering parseMapFileString"); #STRIPED_LOG# */
$szToken =& $oTokMapFile->getNextToken();
while(strcasecmp($szToken, "END") != 0 && $szToken !== FALSE)
{
$this->maoTypes['STYLE']->setValue($this->maoTypes['STYLE']->getValue()."\n".$szToken );
//process the next token
$szToken =& $oTokMapFile->getNextToken();
}
/* #STRIPED_LOG# $this->logFuncEnd(LOG_ALL, "done parseMapFileString"); #STRIPED_LOG# */
return $szToken;
}
/**
* override default behaviour because if the contents of STYLE is not
* defined then don't write the object tag
*/
function renderAsMapFileString( $szIndent = "" )
{
//this we can do
$szResult = "";
$szComments = "";
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering renderAsMapFileString" ); #STRIPED_LOG# */
//make sure there's something to put in the POINTS tag, otherwise just return
//an empty string
foreach( $this->maoTypes as $oElement )
$szResult .= $oElement->renderAsMapFileString( $szIndent." " );
if ($szResult != "" )
{
//implementation
if ($this->mszComments != "")
{
$szComments .= str_replace("#", "$szIndent#", $this->mszComments);
}
$szResult = $szComments.$szIndent.$this->mszName."\n".$szResult;
if ($this->mszEndingComments != "")
$szResult .= str_replace("#", "$szIndent#", $this->mszEndingComments);
$szResult .= $szIndent."END\n";
}
/* #STRIPED_LOG# //$this->log( LOG_ALL, "rendering result is:\n$szResult"); #STRIPED_LOG# */
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done renderAsMapFileString" ); #STRIPED_LOG# */
return $szResult;
}
}
/**
* A StyleObj class
*/
class StyleObj extends BaseObj
{
/**
* initialize the class
*/
function StyleObj( )
{
$this->BaseObj();
$this->Logger( "StyleObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering StyleObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "STYLE";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done StyleObj" ); #STRIPED_LOG# */
}
}
/**
* A JoinObj class
*/
class JoinObj extends BaseObj
{
/**
* initialize the class
*/
function JoinObj( )
{
$this->BaseObj();
$this->Logger( "JoinObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering JoinObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "JOIN";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done JoinObj" ); #STRIPED_LOG# */
}
}
/**
* A MapObj class
*/
class MapObj extends BaseObj
{
/**
* initialize the class
*/
function MapObj( )
{
$this->BaseObj();
$this->Logger( "MapObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering MapObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "MAP";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done MapObj" ); #STRIPED_LOG# */
}
function getLayerIndex($szIndex)
{
/* #STRIPED_LOG# $this->logFuncStart(LOG_VERBOSE, "Entering getLayerIndex($szIndex)"); #STRIPED_LOG# */
$oLayer = false;
$nCnt = 0;
foreach($this->maoObjs as $oObj)
{
if ($oObj->mszName == "LAYER")
{
if ($oObj->mszIndex == substr($szIndex, 0, 3))
{
break;
}
$nCnt ++;
}
}
/* #STRIPED_LOG# $this->logFuncEnd(LOG_VERBOSE, "getLayerIndex() returning $nCnt."); #STRIPED_LOG# */
return $nCnt;
}
function getLayerByIndex($nLayerIndex)
{
/* #STRIPED_LOG# $this->logFuncStart(LOG_VERBOSE, "Entering getLayerByIndex($nLayerIndex)"); #STRIPED_LOG# */
$oLayer = false;
$nCnt = 0;
foreach($this->maoObjs as $oObj)
{
if ($oObj->mszName == "LAYER")
{
if ($nCnt == $nLayerIndex)
{
$oLayer = $oObj;
break;
}
$nCnt ++;
}
}
if ($oLayer == false)
$this->error(0, "No layer at position $nLayerIndex.");
/* #STRIPED_LOG# $this->logFuncEnd(LOG_VERBOSE, "getLayerByIndex() returning."); #STRIPED_LOG# */
return $oLayer;
}
/**
* get the index of the first layer object
*/
function getFirstLayerIndex()
{
/* #STRIPED_LOG# //$this->log( LOG_ALL, "getFirstLayerIndex() called" ); #STRIPED_LOG# */
$szIndex = false;
foreach($this->maoObjs as $oObj)
{
if ($oObj->mszName == "LAYER")
{
$szIndex = $oObj->getIndex();
break;
}
}
/* #STRIPED_LOG# //$this->log( LOG_ALL, "returning index $szIndex" ); #STRIPED_LOG# */
return $szIndex;
}
}
/**
* A ReferenceObj class
*/
class ReferenceObj extends BaseObj
{
/**
* initialize the class
*/
function ReferenceObj( )
{
$this->BaseObj();
$this->Logger( "ReferenceObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering ReferenceObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "REFERENCE";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done ReferenceObj" ); #STRIPED_LOG# */
}
}
/**
* A QueryMapObj class
*/
class QueryMapObj extends BaseObj
{
/**
* initialize the class
*/
function QueryMapObj( )
{
$this->BaseObj();
$this->Logger( "QueryMapObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering QueryMapObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "QUERYMAP";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done QueryMapObj" ); #STRIPED_LOG# */
}
}
/**
* A ProjectionObj class
*/
class ProjectionObj extends BaseObj
{
/**
* protection attributes
*/
var $maszProjectionAttr;
/**
* initialize the class
*/
function ProjectionObj( )
{
$this->BaseObj();
$this->Logger( "ProjectionObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering ProjectionObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "PROJECTION";
$this->maszProjectionAttr = array();
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done ProjectionObj" ); #STRIPED_LOG# */
}
/**
* Reset all attribute to empty
*/
function clearObject()
{
parent::clearObject();
$this->maszProjectionAttrs = array();
}
/**
* override parsing the mapfile string
*
* @param $oTokMapFile Object needed to navigate in mapfile
* @return false if something gone wrong
*/
function parseMapFileString( &$oTokMapFile )
{
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "parseMapFileString()"); #STRIPED_LOG# */
$szToken =& $oTokMapFile->getNextToken();
while(strcasecmp($szToken, "END") != 0 && $szToken !== FALSE)
{
/* #STRIPED_LOG# //$this->log(LOG_ALL, "parsing token $szToken"); #STRIPED_LOG# */
/* #STRIPED_LOG# //$this->log( LOG_ALL, "inspecting line $szLine" ); #STRIPED_LOG# */
if ($szToken[0] == "\"" || $szToken[0] == "'")
{
$szToken = substr($szToken, 1, -1);
}
array_push($this->maszProjectionAttr, $szToken);
$szToken =& $oTokMapFile->getNextToken();
}
/* #STRIPED_LOG# $this->logFuncEnd( LOG_VERBOSE, "parseMapFileString()"); #STRIPED_LOG# */
return $szToken;
}
/**
* render an HTML input page
*/
function renderAsHTML()
{
$szURI = "http://".$_SERVER['HTTP_HOST'].
$_SERVER['PHP_SELF'];
$szResult = "";
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering renderAsHTML" ); #STRIPED_LOG# */
//implementation
//$this->error( 0, "BaseObj doesn't support rendering to HTML :(");
/* $szResult = "
\n";
$szResult .= "
\n";
$szResult .= "
mszName).
".gif\" WIDTH='20' HEIGHT='20'>
".
"".
$this->mszTitle.
"
\n";
$szResult .= "
\n";*/
$szResult = "\n";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done renderAsHTML" ); #STRIPED_LOG# */
return $szResult;
}
/**
* render as a map file string
*/
function renderAsMapFileString( $szIndent="" )
{
$szResult = "";
if ($this->mszComments != "")
$szResult .= str_replace("#", "$szIndent#", $this->mszComments);
$szResult .= $szIndent.$this->mszName."\n";
$szComment = "";
foreach($this->maszProjectionAttr as $szProj)
{
$szProj = str_replace("\r", "", $szProj);
$szProj = str_replace("\"", "", $szProj);
if (substr($szProj, 0, 1) == "#")
{
$szResult .= $szIndent." $szProj\n";
}
else
{
$szResult .= $szIndent." \"".$szProj."\" $szComment\n";
}
$szComment = "";
}
if ($this->mszEndingComments != "")
$szResult .= str_replace("#", "$szIndent#", $this->mszEndingComments);
$szResult .= $szIndent."END\n";
return $szResult;
}
function processFormVars( $szIndex, $aszFormVars )
{
$bResult = true;
/* #STRIPED_LOG# $this->logFuncStart( LOG_ALL, "entering processFormVars($szIndex, $aszFormVars)" ); #STRIPED_LOG# */
/* #STRIPED_LOG# //$this->log( LOG_ALL, $aszFormVars ); #STRIPED_LOG# */
//process on this obj.\
if (!isset($aszFormVars["PROJECTION"]))
{
$bResult = false;
}
else
{
$this->maszProjectionAttr = explode("\n", $aszFormVars["PROJECTION"]);
}
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done processFormVars()" ); #STRIPED_LOG# */
return $bResult;
}
}
/**
* A LegendObj class
*/
class LegendObj extends BaseObj
{
/**
* initialize the class
*/
function LegendObj( )
{
$this->BaseObj();
$this->Logger( "LegendObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering LegendObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "LEGEND";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done LegendObj" ); #STRIPED_LOG# */
}
}
/**
* A ScalebarObj class
*/
class ScalebarObj extends BaseObj
{
/**
* initialize the class
*/
function ScalebarObj( )
{
$this->BaseObj();
$this->Logger( "ScalebarObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering ScalebarObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "SCALEBAR";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done ScalebarObj" ); #STRIPED_LOG# */
}
}
/**
* A LayerObj class
*/
class LayerObj extends BaseObj
{
/**
* initialize the class
*/
function LayerObj( )
{
$this->BaseObj();
$this->Logger( "LayerObj" );
//log entry
/* #STRIPED_LOG# $this->logFuncStart( LOG_VERBOSE, "entering LayerObj" ); #STRIPED_LOG# */
//implementation
$this->mszName = "LAYER";
//log exit
/* #STRIPED_LOG# $this->logFuncEnd( LOG_ALL, "done LayerObj" ); #STRIPED_LOG# */
}
}
class OutputFormatObj extends BaseObj
{
/**
* initialize the class
*/
function OutputFormatObj( )
{
$this->BaseObj();
$this->Logger( "OutputFormatObj" );
//implementation
$this->mszName = "OUTPUTFORMAT";
$this->maszFormatOption = array();
$this->maszRestricted = array();
$this->maszFormatOptionItemType = array("STRING", "INTEGER", "ENUMERATION");
}
/**
* Reset all attributes to empty
*/
function clearObject()
{
parent::clearObject();
$this->maszFormatOption = array();
$this->maszRestricted = array();
}
/**
* override baseobj implementation because OutputFormat is a special case
*
* @param $oTokMapFile Object needed to navigate in mapfile
* @return false if something gone wrong
**/
function parseMapFileString(&$oTokMapFile)
{
$szComments = "";
$szToken =& $oTokMapFile->getNextToken();
while($szToken[0] == "#")
$szToken =& $oTokMapFile->getNextToken();
//add outputformat elements, with special handling of formatoption:
//the formatoption elements are added to an array.
while(strcasecmp($szToken, "END") != 0 && $szToken !== FALSE)
{
if ($szToken[0] == "#")
{
//found a comment
$szComments .= "$szToken\n";
}
elseif(strcasecmp($szToken, $this->mszName) == 0)
{
//skip the empty line
$this->mszComments = $szComments;
$szComments = "";
}
elseif(strcasecmp($szToken, "FORMATOPTION") == 0)
{
$szValue =& $oTokMapFile->getNextToken();
if ($szValue === FALSE || strcasecmp($szValue, "END") == 0)
{
// Big error, no value found for formatoption
$this->error(ERR_CRITICAL, "No value set for FormatOption ($szToken). Please check your mapfile.");
return false;
}
array_push($this->maszFormatOption, array($szToken, $szValue));
}
else //non-formatoption element.
{
if(isset($this->maoTypes[strtoupper($szToken)]))
{
//okay, its valid
$nResult = $this->maoTypes[strtoupper($szToken)]->parseValue( $oTokMapFile );
if($nResult === false)
{
//something went terribly wrong
$this->error(0, "error parsing map file");
return false;
}
$this->maoTypes[strtoupper($szToken)]->mszComments = $szComments;
$szComments = "";
}
else
{
$this->error( 0, "invalid map file entry $szToken in ". $this->mszName);
}
}
$szToken =& $oTokMapFile->getNextToken();
}
/* #STRIPED_LOG# $this->logFuncEnd(LOG_ALL, "done parseMapFileString"); #STRIPED_LOG# */
return $szToken;
}
/**
* renderAsMapFileString overrides basobj to handle formatoptions
*/
function renderAsMapFileString( $szIndent = "" )
{
$szResult = "";
if ($this->mszComments != "")
$szResult .= str_replace("#", "$szIndent#", $this->mszComments);
$szResult .= $szIndent.$this->mszName."\n";
//outputformat has no subobjects so we just render the internal types
foreach( $this->maoTypes as $oElement )
$szResult .= $oElement->renderAsMapFileString( $szIndent." " );
foreach($this->maszFormatOption as $szKey => $aItem)
{
$szResult .= $szIndent." ".$aItem[0]." \"".$aItem[1]."\"\n";
}
if ($this->mszEndingComments != "")
$szResult .= str_replace("#", "$szIndent#", $this->mszEndingComments);
$szResult .= $szIndent."END\n";
/* #STRIPED_LOG# $this->logFuncEnd(LOG_ALL, "done renderAsMapFileString"); #STRIPED_LOG# */
return $szResult;
}
/**
* addObj adds a new format option item
*/
function addNewObject( $szIndex, $szName )
{
$bResult = false;
//implementation
//$bResult = array_push($this->maszFormatOption, array( $szName, "" ) );
array_push($this->maszFormatOption, array( $szName, "" ) );
return $bResult;
}
/**
* Set all current object attribute with
* oObj values.
*/
function restoreObject($oObj)
{
parent::restoreObject($oObj);
// reset this object and copy all type from oObj
$this->maszFormatOption = array();
foreach($oObj->maszFormatOption as $oFormatOption)
{
array_push($this->maszFormatOption, $oFormatOption);
}
}
function processFormVars( $szIndex, $aszFormVars )
{
$bResult = true;
//process on this obj.\
//handle the rest of the fields
parent::processFormVars( $szIndex, $aszFormVars);
foreach( $this->maszFormatOption as $szKey => $aItem )
{
if (isset($aszFormVars["FORMATOPTION".$szKey]))
{
$szNewValue = $aszFormVars["FORMATOPTION".$szKey];
if ( trim($szNewValue) == "" )
unset($this->maszFormatOption[$szKey]);
else
{
$this->maszFormatOption[$szKey] =
array( "FORMATOPTION", $szNewValue);
}
}
}
//pack the array
$this->maszFormatOption = array_values($this->maszFormatOption);
return $bResult;
}
/**
* render as HTML
*/
function renderAsHTML()
{
$szResult = "";
//log entry
$szURI = "http://".$_SERVER['HTTP_HOST'].
$_SERVER['PHP_SELF'];
//implementation
$szResult .= "