Module: nagvis Branch: master Commit: be00c99d7f6397a096377ead12223955923bc0c8 URL: http://nagvis.git.sourceforge.net/git/gitweb.cgi?p=nagvis/nagvis;a=commit;h=be00c99d7f6397a096377ead12223955923bc0c8
Author: Lars Michelsen <[email protected]> Date: Fri Dec 10 17:48:21 2010 +0100 Refactored map config parsing code to be better readable Conflicts: ChangeLog share/server/core/classes/GlobalMapCfg.php --- ChangeLog | 3 +- share/server/core/classes/GlobalMapCfg.php | 116 ++++++++++++++++------------ 2 files changed, 70 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index de9eede..5386aca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -1.1.6a1 +1.6a1 Core * Added user/role profile config files located in nagvis/etc/profiles/(user|role).profile @@ -11,6 +11,7 @@ Core are build of two arrows * Better handling for map config errors on overview page and map links - no whole screen errors anymore + * Refactored map configuration parsing code * Bugfix: SQLite Update problem while updating from 1.5b1-1.5b3 to 1.5.4/1.5.5 * Bugfix: Fixed configuration file cache when using multiple main config files diff --git a/share/server/core/classes/GlobalMapCfg.php b/share/server/core/classes/GlobalMapCfg.php index a3aa75b..2742d8f 100644 --- a/share/server/core/classes/GlobalMapCfg.php +++ b/share/server/core/classes/GlobalMapCfg.php @@ -1585,55 +1585,75 @@ class GlobalMapCfg { for($l = 0; $l < $iNumLines; $l++) { // Remove spaces, newlines, tabs, etc. (http://de.php.net/rtrim) $file[$l] = rtrim($file[$l]); + // Don't recognize empty lines - if($file[$l] != '') { - // Don't recognize comments and empty lines, do nothing with ending delimiters - $sFirstChar = substr(ltrim($file[$l]), 0, 1); - if($sFirstChar != ';' && $sFirstChar != '#' && $sFirstChar != '}') { - // Determine if this is a new object definition - if(strpos($file[$l], 'define') !== FALSE) { - // If only the global section should be read break the loop after the global section - if($onlyGlobal == 1 && $types['global'] == 1) { - break; - } - - $iDelimPos = strpos($file[$l], '{', 8); - $sObjType = substr($file[$l], 7, ($iDelimPos - 8)); - - if(isset($sObjType) && isset(self::$validConfig[$sObjType])) { - // This is a new definition and it's a valid one - - // Get the type index - $iObjTypeId = $types[$sObjType]; - - $this->mapConfig[$sObjType][$iObjTypeId] = Array( - 'type' => $sObjType, - 'object_id' => $iObjId - ); - - // increase type index - $types[$sObjType]++; - - // Increase the map object id to identify the object on the map - $iObjId++; - } else { - $unknownObject = $this->CORE->getLang()->getText('unknownObject',Array('TYPE' => $sObjType, 'MAPNAME' => $this->name)); - } - } else { - // This is another attribute - $iDelimPos = strpos($file[$l], '='); - $sKey = trim(substr($file[$l],0,$iDelimPos)); - $sValue = trim(substr($file[$l],($iDelimPos+1))); - - if(!isset($ignoreKeys[$sKey])) { - if(isset($createArray[$sKey])) { - $this->mapConfig[$sObjType][$iObjTypeId][$sKey] = explode(',', $sValue); - } else { - $this->mapConfig[$sObjType][$iObjTypeId][$sKey] = $sValue; - } - } - } - } + if($file[$l] == '') + continue; + + // Don't recognize comments and empty lines, do nothing with ending delimiters + $sFirstChar = substr(ltrim($file[$l]), 0, 1); + if($sFirstChar == ';' || $sFirstChar == '#') + continue; + + // This is an object ending. Reset the object type and skip to next line + if($sFirstChar == '}') { + $sObjType = ''; + $iObjTypeId = 0; + + // If only the global section should be read break the loop after the global section + if($onlyGlobal == 1 && $types['global'] == 1) + break; + else + continue; + } + + // Determine if this is a new object definition + if(strpos($file[$l], 'define') !== FALSE) { + $sObjType = substr($file[$l], 7, (strpos($file[$l], '{', 8) - 8)); + if(!isset($sObjType) || !isset(self::$validConfig[$sObjType])) { + new GlobalMessage('ERROR', $this->CORE->getLang()->getText('unknownObject',Array('TYPE' => $sObjType, 'MAPNAME' => $this->name))); + return FALSE; + } + + // This is a new definition and it's a valid one + + // Get the type index + $iObjTypeId = $types[$sObjType]; + + $this->mapConfig[$sObjType][$iObjTypeId] = Array( + 'type' => $sObjType, + 'object_id' => $iObjId + ); + + // increase type index + $types[$sObjType]++; + + // Increase the map object id to identify the object on the map + $iObjId++; + + continue; + } + + // This is another attribute. But it is only ok to proceed here when + // there is an open object + if($sObjType === '') { + new GlobalMessage('ERROR', + $this->CORE->getLang()->getText('Attribute definition out of object. In map [MAPNAME] at line #[LINE].', + Array('MAPNAME' => $this->name, 'LINE' => $l+1))); + return FALSE; + } + + $iDelimPos = strpos($file[$l], '='); + $sKey = trim(substr($file[$l],0,$iDelimPos)); + $sValue = trim(substr($file[$l],($iDelimPos+1))); + + if(isset($ignoreKeys[$sKey])) + continue; + + if(isset($createArray[$sKey])) { + $this->mapConfig[$sObjType][$iObjTypeId][$sKey] = explode(',', $sValue); + } else { + $this->mapConfig[$sObjType][$iObjTypeId][$sKey] = $sValue; } } ------------------------------------------------------------------------------ Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL, new data types, scalar functions, improved concurrency, built-in packages, OCI, SQL*Plus, data movement tools, best practices and more. http://p.sf.net/sfu/oracle-sfdev2dev _______________________________________________ Nagvis-checkins mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/nagvis-checkins
