Author: jonesde
Date: Sat Nov 18 14:16:35 2006 New Revision: 476624 URL: http://svn.apache.org/viewvc?view=rev&rev=476624 Log: A few include enhancements so that everything in the other controller.xml file is included, though everything can be overriden Modified: incubator/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java Modified: incubator/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd?view=diff&rev=476624&r1=476623&r2=476624 ============================================================================== --- incubator/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd (original) +++ incubator/ofbiz/trunk/framework/webapp/dtd/site-conf.xsd Sat Nov 18 14:16:35 2006 @@ -33,6 +33,23 @@ </xs:sequence> </xs:complexType> </xs:element> + <xs:element name="include"> + <xs:annotation> + <xs:documentation> + This includes all elements of the controller.xml file references. + + Note that if you define any of the event blocks in this file (the including file) they + will override (replace) the one in the included file, effectively emptying it. The event + blocks are: firstvisit, preprocessor, postprocessor, after-login, and before-logout. + </xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:attributeGroup ref="attlist.include"/> + </xs:complexType> + </xs:element> + <xs:attributeGroup name="attlist.include"> + <xs:attribute type="xs:string" name="location" use="required"/> + </xs:attributeGroup> <xs:element name="description" type="xs:string"/> <xs:element name="owner" type="xs:string"/> <xs:element name="errorpage" type="xs:string"/> @@ -88,14 +105,6 @@ </xs:sequence> </xs:complexType> </xs:element> - <xs:element name="include"> - <xs:complexType> - <xs:attributeGroup ref="attlist.include"/> - </xs:complexType> - </xs:element> - <xs:attributeGroup name="attlist.include"> - <xs:attribute type="xs:string" name="location" use="required"/> - </xs:attributeGroup> <xs:element name="request-map"> <xs:complexType> <xs:sequence> Modified: incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java URL: http://svn.apache.org/viewvc/incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java?view=diff&rev=476624&r1=476623&r2=476624 ============================================================================== --- incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java (original) +++ incubator/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java Sat Nov 18 14:16:35 2006 @@ -175,7 +175,7 @@ map.putAll(subMap); } catch (MalformedURLException mue) { - mue.printStackTrace(); + Debug.logError(mue, "Error processing include at [" + includeLocation + "]:" + mue.toString(), module); } } } @@ -311,7 +311,7 @@ map.putAll(subMap); } catch (MalformedURLException mue) { - mue.printStackTrace(); + Debug.logError(mue, "Error processing include at [" + includeLocation + "]:" + mue.toString(), module); } } } @@ -390,119 +390,136 @@ if (root == null) { root = loadDocument(xml); } + + if (root == null) { + return map; + } - if (root != null) { - // default error page - String errorpage = UtilXml.childElementValue(root, DEFAULT_ERROR_PAGE); - if (UtilValidate.isNotEmpty(errorpage)) map.put(DEFAULT_ERROR_PAGE, errorpage); - - // site owner - String owner = UtilXml.childElementValue(root, SITE_OWNER); - if (UtilValidate.isNotEmpty(owner)) map.put(SITE_OWNER, owner); - - // security class - String securityClass = UtilXml.childElementValue(root, SECURITY_CLASS); - if (UtilValidate.isNotEmpty(securityClass)) map.put(SECURITY_CLASS, securityClass); - - // first visit event - Element firstvisitElement = UtilXml.firstChildElement(root, FIRSTVISIT); - if (firstvisitElement != null) { - List eventList = FastList.newInstance(); - List eventElementList = UtilXml.childElementList(firstvisitElement, EVENT); - Iterator eventElementIter = eventElementList.iterator(); - while (eventElementIter.hasNext()) { - Element eventElement = (Element) eventElementIter.next(); - FastMap eventMap = FastMap.newInstance(); - eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); - eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); - eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); - - // Check for a global-transaction attribute - default to true - eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - eventList.add(eventMap); + List includeElementList = UtilXml.childElementList(root, INCLUDE); + Iterator includeElementIter = includeElementList.iterator(); + while (includeElementIter.hasNext()) { + Element includeElement = (Element) includeElementIter.next(); + String includeLocation = includeElement.getAttribute(INCLUDE_LOCATION); + if ((includeLocation != null) && (includeLocation.length() > 0)) { + try { + Map subMap = loadConfigMap(null, FlexibleLocation.resolveLocation(includeLocation)); + map.putAll(subMap); + } catch (MalformedURLException mue) { + Debug.logError(mue, "Error processing include at [" + includeLocation + "]:" + mue.toString(), module); } - map.put(FIRSTVISIT, eventList); } + } - // preprocessor events - Element preprocessorElement = UtilXml.firstChildElement(root, PREPROCESSOR); - if (preprocessorElement != null) { - List eventList = FastList.newInstance(); - List eventElementList = UtilXml.childElementList(preprocessorElement, EVENT); - Iterator eventElementIter = eventElementList.iterator(); - while (eventElementIter.hasNext()) { - Element eventElement = (Element) eventElementIter.next(); - FastMap eventMap = FastMap.newInstance(); - eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); - eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); - eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); - - // Check for a global-transaction attribute - default to true - eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - eventList.add(eventMap); - } - map.put(PREPROCESSOR, eventList); + // default error page + String errorpage = UtilXml.childElementValue(root, DEFAULT_ERROR_PAGE); + if (UtilValidate.isNotEmpty(errorpage)) map.put(DEFAULT_ERROR_PAGE, errorpage); + + // site owner + String owner = UtilXml.childElementValue(root, SITE_OWNER); + if (UtilValidate.isNotEmpty(owner)) map.put(SITE_OWNER, owner); + + // security class + String securityClass = UtilXml.childElementValue(root, SECURITY_CLASS); + if (UtilValidate.isNotEmpty(securityClass)) map.put(SECURITY_CLASS, securityClass); + + // first visit event + Element firstvisitElement = UtilXml.firstChildElement(root, FIRSTVISIT); + if (firstvisitElement != null) { + List eventList = FastList.newInstance(); + List eventElementList = UtilXml.childElementList(firstvisitElement, EVENT); + Iterator eventElementIter = eventElementList.iterator(); + while (eventElementIter.hasNext()) { + Element eventElement = (Element) eventElementIter.next(); + FastMap eventMap = FastMap.newInstance(); + eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); + eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); + eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); + + // Check for a global-transaction attribute - default to true + eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); + eventList.add(eventMap); } + map.put(FIRSTVISIT, eventList); + } - // postprocessor events - Element postprocessorElement = UtilXml.firstChildElement(root, POSTPROCESSOR); - if (postprocessorElement != null) { - List eventList = FastList.newInstance(); - List eventElementList = UtilXml.childElementList(postprocessorElement, EVENT); - Iterator eventElementIter = eventElementList.iterator(); - while (eventElementIter.hasNext()) { - Element eventElement = (Element) eventElementIter.next(); - FastMap eventMap = FastMap.newInstance(); - eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); - eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); - eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); - - // Check for a global-transaction attribute - default to true - eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - eventList.add(eventMap); - } - map.put(POSTPROCESSOR, eventList); + // preprocessor events + Element preprocessorElement = UtilXml.firstChildElement(root, PREPROCESSOR); + if (preprocessorElement != null) { + List eventList = FastList.newInstance(); + List eventElementList = UtilXml.childElementList(preprocessorElement, EVENT); + Iterator eventElementIter = eventElementList.iterator(); + while (eventElementIter.hasNext()) { + Element eventElement = (Element) eventElementIter.next(); + FastMap eventMap = FastMap.newInstance(); + eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); + eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); + eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); + + // Check for a global-transaction attribute - default to true + eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); + eventList.add(eventMap); } + map.put(PREPROCESSOR, eventList); + } - // after-login events - Element afterLoginElement = UtilXml.firstChildElement(root, "after-login"); - if (afterLoginElement != null) { - List eventList = FastList.newInstance(); - List eventElementList = UtilXml.childElementList(afterLoginElement, EVENT); - Iterator eventElementIter = eventElementList.iterator(); - while (eventElementIter.hasNext()) { - Element eventElement = (Element) eventElementIter.next(); - FastMap eventMap = FastMap.newInstance(); - eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); - eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); - eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); - - // Check for a global-transaction attribute - default to true - eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - eventList.add(eventMap); - } - map.put("after-login", eventList); + // postprocessor events + Element postprocessorElement = UtilXml.firstChildElement(root, POSTPROCESSOR); + if (postprocessorElement != null) { + List eventList = FastList.newInstance(); + List eventElementList = UtilXml.childElementList(postprocessorElement, EVENT); + Iterator eventElementIter = eventElementList.iterator(); + while (eventElementIter.hasNext()) { + Element eventElement = (Element) eventElementIter.next(); + FastMap eventMap = FastMap.newInstance(); + eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); + eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); + eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); + + // Check for a global-transaction attribute - default to true + eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); + eventList.add(eventMap); } + map.put(POSTPROCESSOR, eventList); + } - // before-logout events - Element beforeLogoutElement = UtilXml.firstChildElement(root, "before-logout"); - if (beforeLogoutElement != null) { - List eventList = FastList.newInstance(); - List eventElementList = UtilXml.childElementList(beforeLogoutElement, EVENT); - Iterator eventElementIter = eventElementList.iterator(); - while (eventElementIter.hasNext()) { - Element eventElement = (Element) eventElementIter.next(); - FastMap eventMap = FastMap.newInstance(); - eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); - eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); - eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); - - // Check for a global-transaction attribute - default to true - eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); - eventList.add(eventMap); - } - map.put("before-logout", eventList); + // after-login events + Element afterLoginElement = UtilXml.firstChildElement(root, "after-login"); + if (afterLoginElement != null) { + List eventList = FastList.newInstance(); + List eventElementList = UtilXml.childElementList(afterLoginElement, EVENT); + Iterator eventElementIter = eventElementList.iterator(); + while (eventElementIter.hasNext()) { + Element eventElement = (Element) eventElementIter.next(); + FastMap eventMap = FastMap.newInstance(); + eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); + eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); + eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); + + // Check for a global-transaction attribute - default to true + eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); + eventList.add(eventMap); + } + map.put("after-login", eventList); + } + + // before-logout events + Element beforeLogoutElement = UtilXml.firstChildElement(root, "before-logout"); + if (beforeLogoutElement != null) { + List eventList = FastList.newInstance(); + List eventElementList = UtilXml.childElementList(beforeLogoutElement, EVENT); + Iterator eventElementIter = eventElementList.iterator(); + while (eventElementIter.hasNext()) { + Element eventElement = (Element) eventElementIter.next(); + FastMap eventMap = FastMap.newInstance(); + eventMap.put(EVENT_TYPE, eventElement.getAttribute(EVENT_TYPE)); + eventMap.put(EVENT_PATH, eventElement.getAttribute(EVENT_PATH)); + eventMap.put(EVENT_METHOD, eventElement.getAttribute(EVENT_METHOD)); + + // Check for a global-transaction attribute - default to true + eventMap.put(EVENT_GLOBAL_TRANSACTION, eventElement.hasAttribute(EVENT_GLOBAL_TRANSACTION) ? eventElement.getAttribute(EVENT_GLOBAL_TRANSACTION) : "true"); + eventList.add(eventMap); } + map.put("before-logout", eventList); } /* Debugging */ @@ -545,27 +562,43 @@ if (root == null) { root = loadDocument(xml); } + if (root == null) { + return map; + } - if (root != null) { - Map rMap = FastMap.newInstance(); - Map vMap = FastMap.newInstance(); - - List handlerElementList = UtilXml.childElementList(root, HANDLER); - Iterator handlerElementIter = handlerElementList.iterator(); - while (handlerElementIter.hasNext()) { - Element handlerElement = (Element) handlerElementIter.next(); - String hName = checkEmpty(handlerElement.getAttribute(HANDLER_NAME)); - String hClass = checkEmpty(handlerElement.getAttribute(HANDLER_CLASS)); - String hType = checkEmpty(handlerElement.getAttribute(HANDLER_TYPE)); - if (hType.equals("view")) { - vMap.put(hName, hClass); - } else { - rMap.put(hName, hClass); + List includeElementList = UtilXml.childElementList(root, INCLUDE); + Iterator includeElementIter = includeElementList.iterator(); + while (includeElementIter.hasNext()) { + Element includeElement = (Element) includeElementIter.next(); + String includeLocation = includeElement.getAttribute(INCLUDE_LOCATION); + if ((includeLocation != null) && (includeLocation.length() > 0)) { + try { + Map subMap = loadHandlerMap(null, FlexibleLocation.resolveLocation(includeLocation)); + map.putAll(subMap); + } catch (MalformedURLException mue) { + Debug.logError(mue, "Error processing include at [" + includeLocation + "]:" + mue.toString(), module); } } - map.put("view", vMap); - map.put("event", rMap); } + + Map rMap = FastMap.newInstance(); + Map vMap = FastMap.newInstance(); + + List handlerElementList = UtilXml.childElementList(root, HANDLER); + Iterator handlerElementIter = handlerElementList.iterator(); + while (handlerElementIter.hasNext()) { + Element handlerElement = (Element) handlerElementIter.next(); + String hName = checkEmpty(handlerElement.getAttribute(HANDLER_NAME)); + String hClass = checkEmpty(handlerElement.getAttribute(HANDLER_CLASS)); + String hType = checkEmpty(handlerElement.getAttribute(HANDLER_TYPE)); + if (hType.equals("view")) { + vMap.put(hName, hClass); + } else { + rMap.put(hName, hClass); + } + } + map.put("view", vMap); + map.put("event", rMap); /* Debugging */ if (Debug.verboseOn()) { |
Free forum by Nabble | Edit this page |