You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by do...@apache.org on 2008/09/22 18:27:29 UTC
svn commit: r697890 - in /ofbiz/trunk/framework/widget/src/org/ofbiz/widget:
./ screen/
Author: doogie
Date: Mon Sep 22 09:27:27 2008
New Revision: 697890
URL: http://svn.apache.org/viewvc?rev=697890&view=rev
Log:
Some more minor code things, generics, string + -> StringBuilder,
javolution, Integer object creation, etc.
Modified:
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreen.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java
ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java?rev=697890&r1=697889&r2=697890&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/ModelWidget.java Mon Sep 22 09:27:27 2008
@@ -21,6 +21,7 @@
import java.io.Serializable;
import java.util.Map;
import org.w3c.dom.Element;
+import org.ofbiz.base.util.UtilGenerics;
import org.ofbiz.base.util.UtilProperties;
/**
@@ -94,7 +95,8 @@
* @param context The screen rendering context
*/
public void setWidgetBoundaryComments(Map<String, Object> context) {
- enableWidgetBoundaryComments = widgetBoundaryCommentsEnabled((Map) context.get("parameters"));
+ Map<String, ? extends Object> parameters = UtilGenerics.checkMap(context.get("parameters"));
+ enableWidgetBoundaryComments = widgetBoundaryCommentsEnabled(parameters);
}
/**
@@ -103,7 +105,7 @@
* widget.verbose=true in debug.properties.
* @param parameters Optional parameters Map
*/
- public static boolean widgetBoundaryCommentsEnabled(Map parameters) {
+ public static boolean widgetBoundaryCommentsEnabled(Map<String, ? extends Object> parameters) {
boolean result = "true".equals(UtilProperties.getPropertyValue("widget", "widget.verbose"));
if (!result && parameters != null) {
result = "true".equals(parameters.get(enableBoundaryCommentsParam));
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java?rev=697890&r1=697889&r2=697890&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/HtmlWidget.java Mon Sep 22 09:27:27 2008
@@ -21,13 +21,15 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import javolution.util.FastMap;
+
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;
import org.ofbiz.base.util.collections.MapStack;
@@ -87,7 +89,7 @@
if (location.endsWith(".ftl")) {
try {
- Map parameters = (Map) context.get("parameters");
+ Map<String, ? extends Object> parameters = UtilGenerics.checkMap(context.get("parameters"));
boolean insertWidgetBoundaryComments = ModelWidget.widgetBoundaryCommentsEnabled(parameters);
if (insertWidgetBoundaryComments) {
writer.append(HtmlWidgetRenderer.formatBoundaryComment("Begin", "Template", location));
@@ -145,16 +147,14 @@
public static class HtmlTemplateDecorator extends ModelScreenWidget {
protected FlexibleStringExpander locationExdr;
- protected Map<String, HtmlTemplateDecoratorSection> sectionMap = new HashMap<String, HtmlTemplateDecoratorSection>();
+ protected Map<String, HtmlTemplateDecoratorSection> sectionMap = FastMap.newInstance();
public HtmlTemplateDecorator(ModelScreen modelScreen, Element htmlTemplateDecoratorElement) {
super(modelScreen, htmlTemplateDecoratorElement);
this.locationExdr = FlexibleStringExpander.getInstance(htmlTemplateDecoratorElement.getAttribute("location"));
- List htmlTemplateDecoratorSectionElementList = UtilXml.childElementList(htmlTemplateDecoratorElement, "html-template-decorator-section");
- Iterator htmlTemplateDecoratorSectionElementIter = htmlTemplateDecoratorSectionElementList.iterator();
- while (htmlTemplateDecoratorSectionElementIter.hasNext()) {
- Element htmlTemplateDecoratorSectionElement = (Element) htmlTemplateDecoratorSectionElementIter.next();
+ List<? extends Element> htmlTemplateDecoratorSectionElementList = UtilXml.childElementList(htmlTemplateDecoratorElement, "html-template-decorator-section");
+ for (Element htmlTemplateDecoratorSectionElement: htmlTemplateDecoratorSectionElementList) {
String name = htmlTemplateDecoratorSectionElement.getAttribute("name");
this.sectionMap.put(name, new HtmlTemplateDecoratorSection(modelScreen, htmlTemplateDecoratorSectionElement));
}
@@ -163,14 +163,16 @@
@SuppressWarnings("unchecked")
public void renderWidgetString(Appendable writer, Map<String, Object> context, ScreenStringRenderer screenStringRenderer) {
// isolate the scope
+ MapStack<String> contextMs;
if (!(context instanceof MapStack)) {
- context = MapStack.create(context);
+ contextMs = MapStack.create(context);
+ context = contextMs;
+ } else {
+ contextMs = UtilGenerics.cast(context);
}
- MapStack contextMs = (MapStack) context;
-
// 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
- MapStack standAloneStack = contextMs.standAloneChildStack();
+ MapStack<String> standAloneStack = contextMs.standAloneChildStack();
standAloneStack.put("screens", new ScreenRenderer(writer, standAloneStack, screenStringRenderer));
SectionsRenderer sections = new SectionsRenderer(this.sectionMap, standAloneStack, writer, screenStringRenderer);
@@ -189,13 +191,13 @@
public static class HtmlTemplateDecoratorSection extends ModelScreenWidget {
protected String name;
- protected List subWidgets;
+ protected List<ModelScreenWidget> subWidgets;
public HtmlTemplateDecoratorSection(ModelScreen modelScreen, Element htmlTemplateDecoratorSectionElement) {
super(modelScreen, htmlTemplateDecoratorSectionElement);
this.name = htmlTemplateDecoratorSectionElement.getAttribute("name");
// read sub-widgets
- List subElementList = UtilXml.childElementList(htmlTemplateDecoratorSectionElement);
+ List<? extends Element> subElementList = UtilXml.childElementList(htmlTemplateDecoratorSectionElement);
this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList);
}
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java?rev=697890&r1=697889&r2=697890&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/IterateSectionWidget.java Mon Sep 22 09:27:27 2008
@@ -82,10 +82,8 @@
setViewSize(iterateSectionElement.getAttribute("view-size"));
}
sectionList = new ArrayList<ModelScreenWidget.Section>();
- List childElementList = UtilXml.childElementList(iterateSectionElement);
- Iterator childElementIter = childElementList.iterator();
- while (childElementIter.hasNext()) {
- Element sectionElement = (Element) childElementIter.next();
+ List<? extends Element> childElementList = UtilXml.childElementList(iterateSectionElement);
+ for (Element sectionElement: childElementList) {
ModelScreenWidget.Section section = new ModelScreenWidget.Section(modelScreen, sectionElement);
sectionList.add(section);
}
@@ -181,8 +179,7 @@
public void setViewSize(String val) {
try {
- Integer sz = Integer.valueOf(val);
- viewSize = sz.intValue();
+ viewSize = Integer.parseInt(val);
} catch(NumberFormatException e) {
viewSize = DEFAULT_PAGE_SIZE;
}
@@ -227,7 +224,7 @@
return actualPageSize;
}
- public void getListLimits(Map<String, Object> context, List items) {
+ public void getListLimits(Map<String, Object> context, List<?> items) {
listSize = items.size();
if (paginate) {
@@ -330,34 +327,34 @@
writer.append(" <b>\n");
if (viewIndex > 0) {
writer.append(" <a href=\"");
- String linkText = targetService;
- if (linkText.indexOf("?") < 0) linkText += "?";
- else linkText += "&";
+ StringBuilder linkText = new StringBuilder(targetService);
+ if (linkText.indexOf("?") < 0) linkText.append("?");
+ else linkText.append("&");
//if (queryString != null && !queryString.equals("null")) linkText += queryString + "&";
- linkText += "VIEW_SIZE=" + viewSize + "&VIEW_INDEX=" + (viewIndex - 1) + "\"";
+ linkText.append("VIEW_SIZE=").append(viewSize).append("&VIEW_INDEX=").append(viewIndex - 1).append("\"");
// make the link
- writer.append(rh.makeLink(request, response, linkText, false, false, false));
+ writer.append(rh.makeLink(request, response, linkText.toString(), false, false, false));
String previous = UtilProperties.getMessage("CommonUiLabels", "CommonPrevious", (Locale) context.get("locale"));
- writer.append(" class=\"buttontext\">[" + previous +"]</a>\n");
+ writer.append(" class=\"buttontext\">[").append(previous).append("]</a>\n");
}
if (listSize > 0) {
Map<String, Integer> messageMap = UtilMisc.toMap("lowCount", Integer.valueOf(lowIndex + 1), "highCount", Integer.valueOf(lowIndex + actualPageSize), "total", Integer.valueOf(listSize));
String commonDisplaying = UtilProperties.getMessage("CommonUiLabels", "CommonDisplaying", messageMap, (Locale) context.get("locale"));
- writer.append(" <span class=\"tabletext\">" + commonDisplaying + "</span> \n");
+ writer.append(" <span class=\"tabletext\">").append(commonDisplaying).append("</span> \n");
}
if (highIndex < listSize) {
writer.append(" <a href=\"");
- String linkText = targetService;
- if (linkText.indexOf("?") < 0) linkText += "?";
- else linkText += "&";
- linkText += "VIEW_SIZE=" + viewSize + "&VIEW_INDEX=" + (viewIndex + 1) + "\"";
+ StringBuilder linkText = new StringBuilder(targetService);
+ if (linkText.indexOf("?") < 0) linkText.append("?");
+ else linkText.append("&");
+ linkText.append("VIEW_SIZE=").append(viewSize).append("&VIEW_INDEX=").append(viewIndex + 1).append("\"");
// make the link
- writer.append(rh.makeLink(request, response, linkText, false, false, false));
+ writer.append(rh.makeLink(request, response, linkText.toString(), false, false, false));
String next = UtilProperties.getMessage("CommonUiLabels", "CommonNext", (Locale) context.get("locale"));
- writer.append(" class=\"buttontext\">[" + next +"]</a>\n");
+ writer.append(" class=\"buttontext\">[").append(next).append("]</a>\n");
}
writer.append(" </b>\n");
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=697890&r1=697889&r2=697890&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 Mon Sep 22 09:27:27 2008
@@ -50,7 +50,7 @@
protected String sourceLocation;
protected FlexibleStringExpander transactionTimeoutExdr;
- protected Map modelScreenMap;
+ protected Map<String, ModelScreen> modelScreenMap;
protected boolean useCache;
protected ModelScreenWidget.Section section;
@@ -60,7 +60,7 @@
protected ModelScreen() {}
/** XML Constructor */
- public ModelScreen(Element screenElement, Map modelScreenMap, String sourceLocation) {
+ public ModelScreen(Element screenElement, Map<String, ModelScreen> modelScreenMap, String sourceLocation) {
super(screenElement);
this.sourceLocation = sourceLocation;
this.transactionTimeoutExdr = FlexibleStringExpander.getInstance(screenElement.getAttribute("transaction-timeout"));
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java?rev=697890&r1=697889&r2=697890&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenCondition.java Mon Sep 22 09:27:27 2008
@@ -81,10 +81,8 @@
public static List<ScreenCondition> readSubConditions(ModelScreen modelScreen, Element conditionElement) {
List<ScreenCondition> condList = FastList.newInstance();
- List subElementList = UtilXml.childElementList(conditionElement);
- Iterator subElementIter = subElementList.iterator();
- while (subElementIter.hasNext()) {
- Element subElement = (Element) subElementIter.next();
+ List<? extends Element> subElementList = UtilXml.childElementList(conditionElement);
+ for (Element subElement: subElementList) {
condList.add(readCondition(modelScreen, subElement));
}
return condList;
@@ -124,7 +122,7 @@
}
public static class And extends ScreenCondition {
- protected List subConditions;
+ protected List<ScreenCondition> subConditions;
public And(ModelScreen modelScreen, Element condElement) {
super (modelScreen, condElement);
@@ -133,9 +131,7 @@
public boolean eval(Map<String, Object> context) {
// return false for the first one in the list that is false, basic and algo
- Iterator subConditionIter = this.subConditions.iterator();
- while (subConditionIter.hasNext()) {
- ScreenCondition subCondition = (ScreenCondition) subConditionIter.next();
+ for (ScreenCondition subCondition: this.subConditions) {
if (!subCondition.eval(context)) {
return false;
}
@@ -145,7 +141,7 @@
}
public static class Xor extends ScreenCondition {
- protected List subConditions;
+ protected List<ScreenCondition> subConditions;
public Xor(ModelScreen modelScreen, Element condElement) {
super (modelScreen, condElement);
@@ -155,9 +151,7 @@
public boolean eval(Map<String, Object> context) {
// if more than one is true stop immediately and return false; if all are false return false; if only one is true return true
boolean foundOneTrue = false;
- Iterator subConditionIter = this.subConditions.iterator();
- while (subConditionIter.hasNext()) {
- ScreenCondition subCondition = (ScreenCondition) subConditionIter.next();
+ for (ScreenCondition subCondition: this.subConditions) {
if (subCondition.eval(context)) {
if (foundOneTrue) {
// now found two true, so return false
@@ -172,7 +166,7 @@
}
public static class Or extends ScreenCondition {
- protected List subConditions;
+ protected List<ScreenCondition> subConditions;
public Or(ModelScreen modelScreen, Element condElement) {
super (modelScreen, condElement);
@@ -181,9 +175,7 @@
public boolean eval(Map<String, Object> context) {
// return true for the first one in the list that is true, basic or algo
- Iterator subConditionIter = this.subConditions.iterator();
- while (subConditionIter.hasNext()) {
- ScreenCondition subCondition = (ScreenCondition) subConditionIter.next();
+ for (ScreenCondition subCondition: this.subConditions) {
if (subCondition.eval(context)) {
return true;
}
@@ -417,10 +409,9 @@
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 + "]: ");
- StringBuffer fullString = new StringBuffer();
- Iterator miter = messages.iterator();
- while (miter.hasNext()) {
- fullString.append((String) miter.next());
+ StringBuilder fullString = new StringBuilder();
+ for (Object item: messages) {
+ fullString.append(item.toString());
}
Debug.logWarning(fullString.toString(), module);
@@ -466,10 +457,9 @@
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 + "]: ");
- StringBuffer fullString = new StringBuffer();
- Iterator miter = messages.iterator();
- while (miter.hasNext()) {
- fullString.append((String) miter.next());
+ StringBuilder fullString = new StringBuilder();
+ for (Object item: messages) {
+ fullString.append(item.toString());
}
Debug.logWarning(fullString.toString(), module);
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java?rev=697890&r1=697889&r2=697890&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ModelScreenWidget.java Mon Sep 22 09:27:27 2008
@@ -20,11 +20,9 @@
import java.io.IOException;
import java.io.Serializable;
-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;
@@ -32,6 +30,8 @@
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.ParserConfigurationException;
+import javolution.util.FastList;
+
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.UtilFormatOut;
@@ -80,11 +80,9 @@
public abstract String rawString();
- public static List<ModelScreenWidget> readSubWidgets(ModelScreen modelScreen, List subElementList) {
- List<ModelScreenWidget> subWidgets = new LinkedList<ModelScreenWidget>();
- Iterator subElementIter = subElementList.iterator();
- while (subElementIter.hasNext()) {
- Element subElement = (Element) subElementIter.next();
+ public static List<ModelScreenWidget> readSubWidgets(ModelScreen modelScreen, List<? extends Element> subElementList) {
+ List<ModelScreenWidget> subWidgets = FastList.newInstance();
+ for (Element subElement: subElementList) {
if ("section".equals(subElement.getNodeName())) {
subWidgets.add(new Section(modelScreen, subElement));
@@ -128,13 +126,11 @@
return subWidgets;
}
- public static void renderSubWidgetsString(List subWidgets, Appendable writer, Map<String, Object> context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException {
+ public static void renderSubWidgetsString(List<ModelScreenWidget> subWidgets, Appendable writer, Map<String, Object> context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException {
if (subWidgets == null) {
return;
}
- Iterator subWidgetIter = subWidgets.iterator();
- while (subWidgetIter.hasNext()) {
- ModelScreenWidget subWidget = (ModelScreenWidget) subWidgetIter.next();
+ for (ModelScreenWidget subWidget: subWidgets) {
if (Debug.verboseOn()) Debug.logVerbose("Rendering screen " + subWidget.modelScreen.getName() + "; widget class is " + subWidget.getClass().getName(), module);
// render the sub-widget itself
@@ -195,13 +191,13 @@
// read sub-widgets
Element widgetsElement = UtilXml.firstChildElement(sectionElement, "widgets");
- List subElementList = UtilXml.childElementList(widgetsElement);
+ List<? extends Element> subElementList = UtilXml.childElementList(widgetsElement);
this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList);
// read fail-widgets
Element failWidgetsElement = UtilXml.firstChildElement(sectionElement, "fail-widgets");
if (failWidgetsElement != null) {
- List failElementList = UtilXml.childElementList(failWidgetsElement);
+ List<? extends Element> failElementList = UtilXml.childElementList(failWidgetsElement);
this.failWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, failElementList);
}
}
@@ -282,7 +278,7 @@
}
// read sub-widgets
- List subElementList = UtilXml.childElementList(containerElement);
+ List<? extends Element> subElementList = UtilXml.childElementList(containerElement);
this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList);
}
@@ -347,7 +343,7 @@
throw new IllegalArgumentException("Collapsible screenlets must have a name or id [" + this.modelScreen.getName() + "]");
}
this.titleExdr = FlexibleStringExpander.getInstance(screenletElement.getAttribute("title"));
- List subElementList = UtilXml.childElementList(screenletElement);
+ List<? extends Element> subElementList = UtilXml.childElementList(screenletElement);
this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList);
String navMenuName = screenletElement.getAttribute("navigation-menu-name");
if (UtilValidate.isNotEmpty(navMenuName)) {
@@ -387,7 +383,7 @@
boolean collapsed = initiallyCollapsed;
if (this.collapsible) {
String preferenceKey = getPreferenceKey(context) + "_collapsed";
- Map requestParameters = (Map)context.get("requestParameters");
+ Map<String, Object> requestParameters = UtilGenerics.checkMap(context.get("requestParameters"));
if (requestParameters != null) {
String collapsedParam = (String) requestParameters.get(preferenceKey);
if (UtilValidate.isNotEmpty(collapsedParam)) {
@@ -507,7 +503,7 @@
// build the widgetpath
List<String> widgetTrail = UtilGenerics.toList(context.get("_WIDGETTRAIL_"));
if (widgetTrail == null) {
- widgetTrail = new ArrayList<String>();
+ widgetTrail = FastList.newInstance();
}
String thisName = nameExdr.expandString(context);
@@ -549,7 +545,7 @@
throw new RuntimeException(errMsg);
}
} else {
- modelScreen = (ModelScreen) this.modelScreen.modelScreenMap.get(name);
+ modelScreen = this.modelScreen.modelScreenMap.get(name);
if (modelScreen == null) {
throw new IllegalArgumentException("Could not find screen with name [" + name + "] in the same file as the screen with name [" + this.modelScreen.getName() + "]");
}
@@ -591,10 +587,8 @@
this.nameExdr = FlexibleStringExpander.getInstance(decoratorScreenElement.getAttribute("name"));
this.locationExdr = FlexibleStringExpander.getInstance(decoratorScreenElement.getAttribute("location"));
- List decoratorSectionElementList = UtilXml.childElementList(decoratorScreenElement, "decorator-section");
- Iterator decoratorSectionElementIter = decoratorSectionElementList.iterator();
- while (decoratorSectionElementIter.hasNext()) {
- Element decoratorSectionElement = (Element) decoratorSectionElementIter.next();
+ List<? extends Element> decoratorSectionElementList = UtilXml.childElementList(decoratorScreenElement, "decorator-section");
+ for (Element decoratorSectionElement: decoratorSectionElementList) {
String name = decoratorSectionElement.getAttribute("name");
this.sectionMap.put(name, new DecoratorSection(modelScreen, decoratorSectionElement));
}
@@ -646,7 +640,7 @@
throw new RuntimeException(errMsg);
}
} else {
- modelScreen = (ModelScreen) this.modelScreen.modelScreenMap.get(name);
+ modelScreen = this.modelScreen.modelScreenMap.get(name);
if (modelScreen == null) {
throw new IllegalArgumentException("Could not find screen with name [" + name + "] in the same file as the screen with name [" + this.modelScreen.getName() + "]");
}
@@ -676,7 +670,7 @@
public DecoratorSection(ModelScreen modelScreen, Element decoratorSectionElement) {
super(modelScreen, decoratorSectionElement);
// read sub-widgets
- List subElementList = UtilXml.childElementList(decoratorSectionElement);
+ List<? extends Element> subElementList = UtilXml.childElementList(decoratorSectionElement);
this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList);
}
@@ -698,7 +692,7 @@
}
public void renderWidgetString(Appendable writer, Map<String, Object> context, ScreenStringRenderer screenStringRenderer) throws GeneralException, IOException {
- Map preRenderedContent = (Map) context.get("preRenderedContent");
+ Map<String, ? extends Object> preRenderedContent = UtilGenerics.checkMap(context.get("preRenderedContent"));
if (preRenderedContent != null && preRenderedContent.containsKey(this.name)) {
try {
writer.append((String) preRenderedContent.get(this.name));
@@ -957,11 +951,9 @@
public PlatformSpecific(ModelScreen modelScreen, Element platformSpecificElement) {
super(modelScreen, platformSpecificElement);
subWidgets = new HashMap<String, ModelScreenWidget>();
- List childElements = UtilXml.childElementList(platformSpecificElement);
+ List<? extends Element> childElements = UtilXml.childElementList(platformSpecificElement);
if (childElements != null) {
- Iterator childElementsIt = childElements.iterator();
- while (childElementsIt.hasNext()) {
- Element childElement = (Element)childElementsIt.next();
+ for (Element childElement: childElements) {
if ("html".equals(childElement.getNodeName())) {
subWidgets.put("html", new HtmlWidget(modelScreen, childElement));
} else if ("xsl-fo".equals(childElement.getNodeName())) {
@@ -999,11 +991,11 @@
public String rawString() {
Collection<ModelScreenWidget> subWidgetList = this.subWidgets.values();
- String subWidgetsRawString = "";
+ StringBuilder subWidgetsRawString = new StringBuilder("<platform-specific>");
for (ModelScreenWidget subWidget: subWidgetList) {
- subWidgetsRawString = subWidgetsRawString + subWidget.rawString();
+ subWidgetsRawString.append(subWidget.rawString());
}
- return "<platform-specific>" + subWidgetsRawString + "</platform-specific>";
+ return subWidgetsRawString.append("</platform-specific>").toString();
}
}
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java?rev=697890&r1=697889&r2=697890&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenFactory.java Mon Sep 22 09:27:27 2008
@@ -20,7 +20,6 @@
import java.io.IOException;
import java.net.URL;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -28,6 +27,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.xml.parsers.ParserConfigurationException;
+import javolution.util.FastMap;
+
import org.ofbiz.base.location.FlexibleLocation;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilHttp;
@@ -95,15 +96,15 @@
public static ModelScreen getScreenFromLocation(String resourceName, String screenName)
throws IOException, SAXException, ParserConfigurationException {
- Map modelScreenMap = getScreensFromLocation(resourceName);
- ModelScreen modelScreen = (ModelScreen) modelScreenMap.get(screenName);
+ Map<String, ModelScreen> modelScreenMap = getScreensFromLocation(resourceName);
+ ModelScreen modelScreen = modelScreenMap.get(screenName);
if (modelScreen == null) {
throw new IllegalArgumentException("Could not find screen with name [" + screenName + "] in class resource [" + resourceName + "]");
}
return modelScreen;
}
- public static Map getScreensFromLocation(String resourceName)
+ public static Map<String, ModelScreen> getScreensFromLocation(String resourceName)
throws IOException, SAXException, ParserConfigurationException {
Map<String, ModelScreen> modelScreenMap = screenLocationCache.get(resourceName);
if (modelScreenMap == null) {
@@ -165,14 +166,12 @@
}
public static Map<String, ModelScreen> readScreenDocument(Document screenFileDoc, String sourceLocation) {
- Map<String, ModelScreen> modelScreenMap = new HashMap<String, ModelScreen>();
+ Map<String, ModelScreen> modelScreenMap = FastMap.newInstance();
if (screenFileDoc != null) {
// read document and construct ModelScreen for each screen element
Element rootElement = screenFileDoc.getDocumentElement();
- List screenElements = UtilXml.childElementList(rootElement, "screen");
- Iterator screenElementIter = screenElements.iterator();
- while (screenElementIter.hasNext()) {
- Element screenElement = (Element) screenElementIter.next();
+ List<? extends Element> screenElements = UtilXml.childElementList(rootElement, "screen");
+ for (Element screenElement: screenElements) {
ModelScreen modelScreen = new ModelScreen(screenElement, modelScreenMap, sourceLocation);
//Debug.logInfo("Read Screen with name: " + modelScreen.getName(), module);
modelScreenMap.put(modelScreen.getName(), modelScreen);
Modified: ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java?rev=697890&r1=697889&r2=697890&view=diff
==============================================================================
--- ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java (original)
+++ ofbiz/trunk/framework/widget/src/org/ofbiz/widget/screen/ScreenRenderer.java Mon Sep 22 09:27:27 2008
@@ -21,7 +21,6 @@
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
-import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -33,6 +32,7 @@
import javax.servlet.http.HttpSession;
import javax.xml.parsers.ParserConfigurationException;
+import javolution.util.FastList;
import javolution.util.FastMap;
import org.ofbiz.base.util.GeneralException;
@@ -242,9 +242,9 @@
// setup message lists
List<String> eventMessageList = UtilGenerics.toList(request.getAttribute("eventMessageList"));
- if (eventMessageList == null) eventMessageList = new LinkedList<String>();
+ if (eventMessageList == null) eventMessageList = FastList.newInstance();
List<String> errorMessageList = UtilGenerics.toList(request.getAttribute("errorMessageList"));
- if (errorMessageList == null) errorMessageList = new LinkedList<String>();
+ if (errorMessageList == null) errorMessageList = FastList.newInstance();
if (request.getAttribute("_EVENT_MESSAGE_") != null) {
eventMessageList.add(UtilFormatOut.replaceString((String) request.getAttribute("_EVENT_MESSAGE_"), "\n", "<br/>"));
@@ -277,11 +277,7 @@
}
// if there was an error message, this is an error
- if (errorMessageList.size() > 0) {
- context.put("isError", Boolean.TRUE);
- } else {
- context.put("isError", Boolean.FALSE);
- }
+ context.put("isError", errorMessageList.size() > 0 ? Boolean.TRUE : Boolean.FALSE);
// if a parameter was passed saying this is an error, it is an error
if ("true".equals(parameterMap.get("isError"))) {
context.put("isError", Boolean.TRUE);