List of usage examples for java.io StringWriter append
public StringWriter append(char c)
From source file:org.ofbiz.widget.form.MacroFormRenderer.java
public void renderImageField(Appendable writer, Map<String, Object> context, ImageField imageField) throws IOException { ModelFormField modelFormField = imageField.getModelFormField(); String value = modelFormField.getEntry(context, imageField.getValue(context)); String description = imageField.getDescription(context); String alternate = imageField.getAlternate(context); String style = imageField.getStyle(context); if (UtilValidate.isEmpty(description)) { description = imageField.getModelFormField().getTitle(context); }/*from ww w .j a va2 s.c om*/ if (UtilValidate.isEmpty(alternate)) { alternate = description; } if (UtilValidate.isNotEmpty(value)) { if (!value.startsWith("http")) { StringBuilder buffer = new StringBuilder(); ContentUrlTag.appendContentPrefix(request, buffer); buffer.append(value); value = buffer.toString(); } } else if (value == null) { value = ""; } String event = modelFormField.getEvent(); String action = modelFormField.getAction(context); StringWriter sr = new StringWriter(); sr.append("<@renderImageField "); sr.append(" value=\""); sr.append(value); sr.append("\" description=\""); sr.append(encode(description, modelFormField, context)); sr.append("\" alternate=\""); sr.append(encode(alternate, modelFormField, context)); sr.append("\" style=\""); sr.append(style); sr.append("\" event=\""); sr.append(event == null ? "" : event); sr.append("\" action=\""); sr.append(action == null ? "" : action); sr.append("\" />"); executeMacro(writer, sr.toString()); this.makeHyperlinkString(writer, imageField.getSubHyperlink(), context); this.appendTooltip(writer, context, modelFormField); }
From source file:org.ofbiz.widget.form.MacroFormRenderer.java
public void renderFileField(Appendable writer, Map<String, Object> context, FileField textField) throws IOException { ModelFormField modelFormField = textField.getModelFormField(); String className = ""; String alert = "false"; String name = modelFormField.getParameterName(context); String value = modelFormField.getEntry(context, textField.getDefaultValue(context)); String size = Integer.toString(textField.getSize()); String maxlength = ""; String autocomplete = ""; if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) { className = modelFormField.getWidgetStyle(); if (modelFormField.shouldBeRed(context)) { alert = "true"; }/* w w w . j av a 2 s . c o m*/ } if (UtilValidate.isEmpty(value)) { value = ""; } if (textField.getMaxlength() != null) { maxlength = textField.getMaxlength().toString(); } if (!textField.getClientAutocompleteField()) { autocomplete = "off"; } StringWriter sr = new StringWriter(); sr.append("<@renderFileField "); sr.append(" className=\""); sr.append(className); sr.append("\" alert=\""); sr.append(alert); sr.append("\" name=\""); sr.append(name); sr.append("\" value=\""); sr.append(value); sr.append("\" size=\""); sr.append(size); sr.append("\" maxlength=\""); sr.append(maxlength); sr.append("\" autocomplete=\""); sr.append(autocomplete); sr.append("\" />"); executeMacro(writer, sr.toString()); this.makeHyperlinkString(writer, textField.getSubHyperlink(), context); this.appendTooltip(writer, context, modelFormField); }
From source file:org.ofbiz.widget.form.MacroFormRenderer.java
public void renderFormOpen(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException { this.widgetCommentsEnabled = ModelWidget.widgetBoundaryCommentsEnabled(context); renderBeginningBoundaryComment(writer, "Form Widget - Form Element", modelForm); String targetType = modelForm.getTargetType(); 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);/*w w w. j a va 2s . c o m*/ } String formType = modelForm.getType(); String targetWindow = modelForm.getTargetWindow(context); String containerId = modelForm.getCurrentContainerId(context); String containerStyle = modelForm.getContainerStyle(); String autocomplete = ""; String name = modelForm.getCurrentFormName(context); String viewIndexField = modelForm.getMultiPaginateIndexField(context); String viewSizeField = modelForm.getMultiPaginateSizeField(context); int viewIndex = modelForm.getViewIndex(context); int viewSize = modelForm.getViewSize(context); boolean useRowSubmit = modelForm.getUseRowSubmit(); if (!modelForm.getClientAutocompleteFields()) { autocomplete = "off"; } StringWriter sr = new StringWriter(); sr.append("<@renderFormOpen "); sr.append(" linkUrl=\""); sr.append(linkUrl); sr.append("\" formType=\""); sr.append(formType); sr.append("\" targetWindow=\""); sr.append(targetWindow); sr.append("\" containerId=\""); sr.append(containerId); sr.append("\" containerStyle=\""); sr.append(containerStyle); sr.append("\" autocomplete=\""); sr.append(autocomplete); sr.append("\" name=\""); sr.append(name); sr.append("\" viewIndexField=\""); sr.append(viewIndexField); sr.append("\" viewSizeField=\""); sr.append(viewSizeField); sr.append("\" viewIndex=\""); sr.append(Integer.toString(viewIndex)); sr.append("\" viewSize=\""); sr.append(Integer.toString(viewSize)); sr.append("\" useRowSubmit="); sr.append(Boolean.toString(useRowSubmit)); sr.append(" />"); executeMacro(writer, sr.toString()); }
From source file:org.ofbiz.widget.form.MacroFormRenderer.java
public void renderFormatListWrapperOpen(Appendable writer, Map<String, Object> context, ModelForm modelForm) throws IOException { Map<String, Object> inputFields = UtilGenerics.checkMap(context.get("requestParameters")); Map<String, Object> queryStringMap = UtilGenerics.toMap(context.get("queryStringMap")); if (UtilValidate.isNotEmpty(queryStringMap)) { inputFields.putAll(queryStringMap); }/* w w w .j a v a2 s.c o m*/ if (modelForm.getType().equals("multi")) { inputFields = UtilHttp.removeMultiFormParameters(inputFields); } String queryString = UtilHttp.urlEncodeArgs(inputFields); context.put("_QBESTRING_", queryString); renderBeginningBoundaryComment(writer, "Form Widget", modelForm); if (this.renderPagination) { this.renderNextPrev(writer, context, modelForm); } List<ModelFormField> childFieldList = modelForm.getFieldList(); List<String> columnStyleList = FastList.newInstance(); List<String> fieldNameList = FastList.newInstance(); for (ModelFormField childField : childFieldList) { int childFieldType = childField.getFieldInfo().getFieldType(); if (childFieldType == ModelFormField.FieldInfo.HIDDEN || childFieldType == ModelFormField.FieldInfo.IGNORED) { continue; } String areaStyle = childField.getTitleAreaStyle(); if (UtilValidate.isEmpty(areaStyle)) { areaStyle = ""; } if (fieldNameList.contains(childField.getName())) { if (UtilValidate.isNotEmpty(areaStyle)) { columnStyleList.set(fieldNameList.indexOf(childField.getName()), areaStyle); } } else { columnStyleList.add(areaStyle); fieldNameList.add(childField.getName()); } } columnStyleList = StringUtil.quoteStrList(columnStyleList); String columnStyleListString = StringUtil.join(columnStyleList, ", "); StringWriter sr = new StringWriter(); sr.append("<@renderFormatListWrapperOpen "); sr.append(" formName=\""); sr.append(modelForm.getName()); sr.append("\" style=\""); sr.append(FlexibleStringExpander.expandString(modelForm.getDefaultTableStyle(), context)); sr.append("\" columnStyles=["); if (UtilValidate.isNotEmpty(columnStyleListString)) { // this is a fix for forms with no fields sr.append(columnStyleListString); } sr.append("] />"); executeMacro(writer, sr.toString()); }
From source file:org.ofbiz.widget.form.MacroFormRenderer.java
public void renderRadioField(Appendable writer, Map<String, Object> context, RadioField radioField) throws IOException { ModelFormField modelFormField = radioField.getModelFormField(); modelFormField.getModelForm();//from w w w. j a va2 s . c o m List<ModelFormField.OptionValue> allOptionValues = radioField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); String currentValue = modelFormField.getEntry(context); String className = ""; String alert = "false"; String name = modelFormField.getParameterName(context); String event = modelFormField.getEvent(); String action = modelFormField.getAction(context); StringBuilder items = new StringBuilder(); if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) { className = modelFormField.getWidgetStyle(); if (modelFormField.shouldBeRed(context)) { alert = "true"; } } String noCurrentSelectedKey = radioField.getNoCurrentSelectedKey(context); items.append("["); for (ModelFormField.OptionValue optionValue : allOptionValues) { if (items.length() > 1) { items.append(","); } items.append("{'key':'"); items.append(optionValue.getKey()); items.append("', 'description':'" + encode(optionValue.getDescription(), modelFormField, context)); items.append("'}"); } items.append("]"); StringWriter sr = new StringWriter(); sr.append("<@renderRadioField "); sr.append("items="); sr.append(items.toString()); sr.append(" className=\""); sr.append(className); sr.append("\" alert=\""); sr.append(alert); sr.append("\" currentValue=\""); sr.append(currentValue); sr.append("\" noCurrentSelectedKey=\""); sr.append(noCurrentSelectedKey); sr.append("\" name=\""); sr.append(name); sr.append("\" event=\""); if (event != null) { sr.append(event); } sr.append("\" action=\""); if (action != null) { sr.append(action); } sr.append("\" />"); executeMacro(writer, sr.toString()); this.appendTooltip(writer, context, modelFormField); }
From source file:org.ofbiz.widget.form.MacroFormRenderer.java
public void renderPasswordField(Appendable writer, Map<String, Object> context, PasswordField passwordField) throws IOException { ModelFormField modelFormField = passwordField.getModelFormField(); String className = ""; String alert = "false"; String name = modelFormField.getParameterName(context); String size = Integer.toString(passwordField.getSize()); String maxlength = ""; String id = modelFormField.getCurrentContainerId(context); String autocomplete = ""; if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) { className = modelFormField.getWidgetStyle(); if (modelFormField.shouldBeRed(context)) { alert = "true"; }/*from ww w . j a v a2s .c om*/ } String value = modelFormField.getEntry(context, passwordField.getDefaultValue(context)); if (value == null) { value = ""; } if (passwordField.getMaxlength() != null) { maxlength = passwordField.getMaxlength().toString(); } if (id == null) { id = ""; } if (!passwordField.getClientAutocompleteField()) { autocomplete = "off"; } StringWriter sr = new StringWriter(); sr.append("<@renderPasswordField "); sr.append(" className=\""); sr.append(className); sr.append("\" alert=\""); sr.append(alert); sr.append("\" name=\""); sr.append(name); sr.append("\" value=\""); sr.append(value); sr.append("\" size=\""); sr.append(size); sr.append("\" maxlength=\""); sr.append(maxlength); sr.append("\" id=\""); sr.append(id); sr.append("\" autocomplete=\""); sr.append(autocomplete); sr.append("\" />"); executeMacro(writer, sr.toString()); this.addAsterisks(writer, context, modelFormField); this.makeHyperlinkString(writer, passwordField.getSubHyperlink(), context); this.appendTooltip(writer, context, modelFormField); }
From source file:org.ofbiz.widget.form.MacroFormRenderer.java
public void renderCheckField(Appendable writer, Map<String, Object> context, CheckField checkField) throws IOException { ModelFormField modelFormField = checkField.getModelFormField(); modelFormField.getModelForm();/* w w w . ja v a2 s.c o m*/ String currentValue = modelFormField.getEntry(context); Boolean allChecked = checkField.isAllChecked(context); String id = modelFormField.getCurrentContainerId(context); String className = ""; String alert = "false"; String name = modelFormField.getParameterName(context); String event = modelFormField.getEvent(); String action = modelFormField.getAction(context); StringBuilder items = new StringBuilder(); if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) { className = modelFormField.getWidgetStyle(); if (modelFormField.shouldBeRed(context)) { alert = "true"; } } List<ModelFormField.OptionValue> allOptionValues = checkField.getAllOptionValues(context, WidgetWorker.getDelegator(context)); items.append("["); for (ModelFormField.OptionValue optionValue : allOptionValues) { if (items.length() > 1) { items.append(","); } items.append("{'value':'"); items.append(optionValue.getKey()); items.append("', 'description':'" + encode(optionValue.getDescription(), modelFormField, context)); items.append("'}"); } items.append("]"); StringWriter sr = new StringWriter(); sr.append("<@renderCheckField "); sr.append("items="); sr.append(items.toString()); sr.append(" className=\""); sr.append(className); sr.append("\" alert=\""); sr.append(alert); sr.append("\" id=\""); sr.append(id); sr.append("\" allChecked="); sr.append((allChecked != null ? Boolean.toString(allChecked) : "\"\"")); sr.append(" currentValue=\""); sr.append(currentValue); sr.append("\" name=\""); sr.append(name); sr.append("\" event=\""); if (event != null) { sr.append(event); } sr.append("\" action=\""); if (action != null) { sr.append(action); } sr.append("\" />"); executeMacro(writer, sr.toString()); this.appendTooltip(writer, context, modelFormField); }
From source file:org.ofbiz.widget.form.MacroFormRenderer.java
public void renderTextareaField(Appendable writer, Map<String, Object> context, TextareaField textareaField) throws IOException { ModelFormField modelFormField = textareaField.getModelFormField(); String name = modelFormField.getParameterName(context); String cols = Integer.toString(textareaField.getCols()); String rows = Integer.toString(textareaField.getRows()); String id = modelFormField.getCurrentContainerId(context); String className = ""; String alert = "false"; if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) { className = modelFormField.getWidgetStyle(); if (modelFormField.shouldBeRed(context)) { alert = "true"; }// w ww . j a v a 2 s . com } //check for required field style on single forms if ("single".equals(modelFormField.getModelForm().getType()) && modelFormField.getRequiredField()) { String requiredStyle = modelFormField.getRequiredFieldStyle(); if (UtilValidate.isEmpty(requiredStyle)) requiredStyle = "required"; if (UtilValidate.isEmpty(className)) className = requiredStyle; else className = requiredStyle + " " + className; } String visualEditorEnable = ""; String buttons = ""; if (textareaField.getVisualEditorEnable()) { visualEditorEnable = "true"; buttons = textareaField.getVisualEditorButtons(context); if (UtilValidate.isEmpty(buttons)) { buttons = "maxi"; } } String readonly = ""; if (textareaField.isReadOnly()) { readonly = "readonly"; } Map<String, Object> userLogin = UtilGenerics.checkMap(context.get("userLogin")); String language = "en"; if (userLogin != null) { language = UtilValidate.isEmpty((String) userLogin.get("lastLocale")) ? "en" : (String) userLogin.get("lastLocale"); } String value = modelFormField.getEntry(context, textareaField.getDefaultValue(context)); StringWriter sr = new StringWriter(); sr.append("<@renderTextareaField "); sr.append("name=\""); sr.append(name); sr.append("\" className=\""); sr.append(className); sr.append("\" alert=\""); sr.append(alert); sr.append("\" value=\""); sr.append(value); sr.append("\" cols=\""); sr.append(cols); sr.append("\" rows=\""); sr.append(rows); sr.append("\" id=\""); sr.append(id); sr.append("\" readonly=\""); sr.append(readonly); sr.append("\" visualEditorEnable=\""); sr.append(visualEditorEnable); sr.append("\" language=\""); sr.append(language); sr.append("\" buttons=\""); sr.append(buttons); sr.append("\" />"); executeMacro(writer, sr.toString()); this.addAsterisks(writer, context, modelFormField); this.appendTooltip(writer, context, modelFormField); }
From source file:org.ofbiz.widget.form.MacroFormRenderer.java
public void renderSubmitField(Appendable writer, Map<String, Object> context, SubmitField submitField) throws IOException { ModelFormField modelFormField = submitField.getModelFormField(); ModelForm modelForm = modelFormField.getModelForm(); String event = modelFormField.getEvent(); String action = modelFormField.getAction(context); String title = modelFormField.getTitle(context); String name = modelFormField.getParameterName(context); String buttonType = submitField.getButtonType(); String formName = modelForm.getCurrentFormName(context); String imgSrc = submitField.getImageLocation(context); String confirmation = submitField.getConfirmation(context); String className = ""; String alert = "false"; if (UtilValidate.isNotEmpty(modelFormField.getWidgetStyle())) { className = modelFormField.getWidgetStyle(); if (modelFormField.shouldBeRed(context)) { alert = "true"; }/*from ww w .j a v a 2 s.c om*/ } String formId = modelForm.getCurrentContainerId(context); List<ModelForm.UpdateArea> updateAreas = modelForm.getOnSubmitUpdateAreas(); // This is here for backwards compatibility. Use on-event-update-area // elements instead. String backgroundSubmitRefreshTarget = submitField.getBackgroundSubmitRefreshTarget(context); if (UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) { if (updateAreas == null) { updateAreas = FastList.newInstance(); } updateAreas.add(new ModelForm.UpdateArea("submit", formId, backgroundSubmitRefreshTarget)); } boolean ajaxEnabled = (updateAreas != null || UtilValidate.isNotEmpty(backgroundSubmitRefreshTarget)) && this.javaScriptEnabled; String ajaxUrl = ""; if (ajaxEnabled) { ajaxUrl = createAjaxParamsFromUpdateAreas(updateAreas, null, context); } StringWriter sr = new StringWriter(); sr.append("<@renderSubmitField "); sr.append("buttonType=\""); sr.append(buttonType); sr.append("\" className=\""); sr.append(className); sr.append("\" alert=\""); sr.append(alert); sr.append("\" formName=\""); sr.append(formName); sr.append("\" title=\""); sr.append(encode(title, modelFormField, context)); sr.append("\" name=\""); sr.append(name); sr.append("\" event=\""); if (event != null) { sr.append(event); } sr.append("\" action=\""); if (action != null) { sr.append(action); } sr.append("\" imgSrc=\""); sr.append(imgSrc); sr.append("\" containerId=\""); if (ajaxEnabled) { sr.append(formId); } sr.append("\" confirmation =\""); sr.append(confirmation); sr.append("\" ajaxUrl=\""); if (ajaxEnabled) { sr.append(ajaxUrl); } sr.append("\" />"); executeMacro(writer, sr.toString()); this.appendTooltip(writer, context, modelFormField); }
From source file:org.ofbiz.widget.form.MacroFormRenderer.java
public void makeHyperlinkString(Appendable writer, String linkStyle, String targetType, String target, Map<String, String> parameterMap, String description, String confirmation, ModelFormField modelFormField, HttpServletRequest request, HttpServletResponse response, Map<String, Object> context, String targetWindow) throws IOException { if (UtilValidate.isNotEmpty(description) || UtilValidate.isNotEmpty(request.getAttribute("image"))) { StringBuilder linkUrl = new StringBuilder(); WidgetWorker.buildHyperlinkUrl(linkUrl, target, targetType, parameterMap, null, false, false, true, request, response, context); String event = ""; String action = ""; String imgSrc = ""; String alt = ""; String imgTitle = ""; String hiddenFormName = WidgetWorker.makeLinkHiddenFormName(context, modelFormField); if (UtilValidate.isNotEmpty(modelFormField.getEvent()) && UtilValidate.isNotEmpty(modelFormField.getAction(context))) { event = modelFormField.getEvent(); action = modelFormField.getAction(context); }/* ww w.ja v a2s. co m*/ if (UtilValidate.isNotEmpty(request.getAttribute("image"))) { imgSrc = request.getAttribute("image").toString(); } if (UtilValidate.isNotEmpty(request.getAttribute("alternate"))) { alt = request.getAttribute("alternate").toString(); } if (UtilValidate.isNotEmpty(request.getAttribute("imageTitle"))) { imgTitle = request.getAttribute("imageTitle").toString(); } Integer size = Integer.valueOf("0"); if (UtilValidate.isNotEmpty(request.getAttribute("descriptionSize"))) { size = Integer.valueOf(request.getAttribute("descriptionSize").toString()); } if (UtilValidate.isNotEmpty(description) && size > 0 && description.length() > size) { imgTitle = description; description = description.substring(0, size - 8) + "..." + description.substring(description.length() - 5); } if (UtilValidate.isEmpty(imgTitle)) { imgTitle = modelFormField.getTitle(context); } StringWriter sr = new StringWriter(); sr.append("<@makeHyperlinkString "); sr.append("linkStyle=\""); sr.append(linkStyle == null ? "" : linkStyle); sr.append("\" hiddenFormName=\""); sr.append(hiddenFormName == null ? "" : hiddenFormName); sr.append("\" event=\""); sr.append(event); sr.append("\" action=\""); sr.append(action); sr.append("\" imgSrc=\""); sr.append(imgSrc); sr.append("\" title=\""); sr.append(imgTitle); sr.append("\" alternate=\""); sr.append(alt); sr.append("\" linkUrl=\""); sr.append(linkUrl.toString()); sr.append("\" targetWindow=\""); sr.append(targetWindow); sr.append("\" description=\""); sr.append(description); sr.append("\" confirmation =\""); sr.append(confirmation); sr.append("\" />"); executeMacro(writer, sr.toString()); } }