A patch from Adrian Crum "Screen widget show where code came from in html" (https://issues.apache.org/jira/browse/OFBIZ-1318) - OFBIZ-1318

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@594042 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jacques Le Roux
2007-11-12 08:06:40 +00:00
parent 14d45b24b5
commit b6b7c017c8
19 changed files with 419 additions and 202 deletions
+3
View File
@@ -32,3 +32,6 @@ print.important=true
print.warning=true
print.error=true
print.fatal=true
# Enable screen widget boundary comments
#widget.verbose=true
@@ -36,6 +36,16 @@ under the License.
<param-value>component://example/widget/example/CommonScreens.xml</param-value>
<description>The location of the main-decorator screen to use for this webapp; referred to as a context variable in screen def XML files.</description>
</context-param>
<context-param>
<param-name>widgetVerbose</param-name>
<param-value>false</param-value>
<description>Enable widget boundary comments. See org.ofbiz.widget.ModelWidget.widgetBoundaryCommentsEnabled().</description>
</context-param>
<context-param>
<param-name>compressHTML</param-name>
<param-value>false</param-value>
<description>Remove unnecessary whitespace from HTML output.</description>
</context-param>
<filter>
<filter-name>ContextFilter</filter-name>
@@ -0,0 +1,112 @@
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
package org.ofbiz.widget;
import java.io.Serializable;
import java.util.Map;
import org.w3c.dom.Element;
import org.ofbiz.base.util.UtilProperties;
/**
* Widget Library - Widget model class. ModelWidget is a base class that is
* extended by other widget model classes.
*/
public class ModelWidget implements Serializable {
/**
* The parameter name used to control widget boundary comments. Currently
* set to "widgetVerbose". Set the parameter to "true" to enable widget
* boundary comments.<br/><br/>
* <code>WEB-INF/web.xml</code> example:<br/><br/>
* <code>
* &lt;context-param&gt;<br/>
* &nbsp;&nbsp;&lt;param-name&gt;widgetVerbose&lt;/param-name&gt;<br/>
* &nbsp;&nbsp;&lt;param-value&gt;true&lt;/param-value&gt;<br/>
* &lt;/context-param&gt;
* </code><br/><br/>
* Screen widget example:<br/><br/>
* <code>
* &lt;actions&gt;<br/>
* &nbsp;&nbsp;&lt;set field="parameters.widgetVerbose" value="true" global="true"/&gt;<br/>
* &lt;/actions&gt;
* </code>
*/
public static final String enableBoundaryCommentsParam = "widgetVerbose";
protected String name;
protected boolean enableWidgetBoundaryComments = false;
protected ModelWidget() {}
/**
* Derived classes must call this constructor.
* @param widgetElement The XML Element for the widget
*/
public ModelWidget(Element widgetElement) {
this.name = widgetElement.getAttribute("name");
}
/**
* Returns the widget's name.
* @return Widget's name
*/
public String getName() {
return name;
}
/**
* Returns the widget's name to be used in boundary comments. The default action
* is to return the widget's name. Derived classes can override this method to
* return a customized name.
* @return Name to be used in boundary comments
*/
public String getBoundaryCommentName() {
return name;
}
/**
* Returns true if boundary comments are enabled for this widget, otherwise
* returns false.
* @return True if boundary comments are enabled for this widget
*/
public boolean boundaryCommentsEnabled() {
return enableWidgetBoundaryComments;
}
/**
* Enables/disables boundary comments for this widget.
* @param context The screen rendering context
*/
public void setWidgetBoundaryComments(Map context) {
enableWidgetBoundaryComments = widgetBoundaryCommentsEnabled((Map) context.get("parameters"));
}
/**
* Returns true if widget boundary comments are enabled. Widget boundary comments are
* enabled by setting widgetVerbose true in the parameters Map, or by setting
* widget.verbose=true in debug.properties.
* @param parameters Optional parameters Map
*/
public static boolean widgetBoundaryCommentsEnabled(Map parameters) {
boolean result = "true".equals(UtilProperties.getPropertyValue("debug", "widget.verbose"));
if (!result && parameters != null) {
result = "true".equals(parameters.get(enableBoundaryCommentsParam));
}
return result;
}
}
@@ -65,7 +65,7 @@ public class FormFactory {
URL formFileUrl = null;
formFileUrl = FlexibleLocation.resolveLocation(resourceName); //, loader);
Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true);
modelFormMap = readFormDocument(formFileDoc, delegator, dispatcher);
modelFormMap = readFormDocument(formFileDoc, delegator, dispatcher, resourceName);
formLocationCache.put(resourceName, modelFormMap);
}
}
@@ -95,7 +95,7 @@ public class FormFactory {
URL formFileUrl = servletContext.getResource(resourceName);
Document formFileDoc = UtilXml.readXmlDocument(formFileUrl, true);
modelFormMap = readFormDocument(formFileDoc, delegator, dispatcher);
modelFormMap = readFormDocument(formFileDoc, delegator, dispatcher, cacheKey);
formWebappCache.put(cacheKey, modelFormMap);
}
}
@@ -108,7 +108,7 @@ public class FormFactory {
return modelForm;
}
public static Map readFormDocument(Document formFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher) {
public static Map readFormDocument(Document formFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher, String formLocation) {
Map modelFormMap = new HashMap();
if (formFileDoc != null) {
// read document and construct ModelForm for each form element
@@ -118,6 +118,7 @@ public class FormFactory {
while (formElementIter.hasNext()) {
Element formElement = (Element) formElementIter.next();
ModelForm modelForm = new ModelForm(formElement, delegator, dispatcher);
modelForm.setFormLocation(formLocation);
modelFormMap.put(modelForm.getName(), modelForm);
}
}
@@ -52,13 +52,14 @@ import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelParam;
import org.ofbiz.service.ModelService;
import org.ofbiz.widget.ModelWidget;
import org.w3c.dom.Element;
/**
* Widget Library - Form model class
*/
public class ModelForm {
public class ModelForm extends ModelWidget {
public static final String module = ModelForm.class.getName();
public static final String DEFAULT_FORM_RESULT_LIST_NAME = "defaultFormResultList";
@@ -66,7 +67,7 @@ public class ModelForm {
protected GenericDelegator delegator;
protected LocalDispatcher dispatcher;
protected String name;
protected String formLocation;
protected String type;
protected FlexibleStringExpander target;
protected String targetType;
@@ -179,12 +180,14 @@ public class ModelForm {
/** XML Constructor */
public ModelForm(Element formElement, GenericDelegator delegator, LocalDispatcher dispatcher) {
super(formElement);
this.delegator = delegator;
this.dispatcher = dispatcher;
initForm(formElement);
}
public ModelForm(Element formElement) {
super(formElement);
initForm(formElement);
}
@@ -274,7 +277,6 @@ public class ModelForm {
}
}
this.name = formElement.getAttribute("name");
if (this.type == null || formElement.hasAttribute("type")) {
this.type = formElement.getAttribute("type");
}
@@ -685,6 +687,8 @@ public class ModelForm {
public void renderFormString(StringBuffer buffer, Map context, FormStringRenderer formStringRenderer) {
ModelFormAction.runSubActions(this.actions, context);
setWidgetBoundaryComments(context);
// if this is a list form, don't useRequestParameters
if ("list".equals(this.type) || "multi".equals(this.type)) {
context.put("useRequestParameters", Boolean.FALSE);
@@ -1905,6 +1909,10 @@ public class ModelForm {
return this.type;
}
public String getBoundaryCommentName() {
return formLocation + "#" + name;
}
public void resetBshInterpreter(Map context) {
context.remove("bshInterpreter");
}
@@ -2023,6 +2031,13 @@ public class ModelForm {
this.itemIndexSeparator = string;
}
/**
* @param string Form's location
*/
public void setFormLocation(String formLocation) {
this.formLocation = formLocation;
}
/**
* @param string
*/
@@ -1087,13 +1087,13 @@ public class ModelFormField {
condTrue = boolVal.booleanValue();
} else {
throw new IllegalArgumentException("Return value from use-when condition eval was not a Boolean: "
+ retVal.getClass().getName() + " [" + retVal + "] on the field " + this.name + " of form " + this.modelForm.name);
+ retVal.getClass().getName() + " [" + retVal + "] on the field " + this.name + " of form " + this.modelForm.getName());
}
return condTrue;
} catch (EvalError e) {
String errMsg = "Error evaluating BeanShell use-when condition [" + useWhenStr + "] on the field "
+ this.name + " of form " + this.modelForm.name + ": " + e.toString();
+ this.name + " of form " + this.modelForm.getName() + ": " + e.toString();
Debug.logError(e, errMsg, module);
//Debug.logError("For use-when eval error context is: " + context, module);
throw new IllegalArgumentException(errMsg);
@@ -31,7 +31,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilFormatOut;
import org.ofbiz.base.util.UtilHttp;
import org.ofbiz.base.util.UtilProperties;
import org.ofbiz.base.util.UtilValidate;
@@ -68,7 +67,7 @@ import org.apache.commons.lang.StringEscapeUtils;
/**
* Widget Library - HTML Form Renderer implementation
*/
public class HtmlFormRenderer implements FormStringRenderer {
public class HtmlFormRenderer extends HtmlWidgetRenderer implements FormStringRenderer {
public static final String module = HtmlFormRenderer.class.getName();
@@ -83,12 +82,6 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.response = response;
}
public void appendWhitespace(StringBuffer buffer) {
// appending line ends for now, but this could be replaced with a simple space or something
buffer.append("\r\n");
//buffer.append(' ');
}
public void appendOfbizUrl(StringBuffer buffer, String location) {
ServletContext ctx = (ServletContext) this.request.getAttribute("servletContext");
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
@@ -184,7 +177,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -202,7 +195,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
modelFormField.getEvent(),
modelFormField.getAction(context));
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
public void makeHyperlinkString(StringBuffer buffer, ModelFormField.SubHyperlink subHyperlink, Map context) {
@@ -284,7 +277,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -355,7 +348,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -544,7 +537,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -698,7 +691,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -756,7 +749,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -811,7 +804,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -906,7 +899,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -934,7 +927,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -960,8 +953,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
}
buffer.append("/>");
//this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -996,7 +988,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("</span>");
}
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
}
@@ -1022,7 +1014,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("</span>");
}
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
} else {
renderFieldTitle(buffer, context, modelFormField);
}
@@ -1032,8 +1024,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
* @see org.ofbiz.widget.form.FormStringRenderer#renderFormOpen(java.lang.StringBuffer, java.util.Map, org.ofbiz.widget.form.ModelForm)
*/
public void renderFormOpen(StringBuffer buffer, Map context, ModelForm modelForm) {
buffer.append("<!-- begin form widget -->");
this.appendWhitespace(buffer);
renderBeginningBoundaryComment(buffer, "Form Widget", modelForm);
buffer.append("<form method=\"post\" ");
String targetType = modelForm.getTargetType();
String targ = modelForm.getTarget(context, targetType);
@@ -1080,7 +1071,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append(modelForm.getCurrentFormName(context));
buffer.append("\">");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1090,18 +1081,16 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("</form>");
String focusFieldName = modelForm.getfocusFieldName();
if (UtilValidate.isNotEmpty(focusFieldName)) {
this.appendWhitespace(buffer);
appendWhitespace(buffer);
buffer.append("<script language=\"JavaScript\" type=\"text/javascript\">");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
buffer.append("document." + modelForm.getCurrentFormName(context) + ".");
buffer.append(focusFieldName + ".focus();");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
buffer.append("</script>");
}
this.appendWhitespace(buffer);
buffer.append("<!-- end form widget -->");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
renderEndingBoundaryComment(buffer, "Form Widget", modelForm);
}
/* (non-Javadoc)
@@ -1145,10 +1134,8 @@ public class HtmlFormRenderer implements FormStringRenderer {
}
}
buffer.append("</form>");
this.appendWhitespace(buffer);
buffer.append("<!-- end form widget -->");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
renderEndingBoundaryComment(buffer, "Form Widget", modelForm);
}
public void renderFormatListWrapperOpen(StringBuffer buffer, Map context, ModelForm modelForm) {
@@ -1166,8 +1153,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
}
context.put("_QBESTRING_", queryString);
buffer.append("<!-- begin form widget -->");
this.appendWhitespace(buffer);
renderBeginningBoundaryComment(buffer, "Form Widget", modelForm);
this.renderNextPrev(buffer, context, modelForm);
buffer.append(" <table cellspacing=\"0\" class=\"");
if(UtilValidate.isNotEmpty(modelForm.getDefaultTableStyle())) {
@@ -1176,16 +1162,15 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("basic-table form-widget-table dark-grid");
}
buffer.append("\">");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
public void renderFormatListWrapperClose(StringBuffer buffer, Map context, ModelForm modelForm) {
buffer.append(" </table>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
this.renderNextPrev(buffer, context, modelForm);
buffer.append("<!-- end form widget -->");
this.appendWhitespace(buffer);
renderEndingBoundaryComment(buffer, "Form Widget", modelForm);
}
/* (non-Javadoc)
@@ -1201,7 +1186,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("header-row");
}
buffer.append("\">");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1210,7 +1195,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
public void renderFormatHeaderRowClose(StringBuffer buffer, Map context, ModelForm modelForm) {
buffer.append(" </tr>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1230,7 +1215,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("\"");
}
buffer.append(">");
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1238,7 +1223,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
*/
public void renderFormatHeaderRowCellClose(StringBuffer buffer, Map context, ModelForm modelForm, ModelFormField modelFormField) {
buffer.append("</td>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
public void renderFormatHeaderRowFormCellOpen(StringBuffer buffer, Map context, ModelForm modelForm) {
@@ -1250,7 +1235,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("\"");
}
buffer.append(">");
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1258,7 +1243,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
*/
public void renderFormatHeaderRowFormCellClose(StringBuffer buffer, Map context, ModelForm modelForm) {
buffer.append("</td>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1308,7 +1293,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
}
}
buffer.append(">");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1317,7 +1302,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
public void renderFormatItemRowClose(StringBuffer buffer, Map context, ModelForm modelForm) {
buffer.append(" </tr>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1337,7 +1322,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("\"");
}
buffer.append(">");
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1345,7 +1330,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
*/
public void renderFormatItemRowCellClose(StringBuffer buffer, Map context, ModelForm modelForm, ModelFormField modelFormField) {
buffer.append("</td>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1360,7 +1345,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("\"");
}
buffer.append(">");
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1368,19 +1353,21 @@ public class HtmlFormRenderer implements FormStringRenderer {
*/
public void renderFormatItemRowFormCellClose(StringBuffer buffer, Map context, ModelForm modelForm) {
buffer.append("</td>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
public void renderFormatSingleWrapperOpen(StringBuffer buffer, Map context, ModelForm modelForm) {
buffer.append(" <table cellspacing=\"0\">");
this.appendWhitespace(buffer);
buffer.append(" <table cellspacing=\"0\"");
if(UtilValidate.isNotEmpty(modelForm.getDefaultTableStyle())) {
buffer.append(" class=\"" + modelForm.getDefaultTableStyle() + "\"");
}
buffer.append(">");
appendWhitespace(buffer);
}
public void renderFormatSingleWrapperClose(StringBuffer buffer, Map context, ModelForm modelForm) {
buffer.append(" </table>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1388,8 +1375,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
*/
public void renderFormatFieldRowOpen(StringBuffer buffer, Map context, ModelForm modelForm) {
buffer.append(" <tr>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1397,8 +1383,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
*/
public void renderFormatFieldRowClose(StringBuffer buffer, Map context, ModelForm modelForm) {
buffer.append(" </tr>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1415,7 +1400,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append(" class=\"label\"");
}
buffer.append(">");
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1423,7 +1408,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
*/
public void renderFormatFieldRowTitleCellClose(StringBuffer buffer, Map context, ModelFormField modelFormField) {
buffer.append("</td>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1433,7 +1418,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
// Embedded styling - bad idea
//buffer.append("<td>&nbsp;</td>");
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1463,7 +1448,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
}
buffer.append(">");
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1471,7 +1456,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
*/
public void renderFormatFieldRowWidgetCellClose(StringBuffer buffer, Map context, ModelFormField modelFormField, int positions, int positionSpan, Integer nextPositionInRow) {
buffer.append("</td>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
public void renderFormatEmptySpace(StringBuffer buffer, Map context, ModelForm modelForm) {
@@ -1550,7 +1535,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1660,7 +1645,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1862,7 +1847,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -1939,7 +1924,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.makeHyperlinkString(buffer, lookupField.getSubHyperlink(), context);
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
public void renderNextPrev(StringBuffer buffer, Map context, ModelForm modelForm) {
@@ -2101,7 +2086,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
buffer.append("</li>");
buffer.append("</ul>").append("</div>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -2142,7 +2127,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -2192,7 +2177,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -2246,7 +2231,7 @@ public class HtmlFormRenderer implements FormStringRenderer {
this.appendTooltip(buffer, context, modelFormField);
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
public void renderFieldGroupOpen(StringBuffer buffer, Map context, ModelForm.FieldGroup fieldGroup) {
@@ -79,6 +79,8 @@ public class HtmlFormWrapper {
//make sure the locale is in the context
context.put("locale", UtilHttp.getLocale(request));
//make sure the timeZone is in the context
context.put("timeZone", UtilHttp.getTimeZone(request));
// if there was an error message, this is an error
if (UtilValidate.isNotEmpty((String) request.getAttribute("_ERROR_MESSAGE_"))) {
@@ -42,7 +42,7 @@ import org.ofbiz.widget.menu.ModelMenuItem.Link;
/**
* Widget Library - HTML Menu Renderer implementation
*/
public class HtmlMenuRenderer implements MenuStringRenderer {
public class HtmlMenuRenderer extends HtmlWidgetRenderer implements MenuStringRenderer {
HttpServletRequest request;
HttpServletResponse response;
@@ -59,12 +59,6 @@ public class HtmlMenuRenderer implements MenuStringRenderer {
this.response = response;
}
public void appendWhitespace(StringBuffer buffer) {
// appending line ends for now, but this could be replaced with a simple space or something
buffer.append("\r\n");
//buffer.append(' ');
}
public void appendOfbizUrl(StringBuffer buffer, String location) {
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
if (ctx == null) {
@@ -189,7 +183,7 @@ public class HtmlMenuRenderer implements MenuStringRenderer {
buffer.append("</li>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
public boolean isDisableIfEmpty(ModelMenuItem menuItem, Map context) {
@@ -224,8 +218,7 @@ public class HtmlMenuRenderer implements MenuStringRenderer {
}
//Debug.logInfo("in HtmlMenuRenderer, userLoginIdHasChanged:" + userLoginIdHasChanged,"");
buffer.append("<!-- begin menu widget -->");
this.appendWhitespace(buffer);
renderBeginningBoundaryComment(buffer, "Menu Widget", modelMenu);
buffer.append("<div");
String menuId = modelMenu.getId();
if (UtilValidate.isNotEmpty(menuId)) {
@@ -245,13 +238,13 @@ public class HtmlMenuRenderer implements MenuStringRenderer {
buffer.append(">");
String menuTitle = modelMenu.getTitle(context);
if (UtilValidate.isNotEmpty(menuTitle)) {
this.appendWhitespace(buffer);
appendWhitespace(buffer);
buffer.append(" <h2>" + menuTitle + "</h2>");
}
this.appendWhitespace(buffer);
appendWhitespace(buffer);
buffer.append(" <ul>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
}
/* (non-Javadoc)
@@ -264,13 +257,12 @@ public class HtmlMenuRenderer implements MenuStringRenderer {
}
//String menuContainerStyle = modelMenu.getMenuContainerStyle(context);
buffer.append(" </ul>");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
buffer.append(" <br class=\"clear\" />");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
buffer.append("</div>");
this.appendWhitespace(buffer);
buffer.append("<!-- end menu widget -->");
this.appendWhitespace(buffer);
appendWhitespace(buffer);
renderEndingBoundaryComment(buffer, "Menu Widget", modelMenu);
userLoginIdHasChanged = userLoginIdHasChanged();
GenericValue userLogin = (GenericValue)request.getSession().getAttribute("userLogin");
@@ -285,11 +277,11 @@ public class HtmlMenuRenderer implements MenuStringRenderer {
}
public void renderFormatSimpleWrapperOpen(StringBuffer buffer, Map context, ModelMenu modelMenu) {
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
public void renderFormatSimpleWrapperClose(StringBuffer buffer, Map context, ModelMenu modelMenu) {
//this.appendWhitespace(buffer);
//appendWhitespace(buffer);
}
public void setRequest(HttpServletRequest request) {
@@ -37,6 +37,7 @@ import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.webapp.control.RequestHandler;
import org.ofbiz.webapp.taglib.ContentUrlTag;
import org.ofbiz.widget.html.HtmlWidgetRenderer;
import org.ofbiz.widget.WidgetContentWorker;
import org.ofbiz.widget.WidgetDataResourceWorker;
import org.ofbiz.widget.screen.ModelScreenWidget;
@@ -47,17 +48,17 @@ import javolution.util.FastMap;
/**
* Widget Library - HTML Form Renderer implementation
*/
public class HtmlScreenRenderer implements ScreenStringRenderer {
public class HtmlScreenRenderer extends HtmlWidgetRenderer implements ScreenStringRenderer {
public static final String module = HtmlScreenRenderer.class.getName();
public HtmlScreenRenderer() {}
public void renderSectionBegin(Writer writer, Map context, ModelScreenWidget.Section section) throws IOException {
// do nothing, this is just a place holder container for HTML
renderBeginningBoundaryComment(writer, section.isMainSection?"Screen":"Section Widget", section);
}
public void renderSectionEnd(Writer writer, Map context, ModelScreenWidget.Section section) throws IOException {
// do nothing, this is just a place holder container for HTML
renderEndingBoundaryComment(writer, section.isMainSection?"Screen":"Section Widget", section);
}
public void renderContainerBegin(Writer writer, Map context, ModelScreenWidget.Container container) throws IOException {
@@ -515,10 +516,4 @@ public class HtmlScreenRenderer implements ScreenStringRenderer {
appendWhitespace(writer);
}
}
public void appendWhitespace(Writer writer) throws IOException {
// appending line ends for now, but this could be replaced with a simple space or something
writer.write("\r\n");
//writer.write(' ');
}
}
@@ -40,7 +40,7 @@ import org.ofbiz.widget.tree.TreeStringRenderer;
/**
* Widget Library - HTML Tree Renderer implementation
*/
public class HtmlTreeRenderer implements TreeStringRenderer {
public class HtmlTreeRenderer extends HtmlWidgetRenderer implements TreeStringRenderer {
ScreenStringRenderer screenStringRenderer = null;
public static final String module = HtmlTreeRenderer.class.getName();
@@ -68,6 +68,7 @@ public class HtmlTreeRenderer implements TreeStringRenderer {
context.put("depth", Integer.toString(depth));
if (node.isRootNode()) {
appendWhitespace(writer);
renderBeginningBoundaryComment(writer, "Tree Widget", node.getModelTree());
writer.write("<ul class=\"basic-tree\">");
}
appendWhitespace(writer);
@@ -170,6 +171,7 @@ public class HtmlTreeRenderer implements TreeStringRenderer {
appendWhitespace(writer);
writer.write("</ul>");
appendWhitespace(writer);
renderEndingBoundaryComment(writer, "Tree Widget", node.getModelTree());
}
}
@@ -356,12 +358,6 @@ public class HtmlTreeRenderer implements TreeStringRenderer {
}
public void appendWhitespace(Writer writer) throws IOException {
// appending line ends for now, but this could be replaced with a simple space or something
writer.write("\r\n");
//writer.write(' ');
}
public ScreenStringRenderer getScreenStringRenderer(Map context) {
ScreenRenderer screenRenderer = (ScreenRenderer)context.get("screens");
@@ -0,0 +1,111 @@
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
package org.ofbiz.widget.html;
import java.io.IOException;
import java.io.Writer;
import org.ofbiz.widget.ModelWidget;
/**
* Widget Library - HTML Widget Renderer implementation. HtmlWidgetRenderer
* is a base class that is extended by other widget HTML rendering classes.
*/
public class HtmlWidgetRenderer {
/**
* Characters that are appended to the end of each rendered element. Currently set to
* CR/LF.
*/
public static final String whiteSpace = "\r\n";
/**
* Helper method used to append whitespace characters to the end of each rendered element.
* @param writer The writer to write to
*/
public static void appendWhitespace(Writer writer) throws IOException {
writer.write(whiteSpace);
}
/**
* Helper method used to append whitespace characters to the end of each rendered element.
* @param buffer The buffer to write to
*/
public static void appendWhitespace(StringBuffer buffer) {
buffer.append(whiteSpace);
}
/**
* Helper method used to build the boundary comment string.
* @param boundaryType The boundary type: "Begin" or "End"
* @param widgetType The widget type: "Screen Widget", "Form Widget", etc.
* @param widgetName The widget name
*/
public static String buildBoundaryComment(String boundaryType, String widgetType, String widgetName) {
return "<!-- " + boundaryType + " " + widgetType + " " + widgetName + " -->" + whiteSpace;
}
/**
* Renders the beginning boundary comment string.
* @param buffer The buffer to write to
* @param widgetType The widget type: "Screen Widget", "Form Widget", etc.
* @param modelWidget The widget
*/
public void renderBeginningBoundaryComment(StringBuffer buffer, String widgetType, ModelWidget modelWidget) {
if (modelWidget.boundaryCommentsEnabled()) {
buffer.append(buildBoundaryComment("Begin", widgetType, modelWidget.getBoundaryCommentName()));
}
}
/**
* Renders the beginning boundary comment string.
* @param writer The writer to write to
* @param widgetType The widget type: "Screen Widget", "Form Widget", etc.
* @param modelWidget The widget
*/
public void renderBeginningBoundaryComment(Writer writer, String widgetType, ModelWidget modelWidget) throws IOException {
if (modelWidget.boundaryCommentsEnabled()) {
writer.write(buildBoundaryComment("Begin", widgetType, modelWidget.getBoundaryCommentName()));
}
}
/**
* Renders the ending boundary comment string.
* @param writer The writer to write to
* @param widgetType The widget type: "Screen Widget", "Form Widget", etc.
* @param modelWidget The widget
*/
public void renderEndingBoundaryComment(Writer writer, String widgetType, ModelWidget modelWidget) throws IOException {
if (modelWidget.boundaryCommentsEnabled()) {
writer.write(buildBoundaryComment("End", widgetType, modelWidget.getBoundaryCommentName()));
}
}
/**
* Renders the ending boundary comment string.
* @param buffer The buffer to write to
* @param widgetType The widget type: "Screen Widget", "Form Widget", etc.
* @param modelWidget The widget
*/
public void renderEndingBoundaryComment(StringBuffer buffer, String widgetType, ModelWidget modelWidget) {
if (modelWidget.boundaryCommentsEnabled()) {
buffer.append(buildBoundaryComment("End", widgetType, modelWidget.getBoundaryCommentName()));
}
}
}
@@ -68,7 +68,7 @@ public class MenuFactory {
URL menuFileUrl = servletContext.getResource(resourceName);
Document menuFileDoc = UtilXml.readXmlDocument(menuFileUrl, true);
modelMenuMap = readMenuDocument(menuFileDoc, delegator, dispatcher);
modelMenuMap = readMenuDocument(menuFileDoc, delegator, dispatcher, cacheKey);
menuWebappCache.put(cacheKey, modelMenuMap);
}
}
@@ -85,7 +85,7 @@ public class MenuFactory {
return modelMenu;
}
public static Map readMenuDocument(Document menuFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher) {
public static Map readMenuDocument(Document menuFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher, String menuLocation) {
Map modelMenuMap = new HashMap();
if (menuFileDoc != null) {
// read document and construct ModelMenu for each menu element
@@ -95,6 +95,7 @@ public class MenuFactory {
while (menuElementIter.hasNext()) {
Element menuElement = (Element) menuElementIter.next();
ModelMenu modelMenu = new ModelMenu(menuElement, delegator, dispatcher);
modelMenu.setMenuLocation(menuLocation);
modelMenuMap.put(modelMenu.getName(), modelMenu);
}
}
@@ -116,7 +117,7 @@ public class MenuFactory {
URL menuFileUrl = null;
menuFileUrl = FlexibleLocation.resolveLocation(resourceName); //, loader);
Document menuFileDoc = UtilXml.readXmlDocument(menuFileUrl, true);
modelMenuMap = readMenuDocument(menuFileDoc, delegator, dispatcher);
modelMenuMap = readMenuDocument(menuFileDoc, delegator, dispatcher, resourceName);
menuLocationCache.put(resourceName, modelMenuMap);
}
}
@@ -32,6 +32,7 @@ import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.base.util.collections.FlexibleMapAccessor;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.widget.ModelWidget;
import org.w3c.dom.Element;
import bsh.EvalError;
@@ -40,14 +41,14 @@ import bsh.Interpreter;
/**
* Widget Library - Menu model class
*/
public class ModelMenu {
public class ModelMenu extends ModelWidget {
public static final String module = ModelMenu.class.getName();
protected GenericDelegator delegator;
protected LocalDispatcher dispatcher;
protected String name;
protected String menuLocation;
protected String type;
protected String target;
protected String id;
@@ -102,6 +103,7 @@ public class ModelMenu {
/** XML Constructor */
public ModelMenu(Element menuElement, GenericDelegator delegator, LocalDispatcher dispatcher) {
super(menuElement);
this.delegator = delegator;
this.dispatcher = dispatcher;
@@ -167,7 +169,6 @@ public class ModelMenu {
}
}
this.name = menuElement.getAttribute("name");
if (this.type == null || menuElement.hasAttribute("type"))
this.type = menuElement.getAttribute("type");
if (this.target == null || menuElement.hasAttribute("target"))
@@ -301,7 +302,8 @@ public class ModelMenu {
* use the same menu definitions for many types of menu UIs
*/
public void renderMenuString(StringBuffer buffer, Map context, MenuStringRenderer menuStringRenderer) {
setWidgetBoundaryComments(context);
boolean passed = true;
//Debug.logInfo("in ModelMenu, name:" + this.getName(), module);
@@ -439,14 +441,6 @@ public class ModelMenu {
return this.defaultMenuItemName;
}
/**
* @return
*/
public String getName() {
return this.name;
}
public String getCurrentMenuName(Map context) {
return this.name;
}
@@ -479,6 +473,10 @@ public class ModelMenu {
return this.type;
}
public String getBoundaryCommentName() {
return menuLocation + "#" + name;
}
public Interpreter getBshInterpreter(Map context) throws EvalError {
Interpreter bsh = (Interpreter) context.get("bshInterpreter");
if (bsh == null) {
@@ -538,6 +536,12 @@ public class ModelMenu {
this.currentMenuItemName = string;
}
/**
* @param string
*/
public void setMenuLocation(String menuLocation) {
this.menuLocation = menuLocation;
}
/**
* @param string
@@ -33,6 +33,8 @@ import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.collections.MapStack;
import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.base.util.template.FreeMarkerWorker;
import org.ofbiz.widget.ModelWidget;
import org.ofbiz.widget.html.HtmlWidgetRenderer;
import org.w3c.dom.Element;
import freemarker.template.TemplateException;
@@ -79,7 +81,15 @@ public class HtmlWidget extends ModelScreenWidget {
if (location.endsWith(".ftl")) {
try {
Map parameters = (Map) context.get("parameters");
boolean insertWidgetBoundaryComments = ModelWidget.widgetBoundaryCommentsEnabled(parameters);
if (insertWidgetBoundaryComments) {
writer.write(HtmlWidgetRenderer.buildBoundaryComment("Begin", "Template", location));
}
FreeMarkerWorker.renderTemplateAtLocation(location, context, writer);
if (insertWidgetBoundaryComments) {
writer.write(HtmlWidgetRenderer.buildBoundaryComment("End", "Template", location));
}
} catch (MalformedURLException e) {
String errMsg = "Error rendering included template at location [" + location + "]: " + e.toString();
Debug.logError(e, errMsg, module);
@@ -188,7 +198,3 @@ public class HtmlWidget extends ModelScreenWidget {
}
}
@@ -23,7 +23,6 @@ import java.io.Writer;
import java.util.Map;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.string.FlexibleStringExpander;
@@ -32,16 +31,16 @@ import org.ofbiz.entity.GenericEntity;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.entity.transaction.TransactionUtil;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.widget.ModelWidget;
import org.w3c.dom.Element;
/**
* Widget Library - Screen model class
*/
public class ModelScreen implements Serializable {
public class ModelScreen extends ModelWidget implements Serializable {
public static final String module = ModelScreen.class.getName();
protected String name;
protected String sourceLocation;
protected FlexibleStringExpander transactionTimeoutExdr;
protected Map modelScreenMap;
@@ -55,8 +54,8 @@ public class ModelScreen implements Serializable {
/** XML Constructor */
public ModelScreen(Element screenElement, Map modelScreenMap, String sourceLocation) {
super(screenElement);
this.sourceLocation = sourceLocation;
this.name = screenElement.getAttribute("name");
this.transactionTimeoutExdr = new FlexibleStringExpander(screenElement.getAttribute("transaction-timeout"));
this.modelScreenMap = modelScreenMap;
this.useCache = "true".equals(screenElement.getAttribute("use-cache"));
@@ -67,6 +66,11 @@ public class ModelScreen implements Serializable {
throw new IllegalArgumentException("No section found for the screen definition with name: " + this.name);
}
this.section = new ModelScreenWidget.Section(this, sectionElement);
this.section.isMainSection = true;
}
public String getSourceLocation() {
return sourceLocation;
}
/**
@@ -93,9 +97,11 @@ public class ModelScreen implements Serializable {
// make sure the "null" object is in there for entity ops
context.put("null", GenericEntity.NULL_FIELD);
setWidgetBoundaryComments(context);
// wrap the whole screen rendering in a transaction, should improve performance in querying and such
boolean beganTransaction = false;
Map parameters = (Map) context.get("parameters");
boolean beganTransaction = false;
int transactionTimeout = -1;
if (parameters != null) {
String transactionTimeoutPar = (String) parameters.get("TRANSACTION_TIMEOUT");
@@ -180,9 +186,5 @@ public class ModelScreen implements Serializable {
GenericDelegator delegator = (GenericDelegator) context.get("delegator");
return delegator;
}
public String getName() {
return name;
}
}
@@ -40,6 +40,7 @@ import org.ofbiz.base.util.UtilXml;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.collections.MapStack;
import org.ofbiz.base.util.string.FlexibleStringExpander;
import org.ofbiz.widget.ModelWidget;
import org.ofbiz.widget.form.FormFactory;
import org.ofbiz.widget.form.FormStringRenderer;
import org.ofbiz.widget.form.ModelForm;
@@ -61,12 +62,13 @@ import org.xml.sax.SAXException;
/**
* Widget Library - Screen model class
*/
public abstract class ModelScreenWidget implements Serializable {
public abstract class ModelScreenWidget extends ModelWidget implements Serializable {
public static final String module = ModelScreenWidget.class.getName();
protected ModelScreen modelScreen;
public ModelScreenWidget(ModelScreen modelScreen, Element widgetElement) {
super(widgetElement);
this.modelScreen = modelScreen;
if (Debug.verboseOn()) Debug.logVerbose("Reading Screen sub-widget with name: " + widgetElement.getNodeName(), module);
}
@@ -126,42 +128,17 @@ public abstract class ModelScreenWidget implements Serializable {
Iterator subWidgetIter = subWidgets.iterator();
while (subWidgetIter.hasNext()) {
ModelScreenWidget subWidget = (ModelScreenWidget) subWidgetIter.next();
if (Debug.verboseOn()) Debug.logVerbose("Rendering screen " + subWidget.modelScreen.name + "; widget class is " + subWidget.getClass().getName(), module);
if (Debug.verboseOn()) Debug.logVerbose("Rendering screen " + subWidget.modelScreen.getName() + "; widget class is " + subWidget.getClass().getName(), module);
Map parameters = (Map) context.get("parameters");
boolean insertWidgetBoundaryComments = "true".equals(parameters==null?null:parameters.get("widgetVerbose"));
StringBuffer widgetDescription = null;
if (insertWidgetBoundaryComments) {
widgetDescription = new StringBuffer();
widgetDescription.append("Widget [screen:");
widgetDescription.append(subWidget.modelScreen.name);
widgetDescription.append("] ");
widgetDescription.append(subWidget.rawString());
try {
writer.write("<!-- === BEGIN ");
writer.write(widgetDescription.toString());
writer.write(" -->\n");
} catch (IOException e) {
throw new GeneralException("Error adding verbose sub-widget HTML/XML comments:", e);
}
}
// render the sub-widget itself
subWidget.renderWidgetString(writer, context, screenStringRenderer);
if (insertWidgetBoundaryComments) {
try {
writer.write("\n<!-- === END ");
writer.write(widgetDescription.toString());
writer.write(" -->\n");
} catch (IOException e) {
throw new GeneralException("Error adding verbose sub-widget HTML/XML comments:", e);
}
}
}
}
public boolean boundaryCommentsEnabled() {
return modelScreen.boundaryCommentsEnabled();
}
public static class SectionsRenderer {
protected Map sectionMap;
protected ScreenStringRenderer screenStringRenderer;
@@ -187,15 +164,14 @@ public abstract class ModelScreenWidget implements Serializable {
}
public static class Section extends ModelScreenWidget {
protected String name;
protected ModelScreenCondition condition;
protected List actions;
protected List subWidgets;
protected List failWidgets;
public boolean isMainSection = false;
public Section(ModelScreen modelScreen, Element sectionElement) {
super(modelScreen, sectionElement);
this.name = sectionElement.getAttribute("name");
// read condition under the "condition" element
Element conditionElement = UtilXml.firstChildElement(sectionElement, "condition");
@@ -221,7 +197,7 @@ public abstract class ModelScreenWidget implements Serializable {
this.failWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, failElementList);
}
}
public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
// check the condition, if there is one
boolean condTrue = true;
@@ -267,10 +243,14 @@ public abstract class ModelScreenWidget implements Serializable {
}
public String getName() {
return name;
public String getBoundaryCommentName() {
if (isMainSection) {
return modelScreen.getSourceLocation() + "#" + modelScreen.getName();
} else {
return name;
}
}
public String rawString() {
return "<section" + (UtilValidate.isNotEmpty(this.name)?" name=\"" + this.name + "\"":"") + ">";
}
@@ -505,12 +485,10 @@ public abstract class ModelScreenWidget implements Serializable {
}
public static class DecoratorSection extends ModelScreenWidget {
protected String name;
protected List subWidgets;
public DecoratorSection(ModelScreen modelScreen, Element decoratorSectionElement) {
super(modelScreen, decoratorSectionElement);
this.name = decoratorSectionElement.getAttribute("name");
// read sub-widgets
List subElementList = UtilXml.childElementList(decoratorSectionElement);
this.subWidgets = ModelScreenWidget.readSubWidgets(this.modelScreen, subElementList);
@@ -527,11 +505,9 @@ public abstract class ModelScreenWidget implements Serializable {
}
public static class DecoratorSectionInclude extends ModelScreenWidget {
protected String name;
public DecoratorSectionInclude(ModelScreen modelScreen, Element decoratorSectionElement) {
super(modelScreen, decoratorSectionElement);
this.name = decoratorSectionElement.getAttribute("name");
}
public void renderWidgetString(Writer writer, Map context, ScreenStringRenderer screenStringRenderer) throws GeneralException {
@@ -51,6 +51,7 @@ import org.ofbiz.entity.model.ModelEntity;
import org.ofbiz.entity.model.ModelField;
import org.ofbiz.entity.util.EntityListIterator;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.widget.ModelWidget;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
@@ -59,11 +60,11 @@ import org.xml.sax.SAXException;
/**
* Widget Library - Tree model class
*/
public class ModelTree {
public class ModelTree extends ModelWidget {
public static final String module = ModelTree.class.getName();
protected String name;
protected String treeLocation;
protected String rootNodeName;
protected String defaultRenderStyle;
protected FlexibleStringExpander defaultWrapStyleExdr;
@@ -89,8 +90,7 @@ public class ModelTree {
public ModelTree() {}
public ModelTree(Element treeElement, GenericDelegator delegator, LocalDispatcher dispatcher) {
this.name = treeElement.getAttribute("name");
super(treeElement);
this.rootNodeName = treeElement.getAttribute("root-node-name");
this.defaultRenderStyle = UtilFormatOut.checkEmpty(treeElement.getAttribute("default-render-style"), "simple");
// A temporary hack to accommodate those who might still be using "render-style" instead of "default-render-style"
@@ -134,10 +134,6 @@ public class ModelTree {
}
public String getName() {
return name;
}
public void setDefaultEntityName(String name) {
String nm = name;
if (UtilValidate.isEmpty(nm)) {
@@ -213,7 +209,14 @@ public class ModelTree {
return currentNodeTrail;
}
public String getBoundaryCommentName() {
return treeLocation + "#" + name;
}
public void setTreeLocation(String treeLocation) {
this.treeLocation = treeLocation;
}
/**
* Renders this tree to a String, i.e. in a text format, as defined with the
* TreeStringRenderer implementation.
@@ -230,6 +233,9 @@ public class ModelTree {
* use the same tree definitions for many types of tree UIs
*/
public void renderTreeString(StringBuffer buf, Map context, TreeStringRenderer treeStringRenderer) throws GeneralException {
Map parameters = (Map) context.get("parameters");
setWidgetBoundaryComments(context);
ModelNode node = (ModelNode)nodeMap.get(rootNodeName);
/*
List parentNodeTrail = (List)context.get("currentNodeTrail");
@@ -244,7 +250,6 @@ public class ModelTree {
String trailName = trailNameExdr.expandString(context);
String treeString = (String)context.get(trailName);
if (UtilValidate.isEmpty(treeString)) {
Map parameters = (Map)context.get("parameters");
treeString = (String)parameters.get(trailName);
}
if (UtilValidate.isNotEmpty(treeString)) {
@@ -65,7 +65,7 @@ public class TreeFactory {
URL treeFileUrl = null;
treeFileUrl = FlexibleLocation.resolveLocation(resourceName); //, loader);
Document treeFileDoc = UtilXml.readXmlDocument(treeFileUrl, true);
modelTreeMap = readTreeDocument(treeFileDoc, delegator, dispatcher);
modelTreeMap = readTreeDocument(treeFileDoc, delegator, dispatcher, resourceName);
treeLocationCache.put(resourceName, modelTreeMap);
}
}
@@ -95,7 +95,7 @@ public class TreeFactory {
URL treeFileUrl = servletContext.getResource(resourceName);
Document treeFileDoc = UtilXml.readXmlDocument(treeFileUrl, true);
modelTreeMap = readTreeDocument(treeFileDoc, delegator, dispatcher);
modelTreeMap = readTreeDocument(treeFileDoc, delegator, dispatcher, cacheKey);
treeWebappCache.put(cacheKey, modelTreeMap);
}
}
@@ -108,7 +108,7 @@ public class TreeFactory {
return modelTree;
}
public static Map readTreeDocument(Document treeFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher) {
public static Map readTreeDocument(Document treeFileDoc, GenericDelegator delegator, LocalDispatcher dispatcher, String treeLocation) {
Map modelTreeMap = new HashMap();
if (treeFileDoc != null) {
// read document and construct ModelTree for each tree element
@@ -118,6 +118,7 @@ public class TreeFactory {
while (treeElementIter.hasNext()) {
Element treeElement = (Element) treeElementIter.next();
ModelTree modelTree = new ModelTree(treeElement, delegator, dispatcher);
modelTree.setTreeLocation(treeLocation);
modelTreeMap.put(modelTree.getName(), modelTree);
}
}