Author: jonesde
Date: Wed Apr 2 23:06:48 2008 New Revision: 644179 URL: http://svn.apache.org/viewvc?rev=644179&view=rev Log: Finished form to link/target request artifact info stuff Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java Modified: ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java?rev=644179&r1=644178&r2=644179&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java (original) +++ ofbiz/trunk/framework/base/src/base/org/ofbiz/base/util/UtilHttp.java Wed Apr 2 23:06:48 2008 @@ -675,6 +675,7 @@ } public static String getRequestUriFromTarget(String target) { + if (target == null || target.length() == 0) return null; int endOfRequestUri = target.length(); if (target.indexOf('?') > 0) { endOfRequestUri = target.indexOf('?'); @@ -691,6 +692,7 @@ public static String getWebappMountPointFromTarget(String target) { int firstChar = 0; + if (target == null || target.length() == 0) return null; if (target.charAt(0) == '/') firstChar = 1; int pathSep = target.indexOf('/', 1); String webappMountPoint = null; Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java?rev=644179&r1=644178&r2=644179&view=diff ============================================================================== --- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java (original) +++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ConfigXMLReader.java Wed Apr 2 23:06:48 2008 @@ -35,6 +35,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.FileUtil; import org.ofbiz.base.util.GeneralException; +import org.ofbiz.base.util.UtilHttp; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; import org.ofbiz.base.util.cache.UtilCache; @@ -91,6 +92,10 @@ public static Set<String> findControllerFilesWithRequest(String requestUri, String controllerPartialPath) throws GeneralException { Set<String> allControllerRequestSet = FastSet.newInstance(); + if (UtilValidate.isEmpty(requestUri)) { + return allControllerRequestSet; + } + String cacheId = controllerPartialPath != null ? controllerPartialPath : "NOPARTIALPATH"; List<ControllerConfig> controllerConfigs = (List<ControllerConfig>) controllerSearchResultsCache.get(cacheId); @@ -129,6 +134,38 @@ } return allControllerRequestSet; + } + + public static Set<String> findControllerRequestUniqueForTargetType(String target, String urlMode) throws GeneralException { + if (UtilValidate.isEmpty(urlMode)) { + urlMode = "intra-app"; + } + + int indexOfDollarSignCurlyBrace = target.indexOf("${"); + int indexOfQuestionMark = target.indexOf("?"); + if (indexOfDollarSignCurlyBrace >= 0 && (indexOfQuestionMark < 0 || indexOfQuestionMark > indexOfDollarSignCurlyBrace)) { + // we have an expanded string in the requestUri part of the target, not much we can do about that... + return null; + } + + if ("intra-app".equals(urlMode)) { + // look through all controller.xml files and find those with the request-uri referred to by the target + String requestUri = UtilHttp.getRequestUriFromTarget(target); + + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerFilesWithRequest(requestUri, null); + // if (controllerLocAndRequestSet.size() > 0) Debug.logInfo("============== In findRequestNamesLinkedtoInWidget, controllerLocAndRequestSet: " + controllerLocAndRequestSet, module); + return controllerLocAndRequestSet; + } else if ("inter-app".equals(urlMode)) { + String webappMountPoint = UtilHttp.getWebappMountPointFromTarget(target); + if (webappMountPoint != null) webappMountPoint += "/WEB-INF"; + String requestUri = UtilHttp.getRequestUriFromTarget(target); + + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerFilesWithRequest(requestUri, webappMountPoint); + // if (controllerLocAndRequestSet.size() > 0) Debug.logInfo("============== In findRequestNamesLinkedtoInWidget, controllerLocAndRequestSet: " + controllerLocAndRequestSet, module); + return controllerLocAndRequestSet; + } else { + return FastSet.newInstance(); + } } /** Site Config Variables */ Modified: ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java?rev=644179&r1=644178&r2=644179&view=diff ============================================================================== --- ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java (original) +++ ofbiz/trunk/framework/webtools/src/org/ofbiz/webtools/artifactinfo/FormWidgetArtifactInfo.java Wed Apr 2 23:06:48 2008 @@ -28,6 +28,7 @@ import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilURL; import org.ofbiz.service.ModelService; import org.ofbiz.widget.form.ModelForm; import org.xml.sax.SAXException; @@ -70,7 +71,10 @@ this.populateUsedEntities(); this.populateUsedServices(); this.populateFormExtended(); + this.populateLinkedRequests(); + this.populateTargetedRequests(); } + protected void populateFormExtended() throws GeneralException { // populate formThisFormExtends and the reverse-associate cache in the aif if (this.modelForm.getParentFormName() != null) { @@ -134,6 +138,43 @@ this.servicesUsedInThisForm.add(aif.getServiceArtifactInfo(serviceName)); // the reverse reference UtilMisc.addToSetInMap(this, aif.allFormInfosReferringToServiceName, serviceName); + } + } + + protected void populateLinkedRequests() throws GeneralException{ + Set<String> allRequestUniqueId = this.modelForm.getLinkedRequestsLocationAndUri(); + + for (String requestUniqueId: allRequestUniqueId) { + if (requestUniqueId.contains("${")) { + continue; + } + + if (requestUniqueId.indexOf("#") > -1) { + String controllerXmlUrl = requestUniqueId.substring(0, requestUniqueId.indexOf("#")); + String requestUri = requestUniqueId.substring(requestUniqueId.indexOf("#") + 1); + // the forward reference + this.requestsLinkedToInForm.add(aif.getControllerRequestArtifactInfo(UtilURL.fromUrlString(controllerXmlUrl), requestUri)); + // the reverse reference + UtilMisc.addToSetInMap(this, aif.allFormInfosReferringToRequest, requestUniqueId); + } + } + } + protected void populateTargetedRequests() throws GeneralException{ + Set<String> allRequestUniqueId = this.modelForm.getTargetedRequestsLocationAndUri(); + + for (String requestUniqueId: allRequestUniqueId) { + if (requestUniqueId.contains("${")) { + continue; + } + + if (requestUniqueId.indexOf("#") > -1) { + String controllerXmlUrl = requestUniqueId.substring(0, requestUniqueId.indexOf("#")); + String requestUri = requestUniqueId.substring(requestUniqueId.indexOf("#") + 1); + // the forward reference + this.requestsTargetedByInForm.add(aif.getControllerRequestArtifactInfo(UtilURL.fromUrlString(controllerXmlUrl), requestUri)); + // the reverse reference + UtilMisc.addToSetInMap(this, aif.allFormInfosTargetingRequest, requestUniqueId); + } } } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java?rev=644179&r1=644178&r2=644179&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/form/ModelForm.java Wed Apr 2 23:06:48 2008 @@ -20,28 +20,24 @@ import java.io.IOException; import java.io.Writer; - import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.TreeMap; -import java.util.Collection; import java.util.NoSuchElementException; import java.util.Set; +import java.util.TreeMap; import java.util.TreeSet; import javolution.util.FastList; import javolution.util.FastMap; import javolution.util.FastSet; -import bsh.EvalError; -import bsh.Interpreter; - import org.ofbiz.base.util.BshUtil; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; @@ -58,10 +54,13 @@ import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ModelParam; import org.ofbiz.service.ModelService; +import org.ofbiz.webapp.control.ConfigXMLReader; import org.ofbiz.widget.ModelWidget; - import org.w3c.dom.Element; +import bsh.EvalError; +import bsh.Interpreter; + /** * Widget Library - Form model class */ @@ -122,10 +121,10 @@ protected boolean overridenListSize = false; protected boolean clientAutocompleteFields = true; - protected List altTargets = new LinkedList(); - protected List<AutoFieldsService> autoFieldsServices = new LinkedList(); - protected List<AutoFieldsEntity> autoFieldsEntities = new LinkedList(); - protected List sortOrderFields = new LinkedList(); + protected List<AltTarget> altTargets = FastList.newInstance(); + protected List<AutoFieldsService> autoFieldsServices = FastList.newInstance(); + protected List<AutoFieldsEntity> autoFieldsEntities = FastList.newInstance(); + protected List<String> sortOrderFields = FastList.newInstance(); /** This List will contain one copy of each field for each field name in the order * they were encountered in the service, entity, or form definition; field definitions @@ -136,23 +135,23 @@ * necessary to use the Map. The Map is used when loading the form definition to keep the * list clean and implement the override features for field definitions. */ - protected List<ModelFormField> fieldList = new LinkedList(); + protected List<ModelFormField> fieldList = FastList.newInstance(); /** This Map is keyed with the field name and has a ModelFormField for the value; fields * with conditions will not be put in this Map so field definition overrides for fields * with conditions is not possible. */ - protected Map fieldMap = new HashMap(); + protected Map<String, ModelFormField> fieldMap = FastMap.newInstance(); /** This is a list of FieldGroups in the order they were created. * Can also include Banner objects. */ - protected List fieldGroupList = new ArrayList(); + protected List<FieldGroupBase> fieldGroupList = FastList.newInstance(); /** This Map is keyed with the field name and has a FieldGroup for the value. * Can also include Banner objects. */ - protected Map fieldGroupMap = new HashMap(); + protected Map<String, FieldGroupBase> fieldGroupMap = FastMap.newInstance(); /** This field group will be the "catch-all" group for fields that are not * included in an explicit field-group. @@ -491,7 +490,7 @@ String tagName = sortFieldElement.getTagName(); if (tagName.equals("sort-field")) { String fieldName = sortFieldElement.getAttribute("name"); - this.sortOrderFields.add(fieldName ); + this.sortOrderFields.add(fieldName); this.fieldGroupMap.put(fieldName, lastFieldGroup); } else if (tagName.equals("banner")) { Banner thisBanner = new Banner(sortFieldElement, this); @@ -511,8 +510,8 @@ // reorder fields according to sort order if (sortOrderFields.size() > 0) { - List sortedFields = new ArrayList(this.fieldList.size()); - Iterator sortOrderFieldIter = this.sortOrderFields.iterator(); + List<ModelFormField> sortedFields = FastList.newInstance(); + Iterator<String> sortOrderFieldIter = this.sortOrderFields.iterator(); while (sortOrderFieldIter.hasNext()) { String fieldName = (String) sortOrderFieldIter.next(); if (UtilValidate.isEmpty(fieldName)) { @@ -2590,8 +2589,10 @@ this.defaultPosition = position; } } + + public static interface FieldGroupBase {} - public static class FieldGroup { + public static class FieldGroup implements FieldGroupBase { public String id; public String style; protected ModelForm modelForm; @@ -2643,7 +2644,7 @@ } } - public static class Banner { + public static class Banner implements FieldGroupBase { protected ModelForm modelForm; public FlexibleStringExpander style; public FlexibleStringExpander text; @@ -2748,5 +2749,95 @@ } } return allServiceNamesUsed; + } + + public Set<String> getLinkedRequestsLocationAndUri() throws GeneralException { + Set<String> allRequestsUsed = FastSet.newInstance(); + + if (this.fieldList != null) { + for (ModelFormField modelFormField: this.fieldList) { + if (modelFormField.getFieldInfo() instanceof ModelFormField.HyperlinkField) { + ModelFormField.HyperlinkField link = (ModelFormField.HyperlinkField) modelFormField.getFieldInfo(); + String target = link.getTarget(null); + String urlMode = link.getTargetType(); + // Debug.logInfo("In findRequestNamesLinkedtoInWidget found link [" + link.rawString() + "] with target [" + target + "]", module); + + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target, urlMode); + if (controllerLocAndRequestSet != null) { + allRequestsUsed.addAll(controllerLocAndRequestSet); + } + } else if (modelFormField.getFieldInfo() instanceof ModelFormField.DisplayEntityField) { + ModelFormField.DisplayEntityField parentField = (ModelFormField.DisplayEntityField) modelFormField.getFieldInfo(); + if (parentField.subHyperlink != null) { + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null), parentField.subHyperlink.getTargetType()); + if (controllerLocAndRequestSet != null) { + allRequestsUsed.addAll(controllerLocAndRequestSet); + } + } + } else if (modelFormField.getFieldInfo() instanceof ModelFormField.TextField) { + ModelFormField.TextField parentField = (ModelFormField.TextField) modelFormField.getFieldInfo(); + if (parentField.subHyperlink != null) { + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null), parentField.subHyperlink.getTargetType()); + if (controllerLocAndRequestSet != null) { + allRequestsUsed.addAll(controllerLocAndRequestSet); + } + } + } else if (modelFormField.getFieldInfo() instanceof ModelFormField.DropDownField) { + ModelFormField.DropDownField parentField = (ModelFormField.DropDownField) modelFormField.getFieldInfo(); + if (parentField.subHyperlink != null) { + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null), parentField.subHyperlink.getTargetType()); + if (controllerLocAndRequestSet != null) { + allRequestsUsed.addAll(controllerLocAndRequestSet); + } + } + } else if (modelFormField.getFieldInfo() instanceof ModelFormField.ImageField) { + ModelFormField.ImageField parentField = (ModelFormField.ImageField) modelFormField.getFieldInfo(); + if (parentField.subHyperlink != null) { + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null), parentField.subHyperlink.getTargetType()); + if (controllerLocAndRequestSet != null) { + allRequestsUsed.addAll(controllerLocAndRequestSet); + } + } + } else if (modelFormField.getFieldInfo() instanceof ModelFormField.DropDownField) { + ModelFormField.DropDownField parentField = (ModelFormField.DropDownField) modelFormField.getFieldInfo(); + if (parentField.subHyperlink != null) { + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(parentField.subHyperlink.getTarget(null), parentField.subHyperlink.getTargetType()); + if (controllerLocAndRequestSet != null) { + allRequestsUsed.addAll(controllerLocAndRequestSet); + } + } + } + } + } + return allRequestsUsed; + } + + public Set<String> getTargetedRequestsLocationAndUri() throws GeneralException { + Set<String> allRequestsUsed = FastSet.newInstance(); + + if (this.altTargets != null) { + for (AltTarget altTarget: this.altTargets) { + String target = altTarget.target; + String urlMode = "intra-app"; + + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target, urlMode); + if (controllerLocAndRequestSet != null) { + allRequestsUsed.addAll(controllerLocAndRequestSet); + } + } + } + + if (!this.target.isEmpty()) { + String target = this.target.getOriginal(); + String urlMode = UtilValidate.isNotEmpty(this.targetType) ? this.targetType : "intra-app"; + if (target.indexOf("${") < 0) { + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target, urlMode); + if (controllerLocAndRequestSet != null) { + allRequestsUsed.addAll(controllerLocAndRequestSet); + } + } + } + + return allRequestsUsed; } } Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java?rev=644179&r1=644178&r2=644179&view=diff ============================================================================== --- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java (original) +++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java Wed Apr 2 23:06:48 2008 @@ -280,31 +280,12 @@ if (currentWidget instanceof ModelScreenWidget.Link) { ModelScreenWidget.Link link = (ModelScreenWidget.Link) currentWidget; String target = link.getTarget(null); + String urlMode = link.getUrlMode(); // Debug.logInfo("In findRequestNamesLinkedtoInWidget found link [" + link.rawString() + "] with target [" + target + "]", module); - int indexOfDollarSignCurlyBrace = target.indexOf("${"); - int indexOfQuestionMark = target.indexOf("?"); - if (indexOfDollarSignCurlyBrace >= 0 && (indexOfQuestionMark < 0 || indexOfQuestionMark > indexOfDollarSignCurlyBrace)) { - // we have an expanded string in the requestUri part of the target, not much we can do about that... - return; - } - - if ("intra-app".equals(link.getUrlMode())) { - // look through all controller.xml files and find those with the request-uri referred to by the target - String requestUri = UtilHttp.getRequestUriFromTarget(target); - - Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerFilesWithRequest(requestUri, null); - allRequestNamesIncluded.addAll(controllerLocAndRequestSet); - // if (controllerLocAndRequestSet.size() > 0) Debug.logInfo("============== In findRequestNamesLinkedtoInWidget, controllerLocAndRequestSet: " + controllerLocAndRequestSet, module); - } else if ("inter-app".equals(link.getUrlMode())) { - String webappMountPoint = UtilHttp.getWebappMountPointFromTarget(target); - if (webappMountPoint != null) webappMountPoint += "/WEB-INF"; - String requestUri = UtilHttp.getRequestUriFromTarget(target); - - Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerFilesWithRequest(requestUri, webappMountPoint); - allRequestNamesIncluded.addAll(controllerLocAndRequestSet); - // if (controllerLocAndRequestSet.size() > 0) Debug.logInfo("============== In findRequestNamesLinkedtoInWidget, controllerLocAndRequestSet: " + controllerLocAndRequestSet, module); - } + Set<String> controllerLocAndRequestSet = ConfigXMLReader.findControllerRequestUniqueForTargetType(target, urlMode); + if (controllerLocAndRequestSet == null) return; + allRequestNamesIncluded.addAll(controllerLocAndRequestSet); } else if (currentWidget instanceof ModelScreenWidget.Section) { ModelScreenWidget.Section section = (ModelScreenWidget.Section) currentWidget; if (section.subWidgets != null) { |
Free forum by Nabble | Edit this page |