| 1 | <!----------------------------------------------------------------------- |
|---|
| 2 | ******************************************************************************** |
|---|
| 3 | Copyright 2005-2008 ColdBox Framework by Luis Majano and Ortus Solutions, Corp |
|---|
| 4 | www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com |
|---|
| 5 | ******************************************************************************** |
|---|
| 6 | |
|---|
| 7 | Author : Luis Majano |
|---|
| 8 | Date : September 23, 2005 |
|---|
| 9 | Description : |
|---|
| 10 | This is a utility function for the framework. It includes any methods |
|---|
| 11 | that will be called from the framework for XML parsing. |
|---|
| 12 | -----------------------------------------------------------------------> |
|---|
| 13 | <cfcomponent name="XMLParser" |
|---|
| 14 | hint="This is the XML Parser plugin for the framework. It takes care of any XML parsing for the framework's usage." |
|---|
| 15 | extends="coldbox.system.Plugin" |
|---|
| 16 | output="false" |
|---|
| 17 | cache="false"> |
|---|
| 18 | |
|---|
| 19 | <!------------------------------------------- CONSTRUCTOR -------------------------------------------> |
|---|
| 20 | |
|---|
| 21 | <cffunction name="init" access="public" returntype="XMLParser" output="false" hint="Constructor"> |
|---|
| 22 | <!--- ************************************************************* ---> |
|---|
| 23 | <cfargument name="controller" type="any" required="true"> |
|---|
| 24 | <!--- ************************************************************* ---> |
|---|
| 25 | <cfscript> |
|---|
| 26 | //Call Super |
|---|
| 27 | super.init(arguments.controller); |
|---|
| 28 | |
|---|
| 29 | //Local Plugin Definition |
|---|
| 30 | setpluginName("XMLParser"); |
|---|
| 31 | setpluginVersion("2.0"); |
|---|
| 32 | setpluginDescription("I am the framework's XML parser"); |
|---|
| 33 | |
|---|
| 34 | //ColdBox Properties |
|---|
| 35 | instance.FileSeparator = createObject("java","java.lang.System").getProperty("file.separator"); |
|---|
| 36 | instance.FrameworkConfigFile = ExpandPath("/coldbox/system/config/settings.xml"); |
|---|
| 37 | instance.FrameworkConfigXSDFile = ExpandPath("/coldbox/system/config/config.xsd"); |
|---|
| 38 | |
|---|
| 39 | // Regex for JSON |
|---|
| 40 | instance.jsonRegex = "^(\{|\[)(.)*(\}|\])$"; |
|---|
| 41 | |
|---|
| 42 | //Return |
|---|
| 43 | return this; |
|---|
| 44 | </cfscript> |
|---|
| 45 | </cffunction> |
|---|
| 46 | |
|---|
| 47 | <!------------------------------------------- PUBLIC -------------------------------------------> |
|---|
| 48 | |
|---|
| 49 | <cffunction name="loadFramework" access="public" hint="Load the framework's configuration xml." output="false" returntype="struct"> |
|---|
| 50 | <!--- ************************************************************* ---> |
|---|
| 51 | <cfargument name="overrideConfigFile" required="false" type="string" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file."> |
|---|
| 52 | <!--- ************************************************************* ---> |
|---|
| 53 | <cfscript> |
|---|
| 54 | var settingsStruct = StructNew(); |
|---|
| 55 | var FrameworkParent = ""; |
|---|
| 56 | var distanceToParent = 0; |
|---|
| 57 | var distanceString = ""; |
|---|
| 58 | var fwXML = ""; |
|---|
| 59 | var SettingNodes = ""; |
|---|
| 60 | var ParentAppPath = ""; |
|---|
| 61 | var Conventions = ""; |
|---|
| 62 | var ConfigXMLFilePath = ""; |
|---|
| 63 | var tempFilePath = ""; |
|---|
| 64 | var configFileFound = false; |
|---|
| 65 | var CFMLEngine = controller.oCFMLENGINE.getEngine(); |
|---|
| 66 | var CFMLVersion = controller.oCFMLENGINE.getVersion(); |
|---|
| 67 | var i = 1; |
|---|
| 68 | |
|---|
| 69 | try{ |
|---|
| 70 | //verify Framework settings File |
|---|
| 71 | if ( not fileExists(instance.FrameworkConfigFile) ){ |
|---|
| 72 | $throw("Error finding settings.xml configuration file. The file #instance.FrameworkConfigFile# cannot be found.","","XMLParser.ColdBoxSettingsNotFoundException"); |
|---|
| 73 | } |
|---|
| 74 | //Setup the ColdBox CFML Engine Info |
|---|
| 75 | settingsStruct["CFMLEngine"] = CFMLEngine; |
|---|
| 76 | settingsStruct["CFMLVersion"] = CFMLVersion; |
|---|
| 77 | //Set Internal Parsing And Charting Properties |
|---|
| 78 | if ( CFMLEngine eq controller.oCFMLENGINE.BLUEDRAGON ){ |
|---|
| 79 | settingsStruct["xmlParseActive"] = true; |
|---|
| 80 | settingsStruct["chartingActive"] = true; |
|---|
| 81 | settingsStruct["xmlValidateActive"] = true; |
|---|
| 82 | }//end if bluedragon |
|---|
| 83 | else if ( CFMLEngine eq controller.oCFMLENGINE.RAILO ){ |
|---|
| 84 | settingsStruct["xmlParseActive"] = true; |
|---|
| 85 | if( CFMLVersion gte 8 ){ settingsStruct["chartingActive"] = true; } |
|---|
| 86 | else{ settingsStruct["chartingActive"] = false; } |
|---|
| 87 | settingsStruct["xmlValidateActive"] = true; |
|---|
| 88 | }//end if railo |
|---|
| 89 | else{ |
|---|
| 90 | settingsStruct["chartingActive"] = true; |
|---|
| 91 | //Adobe CF |
|---|
| 92 | settingsStruct["xmlParseActive"] = true; |
|---|
| 93 | settingsStruct["xmlValidateActive"] = true; |
|---|
| 94 | }//end if adobe. |
|---|
| 95 | |
|---|
| 96 | //Determine Parsing Method. |
|---|
| 97 | if ( not settingsStruct["xmlParseActive"] ){ |
|---|
| 98 | fwXML = xmlParse(readFile(instance.FrameworkConfigFile,false,"utf-8")); |
|---|
| 99 | } |
|---|
| 100 | else{ |
|---|
| 101 | fwXML = xmlParse(instance.FrameworkConfigFile); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | //Get SettingNodes From Config |
|---|
| 105 | SettingNodes = XMLSearch(fwXML,"//Settings/Setting"); |
|---|
| 106 | //Insert Settings to Config Struct |
|---|
| 107 | for (i=1; i lte ArrayLen(SettingNodes); i=i+1) |
|---|
| 108 | StructInsert( settingsStruct, SettingNodes[i].XMLAttributes["name"], trim(SettingNodes[i].XMLAttributes["value"])); |
|---|
| 109 | |
|---|
| 110 | //OS File Separator |
|---|
| 111 | StructInsert(settingsStruct, "OSFileSeparator", instance.FileSeparator ); |
|---|
| 112 | |
|---|
| 113 | //Conventions Parsing |
|---|
| 114 | conventions = XMLSearch(fwXML,"//Conventions"); |
|---|
| 115 | StructInsert(settingsStruct, "HandlersConvention", conventions[1].handlerLocation.xmltext); |
|---|
| 116 | StructInsert(settingsStruct, "pluginsConvention", conventions[1].pluginsLocation.xmltext); |
|---|
| 117 | StructInsert(settingsStruct, "LayoutsConvention", conventions[1].layoutsLocation.xmltext); |
|---|
| 118 | StructInsert(settingsStruct, "ViewsConvention", conventions[1].viewsLocation.xmltext); |
|---|
| 119 | StructInsert(settingsStruct, "EventAction", conventions[1].eventAction.xmltext); |
|---|
| 120 | StructInsert(settingsStruct, "ModelsConvention", conventions[1].modelsLocation.xmltext); |
|---|
| 121 | |
|---|
| 122 | //Get ColdBox Config XML File Settings or Override using arguments |
|---|
| 123 | if ( arguments.overrideConfigFile eq ""){ |
|---|
| 124 | //Get the Config XML FIle paths |
|---|
| 125 | ConfigXMLFilePath = replace(conventions[1].configLocation.xmltext, "{sep}", instance.FileSeparator,"all"); |
|---|
| 126 | //Check and validate the list. |
|---|
| 127 | for (i=1; i lte listlen(ConfigXMLFilePath); i=i+1){ |
|---|
| 128 | tempFilePath = controller.GetAppRootPath() & instance.FileSeparator & listgetAt(ConfigXMLFilePath,i); |
|---|
| 129 | if ( fileExists(tempFilePath) ){ |
|---|
| 130 | ConfigXMLFilePath = tempFilePath; |
|---|
| 131 | configFileFound = true; |
|---|
| 132 | break; |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | //Validate the findings |
|---|
| 136 | if( not configFileFound ) |
|---|
| 137 | $throw("ColdBox Application Configuration File can't be found.","The accepted files are: #ConfigXMLFilePath#","XMLParser.ConfigXMLFileNotFoundException"); |
|---|
| 138 | //Insert the correct config file location. |
|---|
| 139 | StructInsert(settingsStruct, "ConfigFileLocation", ConfigXMLFilePath); |
|---|
| 140 | } |
|---|
| 141 | else{ |
|---|
| 142 | StructInsert(settingsStruct, "ConfigFileLocation", getAbsolutePath(arguments.overrideConfigFile) ); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | //Schema Path |
|---|
| 146 | StructInsert(settingsStruct, "ConfigFileSchemaLocation", instance.FrameworkConfigXSDFile); |
|---|
| 147 | |
|---|
| 148 | //Fix Application Path to last / standard. |
|---|
| 149 | if( right(controller.getAppRootPath(),1) neq instance.FileSeparator){ |
|---|
| 150 | controller.setAppRootPath( controller.getAppRootPath() & instance.FileSeparator ); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | //Now set the correct path. |
|---|
| 154 | StructInsert(settingsStruct, "ApplicationPath", controller.getAppRootPath() ); |
|---|
| 155 | |
|---|
| 156 | //Load Framework Path too |
|---|
| 157 | StructInsert(settingsStruct, "FrameworkPath", ExpandPath("/coldbox/system") & instance.FileSeparator ); |
|---|
| 158 | //Load Plugins Path |
|---|
| 159 | StructInsert(settingsStruct, "FrameworkPluginsPath", settingsStruct.FrameworkPath & "plugins"); |
|---|
| 160 | //Set the complete modifylog path |
|---|
| 161 | settingsStruct.ModifyLogLocation = "#settingsStruct.FrameworkPath#config#instance.FileSeparator#readme.txt"; |
|---|
| 162 | |
|---|
| 163 | //return settings |
|---|
| 164 | return settingsStruct; |
|---|
| 165 | } |
|---|
| 166 | catch( Any Exception ){ |
|---|
| 167 | $throw("Error Loading Framework Configuration.","#Exception.Message# #Exception.Detail#","XMLParser.ColdboxSettingsParsingException"); |
|---|
| 168 | } |
|---|
| 169 | </cfscript> |
|---|
| 170 | </cffunction> |
|---|
| 171 | |
|---|
| 172 | <!--- ************************************************************* ---> |
|---|
| 173 | |
|---|
| 174 | <cffunction name="parseConfig" access="public" returntype="struct" output="false" hint="Parse the application configuration file."> |
|---|
| 175 | <!--- ************************************************************* ---> |
|---|
| 176 | <cfargument name="overrideAppMapping" type="string" required="false" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file."/> |
|---|
| 177 | <!--- ************************************************************* ---> |
|---|
| 178 | <cfscript> |
|---|
| 179 | //Create Config Structure |
|---|
| 180 | var ConfigStruct = StructNew(); |
|---|
| 181 | var fwSettingsStruct = getController().getColdboxSettings(); |
|---|
| 182 | var ConfigFileLocation = fwSettingsStruct["ConfigFileLocation"]; |
|---|
| 183 | var configXML = ""; |
|---|
| 184 | //Appmapping Variables |
|---|
| 185 | var webPath = ""; |
|---|
| 186 | var localPath = ""; |
|---|
| 187 | var PathLocation = ""; |
|---|
| 188 | //helper |
|---|
| 189 | var oUtilities = getPlugin("Utilities"); |
|---|
| 190 | //Testers |
|---|
| 191 | var xmlvalidation = ""; |
|---|
| 192 | var errorDetails = ""; |
|---|
| 193 | var i = 1; |
|---|
| 194 | |
|---|
| 195 | try{ |
|---|
| 196 | /* ::::::::::::::::::::::::::::::::::::::::: CONFIG FILE PARSING & VALIDATION :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 197 | //Validate File, just in case. |
|---|
| 198 | if ( not fileExists(ConfigFileLocation) ){ |
|---|
| 199 | $throw("The Config File: #ConfigFileLocation# can't be found.","","XMLParser.ConfigXMLFileNotFoundException"); |
|---|
| 200 | } |
|---|
| 201 | //Determine Parse Type AND Parse Configuration File |
|---|
| 202 | if ( not fwSettingsStruct["xmlParseActive"] ){ |
|---|
| 203 | configXML = xmlParse(readFile(ConfigFileLocation,false,"utf-8")); |
|---|
| 204 | } |
|---|
| 205 | else{ |
|---|
| 206 | configXML = xmlParse(ConfigFileLocation); |
|---|
| 207 | } |
|---|
| 208 | //Validate the config element |
|---|
| 209 | if ( not structKeyExists(configXML, "config") ) |
|---|
| 210 | $throw("No Config element found in the configuration file","","XMLParser.ConfigXMLParsingException"); |
|---|
| 211 | |
|---|
| 212 | /* ::::::::::::::::::::::::::::::::::::::::: APP LOCATION CALCULATIONS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 213 | |
|---|
| 214 | //Setup the Application Path with an Override |
|---|
| 215 | if( arguments.overrideAppMapping neq "" ){ |
|---|
| 216 | ConfigStruct.ApplicationPath = ExpandPath(arguments.overrideAppMapping); |
|---|
| 217 | if( right(ConfigStruct.ApplicationPath,1) neq "/"){ |
|---|
| 218 | ConfigStruct.ApplicationPath = ConfigStruct.ApplicationPath & "/"; |
|---|
| 219 | } |
|---|
| 220 | } |
|---|
| 221 | else{ |
|---|
| 222 | // Setup Default App Path from main controller |
|---|
| 223 | ConfigStruct.ApplicationPath = controller.getAppRootPath(); |
|---|
| 224 | } |
|---|
| 225 | |
|---|
| 226 | //Calculate AppMapping if not set in the config, else auto-calculate |
|---|
| 227 | if ( not structKeyExists(ConfigStruct, "AppMapping") ){ |
|---|
| 228 | webPath = replacenocase(cgi.script_name,getFileFromPath(cgi.script_name),""); |
|---|
| 229 | localPath = getDirectoryFromPath(replacenocase(getTemplatePath(),"\","/","all")); |
|---|
| 230 | PathLocation = findnocase(webPath, localPath); |
|---|
| 231 | |
|---|
| 232 | if ( PathLocation neq 0) |
|---|
| 233 | ConfigStruct.AppMapping = mid(localPath,PathLocation,len(webPath)); |
|---|
| 234 | else |
|---|
| 235 | ConfigStruct.AppMapping = webPath; |
|---|
| 236 | |
|---|
| 237 | //Clean last / |
|---|
| 238 | if ( right(ConfigStruct.AppMapping,1) eq "/" ){ |
|---|
| 239 | if ( len(ConfigStruct.AppMapping) -1 gt 0) |
|---|
| 240 | ConfigStruct.AppMapping = left(ConfigStruct.AppMapping,len(ConfigStruct.AppMapping)-1); |
|---|
| 241 | else |
|---|
| 242 | ConfigStruct.AppMapping = ""; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | //Clean j2ee context |
|---|
| 246 | if( len(getContextRoot()) ) |
|---|
| 247 | ConfigStruct.AppMapping = replacenocase(ConfigStruct.AppMapping,getContextRoot(),""); |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | /* ::::::::::::::::::::::::::::::::::::::::: GET COLDBOX SETTINGS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 251 | parseColdboxSettings(configXML,configStruct,oUtilities,arguments.overrideAppMapping); |
|---|
| 252 | |
|---|
| 253 | /* ::::::::::::::::::::::::::::::::::::::::: YOUR SETTINGS LOADING :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 254 | parseYourSettings(configXML,configStruct,oUtilities); |
|---|
| 255 | |
|---|
| 256 | /* ::::::::::::::::::::::::::::::::::::::::: YOUR CONVENTIONS LOADING :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 257 | parseConventions(configXML,configStruct,oUtilities); |
|---|
| 258 | |
|---|
| 259 | /* ::::::::::::::::::::::::::::::::::::::::: HANDLER-MODELS-PLUGIN INVOCATION PATHS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 260 | parseInvocationPaths(configXML,configStruct,oUtilities); |
|---|
| 261 | |
|---|
| 262 | /* ::::::::::::::::::::::::::::::::::::::::: EXTERNAL LAYOUTS/VIEWS LOCATION :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 263 | parseExternalLocations(configXML,configStruct,oUtilities); |
|---|
| 264 | |
|---|
| 265 | /* ::::::::::::::::::::::::::::::::::::::::: MAIL SETTINGS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 266 | parseMailSettings(configXML,configStruct,oUtilities); |
|---|
| 267 | |
|---|
| 268 | /* ::::::::::::::::::::::::::::::::::::::::: I18N SETTINGS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 269 | parseLocalization(configXML,configStruct,oUtilities); |
|---|
| 270 | |
|---|
| 271 | /* ::::::::::::::::::::::::::::::::::::::::: BUG MAIL SETTINGS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 272 | parseBugTracers(configXML,configStruct,oUtilities); |
|---|
| 273 | |
|---|
| 274 | /* ::::::::::::::::::::::::::::::::::::::::: ENVIRONMENT SETTING :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 275 | ConfigStruct.Environment = "PRODUCTION"; |
|---|
| 276 | |
|---|
| 277 | /* ::::::::::::::::::::::::::::::::::::::::: WS SETTINGS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 278 | parseWebservices(configXML,configStruct,oUtilities); |
|---|
| 279 | |
|---|
| 280 | /* ::::::::::::::::::::::::::::::::::::::::: DATASOURCES SETTINGS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 281 | parseDatasources(configXML,configStruct,oUtilities); |
|---|
| 282 | |
|---|
| 283 | /* ::::::::::::::::::::::::::::::::::::::::: LAYOUT VIEW FOLDER SETTINGS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 284 | parseLayoutsViews(configXML,configStruct,oUtilities); |
|---|
| 285 | |
|---|
| 286 | /* ::::::::::::::::::::::::::::::::::::::::: CACHE SETTINGS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 287 | parseCacheSettings(configXML,configStruct,oUtilities); |
|---|
| 288 | |
|---|
| 289 | /* ::::::::::::::::::::::::::::::::::::::::: DEBUGGER SETTINGS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 290 | parseDebuggerSettings(configXML,configStruct,oUtilities); |
|---|
| 291 | |
|---|
| 292 | /* ::::::::::::::::::::::::::::::::::::::::: INTERCEPTOR SETTINGS :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 293 | parseInterceptors(configXML,configStruct,oUtilities); |
|---|
| 294 | |
|---|
| 295 | /* ::::::::::::::::::::::::::::::::::::::::: LOGBOX Configuration :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 296 | parseLogBox(configXML,configStruct,oUtilities); |
|---|
| 297 | |
|---|
| 298 | /* ::::::::::::::::::::::::::::::::::::::::: CONFIG FILE LAST MODIFIED SETTING :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 299 | ConfigStruct.ConfigTimeStamp = oUtilities.FileLastModified(ConfigFileLocation); |
|---|
| 300 | |
|---|
| 301 | /* ::::::::::::::::::::::::::::::::::::::::: XSD VALIDATION :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 302 | |
|---|
| 303 | } |
|---|
| 304 | catch( Any Exception ){ |
|---|
| 305 | $throw("#Exception.Message# & #Exception.Detail#",Exception.tagContext.toString(), "XMLParser.ConfigXMLParsingException"); |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | //Determine which CF version for XML Parsing method |
|---|
| 309 | if ( fwSettingsStruct["xmlValidateActive"] ){ |
|---|
| 310 | //Finally Validate With XSD |
|---|
| 311 | xmlvalidation = XMLValidate(configXML, fwSettingsStruct["ConfigFileSchemaLocation"]); |
|---|
| 312 | //Validate Errors |
|---|
| 313 | if(NOT xmlvalidation.status){ |
|---|
| 314 | for(i = 1; i lte ArrayLen(xmlvalidation.errors); i = i + 1){ |
|---|
| 315 | errorDetails = errorDetails & xmlvalidation.errors[i] & chr(10) & chr(13); |
|---|
| 316 | } |
|---|
| 317 | //Throw the error. |
|---|
| 318 | $throw("<br>The config.xml file does not validate with the framework's schema.","The error details are:<br/> #errorDetails#","XMLParser.ConfigXMLParsingException"); |
|---|
| 319 | }// if invalid status |
|---|
| 320 | }//if xml validation is on |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | //finish |
|---|
| 324 | return ConfigStruct; |
|---|
| 325 | </cfscript> |
|---|
| 326 | </cffunction> |
|---|
| 327 | |
|---|
| 328 | <!--- parseColdboxSettings ---> |
|---|
| 329 | <cffunction name="parseColdboxSettings" output="false" access="public" returntype="void" hint="Parse ColdBox Settings"> |
|---|
| 330 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 331 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 332 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 333 | <cfargument name="overrideAppMapping" type="string" required="false" default="" hint="Only used for unit testing or reparsing of a specific coldbox config file."/> |
|---|
| 334 | <cfscript> |
|---|
| 335 | var ConfigStruct = arguments.config; |
|---|
| 336 | var fwSettingsStruct = controller.getColdBoxSettings(); |
|---|
| 337 | var SettingNodes = XMLSearch(arguments.xml,"//Settings/Setting"); |
|---|
| 338 | var i=1; |
|---|
| 339 | |
|---|
| 340 | if ( ArrayLen(SettingNodes) eq 0 ) |
|---|
| 341 | $throw("No Setting elements could be found in the configuration file.","","XMLParser.ConfigXMLParsingException"); |
|---|
| 342 | //Insert ColdBox Settings to Config Struct |
|---|
| 343 | for (i=1; i lte ArrayLen(SettingNodes); i=i+1){ |
|---|
| 344 | ConfigStruct[trim(SettingNodes[i].XMLAttributes["name"])] = arguments.utility.placeHolderReplacer(trim(SettingNodes[i].XMLAttributes["value"]),ConfigStruct); |
|---|
| 345 | } |
|---|
| 346 | //overrideAppMapping if passed in. |
|---|
| 347 | if ( arguments.overrideAppMapping neq "" ){ |
|---|
| 348 | ConfigStruct["AppMapping"] = arguments.overrideAppMapping; |
|---|
| 349 | } |
|---|
| 350 | // Clean the first / if found |
|---|
| 351 | if( len(ConfigStruct.AppMapping) eq 1 ){ |
|---|
| 352 | ConfigStruct["AppMapping"] = ""; |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | /* ::::::::::::::::::::::::::::::::::::::::: COLDBOX SETTINGS VALIDATION :::::::::::::::::::::::::::::::::::::::::::: */ |
|---|
| 356 | //Check for AppName or throw |
|---|
| 357 | if ( not StructKeyExists(ConfigStruct, "AppName") ) |
|---|
| 358 | $throw("There was no 'AppName' setting defined. This is required by the framework.","","XMLParser.ConfigXMLParsingException"); |
|---|
| 359 | //Check for Default Event |
|---|
| 360 | if ( not StructKeyExists(ConfigStruct, "DefaultEvent") ) |
|---|
| 361 | $throw("There was no 'DefaultEvent' setting defined. This is required by the framework.","","XMLParser.ConfigXMLParsingException"); |
|---|
| 362 | //Check for Event Name |
|---|
| 363 | if ( not StructKeyExists(ConfigStruct, "EventName") ) |
|---|
| 364 | ConfigStruct["EventName"] = fwSettingsStruct["EventName"] ; |
|---|
| 365 | //Check for Request Start Handler |
|---|
| 366 | if ( not StructKeyExists(ConfigStruct, "ApplicationStartHandler") ) |
|---|
| 367 | ConfigStruct["ApplicationStartHandler"] = ""; |
|---|
| 368 | //Check for Request End Handler |
|---|
| 369 | if ( not StructKeyExists(ConfigStruct, "RequestStartHandler") ) |
|---|
| 370 | ConfigStruct["RequestStartHandler"] = ""; |
|---|
| 371 | //Check for Application Start Handler |
|---|
| 372 | if ( not StructKeyExists(ConfigStruct, "RequestEndHandler") ) |
|---|
| 373 | ConfigStruct["RequestEndHandler"] = ""; |
|---|
| 374 | //Check for Session Start Handler |
|---|
| 375 | if ( not StructKeyExists(ConfigStruct, "SessionStartHandler") ) |
|---|
| 376 | ConfigStruct["SessionStartHandler"] = ""; |
|---|
| 377 | //Check for Session End Handler |
|---|
| 378 | if ( not StructKeyExists(ConfigStruct, "SessionEndHandler") ) |
|---|
| 379 | ConfigStruct["SessionEndHandler"] = ""; |
|---|
| 380 | //Check for InvalidEventHandler |
|---|
| 381 | if ( not StructKeyExists(ConfigStruct, "onInvalidEvent") ) |
|---|
| 382 | ConfigStruct["onInvalidEvent"] = ""; |
|---|
| 383 | //Check For DebugMode in settings |
|---|
| 384 | if ( not structKeyExists(ConfigStruct, "DebugMode") or not isBoolean(ConfigStruct.DebugMode) ) |
|---|
| 385 | ConfigStruct["DebugMode"] = "false"; |
|---|
| 386 | //Check for DebugPassword in settings, else leave blank. |
|---|
| 387 | if ( not structKeyExists(ConfigStruct, "DebugPassword") ) |
|---|
| 388 | ConfigStruct["DebugPassword"] = ""; |
|---|
| 389 | //Check for ReinitPassword |
|---|
| 390 | if ( not structKeyExists(ConfigStruct, "ReinitPassword") ) |
|---|
| 391 | ConfigStruct["ReinitPassword"] = ""; |
|---|
| 392 | //Check For Owner Email or Throw |
|---|
| 393 | if ( not StructKeyExists(ConfigStruct, "OwnerEmail") ) |
|---|
| 394 | ConfigStruct["OwnerEmail"] = ""; |
|---|
| 395 | //Check For EnableDumpvar or set to true |
|---|
| 396 | if ( not StructKeyExists(ConfigStruct, "EnableDumpVar") or not isBoolean(ConfigStruct.EnableDumpVar)) |
|---|
| 397 | ConfigStruct["EnableDumpVar"] = "true"; |
|---|
| 398 | //Check For EnableBugReports Active or set to true |
|---|
| 399 | if ( not StructKeyExists(ConfigStruct, "EnableBugReports") or not isBoolean(ConfigStruct.EnableBugReports)) |
|---|
| 400 | ConfigStruct["EnableBugReports"] = "true"; |
|---|
| 401 | //Check For UDFLibraryFile |
|---|
| 402 | if ( not StructKeyExists(ConfigStruct, "UDFLibraryFile") ) |
|---|
| 403 | ConfigStruct["UDFLibraryFile"] = ""; |
|---|
| 404 | //Check For CustomErrorTemplate |
|---|
| 405 | if ( not StructKeyExists(ConfigStruct, "CustomErrorTemplate") ) |
|---|
| 406 | ConfigStruct["CustomErrorTemplate"] = ""; |
|---|
| 407 | //Check for CustomEmailBugReport |
|---|
| 408 | if ( not StructKeyExists(ConfigStruct, "CustomEmailBugReport") ) |
|---|
| 409 | ConfigStruct["CustomEmailBugReport"] = ""; |
|---|
| 410 | //Check for MessageboxStyleOverride if found, default = false |
|---|
| 411 | if ( not structkeyExists(ConfigStruct, "MessageboxStyleOverride") or not isBoolean(ConfigStruct.MessageboxStyleOverride) ) |
|---|
| 412 | ConfigStruct["MessageboxStyleOverride"] = "false"; |
|---|
| 413 | //Check for HandlersIndexAutoReload, default = false |
|---|
| 414 | if ( not structkeyExists(ConfigStruct, "HandlersIndexAutoReload") or not isBoolean(ConfigStruct.HandlersIndexAutoReload) ) |
|---|
| 415 | ConfigStruct["HandlersIndexAutoReload"] = false; |
|---|
| 416 | //Check for ConfigAutoReload |
|---|
| 417 | if ( not structKeyExists(ConfigStruct, "ConfigAutoReload") or not isBoolean(ConfigStruct.ConfigAutoReload) ) |
|---|
| 418 | ConfigStruct["ConfigAutoReload"] = false; |
|---|
| 419 | //Check for ExceptionHandler if found |
|---|
| 420 | if ( not structkeyExists(ConfigStruct, "ExceptionHandler") ) |
|---|
| 421 | ConfigStruct["ExceptionHandler"] = ""; |
|---|
| 422 | //Check for PluginsExternalLocation if found |
|---|
| 423 | if ( not structkeyExists(ConfigStruct, "PluginsExternalLocation") ) |
|---|
| 424 | ConfigStruct["PluginsExternalLocation"] = ""; |
|---|
| 425 | //Check for Handler Caching |
|---|
| 426 | if ( not structKeyExists(ConfigStruct, "HandlerCaching") or not isBoolean(ConfigStruct.HandlerCaching) ) |
|---|
| 427 | ConfigStruct["HandlerCaching"] = true; |
|---|
| 428 | //Check for Event Caching |
|---|
| 429 | if ( not structKeyExists(ConfigStruct, "EventCaching") or not isBoolean(ConfigStruct.EventCaching) ) |
|---|
| 430 | ConfigStruct["EventCaching"] = true; |
|---|
| 431 | //Check for IOC Framework & Settings |
|---|
| 432 | if ( not structKeyExists(ConfigStruct, "IOCFramework") ) |
|---|
| 433 | ConfigStruct["IOCFramework"] = ""; |
|---|
| 434 | if ( not structKeyExists(ConfigStruct, "IOCFrameworkReload") or not isBoolean(ConfigStruct.IOCFrameworkReload) ) |
|---|
| 435 | ConfigStruct["IOCFrameworkReload"] = false; |
|---|
| 436 | if ( not structKeyExists(ConfigStruct, "IOCDefinitionFile") ) |
|---|
| 437 | ConfigStruct["IOCDefinitionFile"] = ""; |
|---|
| 438 | if ( not structKeyExists(ConfigStruct, "IOCObjectCaching") or not isBoolean(ConfigStruct.IOCObjectCaching) ) |
|---|
| 439 | ConfigStruct["IOCObjectCaching"] = false; |
|---|
| 440 | //RequestContextDecorator |
|---|
| 441 | if ( not structKeyExists(ConfigStruct, "RequestContextDecorator") or len(ConfigStruct["RequestContextDecorator"]) eq 0 ){ |
|---|
| 442 | ConfigStruct["RequestContextDecorator"] = ""; |
|---|
| 443 | } |
|---|
| 444 | //Check for ProxyReturnCollection |
|---|
| 445 | if ( not structKeyExists(ConfigStruct, "ProxyReturnCollection") or not isBoolean(ConfigStruct.ProxyReturnCollection) ) |
|---|
| 446 | ConfigStruct["ProxyReturnCollection"] = false; |
|---|
| 447 | //Check for External Handlers Location |
|---|
| 448 | if ( not structKeyExists(ConfigStruct, "HandlersExternalLocation") or len(ConfigStruct["HandlersExternalLocation"]) eq 0 ) |
|---|
| 449 | ConfigStruct["HandlersExternalLocation"] = ""; |
|---|
| 450 | //Check for Models External Location |
|---|
| 451 | if ( not structKeyExists(ConfigStruct, "ModelsExternalLocation") or len(ConfigStruct["ModelsExternalLocation"]) eq 0 ) |
|---|
| 452 | ConfigStruct["ModelsExternalLocation"] = ""; |
|---|
| 453 | //Check for Models ObjectCaching |
|---|
| 454 | if ( not structKeyExists(ConfigStruct, "ModelsObjectCaching") or not isBoolean(ConfigStruct["ModelsObjectCaching"]) ) |
|---|
| 455 | ConfigStruct["ModelsObjectCaching"] = true; |
|---|
| 456 | //Check for ModelsDebugMode |
|---|
| 457 | if ( not structKeyExists(ConfigStruct, "ModelsDebugMode") or not isBoolean(ConfigStruct["ModelsDebugMode"]) ) |
|---|
| 458 | ConfigStruct["ModelsDebugMode"] = fwSettingsStruct["ModelsDebugMode"]; |
|---|
| 459 | //Check for ModelsSetterInjection |
|---|
| 460 | if ( not structKeyExists(ConfigStruct, "ModelsSetterInjection") or not isBoolean(ConfigStruct["ModelsSetterInjection"]) ) |
|---|
| 461 | ConfigStruct["ModelsSetterInjection"] = fwSettingsStruct["ModelsSetterInjection"]; |
|---|
| 462 | //Check for ModelsDICompleteUDF |
|---|
| 463 | if ( not structKeyExists(ConfigStruct, "ModelsDICompleteUDF") or len(ConfigStruct["ModelsDICompleteUDF"]) eq 0 ) |
|---|
| 464 | ConfigStruct["ModelsDICompleteUDF"] = fwSettingsStruct["ModelsDICompleteUDF"]; |
|---|
| 465 | //Check for ModelsStopRecursion |
|---|
| 466 | if ( not structKeyExists(ConfigStruct, "ModelsStopRecursion") or len(ConfigStruct["ModelsStopRecursion"]) eq 0 ) |
|---|
| 467 | ConfigStruct["ModelsStopRecursion"] = fwSettingsStruct["ModelsStopRecursion"]; |
|---|
| 468 | //Check for ModelsDefinitionFile |
|---|
| 469 | if ( not structKeyExists(ConfigStruct, "ModelsDefinitionFile") or len(ConfigStruct["ModelsDefinitionFile"]) eq 0 ) |
|---|
| 470 | ConfigStruct["ModelsDefinitionFile"] = fwSettingsStruct["ModelsDefinitionFile"]; |
|---|
| 471 | |
|---|
| 472 | /* Flash URL Persist Scope Override */ |
|---|
| 473 | if( structKeyExists(ConfigStruct,"FlashURLPersistScope") and reFindnocase("^(session|client)$",ConfigStruct["FlashURLPersistScope"]) ){ |
|---|
| 474 | fwSettingsStruct["FlashURLPersistScope"] = ConfigStruct["FlashURLPersistScope"]; |
|---|
| 475 | } |
|---|
| 476 | </cfscript> |
|---|
| 477 | </cffunction> |
|---|
| 478 | |
|---|
| 479 | <!--- parseInvocationPaths ---> |
|---|
| 480 | <cffunction name="parseInvocationPaths" output="false" access="public" returntype="void" hint="Parse Invocation paths"> |
|---|
| 481 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 482 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 483 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 484 | <cfscript> |
|---|
| 485 | var ConfigStruct = arguments.config; |
|---|
| 486 | var fwSettingsStruct = controller.getColdBoxSettings(); |
|---|
| 487 | |
|---|
| 488 | //Set the Handlers External Configuration Paths |
|---|
| 489 | if( configStruct["HandlersExternalLocation"] neq "" ){ |
|---|
| 490 | //Expand the external location to get a registration path |
|---|
| 491 | configStruct["HandlersExternalLocationPath"] = ExpandPath("/" & replace(ConfigStruct["HandlersExternalLocation"],".","/","all")); |
|---|
| 492 | } |
|---|
| 493 | else{ |
|---|
| 494 | configStruct["HandlersExternalLocationPath"] = ""; |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | //Set the Handlers,Models, & Custom Plugin Invocation & Physical Path for this Application |
|---|
| 498 | if( ConfigStruct["AppMapping"] neq ""){ |
|---|
| 499 | |
|---|
| 500 | //Parse out the first / to create invocation Path |
|---|
| 501 | if ( left(ConfigStruct["AppMapping"],1) eq "/" ){ |
|---|
| 502 | ConfigStruct["AppMapping"] = removeChars(ConfigStruct["AppMapping"],1,1); |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | //Set the Invocation Path |
|---|
| 506 | ConfigStruct["HandlersInvocationPath"] = replace(ConfigStruct["AppMapping"],"/",".","all") & ".#fwSettingsStruct.handlersConvention#"; |
|---|
| 507 | ConfigStruct["MyPluginsInvocationPath"] = replace(ConfigStruct["AppMapping"],"/",".","all") & ".#fwSettingsStruct.pluginsConvention#"; |
|---|
| 508 | ConfigStruct["ModelsInvocationPath"] = replace(ConfigStruct["AppMapping"],"/",".","all") & ".#fwSettingsStruct.ModelsConvention#"; |
|---|
| 509 | |
|---|
| 510 | //Set the Location Path |
|---|
| 511 | ConfigStruct["HandlersPath"] = ConfigStruct["AppMapping"]; |
|---|
| 512 | ConfigStruct["MyPluginsPath"] = ConfigStruct["AppMapping"]; |
|---|
| 513 | ConfigStruct["ModelsPath"] = ConfigStruct["AppMapping"]; |
|---|
| 514 | |
|---|
| 515 | //Set the physical path according to system. |
|---|
| 516 | ConfigStruct["HandlersPath"] = "/" & ConfigStruct["HandlersPath"] & "/#fwSettingsStruct.handlersConvention#"; |
|---|
| 517 | ConfigStruct["MyPluginsPath"] = "/" & ConfigStruct["MyPluginsPath"] & "/#fwSettingsStruct.pluginsConvention#"; |
|---|
| 518 | ConfigStruct["ModelsPath"] = "/" & ConfigStruct["ModelsPath"] & "/#fwSettingsStruct.ModelsConvention#"; |
|---|
| 519 | |
|---|
| 520 | //Set the Handlerspath expanded. |
|---|
| 521 | ConfigStruct["HandlersPath"] = ExpandPath(ConfigStruct["HandlersPath"]); |
|---|
| 522 | ConfigStruct["MyPluginsPath"] = ExpandPath(ConfigStruct["MyPluginsPath"]); |
|---|
| 523 | ConfigStruct["ModelsPath"] = ExpandPath(ConfigStruct["ModelsPath"]); |
|---|
| 524 | |
|---|
| 525 | } |
|---|
| 526 | else{ |
|---|
| 527 | //Parse out the first / to create the invocation Path |
|---|
| 528 | if ( left(ConfigStruct["AppMapping"],1) eq "/" ){ |
|---|
| 529 | ConfigStruct["AppMapping"] = removeChars(ConfigStruct["AppMapping"],1,1); |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | /* Handler Registration */ |
|---|
| 533 | ConfigStruct["HandlersInvocationPath"] = "#fwSettingsStruct.handlersConvention#"; |
|---|
| 534 | ConfigStruct["HandlersPath"] = controller.getAppRootPath() & "#fwSettingsStruct.handlersConvention#"; |
|---|
| 535 | |
|---|
| 536 | /* Custom Plugins Registration */ |
|---|
| 537 | ConfigStruct["MyPluginsInvocationPath"] = "#fwSettingsStruct.pluginsConvention#"; |
|---|
| 538 | ConfigStruct["MyPluginsPath"] = controller.getAppRootPath() & "#fwSettingsStruct.pluginsConvention#"; |
|---|
| 539 | |
|---|
| 540 | /* Models Registration */ |
|---|
| 541 | ConfigStruct["ModelsInvocationPath"] = "#fwSettingsStruct.ModelsConvention#"; |
|---|
| 542 | ConfigStruct["ModelsPath"] = controller.getAppRootPath() & "#fwSettingsStruct.ModelsConvention#"; |
|---|
| 543 | } |
|---|
| 544 | </cfscript> |
|---|
| 545 | </cffunction> |
|---|
| 546 | |
|---|
| 547 | <!--- parseExternalLocations ---> |
|---|
| 548 | <cffunction name="parseExternalLocations" output="false" access="public" returntype="void" hint="Parse External locations"> |
|---|
| 549 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 550 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 551 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 552 | <cfscript> |
|---|
| 553 | var ConfigStruct = arguments.config; |
|---|
| 554 | |
|---|
| 555 | // check for ViewsExternalLocation |
|---|
| 556 | if( structKeyExists(configStruct,"ViewsExternalLocation") and configStruct["ViewsExternalLocation"] neq "" ){ |
|---|
| 557 | // Verify the locations, do relative to the app mapping first |
|---|
| 558 | if( directoryExists(controller.getAppRootPath() & configStruct["ViewsExternalLocation"]) ){ |
|---|
| 559 | configStruct["ViewsExternalLocation"] = "/" & ConfigStruct["AppMapping"] & "/" & configStruct["ViewsExternalLocation"]; |
|---|
| 560 | } |
|---|
| 561 | else if( not directoryExists(expandPath(configStruct["ViewsExternalLocation"])) ){ |
|---|
| 562 | $throw("ViewsExternalLocation could not be found.","The directories tested was relative and expanded using #configStruct['ViewsExternalLocation']#. Please verify your setting.","XMLParser.ConfigXMLParsingException"); |
|---|
| 563 | } |
|---|
| 564 | // Cleanup |
|---|
| 565 | if ( right(configStruct["ViewsExternalLocation"],1) eq "/" ){ |
|---|
| 566 | configStruct["ViewsExternalLocation"] = left(configStruct["ViewsExternalLocation"],len(configStruct["ViewsExternalLocation"])-1); |
|---|
| 567 | } |
|---|
| 568 | }else{ |
|---|
| 569 | configStruct["ViewsExternalLocation"] = ""; |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | // check for LayoutsExternalLocation |
|---|
| 573 | if( structKeyExists(configStruct,"LayoutsExternalLocation") and configStruct["LayoutsExternalLocation"] neq "" ){ |
|---|
| 574 | // Verify the locations, do relative to the app mapping first |
|---|
| 575 | if( directoryExists(controller.getAppRootPath() & configStruct["LayoutsExternalLocation"]) ){ |
|---|
| 576 | configStruct["LayoutsExternalLocation"] = "/" & ConfigStruct["AppMapping"] & "/" & configStruct["LayoutsExternalLocation"]; |
|---|
| 577 | } |
|---|
| 578 | else if( not directoryExists(expandPath(configStruct["LayoutsExternalLocation"])) ){ |
|---|
| 579 | $throw("LayoutsExternalLocation could not be found.","The directories tested was relative and expanded using #configStruct['LayoutsExternalLocation']#. Please verify your setting.","XMLParser.ConfigXMLParsingException"); |
|---|
| 580 | } |
|---|
| 581 | // Cleanup |
|---|
| 582 | if ( right(configStruct["LayoutsExternalLocation"],1) eq "/" ){ |
|---|
| 583 | configStruct["LayoutsExternalLocation"] = left(configStruct["LayoutsExternalLocation"],len(configStruct["LayoutsExternalLocation"])-1); |
|---|
| 584 | } |
|---|
| 585 | }else{ |
|---|
| 586 | configStruct["LayoutsExternalLocation"] = ""; |
|---|
| 587 | } |
|---|
| 588 | </cfscript> |
|---|
| 589 | </cffunction> |
|---|
| 590 | |
|---|
| 591 | <!--- parseConventions ---> |
|---|
| 592 | <cffunction name="parseConventions" output="false" access="public" returntype="void" hint="Parse Conventions"> |
|---|
| 593 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 594 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 595 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 596 | <cfscript> |
|---|
| 597 | var ConfigStruct = arguments.config; |
|---|
| 598 | var conventions = XMLSearch(arguments.xml,"//Conventions"); |
|---|
| 599 | var fwSettingsStruct = controller.getColdboxSettings(); |
|---|
| 600 | |
|---|
| 601 | if( ArrayLen(conventions) ){ |
|---|
| 602 | /* Override conventions on a per found basis. */ |
|---|
| 603 | if( structKeyExists(conventions[1],"handlersLocation") ){ fwSettingsStruct["handlersConvention"] = trim(conventions[1].handlersLocation.xmltext); } |
|---|
| 604 | if( structKeyExists(conventions[1],"pluginsLocation") ){ fwSettingsStruct["pluginsConvention"] = trim(conventions[1].pluginsLocation.xmltext); } |
|---|
| 605 | if( structKeyExists(conventions[1],"layoutsLocation") ){ fwSettingsStruct["LayoutsConvention"] = trim(conventions[1].layoutsLocation.xmltext); } |
|---|
| 606 | if( structKeyExists(conventions[1],"viewsLocation") ){ fwSettingsStruct["ViewsConvention"] = trim(conventions[1].viewsLocation.xmltext); } |
|---|
| 607 | if( structKeyExists(conventions[1],"eventAction") ){ fwSettingsStruct["eventAction"] = trim(conventions[1].eventAction.xmltext); } |
|---|
| 608 | if( structKeyExists(conventions[1],"modelsLocation") ){ fwSettingsStruct["ModelsConvention"] = trim(conventions[1].modelsLocation.xmltext); } |
|---|
| 609 | } |
|---|
| 610 | </cfscript> |
|---|
| 611 | </cffunction> |
|---|
| 612 | |
|---|
| 613 | <!--- parseYourSettings ---> |
|---|
| 614 | <cffunction name="parseYourSettings" output="false" access="public" returntype="void" hint="Parse Your Settings"> |
|---|
| 615 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 616 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 617 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 618 | <cfscript> |
|---|
| 619 | var ConfigStruct = arguments.config; |
|---|
| 620 | //Your Settings To Load |
|---|
| 621 | var YourSettingNodes = XMLSearch(arguments.xml, "//YourSettings/Setting"); |
|---|
| 622 | var i=1; |
|---|
| 623 | var tester = ""; |
|---|
| 624 | |
|---|
| 625 | if ( ArrayLen(YourSettingNodes) ){ |
|---|
| 626 | //Insert Your Settings to Config Struct |
|---|
| 627 | for (i=1; i lte ArrayLen(YourSettingNodes); i=i+1){ |
|---|
| 628 | /* Get Setting with PlaceHolding */ |
|---|
| 629 | tester = arguments.utility.placeHolderReplacer(trim(YourSettingNodes[i].XMLAttributes["value"]),ConfigStruct); |
|---|
| 630 | //Test for JSON |
|---|
| 631 | if( reFindNocase(instance.jsonRegex,tester) ){ |
|---|
| 632 | ConfigStruct[YourSettingNodes[i].XMLAttributes["name"]] = getPlugin("JSON").decode(replace(tester,"'","""","all")); |
|---|
| 633 | } |
|---|
| 634 | else |
|---|
| 635 | ConfigStruct[YourSettingNodes[i].XMLAttributes["name"]] = tester; |
|---|
| 636 | } |
|---|
| 637 | } |
|---|
| 638 | </cfscript> |
|---|
| 639 | </cffunction> |
|---|
| 640 | |
|---|
| 641 | <!--- parseLocalization ---> |
|---|
| 642 | <cffunction name="parseMailSettings" output="false" access="public" returntype="void" hint="Parse Mail Settings"> |
|---|
| 643 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 644 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 645 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 646 | <cfargument name="isOverride" type="boolean" required="false" default="false" hint="Flag to denote if overriding or first time runner."/> |
|---|
| 647 | <cfscript> |
|---|
| 648 | var ConfigStruct = arguments.config; |
|---|
| 649 | //Mail Settings |
|---|
| 650 | var MailSettingsNodes = XMLSearch(arguments.xml,"//MailServerSettings"); |
|---|
| 651 | |
|---|
| 652 | //Check if empty |
|---|
| 653 | if ( ArrayLen(MailSettingsNodes) gt 0 and ArrayLen(MailSettingsNodes[1].XMLChildren) gt 0){ |
|---|
| 654 | //Checks |
|---|
| 655 | if ( structKeyExists(MailSettingsNodes[1], "MailServer") ) |
|---|
| 656 | ConfigStruct.MailServer = trim(MailSettingsNodes[1].MailServer.xmlText); |
|---|
| 657 | else |
|---|
| 658 | ConfigStruct.MailServer = ""; |
|---|
| 659 | |
|---|
| 660 | //Mail username |
|---|
| 661 | if ( structKeyExists(MailSettingsNodes[1], "MailUsername") ) |
|---|
| 662 | ConfigStruct.MailUsername = trim(MailSettingsNodes[1].MailUsername.xmlText); |
|---|
| 663 | else |
|---|
| 664 | ConfigStruct.MailUsername = ""; |
|---|
| 665 | |
|---|
| 666 | //Mail password |
|---|
| 667 | if ( structKeyExists(MailSettingsNodes[1], "MailPassword") ) |
|---|
| 668 | ConfigStruct.MailPassword = trim(MailSettingsNodes[1].MailPassword.xmlText); |
|---|
| 669 | else |
|---|
| 670 | ConfigStruct.MailPassword = ""; |
|---|
| 671 | |
|---|
| 672 | //Mail Port |
|---|
| 673 | if ( structKeyExists(MailSettingsNodes[1], "MailPort") ){ |
|---|
| 674 | if (trim(MailSettingsNodes[1].MailPort.xmlText) neq "") |
|---|
| 675 | ConfigStruct.MailPort = trim(MailSettingsNodes[1].MailPort.xmlText); |
|---|
| 676 | else |
|---|
| 677 | ConfigStruct.MailPort = 25; |
|---|
| 678 | } |
|---|
| 679 | else |
|---|
| 680 | ConfigStruct.MailPort = 25; |
|---|
| 681 | } |
|---|
| 682 | else if (NOT arguments.isOverride){ |
|---|
| 683 | ConfigStruct.MailServer = ""; |
|---|
| 684 | ConfigStruct.MailUsername = ""; |
|---|
| 685 | ConfigStruct.MailPassword = ""; |
|---|
| 686 | ConfigStruct.MailPort = 25; |
|---|
| 687 | } |
|---|
| 688 | </cfscript> |
|---|
| 689 | </cffunction> |
|---|
| 690 | |
|---|
| 691 | <!--- parseLocalization ---> |
|---|
| 692 | <cffunction name="parseLocalization" output="false" access="public" returntype="void" hint="Parse localization"> |
|---|
| 693 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 694 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 695 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 696 | <cfargument name="isOverride" type="boolean" required="false" default="false" hint="Flag to denote if overriding or first time runner."/> |
|---|
| 697 | <cfscript> |
|---|
| 698 | var ConfigStruct = arguments.config; |
|---|
| 699 | //i18N Settings |
|---|
| 700 | var i18NSettingNodes = XMLSearch(arguments.xml,"//i18N"); |
|---|
| 701 | var i=1; |
|---|
| 702 | var DefaultLocale = ""; |
|---|
| 703 | |
|---|
| 704 | //Check if empty |
|---|
| 705 | if ( ArrayLen(i18NSettingNodes) gt 0 and ArrayLen(i18NSettingNodes[1].XMLChildren) gt 0){ |
|---|
| 706 | //Parse i18N Settings |
|---|
| 707 | for (i=1; i lte ArrayLen(i18NSettingNodes[1].XMLChildren); i=i+1){ |
|---|
| 708 | //Set the Resource Bundle if Using it. |
|---|
| 709 | if ( i18NSettingNodes[1].XMLChildren[i].XMLName eq "DefaultResourceBundle" and len(trim(i18NSettingNodes[1].XMLChildren[i].XMLText)) neq 0 ){ |
|---|
| 710 | i18NSettingNodes[1].XMLChildren[i].XMLText = trim(i18NSettingNodes[1].XMLChildren[i].XMLText); |
|---|
| 711 | } |
|---|
| 712 | //Check if locale is valid. |
|---|
| 713 | if ( i18NSettingNodes[1].XMLChildren[i].XMLName eq "DefaultLocale" ){ |
|---|
| 714 | DefaultLocale = trim(i18NSettingNodes[1].XMLChildren[i].XMLText); |
|---|
| 715 | //set the right syntax just in case. |
|---|
| 716 | i18NSettingNodes[1].XMLChildren[i].XMLText = lcase(listFirst(DefaultLocale,"_")) & "_" & ucase(listLast(DefaultLocale,"_")); |
|---|
| 717 | } |
|---|
| 718 | //Insert to structure. |
|---|
| 719 | ConfigStruct[trim(i18NSettingNodes[1].XMLChildren[i].XMLName)] = trim(i18NSettingNodes[1].XMLChildren[i].XMLText); |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | //set i18n |
|---|
| 723 | ConfigStruct["using_i18N"] = true; |
|---|
| 724 | |
|---|
| 725 | // Empty Checks |
|---|
| 726 | if ( not structKeyExists(ConfigStruct, "DefaultResourceBundle") ){ |
|---|
| 727 | ConfigStruc.DefaultResourceBundle = ""; |
|---|
| 728 | } |
|---|
| 729 | if ( not structKeyExists(ConfigStruct, "UknownTranslation") ){ |
|---|
| 730 | ConfigStruct.UknownTranslation = ""; |
|---|
| 731 | } |
|---|
| 732 | } |
|---|
| 733 | else if (NOT arguments.isOverride){ |
|---|
| 734 | ConfigStruct.DefaultResourceBundle = ""; |
|---|
| 735 | ConfigStruct.DefaultLocale = ""; |
|---|
| 736 | ConfigStruct.LocaleStorage = ""; |
|---|
| 737 | ConfigStruct.UknownTranslation = ""; |
|---|
| 738 | ConfigStruct["using_i18N"] = false; |
|---|
| 739 | } |
|---|
| 740 | </cfscript> |
|---|
| 741 | </cffunction> |
|---|
| 742 | |
|---|
| 743 | <!--- parseBugTracers ---> |
|---|
| 744 | <cffunction name="parseBugTracers" output="false" access="public" returntype="void" hint="Parse bug emails"> |
|---|
| 745 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 746 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 747 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 748 | <cfargument name="isOverride" type="boolean" required="false" default="false" hint="Flag to denote if overriding or first time runner."/> |
|---|
| 749 | <cfscript> |
|---|
| 750 | var ConfigStruct = arguments.config; |
|---|
| 751 | var BugEmailNodes = XMLSearch(arguments.xml,"//BugTracerReports/BugEmail"); |
|---|
| 752 | var i=1; |
|---|
| 753 | var BugEmails = ""; |
|---|
| 754 | |
|---|
| 755 | if( arrayLen(BugEmailNodes) ){ |
|---|
| 756 | for (i=1; i lte ArrayLen(BugEmailNodes); i=i+1){ |
|---|
| 757 | BugEmails = BugEmails & trim(BugEmailNodes[i].XMLText); |
|---|
| 758 | if ( i neq ArrayLen(BugEmailNodes) ) |
|---|
| 759 | BugEmails = BugEmails & ","; |
|---|
| 760 | } |
|---|
| 761 | //Insert Into Config |
|---|
| 762 | ConfigStruct.BugEmails = BugEmails; |
|---|
| 763 | } |
|---|
| 764 | else if( NOT arguments.isOverride ){ |
|---|
| 765 | ConfigStruct.BugEmails = ""; |
|---|
| 766 | } |
|---|
| 767 | </cfscript> |
|---|
| 768 | </cffunction> |
|---|
| 769 | |
|---|
| 770 | <!--- parseWebservices ---> |
|---|
| 771 | <cffunction name="parseWebservices" output="false" access="public" returntype="void" hint="Parse webservices"> |
|---|
| 772 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 773 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 774 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 775 | <cfargument name="isOverride" type="boolean" required="false" default="false" hint="Flag to denote if overriding or first time runner."/> |
|---|
| 776 | <cfscript> |
|---|
| 777 | var ConfigStruct = arguments.config; |
|---|
| 778 | var WebServiceNodes = ""; |
|---|
| 779 | var i=1; |
|---|
| 780 | |
|---|
| 781 | //Get Web Services From Config. |
|---|
| 782 | WebServiceNodes = XMLSearch(arguments.xml,"//WebServices/WebService"); |
|---|
| 783 | if ( ArrayLen(WebServiceNodes) ){ |
|---|
| 784 | // Init webservices holder structure |
|---|
| 785 | configStruct.webservices = structnew(); |
|---|
| 786 | for (i=1; i lte ArrayLen(WebServiceNodes); i=i+1){ |
|---|
| 787 | configStruct.webservices[WebServiceNodes[i].XMLAttributes["name"]] = trim(WebServiceNodes[i].XMLAttributes["URL"]); |
|---|
| 788 | } |
|---|
| 789 | } |
|---|
| 790 | else if( NOT arguments.isOverride ){ |
|---|
| 791 | configStruct.webservices = structnew(); |
|---|
| 792 | } |
|---|
| 793 | </cfscript> |
|---|
| 794 | </cffunction> |
|---|
| 795 | |
|---|
| 796 | <!--- parseDatasources ---> |
|---|
| 797 | <cffunction name="parseDatasources" output="false" access="public" returntype="void" hint="Parse Datsources"> |
|---|
| 798 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 799 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 800 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 801 | <cfargument name="isOverride" type="boolean" required="false" default="false" hint="Flag to denote if overriding or first time runner."/> |
|---|
| 802 | <cfscript> |
|---|
| 803 | var ConfigStruct = arguments.config; |
|---|
| 804 | var DatasourcesNodes = ""; |
|---|
| 805 | var i=1; |
|---|
| 806 | var DSNStruct = ""; |
|---|
| 807 | |
|---|
| 808 | //Datasources Support |
|---|
| 809 | DatasourcesNodes = XMLSearch(arguments.xml,"//Datasources/Datasource"); |
|---|
| 810 | if ( ArrayLen(DatasourcesNodes) ){ |
|---|
| 811 | //Create Structures |
|---|
| 812 | ConfigStruct.Datasources = structnew(); |
|---|
| 813 | for(i=1;i lte ArrayLen(DatasourcesNodes); i=i+1){ |
|---|
| 814 | DSNStruct = structNew(); |
|---|
| 815 | |
|---|
| 816 | if ( not structKeyExists(DatasourcesNodes[i].XMLAttributes, "Alias") or len(Trim(DatasourcesNodes[i].XMLAttributes["Alias"])) eq 0 ) |
|---|
| 817 | $throw("This datasource entry's alias cannot be blank","","XMLParser.ConfigXMLParsingException"); |
|---|
| 818 | else |
|---|
| 819 | DSNStruct.Alias = Trim(DatasourcesNodes[i].XMLAttributes["Alias"]); |
|---|
| 820 | |
|---|
| 821 | if ( not structKeyExists(DatasourcesNodes[i].XMLAttributes, "Name") or len(Trim(DatasourcesNodes[i].XMLAttributes["Name"])) eq 0 ) |
|---|
| 822 | $throw("This datasource entry's name cannot be blank","","XMLParser.ConfigXMLParsingException"); |
|---|
| 823 | else |
|---|
| 824 | DSNStruct.Name = Trim(DatasourcesNodes[i].XMLAttributes["Name"]); |
|---|
| 825 | |
|---|
| 826 | //Optional Entries. |
|---|
| 827 | if ( structKeyExists(DatasourcesNodes[i].XMLAttributes, "dbtype") ) |
|---|
| 828 | DSNStruct.DBType = Trim(DatasourcesNodes[i].XMLAttributes["dbtype"]); |
|---|
| 829 | else |
|---|
| 830 | DSNStruct.DBType = ""; |
|---|
| 831 | |
|---|
| 832 | if ( structKeyExists(DatasourcesNodes[i].XMLAttributes, "Username") ) |
|---|
| 833 | DSNStruct.Username = Trim(DatasourcesNodes[i].XMLAttributes["username"]); |
|---|
| 834 | else |
|---|
| 835 | DSNStruct.Username = ""; |
|---|
| 836 | |
|---|
| 837 | if ( structKeyExists(DatasourcesNodes[i].XMLAttributes, "password") ) |
|---|
| 838 | DSNStruct.Password = Trim(DatasourcesNodes[i].XMLAttributes["password"]); |
|---|
| 839 | else |
|---|
| 840 | DSNStruct.Password = ""; |
|---|
| 841 | |
|---|
| 842 | //Insert to structure with Alias as key |
|---|
| 843 | ConfigStruct.Datasources[DSNStruct.Alias] = DSNStruct; |
|---|
| 844 | } |
|---|
| 845 | } |
|---|
| 846 | else if( NOT arguments.isOverride ){ |
|---|
| 847 | ConfigStruct.Datasources = structnew(); |
|---|
| 848 | } |
|---|
| 849 | </cfscript> |
|---|
| 850 | </cffunction> |
|---|
| 851 | |
|---|
| 852 | <!--- parseLayoutsViews ---> |
|---|
| 853 | <cffunction name="parseLayoutsViews" output="false" access="public" returntype="void" hint="Parse Layouts And Views"> |
|---|
| 854 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 855 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 856 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 857 | <cfscript> |
|---|
| 858 | var ConfigStruct = arguments.config; |
|---|
| 859 | var DefaultLayout = ""; |
|---|
| 860 | var DefaultView = ""; |
|---|
| 861 | var LayoutNodes = ""; |
|---|
| 862 | var Layout = ""; |
|---|
| 863 | var i=1; |
|---|
| 864 | var j=1; |
|---|
| 865 | var Collections = createObject("java", "java.util.Collections"); |
|---|
| 866 | var LayoutViewStruct = Collections.synchronizedMap(CreateObject("java","java.util.LinkedHashMap").init()); |
|---|
| 867 | var LayoutFolderStruct = Collections.synchronizedMap(CreateObject("java","java.util.LinkedHashMap").init()); |
|---|
| 868 | |
|---|
| 869 | //Layout into Config |
|---|
| 870 | DefaultLayout = XMLSearch(arguments.xml,"//Layouts/DefaultLayout"); |
|---|
| 871 | //validate Default Layout. |
|---|
| 872 | if ( ArrayLen(DefaultLayout) eq 0 ) |
|---|
| 873 | $throw("There was no default layout element found.","","XMLParser.ConfigXMLParsingException"); |
|---|
| 874 | if ( ArrayLen(DefaultLayout) gt 1 ) |
|---|
| 875 | $throw("There were more than 1 DefaultLayout elements found. There can only be one.","","XMLParser.ConfigXMLParsingException"); |
|---|
| 876 | //Insert Default Layout |
|---|
| 877 | ConfigStruct.DefaultLayout = Trim(DefaultLayout[1].XMLText); |
|---|
| 878 | |
|---|
| 879 | //Default View into Config |
|---|
| 880 | DefaultView = XMLSearch(arguments.xml,"//Layouts/DefaultView"); |
|---|
| 881 | //validate Default Layout. |
|---|
| 882 | if ( ArrayLen(DefaultView) eq 0 ){ |
|---|
| 883 | ConfigStruct["DefaultView"] = ""; |
|---|
| 884 | } |
|---|
| 885 | else if ( ArrayLen(DefaultView) gt 1 ){ |
|---|
| 886 | $throw("There were more than 1 DefaultView elements found. There can only be one.","","XMLParser.ConfigXMLParsingException"); |
|---|
| 887 | } |
|---|
| 888 | else{ |
|---|
| 889 | //Set the Default View. |
|---|
| 890 | ConfigStruct["DefaultView"] = Trim(DefaultView[1].XMLText); |
|---|
| 891 | } |
|---|
| 892 | |
|---|
| 893 | //Get View Layouts |
|---|
| 894 | LayoutNodes = XMLSearch(arguments.xml,"//Layouts/Layout"); |
|---|
| 895 | for (i=1; i lte ArrayLen(LayoutNodes); i=i+1){ |
|---|
| 896 | //Get Layout for the views |
|---|
| 897 | Layout = Trim(LayoutNodes[i].XMLAttributes["file"]); |
|---|
| 898 | for(j=1; j lte ArrayLen(LayoutNodes[i].XMLChildren); j=j+1){ |
|---|
| 899 | //Check for View |
|---|
| 900 | if( LayoutNodes[i].XMLChildren[j].XMLName eq "View" ){ |
|---|
| 901 | //Check for Key, if it doesn't exist then create |
|---|
| 902 | if ( not StructKeyExists(LayoutViewStruct, lcase(Trim(LayoutNodes[i].XMLChildren[j].XMLText))) ) |
|---|
| 903 | LayoutViewStruct[lcase(Trim(LayoutNodes[i].XMLChildren[j].XMLText))] = Layout; |
|---|
| 904 | } |
|---|
| 905 | //Check for Folder |
|---|
| 906 | else if( LayoutNodes[i].XMLChildren[j].XMLName eq "Folder" ){ |
|---|
| 907 | //Check for Key, if it doesn't exist then create |
|---|
| 908 | if ( not StructKeyExists(LayoutFolderStruct, lcase(Trim(LayoutNodes[i].XMLChildren[j].XMLText))) ) |
|---|
| 909 | LayoutFolderStruct[lcase(Trim(LayoutNodes[i].XMLChildren[j].XMLText))] = Layout; |
|---|
| 910 | } |
|---|
| 911 | |
|---|
| 912 | }//end for loop for the layout children |
|---|
| 913 | }//end for loop of all layout nodes |
|---|
| 914 | |
|---|
| 915 | ConfigStruct.ViewLayouts = LayoutViewStruct; |
|---|
| 916 | ConfigStruct.FolderLayouts = LayoutFolderStruct; |
|---|
| 917 | </cfscript> |
|---|
| 918 | </cffunction> |
|---|
| 919 | |
|---|
| 920 | <!--- parseCacheSettings ---> |
|---|
| 921 | <cffunction name="parseCacheSettings" output="false" access="public" returntype="void" hint="Parse Cache Settings"> |
|---|
| 922 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 923 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 924 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 925 | <cfscript> |
|---|
| 926 | var ConfigStruct = arguments.config; |
|---|
| 927 | var CacheSettingNodes = ""; |
|---|
| 928 | var fwSettingsStruct = controller.getColdboxSettings(); |
|---|
| 929 | |
|---|
| 930 | //Cache Override Settings |
|---|
| 931 | CacheSettingNodes = XMLSearch(arguments.xml,"//Cache"); |
|---|
| 932 | ConfigStruct.CacheSettings = structnew(); |
|---|
| 933 | |
|---|
| 934 | //Check if empty |
|---|
| 935 | if ( ArrayLen(CacheSettingNodes) gt 0 and ArrayLen(CacheSettingNodes[1].XMLChildren) gt 0){ |
|---|
| 936 | //Checks For Default Timeout |
|---|
| 937 | if ( structKeyExists(CacheSettingNodes[1], "ObjectDefaultTimeout") and isNumeric(CacheSettingNodes[1].ObjectDefaultTimeout.xmlText) ) |
|---|
| 938 | ConfigStruct.CacheSettings.ObjectDefaultTimeout = trim(CacheSettingNodes[1].ObjectDefaultTimeout.xmlText); |
|---|
| 939 | else |
|---|
| 940 | $throw("Invalid object timeout. Please see schema.","Value=#CacheSettingNodes[1].ObjectDefaultTimeout.xmlText#","XMLParser.InvalidCacheObjectDefaultTimeout"); |
|---|
| 941 | |
|---|
| 942 | //Check ObjectDefaultLastAccessTimeout |
|---|
| 943 | if ( structKeyExists(CacheSettingNodes[1], "ObjectDefaultLastAccessTimeout") and isNumeric(CacheSettingNodes[1].ObjectDefaultLastAccessTimeout.xmlText)) |
|---|
| 944 | ConfigStruct.CacheSettings.ObjectDefaultLastAccessTimeout = trim(CacheSettingNodes[1].ObjectDefaultLastAccessTimeout.xmlText); |
|---|
| 945 | else |
|---|
| 946 | $throw("Invalid object last access timeout. Please see schema.","Value=#CacheSettingNodes[1].ObjectDefaultLastAccessTimeout.xmlText#","XMLParser.InvalidObjectDefaultLastAccessTimeout"); |
|---|
| 947 | |
|---|
| 948 | //Check ReapFrequency |
|---|
| 949 | if ( structKeyExists(CacheSettingNodes[1], "ReapFrequency") and isNumeric(CacheSettingNodes[1].ReapFrequency.xmlText)) |
|---|
| 950 | ConfigStruct.CacheSettings.ReapFrequency = trim(CacheSettingNodes[1].ReapFrequency.xmlText); |
|---|
| 951 | else |
|---|
| 952 | $throw("Invalid reaping frequency. Please see schema.","Value=#CacheSettingNodes[1].ReapFrequency.xmlText#","XMLParser.InvalidReapFrequency"); |
|---|
| 953 | |
|---|
| 954 | //Check MaxObjects |
|---|
| 955 | if ( structKeyExists(CacheSettingNodes[1], "MaxObjects") and isNumeric(CacheSettingNodes[1].MaxObjects.xmlText)){ |
|---|
| 956 | ConfigStruct.CacheSettings.MaxObjects = trim(CacheSettingNodes[1].MaxObjects.xmlText); |
|---|
| 957 | } |
|---|
| 958 | else |
|---|
| 959 | $throw("Invalid Max Objects. Please see schema.","Value=#CacheSettingNodes[1].MaxObjects.xmlText#","XMLParser.InvalidMaxObjects"); |
|---|
| 960 | |
|---|
| 961 | //Check FreeMemoryPercentageThreshold |
|---|
| 962 | if ( structKeyExists(CacheSettingNodes[1], "FreeMemoryPercentageThreshold") and isNumeric(CacheSettingNodes[1].FreeMemoryPercentageThreshold.xmlText)){ |
|---|
| 963 | ConfigStruct.CacheSettings.FreeMemoryPercentageThreshold = trim(CacheSettingNodes[1].FreeMemoryPercentageThreshold.xmlText); |
|---|
| 964 | } |
|---|
| 965 | else |
|---|
| 966 | $throw("Invalid Free Memory Percentage Threshold. Please see schema.","Value=#CacheSettingNodes[1].FreeMemoryPercentageThreshold.xmlText#","XMLParser.InvalidFreeMemoryPercentageThreshold"); |
|---|
| 967 | |
|---|
| 968 | //Check for CacheUseLastAccessTimeouts |
|---|
| 969 | if ( structKeyExists(CacheSettingNodes[1], "UseLastAccessTimeouts") and isBoolean(CacheSettingNodes[1].UseLastAccessTimeouts.xmlText) ){ |
|---|
| 970 | ConfigStruct.CacheSettings.UseLastAccessTimeouts = trim(CacheSettingNodes[1].UseLastAccessTimeouts.xmlText); |
|---|
| 971 | } |
|---|
| 972 | else{ |
|---|
| 973 | ConfigStruct.CacheSettings.UseLastAccessTimeouts = fwSettingsStruct.CacheUseLastAccessTimeouts; |
|---|
| 974 | } |
|---|
| 975 | |
|---|
| 976 | //Check for CacheEvictionPolicy |
|---|
| 977 | if ( structKeyExists(CacheSettingNodes[1], "EvictionPolicy") ){ |
|---|
| 978 | ConfigStruct.CacheSettings.EvictionPolicy = trim(CacheSettingNodes[1].EvictionPolicy.xmlText); |
|---|
| 979 | } |
|---|
| 980 | else{ |
|---|
| 981 | ConfigStruct.CacheSettings.EvictionPolicy = fwSettingsStruct.CacheEvictionPolicy; |
|---|
| 982 | } |
|---|
| 983 | //Set Override to true. |
|---|
| 984 | ConfigStruct.CacheSettings.Override = true; |
|---|
| 985 | } |
|---|
| 986 | else{ |
|---|
| 987 | ConfigStruct.CacheSettings.Override = false; |
|---|
| 988 | } |
|---|
| 989 | </cfscript> |
|---|
| 990 | </cffunction> |
|---|
| 991 | |
|---|
| 992 | <!--- parseDebuggerSettings ---> |
|---|
| 993 | <cffunction name="parseDebuggerSettings" output="false" access="public" returntype="void" hint="Parse Debugger Settings"> |
|---|
| 994 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 995 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 996 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 997 | <cfargument name="isOverride" type="boolean" required="false" default="false" hint="Flag to denote if overriding or first time runner."/> |
|---|
| 998 | <cfscript> |
|---|
| 999 | var ConfigStruct = arguments.config; |
|---|
| 1000 | var DebuggerSettingNodes = ""; |
|---|
| 1001 | |
|---|
| 1002 | DebuggerSettingNodes = XMLSearch(arguments.xml,"//DebuggerSettings"); |
|---|
| 1003 | |
|---|
| 1004 | //Check if empty |
|---|
| 1005 | if ( ArrayLen(DebuggerSettingNodes) ){ |
|---|
| 1006 | // PersistentRequestProfiler |
|---|
| 1007 | if ( structKeyExists(DebuggerSettingNodes[1], "PersistentRequestProfiler") and isBoolean(DebuggerSettingNodes[1].PersistentRequestProfiler.xmlText) ){ |
|---|
| 1008 | ConfigStruct.DebuggerSettings.PersistentRequestProfiler = trim(DebuggerSettingNodes[1].PersistentRequestProfiler.xmlText); |
|---|
| 1009 | } |
|---|
| 1010 | // maxPersistentRequestProfilers |
|---|
| 1011 | if ( structKeyExists(DebuggerSettingNodes[1], "maxPersistentRequestProfilers") and isNumeric(DebuggerSettingNodes[1].maxPersistentRequestProfilers.xmlText) ){ |
|---|
| 1012 | ConfigStruct.DebuggerSettings.maxPersistentRequestProfilers = trim(DebuggerSettingNodes[1].maxPersistentRequestProfilers.xmlText); |
|---|
| 1013 | } |
|---|
| 1014 | // maxRCPanelQueryRows */ |
|---|
| 1015 | if ( structKeyExists(DebuggerSettingNodes[1], "maxRCPanelQueryRows") and isNumeric(DebuggerSettingNodes[1].maxRCPanelQueryRows.xmlText) ){ |
|---|
| 1016 | ConfigStruct.DebuggerSettings.maxRCPanelQueryRows = trim(DebuggerSettingNodes[1].maxRCPanelQueryRows.xmlText); |
|---|
| 1017 | } |
|---|
| 1018 | // TracerPanel |
|---|
| 1019 | if ( structKeyExists(DebuggerSettingNodes[1], "TracerPanel") ){ |
|---|
| 1020 | debugPanelAttributeInsert(ConfigStruct.DebuggerSettings,"TracerPanel",DebuggerSettingNodes[1].TracerPanel.xmlAttributes); |
|---|
| 1021 | } |
|---|
| 1022 | // InfoPanel |
|---|
| 1023 | if ( structKeyExists(DebuggerSettingNodes[1], "InfoPanel") ){ |
|---|
| 1024 | debugPanelAttributeInsert(ConfigStruct.DebuggerSettings,"InfoPanel",DebuggerSettingNodes[1].InfoPanel.xmlAttributes); |
|---|
| 1025 | } |
|---|
| 1026 | // CachePanel |
|---|
| 1027 | if ( structKeyExists(DebuggerSettingNodes[1], "CachePanel") ){ |
|---|
| 1028 | debugPanelAttributeInsert(ConfigStruct.DebuggerSettings,"CachePanel",DebuggerSettingNodes[1].CachePanel.xmlAttributes); |
|---|
| 1029 | } |
|---|
| 1030 | // RCPanel |
|---|
| 1031 | if ( structKeyExists(DebuggerSettingNodes[1], "RCPanel") ){ |
|---|
| 1032 | debugPanelAttributeInsert(ConfigStruct.DebuggerSettings,"RCPanel",DebuggerSettingNodes[1].RCPanel.xmlAttributes); |
|---|
| 1033 | } |
|---|
| 1034 | //Set Override to true. |
|---|
| 1035 | ConfigStruct.DebuggerSettings.Override = true; |
|---|
| 1036 | } |
|---|
| 1037 | else if (NOT arguments.isOverride){ |
|---|
| 1038 | ConfigStruct.DebuggerSettings = structnew(); |
|---|
| 1039 | ConfigStruct.DebuggerSettings.Override = false; |
|---|
| 1040 | } |
|---|
| 1041 | </cfscript> |
|---|
| 1042 | </cffunction> |
|---|
| 1043 | |
|---|
| 1044 | <!--- parseInterceptors ---> |
|---|
| 1045 | <cffunction name="parseInterceptors" output="false" access="public" returntype="void" hint="Parse Interceptors"> |
|---|
| 1046 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 1047 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 1048 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 1049 | <cfargument name="isOverride" type="boolean" required="false" default="false" hint="Flag to denote if overriding or first time runner."/> |
|---|
| 1050 | <cfscript> |
|---|
| 1051 | var ConfigStruct = arguments.config; |
|---|
| 1052 | var InterceptorBase = ""; |
|---|
| 1053 | var CustomInterceptionPoints = ""; |
|---|
| 1054 | var InterceptorNodes = ""; |
|---|
| 1055 | var i=1; |
|---|
| 1056 | var j=1; |
|---|
| 1057 | var InterceptorStruct = ""; |
|---|
| 1058 | var tempProperty = ""; |
|---|
| 1059 | |
|---|
| 1060 | //Search for Interceptors |
|---|
| 1061 | InterceptorBase = XMLSearch(arguments.xml,"//Interceptors"); |
|---|
| 1062 | if( arrayLen(InterceptorBase) ){ |
|---|
| 1063 | // Interceptor Preparation. |
|---|
| 1064 | ConfigStruct.InterceptorConfig = structnew(); |
|---|
| 1065 | ConfigStruct.InterceptorConfig.Interceptors = arrayNew(1); |
|---|
| 1066 | ConfigStruct.InterceptorConfig.throwOnInvalidStates = true; |
|---|
| 1067 | ConfigStruct.InterceptorConfig.CustomInterceptionPoints = ""; |
|---|
| 1068 | |
|---|
| 1069 | // Invalid States |
|---|
| 1070 | if ( structKeyExists(InterceptorBase[1].XMLAttributes, "throwOnInvalidStates") ){ |
|---|
| 1071 | ConfigStruct.InterceptorConfig['throwOnInvalidStates'] = InterceptorBase[1].XMLAttributes.throwOnInvalidStates; |
|---|
| 1072 | } |
|---|
| 1073 | |
|---|
| 1074 | // Custom Interception Points |
|---|
| 1075 | CustomInterceptionPoints = XMLSearch(arguments.xml,"//Interceptors/CustomInterceptionPoints"); |
|---|
| 1076 | if ( ArrayLen(CustomInterceptionPoints) gt 1 ){ |
|---|
| 1077 | $throw("There were more than 1 CustomInterceptionPoints elements found. There can only be one.","","XMLParser.ConfigXMLParsingException"); |
|---|
| 1078 | } |
|---|
| 1079 | else if( arraylen(CustomInterceptionPoints) ){ |
|---|
| 1080 | ConfigStruct.InterceptorConfig.CustomInterceptionPoints = arguments.utility.placeHolderReplacer(Trim(CustomInterceptionPoints[1].XMLText),ConfigStruct); |
|---|
| 1081 | } |
|---|
| 1082 | |
|---|
| 1083 | //Parse all Interceptor Nodes now. |
|---|
| 1084 | InterceptorNodes = XMLSearch(arguments.xml,"//Interceptors/Interceptor"); |
|---|
| 1085 | for (i=1; i lte ArrayLen(InterceptorNodes); i=i+1){ |
|---|
| 1086 | //Interceptor Struct |
|---|
| 1087 | InterceptorStruct = structnew(); |
|---|
| 1088 | //get Class |
|---|
| 1089 | InterceptorStruct.class = arguments.utility.placeHolderReplacer(Trim(InterceptorNodes[i].XMLAttributes["class"]),ConfigStruct); |
|---|
| 1090 | //Prepare Properties |
|---|
| 1091 | InterceptorStruct.properties = structnew(); |
|---|
| 1092 | //Parse Interceptor Properties |
|---|
| 1093 | if ( ArrayLen(InterceptorNodes[i].XMLChildren) ){ |
|---|
| 1094 | for(j=1; j lte ArrayLen(InterceptorNodes[i].XMLChildren); j=j+1){ |
|---|
| 1095 | //Property Complex Check |
|---|
| 1096 | tempProperty = arguments.utility.placeHolderReplacer(Trim( InterceptorNodes[i].XMLChildren[j].XMLText ),ConfigStruct); |
|---|
| 1097 | //Check for Complex Setup |
|---|
| 1098 | if( reFindNocase(instance.jsonRegex,tempProperty) ){ |
|---|
| 1099 | StructInsert( InterceptorStruct.properties, Trim(InterceptorNodes[i].XMLChildren[j].XMLAttributes["name"]), getPlugin('JSON').decode(replace(tempProperty,"'","""","all")) ); |
|---|
| 1100 | } |
|---|
| 1101 | else{ |
|---|
| 1102 | StructInsert( InterceptorStruct.properties, Trim(InterceptorNodes[i].XMLChildren[j].XMLAttributes["name"]), tempProperty ); |
|---|
| 1103 | } |
|---|
| 1104 | }//end loop of properties |
|---|
| 1105 | }//end if no properties |
|---|
| 1106 | //Add to Array |
|---|
| 1107 | ArrayAppend( ConfigStruct.InterceptorConfig.Interceptors, InterceptorStruct ); |
|---|
| 1108 | }//end interceptor nodes |
|---|
| 1109 | |
|---|
| 1110 | }// end if interceptors found |
|---|
| 1111 | else if (NOT arguments.isOverride){ |
|---|
| 1112 | // Interceptor Defaults. |
|---|
| 1113 | ConfigStruct.InterceptorConfig = structnew(); |
|---|
| 1114 | ConfigStruct.InterceptorConfig.Interceptors = arrayNew(1); |
|---|
| 1115 | ConfigStruct.InterceptorConfig.throwOnInvalidStates = true; |
|---|
| 1116 | ConfigStruct.InterceptorConfig.CustomInterceptionPoints = ""; |
|---|
| 1117 | } |
|---|
| 1118 | </cfscript> |
|---|
| 1119 | </cffunction> |
|---|
| 1120 | |
|---|
| 1121 | <!--- parseLogBox ---> |
|---|
| 1122 | <cffunction name="parseLogBox" output="false" access="public" returntype="void" hint="Parse LogBox"> |
|---|
| 1123 | <cfargument name="xml" type="any" required="true" hint="The xml object"/> |
|---|
| 1124 | <cfargument name="config" type="struct" required="true" hint="The config struct"/> |
|---|
| 1125 | <cfargument name="utility" type="any" required="true" hint="The utility object"/> |
|---|
| 1126 | <cfargument name="isOverride" type="boolean" required="false" default="false" hint="Flag to denote if overriding or first time runner."/> |
|---|
| 1127 | <cfscript> |
|---|
| 1128 | var logboxXML = xmlSearch(arguments.xml,"//LogBox"); |
|---|
| 1129 | var logBoxConfig = ""; |
|---|
| 1130 | var memento = ""; |
|---|
| 1131 | var prop = ""; |
|---|
| 1132 | |
|---|
| 1133 | if( arrayLen(logboxXML) ){ |
|---|
| 1134 | // Get config object From controller's logbox |
|---|
| 1135 | logBoxConfig = controller.getLogBox().getConfig(); |
|---|
| 1136 | // Reset the configuration |
|---|
| 1137 | logBoxConfig.reset(); |
|---|
| 1138 | // Parse and load new configuration data |
|---|
| 1139 | logBoxConfig.parseAndLoad(logboxXML[1]); |
|---|
| 1140 | // Get reference to do ${} replacements |
|---|
| 1141 | memento = logBoxConfig.getMemento(); |
|---|
| 1142 | |
|---|
| 1143 | // Appender Replacements |
|---|
| 1144 | for( key in memento.appenders ){ |
|---|
| 1145 | memento.appenders[key].class = arguments.utility.placeHolderReplacer(memento.appenders[key].class,arguments.config); |
|---|
| 1146 | //Appender properties |
|---|
| 1147 | for(prop in memento.appenders[key].properties){ |
|---|
| 1148 | // ${} replacement |
|---|
| 1149 | memento.appenders[key].properties[prop] = arguments.utility.placeHolderReplacer(memento.appenders[key].properties[prop],arguments.config); |
|---|
| 1150 | } |
|---|
| 1151 | } |
|---|
| 1152 | |
|---|
| 1153 | //Store LogBox Configuration on settings |
|---|
| 1154 | arguments.config["LogBoxConfig"] = memento; |
|---|
| 1155 | } |
|---|
| 1156 | else if( NOT arguments.isOverride){ |
|---|
| 1157 | arguments.config["LogBoxConfig"] = structnew(); |
|---|
| 1158 | } |
|---|
| 1159 | </cfscript> |
|---|
| 1160 | </cffunction> |
|---|
| 1161 | |
|---|
| 1162 | <!------------------------------------------- PRIVATE ------------------------------------------> |
|---|
| 1163 | |
|---|
| 1164 | <!--- Debug Panel attribute insert ---> |
|---|
| 1165 | <cffunction name="debugPanelAttributeInsert" access="private" returntype="void" hint="Insert a key into a panel attribute" output="false" > |
|---|
| 1166 | <!--- ************************************************************* ---> |
|---|
| 1167 | <cfargument name="Config" required="true" type="struct" hint=""> |
|---|
| 1168 | <cfargument name="Panel" required="true" type="string" hint=""> |
|---|
| 1169 | <cfargument name="PanelXML" required="true" type="any" hint=""> |
|---|
| 1170 | <!--- ************************************************************* ---> |
|---|
| 1171 | <cfscript> |
|---|
| 1172 | // Show Key |
|---|
| 1173 | if( structKeyExists(arguments.panelXML,"show") ){ |
|---|
| 1174 | arguments.config["show#arguments.Panel#"] = trim(arguments.panelXML.show); |
|---|
| 1175 | } |
|---|
| 1176 | // Expanded Key |
|---|
| 1177 | if( structKeyExists(arguments.panelXML,"expanded") ){ |
|---|
| 1178 | arguments.config["expanded#arguments.Panel#"] = trim(arguments.panelXML.expanded); |
|---|
| 1179 | } |
|---|
| 1180 | </cfscript> |
|---|
| 1181 | </cffunction> |
|---|
| 1182 | |
|---|
| 1183 | <!--- read file ---> |
|---|
| 1184 | <cffunction name="readFile" access="private" output="false" returntype="string" hint="Facade to Read a file's content"> |
|---|
| 1185 | <!--- ************************************************************* ---> |
|---|
| 1186 | <cfargument name="FileToRead" type="String" required="yes" hint="The absolute path to the file."> |
|---|
| 1187 | <!--- ************************************************************* ---> |
|---|
| 1188 | <cfset var FileContents = ""> |
|---|
| 1189 | <cffile action="read" file="#arguments.FileToRead#" variable="FileContents"> |
|---|
| 1190 | <cfreturn FileContents> |
|---|
| 1191 | </cffunction> |
|---|
| 1192 | |
|---|
| 1193 | <!--- Get Absolute Path ---> |
|---|
| 1194 | <cffunction name="getAbsolutePath" access="private" output="false" returntype="string" hint="Turn any system path, either relative or absolute, into a fully qualified one"> |
|---|
| 1195 | <!--- ************************************************************* ---> |
|---|
| 1196 | <cfargument name="path" type="string" required="true" hint="Abstract pathname"> |
|---|
| 1197 | <!--- ************************************************************* ---> |
|---|
| 1198 | <cfscript> |
|---|
| 1199 | var FileObj = CreateObject("java","java.io.File").init(JavaCast("String",arguments.path)); |
|---|
| 1200 | if(FileObj.isAbsolute()){ |
|---|
| 1201 | return arguments.path; |
|---|
| 1202 | } |
|---|
| 1203 | else{ |
|---|
| 1204 | return ExpandPath(arguments.path); |
|---|
| 1205 | } |
|---|
| 1206 | </cfscript> |
|---|
| 1207 | </cffunction> |
|---|
| 1208 | |
|---|
| 1209 | </cfcomponent> |
|---|