Improved: General refactoring and code improvements, package
org.apache.ofbiz.widget.renderer.macro. (OFBIZ-9960) Thanks Dennis Balkir for reporting and providing the patches. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1818443 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
+64
-45
@@ -108,7 +108,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
|
||||
public static final String module = MacroFormRenderer.class.getName();
|
||||
private final Template macroLibrary;
|
||||
private final WeakHashMap<Appendable, Environment> environments = new WeakHashMap<Appendable, Environment>();
|
||||
private final WeakHashMap<Appendable, Environment> environments = new WeakHashMap<>();
|
||||
private final UtilCodec.SimpleEncoder internalEncoder;
|
||||
private final RequestHandler rh;
|
||||
private final HttpServletRequest request;
|
||||
@@ -142,7 +142,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
this.renderPagination = renderPagination;
|
||||
}
|
||||
|
||||
private void executeMacro(Appendable writer, String macro) throws IOException {
|
||||
private void executeMacro(Appendable writer, String macro) {
|
||||
try {
|
||||
Environment environment = getEnvironment(writer);
|
||||
environment.setVariable("visualTheme", FreeMarkerWorker.autoWrap(visualTheme, environment));
|
||||
@@ -183,7 +183,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
return htmlString.replaceAll("\"", "\\\\\"");
|
||||
}
|
||||
|
||||
public void renderLabel(Appendable writer, Map<String, Object> context, ModelScreenWidget.Label label) throws IOException {
|
||||
public void renderLabel(Appendable writer, Map<String, Object> context, ModelScreenWidget.Label label) {
|
||||
String labelText = label.getText(context);
|
||||
if (UtilValidate.isEmpty(labelText)) {
|
||||
// nothing to render
|
||||
@@ -329,7 +329,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
this.request.setAttribute("width", hyperlinkField.getWidth());
|
||||
this.request.setAttribute("height", hyperlinkField.getHeight());
|
||||
makeHyperlinkByType(writer, hyperlinkField.getLinkType(), modelFormField.getWidgetStyle(), hyperlinkField.getUrlMode(), hyperlinkField.getTarget(context),
|
||||
hyperlinkField.getParameterMap(context, modelFormField.getEntityName(), modelFormField.getServiceName()),
|
||||
hyperlinkField.getParameterMap(context, modelFormField.getEntityName(), modelFormField.getServiceName()),
|
||||
hyperlinkField.getDescription(context), hyperlinkField.getTargetWindow(context),
|
||||
hyperlinkField.getConfirmation(context), modelFormField, this.request, this.response, context);
|
||||
this.appendTooltip(writer, context, modelFormField);
|
||||
@@ -367,12 +367,14 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
//check for required field style on single forms
|
||||
if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
|
||||
String requiredStyle = modelFormField.getRequiredFieldStyle();
|
||||
if (UtilValidate.isEmpty(requiredStyle))
|
||||
if (UtilValidate.isEmpty(requiredStyle)) {
|
||||
requiredStyle = "required";
|
||||
if (UtilValidate.isEmpty(className))
|
||||
}
|
||||
if (UtilValidate.isEmpty(className)) {
|
||||
className = requiredStyle;
|
||||
else
|
||||
} else {
|
||||
className = requiredStyle + " " + className;
|
||||
}
|
||||
}
|
||||
List<ModelForm.UpdateArea> updateAreas = modelFormField.getOnChangeUpdateAreas();
|
||||
boolean ajaxEnabled = updateAreas != null && this.javaScriptEnabled;
|
||||
@@ -455,12 +457,14 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
//check for required field style on single forms
|
||||
if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
|
||||
String requiredStyle = modelFormField.getRequiredFieldStyle();
|
||||
if (UtilValidate.isEmpty(requiredStyle))
|
||||
if (UtilValidate.isEmpty(requiredStyle)) {
|
||||
requiredStyle = "required";
|
||||
if (UtilValidate.isEmpty(className))
|
||||
}
|
||||
if (UtilValidate.isEmpty(className)) {
|
||||
className = requiredStyle;
|
||||
else
|
||||
} else {
|
||||
className = requiredStyle + " " + className;
|
||||
}
|
||||
}
|
||||
String visualEditorEnable = "";
|
||||
String buttons = "";
|
||||
@@ -591,10 +595,11 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
*/
|
||||
ModelFormFieldBuilder builder = new ModelFormFieldBuilder(modelFormField);
|
||||
boolean memEncodeOutput = modelFormField.getEncodeOutput();
|
||||
if (useTimeDropDown)
|
||||
if (useTimeDropDown) {
|
||||
// If time-dropdown deactivate encodingOutput for found hour and minutes
|
||||
// FIXME: Encoding should be controlled by the renderer, not by the model.
|
||||
builder.setEncodeOutput(false);
|
||||
}
|
||||
// FIXME: modelFormField.getEntry ignores shortDateInput when converting Date objects to Strings.
|
||||
if (useTimeDropDown) {
|
||||
builder.setEncodeOutput(memEncodeOutput);
|
||||
@@ -673,12 +678,14 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
//check for required field style on single forms
|
||||
if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
|
||||
String requiredStyle = modelFormField.getRequiredFieldStyle();
|
||||
if (UtilValidate.isEmpty(requiredStyle))
|
||||
if (UtilValidate.isEmpty(requiredStyle)) {
|
||||
requiredStyle = "required";
|
||||
if (UtilValidate.isEmpty(className))
|
||||
}
|
||||
if (UtilValidate.isEmpty(className)) {
|
||||
className = requiredStyle;
|
||||
else
|
||||
} else {
|
||||
className = requiredStyle + " " + className;
|
||||
}
|
||||
}
|
||||
String mask = dateTimeField.getMask();
|
||||
if ("Y".equals(mask)) {
|
||||
@@ -806,12 +813,14 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
//check for required field style on single forms
|
||||
if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
|
||||
String requiredStyle = modelFormField.getRequiredFieldStyle();
|
||||
if (UtilValidate.isEmpty(requiredStyle))
|
||||
if (UtilValidate.isEmpty(requiredStyle)) {
|
||||
requiredStyle = "required";
|
||||
if (UtilValidate.isEmpty(className))
|
||||
}
|
||||
if (UtilValidate.isEmpty(className)) {
|
||||
className = requiredStyle;
|
||||
else
|
||||
} else {
|
||||
className = requiredStyle + " " + className;
|
||||
}
|
||||
}
|
||||
String currentDescription = null;
|
||||
if (UtilValidate.isNotEmpty(currentValue)) {
|
||||
@@ -1147,7 +1156,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
String backgroundSubmitRefreshTarget = submitField.getBackgroundSubmitRefreshTarget(context);
|
||||
if (UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) {
|
||||
if (updateAreas == null) {
|
||||
updateAreas = new LinkedList<ModelForm.UpdateArea>();
|
||||
updateAreas = new LinkedList<>();
|
||||
}
|
||||
updateAreas.add(new ModelForm.UpdateArea("submit", formId, backgroundSubmitRefreshTarget));
|
||||
}
|
||||
@@ -1361,7 +1370,6 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
String targ = modelForm.getTarget(context, targetType);
|
||||
StringBuilder linkUrl = new StringBuilder();
|
||||
if (UtilValidate.isNotEmpty(targ)) {
|
||||
//this.appendOfbizUrl(writer, "/" + targ);
|
||||
WidgetWorker.buildHyperlinkUrl(linkUrl, targ, targetType, null, null, false, false, true, request, response, context);
|
||||
}
|
||||
String formType = modelForm.getType();
|
||||
@@ -1493,8 +1501,8 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
this.renderNextPrev(writer, context, modelForm);
|
||||
}
|
||||
List<ModelFormField> childFieldList = modelForm.getFieldList();
|
||||
List<String> columnStyleList = new LinkedList<String>();
|
||||
List<String> fieldNameList = new LinkedList<String>();
|
||||
List<String> columnStyleList = new LinkedList<>();
|
||||
List<String> fieldNameList = new LinkedList<>();
|
||||
for (ModelFormField childField : childFieldList) {
|
||||
int childFieldType = childField.getFieldInfo().getFieldType();
|
||||
if (childFieldType == FieldInfo.HIDDEN || childFieldType == FieldInfo.IGNORED) {
|
||||
@@ -1874,7 +1882,6 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
String opGreaterThanEquals = UtilProperties.getMessage("conditionalUiLabels", "greater_than_equals", locale);
|
||||
String opLessThan = UtilProperties.getMessage("conditionalUiLabels", "less_than", locale);
|
||||
String opLessThanEquals = UtilProperties.getMessage("conditionalUiLabels", "less_than_equals", locale);
|
||||
//String opIsEmpty = UtilProperties.getMessage("conditionalUiLabels", "is_empty", locale);
|
||||
String className = "";
|
||||
String alert = "false";
|
||||
if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) {
|
||||
@@ -2106,12 +2113,14 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
//check for required field style on single forms
|
||||
if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
|
||||
String requiredStyle = modelFormField.getRequiredFieldStyle();
|
||||
if (UtilValidate.isEmpty(requiredStyle))
|
||||
if (UtilValidate.isEmpty(requiredStyle)) {
|
||||
requiredStyle = "required";
|
||||
if (UtilValidate.isEmpty(className))
|
||||
}
|
||||
if (UtilValidate.isEmpty(className)) {
|
||||
className = requiredStyle;
|
||||
else
|
||||
} else {
|
||||
className = requiredStyle + " " + className;
|
||||
}
|
||||
}
|
||||
String name = modelFormField.getParameterName(context);
|
||||
String value = modelFormField.getEntry(context, lookupField.getDefaultValue(context));
|
||||
@@ -2131,7 +2140,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
autoCompleterTarget = lookupFieldFormName + "&amp;";
|
||||
}
|
||||
autoCompleterTarget = autoCompleterTarget + "ajaxLookup=Y";
|
||||
updateAreas = new LinkedList<ModelForm.UpdateArea>();
|
||||
updateAreas = new LinkedList<>();
|
||||
updateAreas.add(new ModelForm.UpdateArea("change", id, autoCompleterTarget));
|
||||
}
|
||||
boolean ajaxEnabled = UtilValidate.isNotEmpty(updateAreas) && this.javaScriptEnabled;
|
||||
@@ -2280,7 +2289,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
this.appendTooltip(writer, context, modelFormField);
|
||||
}
|
||||
|
||||
public void renderNextPrev(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException {
|
||||
public void renderNextPrev(Appendable writer, Map<String, Object> context, ModelForm modelForm) {
|
||||
boolean ajaxEnabled = false;
|
||||
List<ModelForm.UpdateArea> updateAreas = modelForm.getOnPaginateUpdateAreas();
|
||||
String targetService = modelForm.getPaginateTarget(context);
|
||||
@@ -2318,22 +2327,25 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
commonDisplaying = UtilProperties.getMessage("CommonUiLabels", "CommonDisplaying", messageMap, (Locale) context.get("locale"));
|
||||
}
|
||||
// for legacy support, the viewSizeParam is VIEW_SIZE and viewIndexParam is VIEW_INDEX when the fields are "viewSize" and "viewIndex"
|
||||
if (("viewIndex" + "_" + paginatorNumber).equals(viewIndexParam))
|
||||
if (("viewIndex" + "_" + paginatorNumber).equals(viewIndexParam)) {
|
||||
viewIndexParam = "VIEW_INDEX" + "_" + paginatorNumber;
|
||||
if (("viewSize" + "_" + paginatorNumber).equals(viewSizeParam))
|
||||
}
|
||||
if (("viewSize" + "_" + paginatorNumber).equals(viewSizeParam)) {
|
||||
viewSizeParam = "VIEW_SIZE" + "_" + paginatorNumber;
|
||||
}
|
||||
String str = (String) context.get("_QBESTRING_");
|
||||
// strip legacy viewIndex/viewSize params from the query string
|
||||
String queryString = UtilHttp.stripViewParamsFromQueryString(str, "" + paginatorNumber);
|
||||
// strip parameterized index/size params from the query string
|
||||
Set<String> paramNames = new HashSet<String>();
|
||||
Set<String> paramNames = new HashSet<>();
|
||||
paramNames.add(viewIndexParam);
|
||||
paramNames.add(viewSizeParam);
|
||||
queryString = UtilHttp.stripNamedParamsFromQueryString(queryString, paramNames);
|
||||
String anchor = "";
|
||||
String paginateAnchor = modelForm.getPaginateTargetAnchor();
|
||||
if (UtilValidate.isNotEmpty(paginateAnchor))
|
||||
if (UtilValidate.isNotEmpty(paginateAnchor)) {
|
||||
anchor = "#" + paginateAnchor;
|
||||
}
|
||||
// Create separate url path String and request parameters String,
|
||||
// add viewIndex/viewSize parameters to request parameter String
|
||||
String urlPath = UtilHttp.removeQueryStringFromTarget(targetService);
|
||||
@@ -2590,12 +2602,14 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
//check for required field style on single forms
|
||||
if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) {
|
||||
String requiredStyle = modelFormField.getRequiredFieldStyle();
|
||||
if (UtilValidate.isEmpty(requiredStyle))
|
||||
if (UtilValidate.isEmpty(requiredStyle)) {
|
||||
requiredStyle = "required";
|
||||
if (UtilValidate.isEmpty(className))
|
||||
}
|
||||
if (UtilValidate.isEmpty(className)) {
|
||||
className = requiredStyle;
|
||||
else
|
||||
} else {
|
||||
className = requiredStyle + " " + className;
|
||||
}
|
||||
}
|
||||
|
||||
String tabindex = modelFormField.getTabindex();
|
||||
@@ -2683,7 +2697,6 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
if (UtilValidate.isNotEmpty(style) || UtilValidate.isNotEmpty(id) || UtilValidate.isNotEmpty(title)) {
|
||||
if (fieldGroup.collapsible()) {
|
||||
Map<String, Object> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap"));
|
||||
//Map<String, Object> paramMap = UtilGenerics.checkMap(context.get("requestParameters"));
|
||||
if (uiLabelMap != null) {
|
||||
expandToolTip = (String) uiLabelMap.get("CommonExpand");
|
||||
collapseToolTip = (String) uiLabelMap.get("CommonCollapse");
|
||||
@@ -2740,11 +2753,13 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
public void renderBanner(Appendable writer, Map<String, Object> context, ModelForm.Banner banner) throws IOException {
|
||||
String style = banner.getStyle(context);
|
||||
String leftStyle = banner.getLeftTextStyle(context);
|
||||
if (UtilValidate.isEmpty(leftStyle))
|
||||
if (UtilValidate.isEmpty(leftStyle)) {
|
||||
leftStyle = style;
|
||||
}
|
||||
String rightStyle = banner.getRightTextStyle(context);
|
||||
if (UtilValidate.isEmpty(rightStyle))
|
||||
if (UtilValidate.isEmpty(rightStyle)) {
|
||||
rightStyle = style;
|
||||
}
|
||||
String leftText = banner.getLeftText(context);
|
||||
if (leftText == null) {
|
||||
leftText = "";
|
||||
@@ -2781,7 +2796,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
* @param widgetType The widget type: "Screen Widget", "Form Widget", etc.
|
||||
* @param modelWidget The widget
|
||||
*/
|
||||
public void renderBeginningBoundaryComment(Appendable writer, String widgetType, ModelWidget modelWidget) throws IOException {
|
||||
public void renderBeginningBoundaryComment(Appendable writer, String widgetType, ModelWidget modelWidget) {
|
||||
if (this.widgetCommentsEnabled) {
|
||||
StringWriter sr = new StringWriter();
|
||||
sr.append("<@formatBoundaryComment ");
|
||||
@@ -2802,7 +2817,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
* @param widgetType The widget type: "Screen Widget", "Form Widget", etc.
|
||||
* @param modelWidget The widget
|
||||
*/
|
||||
public void renderEndingBoundaryComment(Appendable writer, String widgetType, ModelWidget modelWidget) throws IOException {
|
||||
public void renderEndingBoundaryComment(Appendable writer, String widgetType, ModelWidget modelWidget) {
|
||||
if (this.widgetCommentsEnabled) {
|
||||
StringWriter sr = new StringWriter();
|
||||
sr.append("<@formatBoundaryComment ");
|
||||
@@ -2817,7 +2832,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
public void renderSortField(Appendable writer, Map<String, Object> context, ModelFormField modelFormField, String titleText) throws IOException {
|
||||
public void renderSortField(Appendable writer, Map<String, Object> context, ModelFormField modelFormField, String titleText) {
|
||||
boolean ajaxEnabled = false;
|
||||
ModelForm modelForm = modelFormField.getModelForm();
|
||||
List<ModelForm.UpdateArea> updateAreas = modelForm.getOnSortColumnUpdateAreas();
|
||||
@@ -3011,7 +3026,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
return targetParams;
|
||||
}
|
||||
|
||||
public void appendTooltip(Appendable writer, Map<String, Object> context, ModelFormField modelFormField) throws IOException {
|
||||
public void appendTooltip(Appendable writer, Map<String, Object> context, ModelFormField modelFormField) {
|
||||
// render the tooltip, in other methods too
|
||||
String tooltip = modelFormField.getTooltip(context);
|
||||
StringWriter sr = new StringWriter();
|
||||
@@ -3029,8 +3044,12 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
return;
|
||||
}
|
||||
if (subHyperlink.shouldUse(context)) {
|
||||
if (UtilValidate.isNotEmpty(subHyperlink.getWidth())) this.request.setAttribute("width", subHyperlink.getWidth());
|
||||
if (UtilValidate.isNotEmpty(subHyperlink.getHeight())) this.request.setAttribute("height", subHyperlink.getHeight());
|
||||
if (UtilValidate.isNotEmpty(subHyperlink.getWidth())) {
|
||||
this.request.setAttribute("width", subHyperlink.getWidth());
|
||||
}
|
||||
if (UtilValidate.isNotEmpty(subHyperlink.getHeight())) {
|
||||
this.request.setAttribute("height", subHyperlink.getHeight());
|
||||
}
|
||||
writer.append(' ');
|
||||
makeHyperlinkByType(writer, subHyperlink.getLinkType(), subHyperlink.getStyle(context), subHyperlink.getUrlMode(),
|
||||
subHyperlink.getTarget(context), subHyperlink.getParameterMap(context, subHyperlink.getModelFormField().getEntityName(), subHyperlink.getModelFormField().getServiceName()), subHyperlink.getDescription(context),
|
||||
@@ -3039,7 +3058,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
public void addAsterisks(Appendable writer, Map<String, Object> context, ModelFormField modelFormField) throws IOException {
|
||||
public void addAsterisks(Appendable writer, Map<String, Object> context, ModelFormField modelFormField) {
|
||||
String requiredField = "false";
|
||||
String requiredStyle = "";
|
||||
if (modelFormField.getRequiredField()) {
|
||||
@@ -3223,7 +3242,7 @@ public final class MacroFormRenderer implements FormStringRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
public void makeHiddenFormLinkAnchor(Appendable writer, String linkStyle, String description, String confirmation, ModelFormField modelFormField, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) throws IOException {
|
||||
public void makeHiddenFormLinkAnchor(Appendable writer, String linkStyle, String description, String confirmation, ModelFormField modelFormField, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context) {
|
||||
if (UtilValidate.isNotEmpty(description) || UtilValidate.isNotEmpty(request.getAttribute("image"))) {
|
||||
String hiddenFormName = WidgetWorker.makeLinkHiddenFormName(context, modelFormField);
|
||||
String event = "";
|
||||
|
||||
+9
-8
@@ -57,7 +57,7 @@ public class MacroMenuRenderer implements MenuStringRenderer {
|
||||
|
||||
public static final String module = MacroMenuRenderer.class.getName();
|
||||
private int macroCount = 999;
|
||||
private final Map<Appendable, Environment> environments = new HashMap<Appendable, Environment>();
|
||||
private final Map<Appendable, Environment> environments = new HashMap<>();
|
||||
private final Template macroLibrary;
|
||||
private final HttpServletRequest request;
|
||||
private final HttpServletResponse response;
|
||||
@@ -72,7 +72,7 @@ public class MacroMenuRenderer implements MenuStringRenderer {
|
||||
|
||||
// Made this a separate method so it can be externalized and reused.
|
||||
private Map<String, Object> createImageParameters(Map<String, Object> context, Image image) {
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("id", image.getId(context));
|
||||
parameters.put("style", image.getStyle(context));
|
||||
parameters.put("width", image.getWidth(context));
|
||||
@@ -199,7 +199,7 @@ public class MacroMenuRenderer implements MenuStringRenderer {
|
||||
|
||||
@Override
|
||||
public void renderLink(Appendable writer, Map<String, Object> context, MenuLink link) throws IOException {
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
String target = link.getTarget(context);
|
||||
ModelMenuItem menuItem = link.getLinkMenuItem();
|
||||
if (isDisableIfEmpty(menuItem, context)) {
|
||||
@@ -221,7 +221,7 @@ public class MacroMenuRenderer implements MenuStringRenderer {
|
||||
if (context.containsKey("parentItemIndex")) {
|
||||
uniqueItemName.append(context.get("parentItemIndex")).append("_").append(context.get("itemIndex"));
|
||||
} else {
|
||||
uniqueItemName.append("_").append(context.get("itemIndex"));
|
||||
uniqueItemName.append("_").append(context.get("itemIndex"));
|
||||
}
|
||||
}
|
||||
parameters.put("uniqueItemName", uniqueItemName.toString());
|
||||
@@ -284,7 +284,7 @@ public class MacroMenuRenderer implements MenuStringRenderer {
|
||||
public void renderMenuClose(Appendable writer, Map<String, Object> context, ModelMenu menu) throws IOException {
|
||||
Map<String, Object> parameters = null;
|
||||
if (ModelWidget.widgetBoundaryCommentsEnabled(context)) {
|
||||
parameters = new HashMap<String, Object>();
|
||||
parameters = new HashMap<>();
|
||||
StringBuilder sb = new StringBuilder("End Menu Widget ");
|
||||
sb.append(menu.getBoundaryCommentName());
|
||||
parameters.put("boundaryComment", sb.toString());
|
||||
@@ -298,9 +298,10 @@ public class MacroMenuRenderer implements MenuStringRenderer {
|
||||
|
||||
@Override
|
||||
public void renderMenuItem(Appendable writer, Map<String, Object> context, ModelMenuItem menuItem) throws IOException {
|
||||
if (isHideIfSelected(menuItem, context))
|
||||
if (isHideIfSelected(menuItem, context)) {
|
||||
return;
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
}
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
String style = menuItem.getWidgetStyle();
|
||||
if (menuItem.isSelected(context)) {
|
||||
String selectedStyle = menuItem.getSelectedStyle();
|
||||
@@ -361,7 +362,7 @@ public class MacroMenuRenderer implements MenuStringRenderer {
|
||||
|
||||
@Override
|
||||
public void renderMenuOpen(Appendable writer, Map<String, Object> context, ModelMenu menu) throws IOException {
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
if (ModelWidget.widgetBoundaryCommentsEnabled(context)) {
|
||||
StringBuilder sb = new StringBuilder("Begin Menu Widget ");
|
||||
sb.append(menu.getBoundaryCommentName());
|
||||
|
||||
+51
-57
@@ -45,7 +45,6 @@ import org.apache.ofbiz.base.util.UtilValidate;
|
||||
import org.apache.ofbiz.base.util.template.FreeMarkerWorker;
|
||||
import org.apache.ofbiz.entity.Delegator;
|
||||
import org.apache.ofbiz.entity.GenericValue;
|
||||
import org.apache.ofbiz.entity.util.EntityUtilProperties;
|
||||
import org.apache.ofbiz.service.LocalDispatcher;
|
||||
import org.apache.ofbiz.webapp.control.RequestHandler;
|
||||
import org.apache.ofbiz.webapp.taglib.ContentUrlTag;
|
||||
@@ -75,7 +74,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
|
||||
public static final String module = MacroScreenRenderer.class.getName();
|
||||
private Template macroLibrary;
|
||||
private WeakHashMap<Appendable, Environment> environments = new WeakHashMap<Appendable, Environment>();
|
||||
private WeakHashMap<Appendable, Environment> environments = new WeakHashMap<>();
|
||||
private String rendererName;
|
||||
private int elementId = 999;
|
||||
protected boolean widgetCommentsEnabled = false;
|
||||
@@ -104,9 +103,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
Template template = new Template((new java.util.Date()).toString(), templateReader, FreeMarkerWorker.getDefaultOfbizConfig());
|
||||
templateReader.close();
|
||||
environment.include(template);
|
||||
} catch (TemplateException e) {
|
||||
Debug.logError(e, "Error rendering screen macro [" + macro + "] thru ftl", module);
|
||||
} catch (IOException e) {
|
||||
} catch (TemplateException |IOException e) {
|
||||
Debug.logError(e, "Error rendering screen macro [" + macro + "] thru ftl", module);
|
||||
}
|
||||
}
|
||||
@@ -160,7 +157,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context);
|
||||
}
|
||||
if (this.widgetCommentsEnabled) {
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
StringBuilder sb = new StringBuilder("Begin ");
|
||||
sb.append(section.isMainSection() ? "Screen " : "Section Widget ");
|
||||
sb.append(section.getBoundaryCommentName());
|
||||
@@ -170,7 +167,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
}
|
||||
public void renderSectionEnd(Appendable writer, Map<String, Object> context, ModelScreenWidget.Section section) throws IOException {
|
||||
if (this.widgetCommentsEnabled) {
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("End ");
|
||||
sb.append(section.isMainSection() ? "Screen " : "Section Widget ");
|
||||
@@ -194,7 +191,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
|
||||
autoUpdateLink = rh.makeLink(request, response, autoUpdateTarget);
|
||||
}
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("id", containerId);
|
||||
parameters.put("style", container.getStyle(context));
|
||||
parameters.put("autoUpdateLink", autoUpdateLink);
|
||||
@@ -207,7 +204,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
}
|
||||
|
||||
public void renderLabel(Appendable writer, Map<String, Object> context, ModelScreenWidget.Label label) throws IOException {
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("text", label.getText(context));
|
||||
parameters.put("id", label.getId(context));
|
||||
parameters.put("style", label.getStyle(context));
|
||||
@@ -215,7 +212,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
}
|
||||
|
||||
public void renderHorizontalSeparator(Appendable writer, Map<String, Object> context, ModelScreenWidget.HorizontalSeparator separator) throws IOException {
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("id", separator.getId(context));
|
||||
parameters.put("style", separator.getStyle(context));
|
||||
executeMacro(writer, "renderHorizontalSeparator", parameters);
|
||||
@@ -316,8 +313,9 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
}
|
||||
|
||||
public void renderImage(Appendable writer, Map<String, Object> context, ModelScreenWidget.ScreenImage image) throws IOException {
|
||||
if (image == null)
|
||||
if (image == null) {
|
||||
return ;
|
||||
}
|
||||
String src = image.getSrc(context);
|
||||
|
||||
String urlMode = image.getUrlMode();
|
||||
@@ -345,7 +343,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
} else {
|
||||
urlString = src;
|
||||
}
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("src", src);
|
||||
parameters.put("id", image.getId(context));
|
||||
parameters.put("style", image.getStyle(context));
|
||||
@@ -362,9 +360,11 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
String enableEditName = content.getEnableEditName(context);
|
||||
String enableEditValue = (String)context.get(enableEditName);
|
||||
|
||||
if (Debug.verboseOn()) Debug.logVerbose("directEditRequest:" + editRequest, module);
|
||||
if (Debug.verboseOn()) {
|
||||
Debug.logVerbose("directEditRequest:" + editRequest, module);
|
||||
}
|
||||
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("editRequest", editRequest);
|
||||
parameters.put("enableEditValue", enableEditValue == null ? "" : enableEditValue);
|
||||
parameters.put("editContainerStyle", content.getEditContainerStyle(context));
|
||||
@@ -373,7 +373,6 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
|
||||
public void renderContentBody(Appendable writer, Map<String, Object> context, ModelScreenWidget.Content content) throws IOException {
|
||||
Locale locale = UtilMisc.ensureLocale(context.get("locale"));
|
||||
//Boolean nullThruDatesOnly = Boolean.valueOf(false);
|
||||
String mimeTypeId = "text/html";
|
||||
String expandedContentId = content.getContentId(context);
|
||||
String expandedDataResourceId = content.getDataResourceId(context);
|
||||
@@ -382,10 +381,12 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
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 = new HashMap<String, Object>();
|
||||
Map<String, Object> contentContext = new HashMap<>();
|
||||
contentContext.putAll(context);
|
||||
String dataResourceId = (String)contentContext.get("dataResourceId");
|
||||
if (Debug.verboseOn()) Debug.logVerbose("expandedContentId:" + expandedContentId, module);
|
||||
if (Debug.verboseOn()) {
|
||||
Debug.logVerbose("expandedContentId:" + expandedContentId, module);
|
||||
}
|
||||
|
||||
try {
|
||||
if (UtilValidate.isNotEmpty(dataResourceId)) {
|
||||
@@ -424,14 +425,9 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
writer.append(renderedContent);
|
||||
}
|
||||
|
||||
} catch (GeneralException e) {
|
||||
} catch (GeneralException |IOException e) {
|
||||
String errMsg = "Error rendering included content with id [" + expandedContentId + "] : " + e.toString();
|
||||
Debug.logError(e, errMsg, module);
|
||||
//throw new RuntimeException(errMsg);
|
||||
} catch (IOException e2) {
|
||||
String errMsg = "Error rendering included content with id [" + expandedContentId + "] : " + e2.toString();
|
||||
Debug.logError(e2, errMsg, module);
|
||||
//throw new RuntimeException(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,16 +446,18 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
HttpServletResponse response = (HttpServletResponse) context.get("response");
|
||||
HttpServletRequest request = (HttpServletRequest) context.get("request");
|
||||
if (request != null && response != null) {
|
||||
if (editRequest.indexOf('?') < 0)
|
||||
if (editRequest.indexOf('?') < 0) {
|
||||
editRequest += "?";
|
||||
else editRequest += "&";
|
||||
} else {
|
||||
editRequest += "&";
|
||||
}
|
||||
editRequest += "contentId=" + expandedContentId;
|
||||
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
|
||||
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
|
||||
urlString = rh.makeLink(request, response, editRequest, false, false, false);
|
||||
}
|
||||
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("urlString", urlString);
|
||||
parameters.put("editMode", editMode);
|
||||
parameters.put("editContainerStyle", content.getEditContainerStyle(context));
|
||||
@@ -481,7 +479,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
fullUrlString = rh.makeLink(request, response, urlString, true, false, false);
|
||||
}
|
||||
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("fullUrl", fullUrlString);
|
||||
parameters.put("width", content.getWidth());
|
||||
parameters.put("height", content.getHeight());
|
||||
@@ -493,7 +491,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
String enableEditName = content.getEnableEditName(context);
|
||||
String enableEditValue = (String)context.get(enableEditName);
|
||||
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("editContainerStyle", content.getEditContainerStyle(context));
|
||||
parameters.put("editRequest", content.getEditRequest(context));
|
||||
parameters.put("enableEditValue", enableEditValue == null ? "" : enableEditValue);
|
||||
@@ -509,13 +507,12 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
LocalDispatcher dispatcher = (LocalDispatcher) context.get("dispatcher");
|
||||
|
||||
// create a new map for the content rendering; so our current context does not get overwritten!
|
||||
Map<String, Object> contentContext = new HashMap<String, Object>();
|
||||
Map<String, Object> contentContext = new HashMap<>();
|
||||
contentContext.putAll(context);
|
||||
|
||||
try {
|
||||
if (WidgetContentWorker.getContentWorker() != null) {
|
||||
renderedContent = WidgetContentWorker.getContentWorker().renderSubContentAsTextExt(dispatcher, expandedContentId, expandedMapKey, contentContext, locale, mimeTypeId, true);
|
||||
//Debug.logInfo("renderedContent=" + renderedContent, module);
|
||||
} else {
|
||||
Debug.logError("Not rendering content, WidgetContentWorker.contentWorker not found.", module);
|
||||
}
|
||||
@@ -536,14 +533,9 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
writer.append(renderedContent);
|
||||
}
|
||||
|
||||
} catch (GeneralException e) {
|
||||
} catch (GeneralException | IOException e) {
|
||||
String errMsg = "Error rendering included content with id [" + expandedContentId + "] : " + e.toString();
|
||||
Debug.logError(e, errMsg, module);
|
||||
//throw new RuntimeException(errMsg);
|
||||
} catch (IOException e2) {
|
||||
String errMsg = "Error rendering included content with id [" + expandedContentId + "] : " + e2.toString();
|
||||
Debug.logError(e2, errMsg, module);
|
||||
//throw new RuntimeException(errMsg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,9 +554,11 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
HttpServletResponse response = (HttpServletResponse) context.get("response");
|
||||
HttpServletRequest request = (HttpServletRequest) context.get("request");
|
||||
if (request != null && response != null) {
|
||||
if (editRequest.indexOf('?') < 0)
|
||||
if (editRequest.indexOf('?') < 0) {
|
||||
editRequest += "?";
|
||||
else editRequest += "&";
|
||||
} else {
|
||||
editRequest += "&";
|
||||
}
|
||||
editRequest += "contentId=" + expandedContentId;
|
||||
if (UtilValidate.isNotEmpty(expandedMapKey)) {
|
||||
editRequest += "&mapKey=" + expandedMapKey;
|
||||
@@ -575,7 +569,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("urlString", urlString);
|
||||
parameters.put("editMode", editMode);
|
||||
parameters.put("editContainerStyle", content.getEditContainerStyle(context));
|
||||
@@ -611,7 +605,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
this.getNextElementId();
|
||||
Map<String, Object> uiLabelMap = UtilGenerics.checkMap(context.get("uiLabelMap"));
|
||||
Map<String, Object> paramMap = UtilGenerics.checkMap(context.get("requestParameters"));
|
||||
Map<String, Object> requestParameters = new HashMap<String, Object>(paramMap);
|
||||
Map<String, Object> requestParameters = new HashMap<>(paramMap);
|
||||
if (uiLabelMap != null) {
|
||||
expandToolTip = (String) uiLabelMap.get("CommonExpand");
|
||||
collapseToolTip = (String) uiLabelMap.get("CommonCollapse");
|
||||
@@ -632,7 +626,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
navMenu.renderWidgetString(sb, context, this);
|
||||
context.put("menuStringRenderer", savedRenderer);
|
||||
} catch (TemplateException e) {
|
||||
Debug.logError(e, module);
|
||||
Debug.logError(e, module);
|
||||
}
|
||||
} else if (navForm != null) {
|
||||
renderScreenletPaginateMenu(sb, context, navForm);
|
||||
@@ -640,7 +634,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
menuString = sb.toString();
|
||||
}
|
||||
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("title", title);
|
||||
parameters.put("collapsible", collapsible);
|
||||
parameters.put("saveCollapsed", screenlet.saveCollapsed());
|
||||
@@ -721,7 +715,9 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
int actualPageSize = Paginator.getActualPageSize(context);
|
||||
|
||||
// if this is all there seems to be (if listSize < 0, then size is unknown)
|
||||
if (actualPageSize >= listSize && listSize >= 0) return;
|
||||
if (actualPageSize >= listSize && listSize >= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// needed for the "Page" and "rows" labels
|
||||
Map<String, String> uiLabelMap = UtilGenerics.cast(context.get("uiLabelMap"));
|
||||
@@ -734,8 +730,12 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
}
|
||||
|
||||
// for legacy support, the viewSizeParam is VIEW_SIZE and viewIndexParam is VIEW_INDEX when the fields are "viewSize" and "viewIndex"
|
||||
if (("viewIndex" + "_" + paginatorNumber).equals(viewIndexParam)) viewIndexParam = "VIEW_INDEX" + "_" + paginatorNumber;
|
||||
if (("viewSize" + "_" + paginatorNumber).equals(viewSizeParam)) viewSizeParam = "VIEW_SIZE" + "_" + paginatorNumber;
|
||||
if (("viewIndex" + "_" + paginatorNumber).equals(viewIndexParam)) {
|
||||
viewIndexParam = "VIEW_INDEX" + "_" + paginatorNumber;
|
||||
}
|
||||
if (("viewSize" + "_" + paginatorNumber).equals(viewSizeParam)) {
|
||||
viewSizeParam = "VIEW_SIZE" + "_" + paginatorNumber;
|
||||
}
|
||||
|
||||
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
|
||||
RequestHandler rh = (RequestHandler) ctx.getAttribute("_REQUEST_HANDLER_");
|
||||
@@ -749,14 +749,16 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
// strip legacy viewIndex/viewSize params from the query string
|
||||
queryString = UtilHttp.stripViewParamsFromQueryString(queryString, "" + paginatorNumber);
|
||||
// strip parametrized index/size params from the query string
|
||||
HashSet<String> paramNames = new HashSet<String>();
|
||||
HashSet<String> paramNames = new HashSet<>();
|
||||
paramNames.add(viewIndexParam);
|
||||
paramNames.add(viewSizeParam);
|
||||
queryString = UtilHttp.stripNamedParamsFromQueryString(queryString, paramNames);
|
||||
|
||||
String anchor = "";
|
||||
String paginateAnchor = modelForm.getPaginateTargetAnchor();
|
||||
if (paginateAnchor != null) anchor = "#" + paginateAnchor;
|
||||
if (paginateAnchor != null) {
|
||||
anchor = "#" + paginateAnchor;
|
||||
}
|
||||
|
||||
// preparing the link text, so that later in the code we can reuse this and just add the viewIndex
|
||||
String prepLinkText = "";
|
||||
@@ -800,7 +802,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
firstLinkUrl = rh.makeLink(request, response, linkText);
|
||||
}
|
||||
|
||||
Map<String, Object> parameters = new HashMap<String, Object>();
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("lowIndex", Paginator.getLowIndex(context));
|
||||
parameters.put("actualPageSize", actualPageSize);
|
||||
parameters.put("ofLabel", ofLabel);
|
||||
@@ -1012,15 +1014,7 @@ public class MacroScreenRenderer implements ScreenStringRenderer {
|
||||
if (UtilValidate.isNotEmpty(screenName) && UtilValidate.isNotEmpty(screenLocation)) {
|
||||
try {
|
||||
modelScreen = ScreenFactory.getScreenFromLocation(screenLocation, screenName);
|
||||
} catch (IOException e) {
|
||||
String errMsg = "Error rendering portlet ID [" + portalPortletId + "]: " + e.toString();
|
||||
Debug.logError(e, errMsg, module);
|
||||
throw new RuntimeException(errMsg);
|
||||
} catch (SAXException e) {
|
||||
String errMsg = "Error rendering portlet ID [" + portalPortletId + "]: " + e.toString();
|
||||
Debug.logError(e, errMsg, module);
|
||||
throw new RuntimeException(errMsg);
|
||||
} catch (ParserConfigurationException e) {
|
||||
} catch (IOException | SAXException | ParserConfigurationException e) {
|
||||
String errMsg = "Error rendering portlet ID [" + portalPortletId + "]: " + e.toString();
|
||||
Debug.logError(e, errMsg, module);
|
||||
throw new RuntimeException(errMsg);
|
||||
|
||||
+3
-12
@@ -20,7 +20,6 @@ package org.apache.ofbiz.widget.renderer.macro;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -31,16 +30,10 @@ import javax.xml.parsers.ParserConfigurationException;
|
||||
import org.apache.ofbiz.base.util.Debug;
|
||||
import org.apache.ofbiz.base.util.GeneralException;
|
||||
import org.apache.ofbiz.base.util.UtilCodec;
|
||||
import org.apache.ofbiz.base.util.UtilGenerics;
|
||||
import org.apache.ofbiz.base.util.UtilHttp;
|
||||
import org.apache.ofbiz.base.util.UtilProperties;
|
||||
import org.apache.ofbiz.base.util.UtilValidate;
|
||||
import org.apache.ofbiz.base.util.collections.MapStack;
|
||||
import org.apache.ofbiz.entity.Delegator;
|
||||
import org.apache.ofbiz.entity.util.EntityUtilProperties;
|
||||
import org.apache.ofbiz.service.LocalDispatcher;
|
||||
import org.apache.ofbiz.service.ModelService;
|
||||
import org.apache.ofbiz.service.ServiceUtil;
|
||||
import org.apache.ofbiz.webapp.view.AbstractViewHandler;
|
||||
import org.apache.ofbiz.webapp.view.ViewHandlerException;
|
||||
import org.apache.ofbiz.widget.model.ModelTheme;
|
||||
@@ -66,8 +59,8 @@ public class MacroScreenViewHandler extends AbstractViewHandler {
|
||||
}
|
||||
|
||||
private ScreenStringRenderer loadRenderers(HttpServletRequest request, HttpServletResponse response,
|
||||
Map<String, Object> context, Writer writer) throws GeneralException, TemplateException, IOException {
|
||||
VisualTheme visualTheme = (VisualTheme) UtilHttp.getVisualTheme(request);
|
||||
Map<String, Object> context, Writer writer) throws TemplateException, IOException {
|
||||
VisualTheme visualTheme = UtilHttp.getVisualTheme(request);
|
||||
ModelTheme modelTheme = visualTheme.getModelTheme();
|
||||
|
||||
String screenMacroLibraryPath = modelTheme.getScreenRendererLocation(getName());
|
||||
@@ -127,9 +120,7 @@ public class MacroScreenViewHandler extends AbstractViewHandler {
|
||||
throw new ViewHandlerException(e.getMessage());
|
||||
} catch (IOException e) {
|
||||
throw new ViewHandlerException("Error in the response writer/output stream: " + e.toString(), e);
|
||||
} catch (SAXException e) {
|
||||
throw new ViewHandlerException("XML Error rendering page: " + e.toString(), e);
|
||||
} catch (ParserConfigurationException e) {
|
||||
} catch (SAXException | ParserConfigurationException e) {
|
||||
throw new ViewHandlerException("XML Error rendering page: " + e.toString(), e);
|
||||
} catch (GeneralException e) {
|
||||
throw new ViewHandlerException("Lower level error rendering page: " + e.toString(), e);
|
||||
|
||||
+21
-25
@@ -50,7 +50,7 @@ import freemarker.template.TemplateException;
|
||||
|
||||
/**
|
||||
* Widget Library - Tree Renderer implementation based on Freemarker macros
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
|
||||
@@ -65,7 +65,7 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
this.environment = FreeMarkerWorker.renderTemplate(this.macroLibrary, input, writer);
|
||||
}
|
||||
|
||||
private void executeMacro(String macro) throws IOException {
|
||||
private void executeMacro(String macro) {
|
||||
try {
|
||||
Reader templateReader = new StringReader(macro);
|
||||
// FIXME: I am using a Date as an hack to provide a unique name for the template...
|
||||
@@ -73,20 +73,18 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
FreeMarkerWorker.getDefaultOfbizConfig());
|
||||
templateReader.close();
|
||||
this.environment.include(template);
|
||||
} catch (TemplateException e) {
|
||||
Debug.logError(e, "Error rendering tree thru ftl", module);
|
||||
} catch (IOException e) {
|
||||
} catch (TemplateException | IOException e) {
|
||||
Debug.logError(e, "Error rendering tree thru ftl", module);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the beginning boundary comment string.
|
||||
* @param writer The writer to write to
|
||||
* @param widgetType The widget type: "Screen Widget", "Tree Widget", etc.
|
||||
* @param modelWidget The widget
|
||||
*/
|
||||
public void renderBeginningBoundaryComment(Appendable writer, String widgetType, ModelWidget modelWidget) throws IOException {
|
||||
public void renderBeginningBoundaryComment(Appendable writer, String widgetType, ModelWidget modelWidget) {
|
||||
StringWriter sr = new StringWriter();
|
||||
sr.append("<@formatBoundaryComment ");
|
||||
sr.append(" boundaryType=\"");
|
||||
@@ -98,14 +96,14 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
sr.append("\" />");
|
||||
executeMacro(sr.toString());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the ending boundary comment string.
|
||||
* @param writer The writer to write to
|
||||
* @param widgetType The widget type: "Screen Widget", "Tree Widget", etc.
|
||||
* @param modelWidget The widget
|
||||
*/
|
||||
public void renderEndingBoundaryComment(Appendable writer, String widgetType, ModelWidget modelWidget) throws IOException {
|
||||
public void renderEndingBoundaryComment(Appendable writer, String widgetType, ModelWidget modelWidget) {
|
||||
StringWriter sr = new StringWriter();
|
||||
sr.append("<@formatBoundaryComment ");
|
||||
sr.append(" boundaryType=\"");
|
||||
@@ -117,11 +115,11 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
sr.append("\" />");
|
||||
executeMacro(sr.toString());
|
||||
}
|
||||
|
||||
|
||||
public void renderNodeBegin(Appendable writer, Map<String, Object> context, ModelTree.ModelNode node, int depth) throws IOException {
|
||||
String currentNodeTrailPiped = null;
|
||||
List<String> currentNodeTrail = UtilGenerics.toList(context.get("currentNodeTrail"));
|
||||
|
||||
|
||||
String style = "";
|
||||
if (node.isRootNode()) {
|
||||
if (ModelWidget.widgetBoundaryCommentsEnabled(context)) {
|
||||
@@ -129,7 +127,7 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
}
|
||||
style = "basic-tree";
|
||||
}
|
||||
|
||||
|
||||
StringWriter sr = new StringWriter();
|
||||
sr.append("<@renderNodeBegin ");
|
||||
sr.append(" style=\"");
|
||||
@@ -163,7 +161,6 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
// Not on the trail
|
||||
if (node.showPeers(depth, context)) {
|
||||
context.put("processChildren", Boolean.FALSE);
|
||||
//expandCollapseLink.setText(" + ");
|
||||
currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|");
|
||||
StringBuilder target = new StringBuilder(node.getModelTree().getExpandCollapseRequest(context));
|
||||
String trailName = node.getModelTree().getTrailName(context);
|
||||
@@ -177,7 +174,6 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
}
|
||||
} else {
|
||||
context.put("processChildren", Boolean.TRUE);
|
||||
//expandCollapseLink.setText(" - ");
|
||||
String lastContentId = currentNodeTrail.remove(currentNodeTrail.size() - 1);
|
||||
currentNodeTrailPiped = StringUtil.join(currentNodeTrail, "|");
|
||||
if (currentNodeTrailPiped == null) {
|
||||
@@ -235,7 +231,7 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
}
|
||||
|
||||
public void renderLabel(Appendable writer, Map<String, Object> context, ModelTree.ModelNode.Label label) throws IOException {
|
||||
String id = label.getId(context);
|
||||
String id = label.getId(context);
|
||||
String style = label.getStyle(context);
|
||||
String labelText = label.getText(context);
|
||||
|
||||
@@ -256,19 +252,19 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
StringBuilder linkUrl = new StringBuilder();
|
||||
HttpServletResponse response = (HttpServletResponse) context.get("response");
|
||||
HttpServletRequest request = (HttpServletRequest) context.get("request");
|
||||
|
||||
|
||||
if (UtilValidate.isNotEmpty(target)) {
|
||||
WidgetWorker.buildHyperlinkUrl(linkUrl, target, link.getUrlMode(), link.getParameterMap(context), link.getPrefix(context),
|
||||
link.getFullPath(), link.getSecure(), link.getEncode(), request, response, context);
|
||||
}
|
||||
|
||||
|
||||
String id = link.getId(context);
|
||||
String style = link.getStyle(context);
|
||||
String name = link.getName(context);
|
||||
String title = link.getTitle(context);
|
||||
String targetWindow = link.getTargetWindow(context);
|
||||
String linkText = link.getText(context);
|
||||
|
||||
|
||||
String imgStr = "";
|
||||
ModelTree.ModelNode.Image img = link.getImage();
|
||||
if (img != null) {
|
||||
@@ -276,7 +272,7 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
renderImage(sw, context, img);
|
||||
imgStr = sw.toString();
|
||||
}
|
||||
|
||||
|
||||
StringWriter sr = new StringWriter();
|
||||
sr.append("<@renderLink ");
|
||||
sr.append("id=\"");
|
||||
@@ -296,16 +292,16 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
sr.append("\" imgStr=\"");
|
||||
sr.append(imgStr.replaceAll("\"", "\\\\\""));
|
||||
sr.append("\" />");
|
||||
executeMacro(sr.toString().replace("|", "%7C")); // Fix for OFBIZ-9191
|
||||
executeMacro(sr.toString().replace("|", "%7C")); // Fix for OFBIZ-9191
|
||||
}
|
||||
|
||||
|
||||
public void renderImage(Appendable writer, Map<String, Object> context, ModelTree.ModelNode.Image image) throws IOException {
|
||||
if (image == null) {
|
||||
return;
|
||||
}
|
||||
HttpServletResponse response = (HttpServletResponse) context.get("response");
|
||||
HttpServletRequest request = (HttpServletRequest) context.get("request");
|
||||
|
||||
|
||||
String urlMode = image.getUrlMode();
|
||||
String src = image.getSrc(context);
|
||||
String id = image.getId(context);
|
||||
@@ -314,12 +310,12 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
String hgt = image.getHeight(context);
|
||||
String border = image.getBorder(context);
|
||||
String alt = ""; //TODO add alt to tree images image.getAlt(context);
|
||||
|
||||
|
||||
boolean fullPath = false;
|
||||
boolean secure = false;
|
||||
boolean encode = false;
|
||||
String urlString = "";
|
||||
|
||||
|
||||
if (urlMode != null && "intra-app".equalsIgnoreCase(urlMode)) {
|
||||
if (request != null && response != null) {
|
||||
ServletContext ctx = (ServletContext) request.getAttribute("servletContext");
|
||||
@@ -364,7 +360,7 @@ public class MacroTreeRenderer implements TreeStringRenderer {
|
||||
ScreenRenderer screenRenderer = (ScreenRenderer)context.get("screens");
|
||||
if (screenRenderer != null) {
|
||||
return screenRenderer.getScreenStringRenderer();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user