/** * Generates the xml representation and mount in rootNode the structure to be included. Fills the * XMLNode structure with the form representation and returns the string. */ public String generateFormXML(Form form, XMLNode rootNode) throws Exception { rootNode.addAttribute(ATTR_ID, form.getId().toString()); addXMLNode("subject", form.getSubject(), rootNode); addXMLNode("name", form.getName(), rootNode); addXMLNode("displayMode", form.getDisplayMode(), rootNode); addXMLNode("labelMode", form.getLabelMode(), rootNode); addXMLNode("showMode", form.getShowMode(), rootNode); addXMLNode( "status", (form.getStatus() != null ? String.valueOf(form.getStatus()) : null), rootNode); addXMLNode("formTemplate", form.getFormTemplate(), rootNode); for (Field field : form.getFormFields()) { generateFieldXML(field, rootNode); } for (DataHolder dataHolder : form.getHolders()) { generateDataHolderXML(dataHolder, rootNode); } StringWriter sw = new StringWriter(); rootNode.writeXML(sw, true); return sw.toString(); }
public void renderPendingFields() throws Exception { WysiwygFormEditor wysiwygFormEditor = WysiwygFormEditor.lookup(); Form form = wysiwygFormEditor.getCurrentForm(); Set<DataHolder> holders = form.getHolders(); renderFragment("outputStart"); for (DataHolder dataHolder : holders) { Set<DataFieldHolder> dataFieldHolders = getUnBindedFields(form, dataHolder); if (dataFieldHolders != null && !dataFieldHolders.isEmpty()) { if (dataHolder.canHaveChildren()) { setAttribute("id", dataHolder.getUniqeId()); setAttribute("type", dataHolder.getTypeCode()); setAttribute("renderColor", dataHolder.getRenderColor()); if (dataHolder.getUniqeId() != null && dataHolder.getUniqeId().equals(wysiwygFormEditor.getLastDataHolderUsedId())) { setAttribute("open", Boolean.TRUE); } else { setAttribute("open", Boolean.FALSE); } String holderName = ""; holderName = dataHolder.getUniqeId(); if (holderName.length() > 20) holderName = holderName.substring(0, 19) + "..."; setAttribute("showHolderName", holderName); renderFragment("outputBinding"); } for (DataFieldHolder dataFieldHolder : dataFieldHolders) { String fieldName = dataFieldHolder.getId(); if (fieldName != null && !form.isFieldBinded(dataHolder, fieldName)) { renderAddField(fieldName, dataFieldHolder, dataHolder); } } if (dataHolder.canHaveChildren()) { renderFragment("outputEndBinding"); } } } renderFragment("outputEnd"); }
public void renderDataHolders() { try { renderFragment("outputStartHeader"); for (DataHolderBuilder builder : dataHolderManager.getHolderBuilders()) { if (builder instanceof RangedDataHolderBuilder) notifyHolderBuilder( (RangedDataHolderBuilder) builder, wysiwygFormEditor.getCurrentEditionContext().getPath()); else notifyHolderBuilder(builder); } renderFragment("outputEndHeader"); renderFragment("outputStart"); Form form = wysiwygFormEditor.getCurrentForm(); Set<DataHolder> holders = form.getHolders(); String existingIds = "\"\""; String existingInputIds = "\"\""; String existingOutputIds = "\"\""; for (DataHolder holder : holders) { if (!StringUtils.isEmpty(holder.getInputId())) existingInputIds += ", \"" + holder.getInputId() + "\" "; if (!StringUtils.isEmpty(holder.getOuputId())) existingOutputIds += ", \"" + holder.getOuputId() + "\" "; if (!StringUtils.isEmpty(holder.getUniqeId())) existingIds += ", \"" + holder.getUniqeId() + "\" "; } setAttribute("existingIds", existingIds); setAttribute("existingInputIds", existingInputIds); setAttribute("existingOutputIds", existingOutputIds); renderFragment("outputFormAddHolderStart"); Map<String, String> colors = dataHolderManager.getHolderColors(); for (Iterator it = colors.keySet().iterator(); it.hasNext(); ) { String color = (String) it.next(); String name = colors.get(color); setAttribute("color", color); setAttribute("name", name); renderFragment("color"); } Map<String, String> builderNames = new HashMap<String, String>(); // Render source types sorted by value. renderFragment("outputFormHolderTypes"); for (DataHolderBuilder builder : dataHolderManager.getHolderBuilders()) { String holderName = builder.getDataHolderName(getLocale()); builderNames.put(builder.getId(), holderName); setAttribute("holderType", builder.getId()); setAttribute("holderName", holderName); renderFragment("outputHolderType"); } renderFragment("outputEndHolderTypes"); renderFragment("outputStartBindings"); int i = 0; for (DataHolder holder : holders) { setAttribute("id", StringUtils.defaultString(holder.getUniqeId())); setAttribute("input_id", StringUtils.defaultString(holder.getInputId())); setAttribute("outId", StringUtils.defaultString(holder.getOuputId())); setAttribute("deleteId", StringUtils.defaultString(holder.getUniqeId())); setAttribute( "type", builderNames.get( StringUtils.defaultIfEmpty(holder.getSupportedType(), holder.getTypeCode()))); setAttribute("renderColor", holder.getRenderColor()); setAttribute("value", holder.getInfo()); setAttribute("rowStyle", i % 2 == 1 ? "skn-even_row" : "skn-odd_row"); i++; renderFragment("outputBindings"); } renderFragment("outputEndBindings"); renderFragment("outputEnd"); } catch (Exception e) { log.error("Error:", e); } }