nosi.core.gui.fields.GenXMLField Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of igrp-core Show documentation
Show all versions of igrp-core Show documentation
IGRP Framework is a powerful and highly customizable platform developed by the Operational Nucleus for the Information Society (NOSi) to create web applications, it provides out of box, several modules to make easy to create stand-alone, production-grade web applications: authentication and access-control, business processes automation, reporting, page builder with automatic code generation and incorporation of the Once-Only-Principle, written in Java. IGRP Framework WAR - Contains some keys resources that give UI to IGRP Framework and others supports files.
package nosi.core.gui.fields;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import nosi.core.webapp.Core;
import nosi.core.xml.XMLWritter;
/**
* @author: Emanuel Pereira
*
* Apr 14, 2017
*
* Description: class to generate xml of fields
*/
public class GenXMLField {
public static String view_img = "";
/*Generate xml field
*
Text 1
*/
public static void toXml(XMLWritter xml, List fields){
if(!fields.isEmpty()){
xml.startElement("fields");
for(Field field:fields){
if(field.isVisible() && !((field instanceof CheckBoxField) && field.getTagName().endsWith("_check"))){
if(field instanceof HiddenField){
xml.startElement(field.propertie().getProperty("hidden_formlist")!=null?field.propertie().getProperty("tag"):"hidden");
field.propertie().remove("maxlength");
}else{
xml.startElement(field.getTagName());
}
writteAttributes(xml,field.propertie());
if(field instanceof FileField && Core.isNotNull(field.getValue()))
xml.writeAttribute("temp-value", ""+field.getValue());
if(!(field instanceof HiddenField)) // Hidden field not contain tag label
xml.setElement("label", field.getLabel());
if(!(field instanceof SeparatorField)) // Separator field not contain tag value
getXmlValue(xml,field);
if(field instanceof LookupField lookupField){
StringBuilder link = new StringBuilder(field.getLookup());
if(field.vertionLookup() == 1) {
link.append("&forLookup=true");
for(Entry param : lookupField.getParams().entrySet())
link.append(String.format("&%s=%s", param.getKey(), param.getValue()));
xml.setElement("lookup", link.toString());
} else {
if (field.vertionLookup() == 2) {
link.append("&jsonLookup=");
link.append(URLEncoder.encode(Core.toJson(lookupField.getLookupParams()), StandardCharsets.UTF_8));
for (Entry param : ((LookupField) field).getParams().entrySet())
link.append(String.format("&%s=%s", param.getKey(), param.getValue()));
xml.setElement("lookup", link.toString());
}
}
}
xml.endElement();
}
}
if(view_img.compareTo("") > 0){//add tag view_img in case the View
xml.setElement("view_img", view_img);//http://igrp.teste.gov.cv/images/legislativas/data/img/candidatos/jon_doe.jpg
view_img = "";
}
xml.endElement();
}
}
/*
* Generate field xml for Generator
*
...
...
...
*/
public static void toXmlV21(XMLWritter xml, List fields){
if(!fields.isEmpty()){
xml.startElement("label");
for(Field field:fields){
if(field.isVisible()){
if(field instanceof HiddenField){
field.setTagName(field.propertie().getProperty("tag"));
}
xml.startElement(field.getTagName());
writteAttributes(xml,field.propertie());
xml.text(field.getLabel());
xml.endElement();
}
}
xml.endElement();
xml.startElement("value");
for(Field field:fields){
if (field.isVisible() && (!(field instanceof ListField) && !(field instanceof RadioListField) && !(field instanceof CheckBoxListField))) {
if (field instanceof HiddenField) {
xml.startElement("hidden");
} else {
xml.startElement(field.getTagName());
}
writteAttributes(xml, field.propertie());
xml.text("" + field.getValue());
if (field instanceof LookupField) {
xml.setElement("lookup", field.getLookup());
}
xml.endElement();
}
}
xml.endElement();
xml.startElement("list");
for(Field field:fields){
if (field.isVisible() && (field instanceof ListField || field instanceof RadioListField || field instanceof CheckBoxListField)) {
xml.startElement(field.getTagName());
writteAttributes(xml, field.propertie());
if (field.getValue() instanceof HashMap, ?> values) {
for (Entry, ?> obj : values.entrySet()) {
xml.startElement("option");
final var valueProperty = field.propertie().get("value");
if (field instanceof ListField && obj.getKey() != null && valueProperty != null && valueProperty.toString().equals(obj.getKey().toString())) {
xml.writeAttribute("selected", "true");
} else if ((field instanceof CheckBoxListField || field instanceof RadioListField) && obj.getKey() != null && valueProperty != null && valueProperty.toString().equals(obj.getKey().toString())) {
xml.writeAttribute("checked", "true");
}
xml.setElement("text", obj.getValue().toString());
if (obj.getKey() == null || obj.getKey().toString().isEmpty())
xml.emptyTag("value");
else
xml.setElement("value", obj.getKey().toString());
xml.endElement();
}
}
xml.endElement();
}
}
xml.endElement();
}
}
/*Generate attributes
* name="p_text_1" type="text"
*/
public static void writteAttributes(XMLWritter xml,java.util.Properties properties) {
for(Entry