Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java?rev=1636282&r1=1636281&r2=1636282&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java Mon Nov 3 06:54:16 2014 @@ -21,6 +21,7 @@ package org.ofbiz.widget.screen; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -43,6 +44,7 @@ import org.ofbiz.base.util.collections.F import org.ofbiz.base.util.collections.MapStack; import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.webapp.control.RequestHandler; +import org.ofbiz.widget.ModelWidgetVisitor; import org.ofbiz.widget.WidgetWorker; import org.w3c.dom.Element; @@ -52,56 +54,69 @@ import org.w3c.dom.Element; */ @SuppressWarnings("serial") public class IterateSectionWidget extends ModelScreenWidget { - public static final String module = IterateSectionWidget.class.getName(); - - protected ModelScreenWidget childWidget; - protected List<ModelScreenWidget.Section> sectionList; - protected FlexibleMapAccessor<Object> listNameExdr; - protected FlexibleStringExpander entryNameExdr; - protected FlexibleStringExpander keyNameExdr; - protected FlexibleStringExpander paginateTarget; - protected FlexibleStringExpander paginate; + public static final String module = IterateSectionWidget.class.getName(); public static int DEFAULT_PAGE_SIZE = 5; public static int MAX_PAGE_SIZE = 10000; - protected int viewIndex = 0; - protected int viewSize = DEFAULT_PAGE_SIZE; - protected int lowIndex = -1; - protected int highIndex = -1; - protected int listSize = 0; - protected int actualPageSize = 0; + private final List<ModelScreenWidget.Section> sectionList; + private final FlexibleMapAccessor<Object> listNameExdr; + private final FlexibleStringExpander entryNameExdr; + private final FlexibleStringExpander keyNameExdr; + private final FlexibleStringExpander paginateTarget; + private final FlexibleStringExpander paginate; + private final int viewSize; public IterateSectionWidget(ModelScreen modelScreen, Element iterateSectionElement) { super(modelScreen, iterateSectionElement); - listNameExdr = FlexibleMapAccessor.getInstance(iterateSectionElement.getAttribute("list")); - if (listNameExdr.isEmpty()) listNameExdr = FlexibleMapAccessor.getInstance(iterateSectionElement.getAttribute("list-name")); - entryNameExdr = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("entry")); - if (entryNameExdr.isEmpty()) entryNameExdr = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("entry-name")); - keyNameExdr = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("key")); - if (keyNameExdr.isEmpty()) keyNameExdr = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("key-name")); - - if (this.paginateTarget == null || iterateSectionElement.hasAttribute("paginate-target")) { - this.paginateTarget = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("paginate-target")); - } - - if (this.paginate == null || iterateSectionElement.hasAttribute("paginate")) { - this.paginate = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("paginate")); + String listName = iterateSectionElement.getAttribute("list"); + if (listName.isEmpty()) { + listName = iterateSectionElement.getAttribute("list-name"); + } + this.listNameExdr = FlexibleMapAccessor.getInstance(listName); + String entryName = iterateSectionElement.getAttribute("entry"); + if (entryName.isEmpty()) { + entryName = iterateSectionElement.getAttribute("entry-name"); + } + this.entryNameExdr = FlexibleStringExpander.getInstance(entryName); + String keyName = iterateSectionElement.getAttribute("key"); + if (keyName.isEmpty()) { + keyName = iterateSectionElement.getAttribute("key-name"); + } + this.keyNameExdr = FlexibleStringExpander.getInstance(keyName); + this.paginateTarget = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("paginate-target")); + this.paginate = FlexibleStringExpander.getInstance(iterateSectionElement.getAttribute("paginate")); + int viewSize = DEFAULT_PAGE_SIZE; + String viewSizeStr = iterateSectionElement.getAttribute("view-size"); + if (!viewSizeStr.isEmpty()) { + viewSize = Integer.parseInt(viewSizeStr); } - - if (iterateSectionElement.hasAttribute("view-size")) { - setViewSize(iterateSectionElement.getAttribute("view-size")); - } - sectionList = new ArrayList<ModelScreenWidget.Section>(); + this.viewSize = viewSize; List<? extends Element> childElementList = UtilXml.childElementList(iterateSectionElement); - for (Element sectionElement: childElementList) { - ModelScreenWidget.Section section = new ModelScreenWidget.Section(modelScreen, sectionElement); - sectionList.add(section); + if (childElementList.isEmpty()) { + this.sectionList = Collections.emptyList(); + } else { + List<ModelScreenWidget.Section> sectionList = new ArrayList<ModelScreenWidget.Section>(childElementList.size()); + for (Element sectionElement: childElementList) { + ModelScreenWidget.Section section = new ModelScreenWidget.Section(modelScreen, sectionElement, false); + sectionList.add(section); + } + this.sectionList = Collections.unmodifiableList(sectionList); } } + public List<ModelScreenWidget.Section> getSectionList() { + return sectionList; + } + @Override public void renderWidgetString(Appendable writer, Map<String, Object> context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException { + int viewIndex = 0; + int viewSize = this.viewSize; + int lowIndex = -1; + int highIndex = -1; + int listSize = 0; + int actualPageSize = 0; boolean isEntrySet = false; // create a standAloneStack, basically a "save point" for this SectionsRenderer, and make a new "screens" object just for it so it is isolated and doesn't follow the stack down @@ -126,10 +141,33 @@ public class IterateSectionWidget extend Debug.logError("Object not list or map type", module); return; } + listSize = theList.size(); WidgetWorker.incrementPaginatorNumber(context); int startPageNumber = WidgetWorker.getPaginatorNumber(context); - getListLimits(context, theList); - int rowCount = 0; + + if (getPaginate(context)) { + try { + Map<String, String> params = UtilGenerics.cast(context.get("parameters")); + String viewIndexString = params.get("VIEW_INDEX" + "_" + WidgetWorker.getPaginatorNumber(context)); + String viewSizeString = params.get("VIEW_SIZE" + "_" + WidgetWorker.getPaginatorNumber(context)); + viewIndex = Integer.parseInt(viewIndexString); + viewSize = Integer.parseInt(viewSizeString); + } catch (Exception e) { + try { + viewIndex = ((Integer) context.get("viewIndex")).intValue(); + } catch (Exception e2) { + viewIndex = 0; + } + } + context.put("viewIndex", Integer.valueOf(viewIndex)); + lowIndex = viewIndex * viewSize; + highIndex = (viewIndex + 1) * viewSize; + } else { + viewIndex = 0; + viewSize = MAX_PAGE_SIZE; + lowIndex = 0; + highIndex = MAX_PAGE_SIZE; + } Iterator<?> iter = theList.iterator(); int itemIndex = -1; int iterateIndex = 0; @@ -155,16 +193,15 @@ public class IterateSectionWidget extend contextMs.put("iterateId",String.valueOf(entryName+iterateIndex)); iterateIndex++; } - rowCount++; for (ModelScreenWidget.Section section: this.sectionList) { section.renderWidgetString(writer, contextMs, screenStringRenderer); } } if ((itemIndex + 1) < highIndex) { - setHighIndex(itemIndex + 1); + highIndex = itemIndex + 1; } - setActualPageSize(highIndex - lowIndex); + actualPageSize = highIndex - lowIndex; if (getPaginate(context)) { try { Integer lastPageNumber = null; @@ -173,9 +210,7 @@ public class IterateSectionWidget extend lastPageNumber = (Integer)globalCtx.get("PAGINATOR_NUMBER"); globalCtx.put("PAGINATOR_NUMBER", Integer.valueOf(startPageNumber)); } - - renderNextPrev(writer, context); - + renderNextPrev(writer, context, listSize, actualPageSize); if (globalCtx != null) { globalCtx.put("PAGINATOR_NUMBER", lastPageNumber); } @@ -194,103 +229,18 @@ public class IterateSectionWidget extend } public boolean getPaginate(Map<String, Object> context) { - if (this.paginate != null && !this.paginate.isEmpty() && UtilValidate.isNotEmpty(this.paginate.expandString(context))) { + if (!this.paginate.isEmpty() && UtilValidate.isNotEmpty(this.paginate.expandString(context))) { return Boolean.valueOf(this.paginate.expandString(context)).booleanValue(); } else { return true; } } - public void setPaginate(boolean val) { - this.paginate = FlexibleStringExpander.getInstance(Boolean.valueOf(val).toString()); - } - - public void setViewIndex(int val) { - viewIndex = val; - } - - public void setViewSize(int val) { - viewSize = val; - } - - public void setViewSize(String val) { - try { - viewSize = Integer.parseInt(val); - } catch (NumberFormatException e) { - viewSize = DEFAULT_PAGE_SIZE; - } - } - - public void setListSize(int val) { - listSize = val; - } - - public void setLowIndex(int val) { - lowIndex = val; - } - - public void setHighIndex(int val) { - highIndex = val; - } - public void setActualPageSize(int val) { - actualPageSize = val; - } - - public int getViewIndex() { - return viewIndex; - } - public int getViewSize() { return viewSize; } - public int getListSize() { - return listSize; - } - - public int getLowIndex() { - return lowIndex; - } - - public int getHighIndex() { - return highIndex; - } - - public int getActualPageSize() { - return actualPageSize; - } - - public <X> void getListLimits(Map<String, Object> context, List<X> items) { - listSize = items.size(); - - if (getPaginate(context)) { - try { - Map<String, String> params = UtilGenerics.cast(context.get("parameters")); - String viewIndexString = params.get("VIEW_INDEX" + "_" + WidgetWorker.getPaginatorNumber(context)); - String viewSizeString = params.get("VIEW_SIZE" + "_" + WidgetWorker.getPaginatorNumber(context)); - viewIndex = Integer.parseInt(viewIndexString); - viewSize = Integer.parseInt(viewSizeString); - } catch (Exception e) { - try { - viewIndex = ((Integer) context.get("viewIndex")).intValue(); - } catch (Exception e2) { - viewIndex = 0; - } - } - context.put("viewIndex", Integer.valueOf(this.viewIndex)); - - lowIndex = viewIndex * viewSize; - highIndex = (viewIndex + 1) * viewSize; - } else { - viewIndex = 0; - viewSize = MAX_PAGE_SIZE; - lowIndex = 0; - highIndex = MAX_PAGE_SIZE; - } - } - - - public void renderNextPrev(Appendable writer, Map<String, Object> context) throws IOException { + public void renderNextPrev(Appendable writer, Map<String, Object> context, int listSize, int actualPageSize) throws IOException { String targetService = this.getPaginateTarget(context); if (targetService == null) { targetService = "${targetService}"; @@ -328,12 +278,6 @@ public class IterateSectionWidget extend viewSize = this.getViewSize(); } - int listSize = -1; - try { - listSize = this.getListSize(); - } catch (Exception e) { - listSize = -1; - } /* int highIndex = -1; @@ -353,7 +297,6 @@ public class IterateSectionWidget extend int lowIndex = viewIndex * viewSize; int highIndex = (viewIndex + 1) * viewSize; - int actualPageSize = this.getActualPageSize(); // if this is all there seems to be (if listSize < 0, then size is unknown) if (actualPageSize >= listSize && listSize > 0) { return; @@ -415,9 +358,8 @@ public class IterateSectionWidget extend } @Override - public String rawString() { - // TODO: something more than the empty tag - return "<iterate-section/>"; + public void accept(ModelWidgetVisitor visitor) { + visitor.visit(this); } } Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/MacroScreenRenderer.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/MacroScreenRenderer.java?rev=1636282&r1=1636281&r2=1636282&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/MacroScreenRenderer.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/MacroScreenRenderer.java Mon Nov 3 06:54:16 2014 @@ -34,8 +34,6 @@ import javax.servlet.http.HttpServletReq import javax.servlet.http.HttpServletResponse; import javax.xml.parsers.ParserConfigurationException; -import javolution.util.FastMap; - import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilFormatOut; @@ -59,7 +57,8 @@ import org.ofbiz.widget.form.MacroFormRe import org.ofbiz.widget.form.ModelForm; import org.ofbiz.widget.html.HtmlScreenRenderer.ScreenletMenuRenderer; import org.ofbiz.widget.menu.MenuStringRenderer; -import org.ofbiz.widget.screen.ModelScreenWidget.*; +import org.ofbiz.widget.screen.ModelScreenWidget.Column; +import org.ofbiz.widget.screen.ModelScreenWidget.ColumnContainer; import org.xml.sax.SAXException; import freemarker.core.Environment; @@ -152,13 +151,13 @@ public class MacroScreenRenderer impleme } public void renderSectionBegin(Appendable writer, Map<String, Object> context, ModelScreenWidget.Section section) throws IOException { - if (section.isMainSection) { + if (section.isMainSection()) { this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); } if (this.widgetCommentsEnabled) { - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); StringBuilder sb = new StringBuilder("Begin "); - sb.append(section.isMainSection ? "Screen " : "Section Widget "); + sb.append(section.isMainSection() ? "Screen " : "Section Widget "); sb.append(section.getBoundaryCommentName()); parameters.put("boundaryComment", sb.toString()); executeMacro(writer, "renderSectionBegin", parameters); @@ -166,10 +165,10 @@ public class MacroScreenRenderer impleme } public void renderSectionEnd(Appendable writer, Map<String, Object> context, ModelScreenWidget.Section section) throws IOException { if (this.widgetCommentsEnabled) { - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); StringBuilder sb = new StringBuilder(); sb.append("End "); - sb.append(section.isMainSection ? "Screen " : "Section Widget "); + sb.append(section.isMainSection() ? "Screen " : "Section Widget "); sb.append(section.getBoundaryCommentName()); parameters.put("boundaryComment", sb.toString()); executeMacro(writer, "renderSectionEnd", parameters); @@ -190,7 +189,7 @@ public class MacroScreenRenderer impleme RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_"); autoUpdateLink = rh.makeLink(request, response, autoUpdateTarget); } - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("id", containerId); parameters.put("style", container.getStyle(context)); parameters.put("autoUpdateLink", autoUpdateLink); @@ -203,7 +202,7 @@ public class MacroScreenRenderer impleme } public void renderLabel(Appendable writer, Map<String, Object> context, ModelScreenWidget.Label label) throws IOException { - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("text", label.getText(context)); parameters.put("id", label.getId(context)); parameters.put("style", label.getStyle(context)); @@ -211,7 +210,7 @@ public class MacroScreenRenderer impleme } public void renderHorizontalSeparator(Appendable writer, Map<String, Object> context, ModelScreenWidget.HorizontalSeparator separator) throws IOException { - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("id", separator.getId(context)); parameters.put("style", separator.getStyle(context)); executeMacro(writer, "renderHorizontalSeparator", parameters); @@ -341,7 +340,7 @@ public class MacroScreenRenderer impleme } else { urlString = src; } - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("src", src); parameters.put("id", image.getId(context)); parameters.put("style", image.getStyle(context)); @@ -360,7 +359,7 @@ public class MacroScreenRenderer impleme if (Debug.verboseOn()) Debug.logVerbose("directEditRequest:" + editRequest, module); - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("editRequest", editRequest); parameters.put("enableEditValue", enableEditValue == null ? "" : enableEditValue); parameters.put("editContainerStyle", content.getEditContainerStyle(context)); @@ -378,7 +377,7 @@ public class MacroScreenRenderer impleme Delegator delegator = (Delegator) context.get("delegator"); // make a new map for content rendering; so our current map does not get clobbered - Map<String, Object> contentContext = FastMap.newInstance(); + Map<String, Object> contentContext = new HashMap<String, Object>(); contentContext.putAll(context); String dataResourceId = (String)contentContext.get("dataResourceId"); if (Debug.verboseOn()) Debug.logVerbose("expandedContentId:" + expandedContentId, module); @@ -454,7 +453,7 @@ public class MacroScreenRenderer impleme urlString = rh.makeLink(request, response, editRequest, false, false, false); } - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("urlString", urlString); parameters.put("editMode", editMode); parameters.put("editContainerStyle", content.getEditContainerStyle(context)); @@ -476,7 +475,7 @@ public class MacroScreenRenderer impleme fullUrlString = rh.makeLink(request, response, urlString, true, false, false); } - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("fullUrl", fullUrlString); parameters.put("width", content.getWidth()); parameters.put("height", content.getHeight()); @@ -488,7 +487,7 @@ public class MacroScreenRenderer impleme String enableEditName = content.getEnableEditName(context); String enableEditValue = (String)context.get(enableEditName); - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("editContainerStyle", content.getEditContainerStyle(context)); parameters.put("editRequest", content.getEditRequest(context)); parameters.put("enableEditValue", enableEditValue == null ? "" : enableEditValue); @@ -505,7 +504,7 @@ public class MacroScreenRenderer impleme Delegator delegator = (Delegator) context.get("delegator"); // create a new map for the content rendering; so our current context does not get overwritten! - Map<String, Object> contentContext = FastMap.newInstance(); + Map<String, Object> contentContext = new HashMap<String, Object>(); contentContext.putAll(context); try { @@ -570,7 +569,7 @@ public class MacroScreenRenderer impleme } } - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("urlString", urlString); parameters.put("editMode", editMode); parameters.put("editContainerStyle", content.getEditContainerStyle(context)); @@ -628,7 +627,7 @@ public class MacroScreenRenderer impleme menuString = sb.toString(); } - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("title", title); parameters.put("collapsible", collapsible); parameters.put("saveCollapsed", screenlet.saveCollapsed()); @@ -781,7 +780,7 @@ public class MacroScreenRenderer impleme firstLinkUrl = rh.makeLink(request, response, linkText); } - Map<String, Object> parameters = FastMap.newInstance(); + Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("lowIndex", modelForm.getLowIndex(context)); parameters.put("actualPageSize", actualPageSize); parameters.put("ofLabel", ofLabel); @@ -802,8 +801,8 @@ public class MacroScreenRenderer impleme } public void renderPortalPageBegin(Appendable writer, Map<String, Object> context, ModelScreenWidget.PortalPage portalPage) throws GeneralException, IOException { - String portalPageId = portalPage.getActualPortalPageId(); - String originalPortalPageId = portalPage.getOriginalPortalPageId(); + String portalPageId = portalPage.getActualPortalPageId(context); + String originalPortalPageId = portalPage.getOriginalPortalPageId(context); String confMode = portalPage.getConfMode(context); Map<String, String> uiLabelMap = UtilGenerics.cast(context.get("uiLabelMap")); @@ -839,8 +838,8 @@ public class MacroScreenRenderer impleme } public void renderPortalPageColumnBegin(Appendable writer, Map<String, Object> context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPageColumn) throws GeneralException, IOException { - String portalPageId = portalPage.getActualPortalPageId(); - String originalPortalPageId = portalPage.getOriginalPortalPageId(); + String portalPageId = portalPage.getActualPortalPageId(context); + String originalPortalPageId = portalPage.getOriginalPortalPageId(context); String columnSeqId = portalPageColumn.getString("columnSeqId"); String columnWidthPercentage = portalPageColumn.getString("columnWidthPercentage"); String columnWidthPixels = portalPageColumn.getString("columnWidthPixels"); @@ -909,8 +908,8 @@ public class MacroScreenRenderer impleme } public void renderPortalPagePortletBegin(Appendable writer, Map<String, Object> context, ModelScreenWidget.PortalPage portalPage, GenericValue portalPortlet) throws GeneralException, IOException { - String portalPageId = portalPage.getActualPortalPageId(); - String originalPortalPageId = portalPage.getOriginalPortalPageId(); + String portalPageId = portalPage.getActualPortalPageId(context); + String originalPortalPageId = portalPage.getOriginalPortalPageId(context); String portalPortletId = portalPortlet.getString("portalPortletId"); String portletSeqId = portalPortlet.getString("portletSeqId"); String columnSeqId = portalPortlet.getString("columnSeqId"); Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java?rev=1636282&r1=1636281&r2=1636282&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java Mon Nov 3 06:54:16 2014 @@ -18,15 +18,9 @@ *******************************************************************************/ package org.ofbiz.widget.screen; -import java.util.Collection; -import java.util.List; import java.util.Map; -import java.util.Set; - -import javolution.util.FastSet; import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.base.util.UtilXml; @@ -36,9 +30,8 @@ import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.transaction.TransactionUtil; import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.webapp.control.ConfigXMLReader; import org.ofbiz.widget.ModelWidget; -import org.ofbiz.widget.ModelWidgetAction; +import org.ofbiz.widget.ModelWidgetVisitor; import org.w3c.dom.Element; /** @@ -49,17 +42,12 @@ public class ModelScreen extends ModelWi public static final String module = ModelScreen.class.getName(); - protected String sourceLocation; - protected FlexibleStringExpander transactionTimeoutExdr; - protected Map<String, ModelScreen> modelScreenMap; - protected boolean useTransaction; - protected boolean useCache; - - protected ModelScreenWidget.Section section; - - // ===== CONSTRUCTORS ===== - /** Default Constructor */ - protected ModelScreen() {} + private final String sourceLocation; + private final FlexibleStringExpander transactionTimeoutExdr; + private final Map<String, ModelScreen> modelScreenMap; + private final boolean useTransaction; + private final boolean useCache; + private final ModelScreenWidget.Section section; /** XML Constructor */ public ModelScreen(Element screenElement, Map<String, ModelScreen> modelScreenMap, String sourceLocation) { @@ -73,259 +61,39 @@ public class ModelScreen extends ModelWi // read in the section, which will read all sub-widgets too Element sectionElement = UtilXml.firstChildElement(screenElement, "section"); if (sectionElement == null) { - throw new IllegalArgumentException("No section found for the screen definition with name: " + this.name); + throw new IllegalArgumentException("No section found for the screen definition with name: " + getName()); } - this.section = new ModelScreenWidget.Section(this, sectionElement); - this.section.isMainSection = true; + this.section = new ModelScreenWidget.Section(this, sectionElement, true); } - public String getSourceLocation() { - return sourceLocation; + @Override + public void accept(ModelWidgetVisitor visitor) { + visitor.visit(this); } - public Set<String> getAllServiceNamesUsed() { - Set<String> allServiceNamesUsed = FastSet.newInstance(); - findServiceNamesUsedInWidget(this.section, allServiceNamesUsed); - return allServiceNamesUsed; - } - - protected static void findServiceNamesUsedInWidget(ModelScreenWidget currentWidget, Set<String> allServiceNamesUsed) { - if (currentWidget instanceof ModelScreenWidget.Section) { - List<ModelWidgetAction> actions = ((ModelScreenWidget.Section)currentWidget).actions; - List<ModelScreenWidget> subWidgets = ((ModelScreenWidget.Section)currentWidget).subWidgets; - List<ModelScreenWidget> failWidgets = ((ModelScreenWidget.Section)currentWidget).failWidgets; - if (actions != null) { - for (ModelWidgetAction screenOperation: actions) { - if (screenOperation instanceof ModelWidgetAction.Service) { - String serviceName = ((ModelWidgetAction.Service) screenOperation).getServiceNameExdr().getOriginal(); - if (UtilValidate.isNotEmpty(serviceName)) allServiceNamesUsed.add(serviceName); - } - } - } - if (subWidgets != null) { - for (ModelScreenWidget widget: subWidgets) { - findServiceNamesUsedInWidget(widget, allServiceNamesUsed); - } - } - if (failWidgets != null) { - for (ModelScreenWidget widget: failWidgets) { - findServiceNamesUsedInWidget(widget, allServiceNamesUsed); - } - } - } else if (currentWidget instanceof ModelScreenWidget.DecoratorSection) { - ModelScreenWidget.DecoratorSection decoratorSection = (ModelScreenWidget.DecoratorSection)currentWidget; - if (decoratorSection.subWidgets != null) { - for (ModelScreenWidget widget: decoratorSection.subWidgets) { - findServiceNamesUsedInWidget(widget, allServiceNamesUsed); - } - } - } else if (currentWidget instanceof ModelScreenWidget.DecoratorScreen) { - ModelScreenWidget.DecoratorScreen decoratorScreen = (ModelScreenWidget.DecoratorScreen)currentWidget; - if (decoratorScreen.sectionMap != null) { - Collection<ModelScreenWidget.DecoratorSection> sections = decoratorScreen.sectionMap.values(); - for (ModelScreenWidget section: sections) { - findServiceNamesUsedInWidget(section, allServiceNamesUsed); - } - } - } else if (currentWidget instanceof ModelScreenWidget.Container) { - ModelScreenWidget.Container container = (ModelScreenWidget.Container)currentWidget; - if (container.subWidgets != null) { - for (ModelScreenWidget widget: container.subWidgets) { - findServiceNamesUsedInWidget(widget, allServiceNamesUsed); - } - } - } else if (currentWidget instanceof ModelScreenWidget.Screenlet) { - ModelScreenWidget.Screenlet screenlet = (ModelScreenWidget.Screenlet)currentWidget; - if (screenlet.subWidgets != null) { - for (ModelScreenWidget widget: screenlet.subWidgets) { - findServiceNamesUsedInWidget(widget, allServiceNamesUsed); - } - } - } + public String getTransactionTimeout() { + return transactionTimeoutExdr.getOriginal(); } - public Set<String> getAllEntityNamesUsed() { - Set<String> allEntityNamesUsed = FastSet.newInstance(); - findEntityNamesUsedInWidget(this.section, allEntityNamesUsed); - return allEntityNamesUsed; - } - protected static void findEntityNamesUsedInWidget(ModelScreenWidget currentWidget, Set<String> allEntityNamesUsed) { - if (currentWidget instanceof ModelScreenWidget.Section) { - List<ModelWidgetAction> actions = ((ModelScreenWidget.Section)currentWidget).actions; - List<ModelScreenWidget> subWidgets = ((ModelScreenWidget.Section)currentWidget).subWidgets; - List<ModelScreenWidget> failWidgets = ((ModelScreenWidget.Section)currentWidget).failWidgets; - if (actions != null) { - for (ModelWidgetAction screenOperation: actions) { - if (screenOperation instanceof ModelWidgetAction.EntityOne) { - String entName = ((ModelWidgetAction.EntityOne) screenOperation).getFinder().getEntityName(); - if (UtilValidate.isNotEmpty(entName)) allEntityNamesUsed.add(entName); - } else if (screenOperation instanceof ModelWidgetAction.EntityAnd) { - String entName = ((ModelWidgetAction.EntityAnd) screenOperation).getFinder().getEntityName(); - if (UtilValidate.isNotEmpty(entName)) allEntityNamesUsed.add(entName); - } else if (screenOperation instanceof ModelWidgetAction.EntityCondition) { - String entName = ((ModelWidgetAction.EntityCondition) screenOperation).getFinder().getEntityName(); - if (UtilValidate.isNotEmpty(entName)) allEntityNamesUsed.add(entName); - } else if (screenOperation instanceof ModelWidgetAction.GetRelated) { - String relationName = ((ModelWidgetAction.GetRelated) screenOperation).getRelationName(); - if (UtilValidate.isNotEmpty(relationName)) allEntityNamesUsed.add(relationName); - } else if (screenOperation instanceof ModelWidgetAction.GetRelatedOne) { - String relationName = ((ModelWidgetAction.GetRelatedOne) screenOperation).getRelationName(); - if (UtilValidate.isNotEmpty(relationName)) allEntityNamesUsed.add(relationName); - } - } - } - if (subWidgets != null) { - for (ModelScreenWidget widget: subWidgets) { - findEntityNamesUsedInWidget(widget, allEntityNamesUsed); - } - } - if (failWidgets != null) { - for (ModelScreenWidget widget: failWidgets) { - findEntityNamesUsedInWidget(widget, allEntityNamesUsed); - } - } - } else if (currentWidget instanceof ModelScreenWidget.DecoratorSection) { - ModelScreenWidget.DecoratorSection decoratorSection = (ModelScreenWidget.DecoratorSection)currentWidget; - if (decoratorSection.subWidgets != null) { - for (ModelScreenWidget widget: decoratorSection.subWidgets) { - findEntityNamesUsedInWidget(widget, allEntityNamesUsed); - } - } - } else if (currentWidget instanceof ModelScreenWidget.DecoratorScreen) { - ModelScreenWidget.DecoratorScreen decoratorScreen = (ModelScreenWidget.DecoratorScreen)currentWidget; - if (decoratorScreen.sectionMap != null) { - Collection<ModelScreenWidget.DecoratorSection> sections = decoratorScreen.sectionMap.values(); - for (ModelScreenWidget section: sections) { - findEntityNamesUsedInWidget(section, allEntityNamesUsed); - } - } - } else if (currentWidget instanceof ModelScreenWidget.Container) { - ModelScreenWidget.Container container = (ModelScreenWidget.Container)currentWidget; - if (container.subWidgets != null) { - for (ModelScreenWidget widget: container.subWidgets) { - findEntityNamesUsedInWidget(widget, allEntityNamesUsed); - } - } - } else if (currentWidget instanceof ModelScreenWidget.Screenlet) { - ModelScreenWidget.Screenlet screenlet = (ModelScreenWidget.Screenlet)currentWidget; - if (screenlet.subWidgets != null) { - for (ModelScreenWidget widget: screenlet.subWidgets) { - findEntityNamesUsedInWidget(widget, allEntityNamesUsed); - } - } - } + + public Map<String, ModelScreen> getModelScreenMap() { + return modelScreenMap; } - public Set<String> getAllFormNamesIncluded() { - Set<String> allFormNamesIncluded = FastSet.newInstance(); - findFormNamesIncludedInWidget(this.section, allFormNamesIncluded); - return allFormNamesIncluded; - } - protected static void findFormNamesIncludedInWidget(ModelScreenWidget currentWidget, Set<String> allFormNamesIncluded) { - if (currentWidget instanceof ModelScreenWidget.Form) { - ModelScreenWidget.Form form = (ModelScreenWidget.Form) currentWidget; - allFormNamesIncluded.add(form.locationExdr.getOriginal() + "#" + form.nameExdr.getOriginal()); - } else if (currentWidget instanceof ModelScreenWidget.Section) { - ModelScreenWidget.Section section = (ModelScreenWidget.Section) currentWidget; - if (section.subWidgets != null) { - for (ModelScreenWidget widget: section.subWidgets) { - findFormNamesIncludedInWidget(widget, allFormNamesIncluded); - } - } - if (section.failWidgets != null) { - for (ModelScreenWidget widget: section.failWidgets) { - findFormNamesIncludedInWidget(widget, allFormNamesIncluded); - } - } - } else if (currentWidget instanceof ModelScreenWidget.DecoratorSection) { - ModelScreenWidget.DecoratorSection decoratorSection = (ModelScreenWidget.DecoratorSection) currentWidget; - if (decoratorSection.subWidgets != null) { - for (ModelScreenWidget widget: decoratorSection.subWidgets) { - findFormNamesIncludedInWidget(widget, allFormNamesIncluded); - } - } - } else if (currentWidget instanceof ModelScreenWidget.DecoratorScreen) { - ModelScreenWidget.DecoratorScreen decoratorScreen = (ModelScreenWidget.DecoratorScreen) currentWidget; - if (decoratorScreen.sectionMap != null) { - Collection<ModelScreenWidget.DecoratorSection> sections = decoratorScreen.sectionMap.values(); - for (ModelScreenWidget section: sections) { - findFormNamesIncludedInWidget(section, allFormNamesIncluded); - } - } - } else if (currentWidget instanceof ModelScreenWidget.Container) { - ModelScreenWidget.Container container = (ModelScreenWidget.Container) currentWidget; - if (container.subWidgets != null) { - for (ModelScreenWidget widget: container.subWidgets) { - findFormNamesIncludedInWidget(widget, allFormNamesIncluded); - } - } - } else if (currentWidget instanceof ModelScreenWidget.Screenlet) { - ModelScreenWidget.Screenlet screenlet = (ModelScreenWidget.Screenlet) currentWidget; - if (screenlet.subWidgets != null) { - for (ModelScreenWidget widget: screenlet.subWidgets) { - findFormNamesIncludedInWidget(widget, allFormNamesIncluded); - } - } - } + + public boolean getUseTransaction() { + return useTransaction; } - public Set<String> getAllRequestsLocationAndUri() throws GeneralException { - Set<String> allRequestNamesIncluded = FastSet.newInstance(); - findRequestNamesLinkedtoInWidget(this.section, allRequestNamesIncluded); - return allRequestNamesIncluded; - } - protected static void findRequestNamesLinkedtoInWidget(ModelScreenWidget currentWidget, Set<String> allRequestNamesIncluded) throws GeneralException { - 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); - - 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) { - for (ModelScreenWidget widget: section.subWidgets) { - findRequestNamesLinkedtoInWidget(widget, allRequestNamesIncluded); - } - } - if (section.failWidgets != null) { - for (ModelScreenWidget widget: section.failWidgets) { - findRequestNamesLinkedtoInWidget(widget, allRequestNamesIncluded); - } - } - } else if (currentWidget instanceof ModelScreenWidget.DecoratorSection) { - ModelScreenWidget.DecoratorSection decoratorSection = (ModelScreenWidget.DecoratorSection) currentWidget; - if (decoratorSection.subWidgets != null) { - for (ModelScreenWidget widget: decoratorSection.subWidgets) { - findRequestNamesLinkedtoInWidget(widget, allRequestNamesIncluded); - } - } - } else if (currentWidget instanceof ModelScreenWidget.DecoratorScreen) { - ModelScreenWidget.DecoratorScreen decoratorScreen = (ModelScreenWidget.DecoratorScreen) currentWidget; - if (decoratorScreen.sectionMap != null) { - Collection<ModelScreenWidget.DecoratorSection> sections = decoratorScreen.sectionMap.values(); - for (ModelScreenWidget section: sections) { - findRequestNamesLinkedtoInWidget(section, allRequestNamesIncluded); - } - } - } else if (currentWidget instanceof ModelScreenWidget.Container) { - ModelScreenWidget.Container container = (ModelScreenWidget.Container) currentWidget; - if (container.subWidgets != null) { - for (ModelScreenWidget widget: container.subWidgets) { - findRequestNamesLinkedtoInWidget(widget, allRequestNamesIncluded); - } - } - } else if (currentWidget instanceof ModelScreenWidget.Screenlet) { - ModelScreenWidget.Screenlet screenlet = (ModelScreenWidget.Screenlet) currentWidget; - if (screenlet.subWidgets != null) { - for (ModelScreenWidget widget: screenlet.subWidgets) { - findRequestNamesLinkedtoInWidget(widget, allRequestNamesIncluded); - } - } - } + public boolean getUseCache() { + return useCache; + } + + public ModelScreenWidget.Section getSection() { + return section; } + public String getSourceLocation() { + return sourceLocation; + } /** * Renders this screen to a String, i.e. in a text format, as defined with the @@ -361,7 +129,7 @@ public class ModelScreen extends ModelWi try { transactionTimeout = Integer.parseInt(transactionTimeoutPar); } catch (NumberFormatException nfe) { - String msg = "TRANSACTION_TIMEOUT parameter for screen [" + this.sourceLocation + "#" + this.name + "] is invalid and it will be ignored: " + nfe.toString(); + String msg = "TRANSACTION_TIMEOUT parameter for screen [" + this.sourceLocation + "#" + getName() + "] is invalid and it will be ignored: " + nfe.toString(); Debug.logWarning(msg, module); } } @@ -397,7 +165,7 @@ public class ModelScreen extends ModelWi } catch (ScreenRenderException e) { throw e; } catch (RuntimeException e) { - String errMsg = "Error rendering screen [" + this.sourceLocation + "#" + this.name + "]: " + e.toString(); + String errMsg = "Error rendering screen [" + this.sourceLocation + "#" + getName() + "]: " + e.toString(); Debug.logError(errMsg + ". Rolling back transaction.", module); try { // only rollback the transaction if we started one... @@ -408,7 +176,7 @@ public class ModelScreen extends ModelWi // after rolling back, rethrow the exception throw new ScreenRenderException(errMsg, e); } catch (Exception e) { - String errMsg = "Error rendering screen [" + this.sourceLocation + "#" + this.name + "]: " + e.toString(); + String errMsg = "Error rendering screen [" + this.sourceLocation + "#" + getName() + "]: " + e.toString(); Debug.logError(errMsg + ". Rolling back transaction.", module); try { // only rollback the transaction if we started one... Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java?rev=1636282&r1=1636281&r2=1636282&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreenAction.java Mon Nov 3 06:54:16 2014 @@ -21,6 +21,8 @@ package org.ofbiz.widget.screen; import java.io.Serializable; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -30,9 +32,6 @@ import java.util.regex.PatternSyntaxExce import javax.servlet.ServletContext; import javax.servlet.http.HttpSession; -import javolution.util.FastList; -import javolution.util.FastMap; - import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.ObjectType; @@ -82,9 +81,8 @@ public abstract class ModelScreenAction @Deprecated public static List<ModelScreenAction> readSubActions(ModelScreen modelScreen, Element parentElement) { - List<ModelScreenAction> actions = FastList.newInstance(); - List<? extends Element> actionElementList = UtilXml.childElementList(parentElement); + List<ModelScreenAction> actions = new ArrayList<ModelScreenAction>(actionElementList.size()); for (Element actionElement: actionElementList) { if ("set".equals(actionElement.getNodeName())) { actions.add(new SetField(modelScreen, actionElement)); @@ -150,6 +148,7 @@ public abstract class ModelScreenAction } } + @SuppressWarnings("rawtypes") @Override public void runAction(Map<String, Object> context) { String globalStr = this.globalExdr.expandString(context); @@ -189,9 +188,9 @@ public abstract class ModelScreenAction if (UtilValidate.isNotEmpty(this.type)) { if ("NewMap".equals(this.type)) { - newValue = FastMap.newInstance(); + newValue = new HashMap(); } else if ("NewList".equals(this.type)) { - newValue = FastList.newInstance(); + newValue = new LinkedList(); } else { try { newValue = ObjectType.simpleTypeConvert(newValue, this.type, null, (TimeZone) context.get("timeZone"), (Locale) context.get("locale"), true); @@ -414,7 +413,7 @@ public abstract class ModelScreenAction @Override public void runAction(Map<String, Object> context) throws GeneralException { if (location.endsWith(".xml")) { - Map<String, Object> localContext = FastMap.newInstance(); + Map<String, Object> localContext = new HashMap<String, Object>(); localContext.putAll(context); DispatchContext ctx = this.modelScreen.getDispatcher(context).getDispatchContext(); MethodContext methodContext = new MethodContext(ctx, localContext, null); @@ -460,7 +459,7 @@ public abstract class ModelScreenAction if ("true".equals(autoFieldMapString)) { DispatchContext dc = this.modelScreen.getDispatcher(context).getDispatchContext(); // try a map called "parameters", try it first so values from here are overriden by values in the main context - Map<String, Object> combinedMap = FastMap.newInstance(); + Map<String, Object> combinedMap = new HashMap<String, Object>(); Map<String, Object> parametersObj = UtilGenerics.toMap(context.get("parameters")); if (parametersObj != null) { combinedMap.putAll(parametersObj); @@ -475,7 +474,7 @@ public abstract class ModelScreenAction } } if (serviceContext == null) { - serviceContext = FastMap.newInstance(); + serviceContext = new HashMap<String, Object>(); } if (this.fieldMap != null) { Modified: ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java URL: http://svn.apache.org/viewvc/ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java?rev=1636282&r1=1636281&r2=1636282&view=diff ============================================================================== --- ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java (original) +++ ofbiz/branches/OFBIZ-5312-ofbiz-ecommerce-seo-2013-10-23/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java Mon Nov 3 06:54:16 2014 @@ -20,13 +20,13 @@ package org.ofbiz.widget.screen; import java.io.Serializable; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.TimeZone; -import javolution.util.FastList; - import org.apache.oro.text.regex.MalformedPatternException; import org.apache.oro.text.regex.Pattern; import org.apache.oro.text.regex.PatternMatcher; @@ -85,8 +85,8 @@ public class ModelScreenCondition implem } public static List<ScreenCondition> readSubConditions(ModelScreen modelScreen, Element conditionElement) { - List<ScreenCondition> condList = FastList.newInstance(); List<? extends Element> subElementList = UtilXml.childElementList(conditionElement); + List<ScreenCondition> condList = new ArrayList<ScreenCondition>(subElementList.size()); for (Element subElement: subElementList) { condList.add(readCondition(modelScreen, subElement)); } @@ -420,7 +420,7 @@ public class ModelScreenCondition implem fieldVal = ""; } - List<Object> messages = FastList.newInstance(); + List<Object> messages = new LinkedList<Object>(); Boolean resultBool = BaseCompare.doRealCompare(fieldVal, value, operator, type, format, messages, null, null, true); if (messages.size() > 0) { messages.add(0, "Error with comparison in if-compare between field [" + fieldAcsr.toString() + "] with value [" + fieldVal + "] and value [" + value + "] with operator [" + operator + "] and type [" + type + "]: "); @@ -471,7 +471,7 @@ public class ModelScreenCondition implem fieldVal = ""; } - List<Object> messages = FastList.newInstance(); + List<Object> messages = new LinkedList<Object>(); Boolean resultBool = BaseCompare.doRealCompare(fieldVal, toFieldVal, operator, type, format, messages, null, null, false); if (messages.size() > 0) { messages.add(0, "Error with comparison in if-compare-field between field [" + fieldAcsr.toString() + "] with value [" + fieldVal + "] and to-field [" + toFieldAcsr.toString() + "] with value [" + toFieldVal + "] with operator [" + operator + "] and type [" + type + "]: "); |
Free forum by Nabble | Edit this page |