From 620fa82e50aa2198ed324036bbf3a6019e5890ed Mon Sep 17 00:00:00 2001 From: Shai Almog <67850168+shai-almog@users.noreply.github.com> Date: Tue, 17 Feb 2026 06:16:13 +0200 Subject: [PATCH] Expand XML parser coverage and wire test into designer CI --- .github/workflows/designer.yml | 10 + CodenameOneDesigner/build.xml | 3 - .../nbproject/project.properties | 10 +- .../codename1/ui/util/EditableResources.java | 11 +- .../src/com/codename1/ui/util/xml/Border.java | 44 ----- .../src/com/codename1/ui/util/xml/Data.java | 12 +- .../src/com/codename1/ui/util/xml/Entry.java | 17 +- .../src/com/codename1/ui/util/xml/Font.java | 52 ++++-- .../com/codename1/ui/util/xml/Gradient.java | 37 ++-- .../src/com/codename1/ui/util/xml/Image.java | 21 ++- .../src/com/codename1/ui/util/xml/L10n.java | 17 +- .../src/com/codename1/ui/util/xml/Lang.java | 17 +- .../com/codename1/ui/util/xml/LegacyFont.java | 12 +- .../ui/util/xml/ResourceFileXML.java | 48 +++-- .../ui/util/xml/SimpleXmlParser.java | 172 ++++++++++++++++++ .../src/com/codename1/ui/util/xml/Theme.java | 32 ++-- .../src/com/codename1/ui/util/xml/Ui.java | 12 +- .../src/com/codename1/ui/util/xml/Val.java | 17 +- .../ui/util/xml/comps/ArrayEntry.java | 8 - .../ui/util/xml/comps/CommandEntry.java | 16 -- .../ui/util/xml/comps/ComponentEntry.java | 105 ----------- .../codename1/ui/util/xml/comps/Custom.java | 19 -- .../ui/util/xml/comps/LayoutConstraint.java | 15 -- .../codename1/ui/util/xml/comps/MapItems.java | 10 - .../ui/util/xml/comps/StringEntry.java | 7 - .../nbproject/project.properties | 2 - maven/designer/pom.xml | 21 +-- .../ui/util/xml/SimpleXmlParserTest.java | 159 ++++++++++++++++ maven/javase-svg/pom.xml | 10 + 29 files changed, 530 insertions(+), 386 deletions(-) create mode 100644 CodenameOneDesigner/src/com/codename1/ui/util/xml/SimpleXmlParser.java create mode 100644 maven/designer/src/test/java/com/codename1/ui/util/xml/SimpleXmlParserTest.java diff --git a/.github/workflows/designer.yml b/.github/workflows/designer.yml index a31f22a7a0..0fac4af16c 100644 --- a/.github/workflows/designer.yml +++ b/.github/workflows/designer.yml @@ -6,12 +6,14 @@ on: - master paths: - 'CodenameOneDesigner/**' + - 'maven/designer/**' - '.github/workflows/designer.yml' pull_request: branches: - master paths: - 'CodenameOneDesigner/**' + - 'maven/designer/**' - '.github/workflows/designer.yml' jobs: @@ -47,6 +49,14 @@ jobs: - name: Run designer CSS localization tests run: xvfb-run -a ant -noinput -buildfile CodenameOneDesigner/build.xml test-css-localization + - name: Run designer XML parser unit tests (Maven) + run: | + mkdir -p maven/target + rm -rf maven/target/cn1-binaries + cp -R ../cn1-binaries maven/target/cn1-binaries + cd maven + mvn -B -pl designer -am -DunitTests=true -Dcodename1.platform=javase -Plocal-dev-javase -Dmaven.javadoc.skip=true -Dmaven.antrun.skip=true -Dtest=SimpleXmlParserTest -DfailIfNoTests=false test + - name: Build designer release jar run: xvfb-run -a ant -noinput -buildfile CodenameOneDesigner/build.xml release diff --git a/CodenameOneDesigner/build.xml b/CodenameOneDesigner/build.xml index cf821e97d0..cdfb14154f 100644 --- a/CodenameOneDesigner/build.xml +++ b/CodenameOneDesigner/build.xml @@ -128,11 +128,8 @@ - - - diff --git a/CodenameOneDesigner/nbproject/project.properties b/CodenameOneDesigner/nbproject/project.properties index 740b858f2e..37debc1f74 100644 --- a/CodenameOneDesigner/nbproject/project.properties +++ b/CodenameOneDesigner/nbproject/project.properties @@ -59,12 +59,8 @@ file.reference.swing-layout-1.0.4.jar=../../cn1-binaries/designer/swing-layout/s file.reference.swing-worker-1.1.jar=../../cn1-binaries/designer/swing-app-framework/swing-worker-1.1.jar file.reference.swingx-beaninfo-1.6.2.jar=../../cn1-binaries/designer/swingx-beaninfo-1.6.2.jar file.reference.swingx-core-1.6.2.jar=../../cn1-binaries/designer/swingx-core-1.6.2.jar -file.reference.xalan-2.6.0.jar=../../cn1-binaries/svg/xalan-2.6.0.jar file.reference.xml-apis-ext.jar=../../cn1-binaries/svg/xml-apis-ext.jar file.reference.xml-apis.jar=../../cn1-binaries/svg/xml-apis.jar -file.reference.jaxb-api-2.2.3.jar=../../cn1-binaries/designer/jaxb-api-2.2.3.jar -file.reference.jaxb-impl-2.3.0.1.jar=../../cn1-binaries/designer/jaxb-impl-2.3.0.1.jar -file.reference.jaxb-core-2.3.0.1.jar=../../cn1-binaries/designer/jaxb-core-2.3.0.1.jar includes=** jar.compress=false javac.classpath=\ @@ -95,16 +91,12 @@ javac.classpath=\ ${file.reference.batik-util.jar}:\ ${file.reference.batik-xml.jar}:\ ${file.reference.js.jar}:\ - ${file.reference.xalan-2.6.0.jar}:\ ${file.reference.xml-apis-ext.jar}:\ ${file.reference.xml-apis.jar}:\ ${reference.CodenameOne.jar}:\ ${reference.JavaSEWithSVGSupport.jar}:\ ${file.reference.flute.jar}:\ - ${file.reference.sac-1.3.jar}:\ - ${file.reference.jaxb-api-2.2.3.jar}:\ - ${file.reference.jaxb-impl-2.3.0.1.jar}:\ - ${file.reference.jaxb-core-2.3.0.1.jar} + ${file.reference.sac-1.3.jar} # Space-separated list of extra javac options javac.compilerargs= diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/EditableResources.java b/CodenameOneDesigner/src/com/codename1/ui/util/EditableResources.java index cd6adf4a9a..7a0ebeb2a2 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/EditableResources.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/EditableResources.java @@ -59,6 +59,7 @@ import com.codename1.ui.util.xml.Lang; import com.codename1.ui.util.xml.LegacyFont; import com.codename1.ui.util.xml.ResourceFileXML; +import com.codename1.ui.util.xml.SimpleXmlParser; import com.codename1.ui.util.xml.Theme; import com.codename1.ui.util.xml.Ui; import com.codename1.ui.util.xml.Val; @@ -100,8 +101,6 @@ import javax.swing.event.TreeModelListener; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; /** * This class enhances the resources class by inheriting it and using package @@ -410,8 +409,7 @@ public void openFileWithXMLSupport(File f) throws IOException { File resDir = new File(res, f.getName().substring(0, f.getName().length() - 4)); // open the XML file... - JAXBContext ctx = JAXBContext.newInstance(ResourceFileXML.class); - ResourceFileXML xmlData = (ResourceFileXML)ctx.createUnmarshaller().unmarshal(xml); + ResourceFileXML xmlData = SimpleXmlParser.parse(xml, ResourceFileXML.class); boolean normalize = xmlData.getMajorVersion() > 1 || xmlData.getMinorVersion() > 5; majorVersion = (short)xmlData.getMajorVersion(); @@ -791,9 +789,8 @@ public void openFileWithXMLSupport(File f) throws IOException { // place renderers first final ArrayList renderers = new ArrayList(); for(Ui d : xmlData.getUi()) { - JAXBContext componentContext = JAXBContext.newInstance(ComponentEntry.class); File uiFile = new File(resDir, normalizeFileName(d.getName()) + ".ui"); - ComponentEntry uiXMLData = (ComponentEntry)componentContext.createUnmarshaller().unmarshal(uiFile); + ComponentEntry uiXMLData = SimpleXmlParser.parse(uiFile, ComponentEntry.class); guiElements.add(uiXMLData); uiXMLData.findRendererers(renderers); } @@ -871,7 +868,7 @@ public int compare(ComponentEntry o1, ComponentEntry o2) { } return; - } catch(JAXBException err) { + } catch(RuntimeException err) { err.printStackTrace(); } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Border.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Border.java index 759a2c4c21..cb8ceb94f8 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Border.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Border.java @@ -22,129 +22,85 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="border") -@XmlAccessorType(XmlAccessType.FIELD) public class Border { - @XmlAttribute private String key; - @XmlAttribute private String type; - @XmlAttribute private Float thickness; - @XmlAttribute private String css; - @XmlAttribute private boolean millimeters; - @XmlAttribute private Integer color; - @XmlAttribute private Integer colorB; - @XmlAttribute private Integer colorC; - @XmlAttribute private Integer colorD; - @XmlAttribute private Integer arcW; - @XmlAttribute private Integer arcH; - @XmlAttribute private String i1; - @XmlAttribute private String i2; - @XmlAttribute private String i3; - @XmlAttribute private String i4; - @XmlAttribute private String i5; - @XmlAttribute private String i6; - @XmlAttribute private String i7; - @XmlAttribute private String i8; - @XmlAttribute private String i9; - @XmlAttribute private int roundBorderColor; - @XmlAttribute private int opacity = 255; - @XmlAttribute private int strokeColor; - @XmlAttribute private int strokeOpacity = 255; - @XmlAttribute private float strokeThickness; - @XmlAttribute private boolean strokeMM; - @XmlAttribute private float shadowSpread; - @XmlAttribute private int shadowOpacity = 0; - @XmlAttribute private float shadowX = 0.5f; - @XmlAttribute private float shadowY = 0.5f; - @XmlAttribute private float shadowBlur = 10; - @XmlAttribute private boolean shadowMM; - @XmlAttribute private boolean rectangle; - @XmlAttribute private float cornerRadius; - @XmlAttribute private boolean bezierCorners; - @XmlAttribute private boolean topOnlyMode; - @XmlAttribute private boolean bottomOnlyMode; /** diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Data.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Data.java index 08bd70120f..2c77ac1ce6 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Data.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Data.java @@ -22,21 +22,13 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="data") -@XmlAccessorType(XmlAccessType.FIELD) public class Data { - @XmlAttribute private String name; /** @@ -45,4 +37,8 @@ public class Data { public String getName() { return name; } + + public void setName(String name) { + this.name = name; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Entry.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Entry.java index 6929e83635..12c8ff80ad 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Entry.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Entry.java @@ -22,24 +22,15 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="entry") -@XmlAccessorType(XmlAccessType.FIELD) public class Entry { - @XmlAttribute private String key; - @XmlAttribute private String value; /** @@ -55,4 +46,12 @@ public String getKey() { public String getValue() { return value; } + + public void setKey(String key) { + this.key = key; + } + + public void setValue(String value) { + this.value = value; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Font.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Font.java index 131684f822..3e83185e7c 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Font.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Font.java @@ -22,45 +22,29 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="font") -@XmlAccessorType(XmlAccessType.FIELD) public class Font { - @XmlAttribute private String key; - @XmlAttribute private String type; - @XmlAttribute private String name; - @XmlAttribute private Integer face; - @XmlAttribute private Integer style; - @XmlAttribute private Integer size; - @XmlAttribute private String family; - @XmlAttribute private Integer sizeSettings; - @XmlAttribute private Float actualSize; /** @@ -125,4 +109,40 @@ public Integer getSizeSettings() { public Float getActualSize() { return actualSize; } + + public void setKey(String key) { + this.key = key; + } + + public void setType(String type) { + this.type = type; + } + + public void setName(String name) { + this.name = name; + } + + public void setFace(Integer face) { + this.face = face; + } + + public void setStyle(Integer style) { + this.style = style; + } + + public void setSize(Integer size) { + this.size = size; + } + + public void setFamily(String family) { + this.family = family; + } + + public void setSizeSettings(Integer sizeSettings) { + this.sizeSettings = sizeSettings; + } + + public void setActualSize(Float actualSize) { + this.actualSize = actualSize; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Gradient.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Gradient.java index e5c7ff4b61..fca0e3ddd1 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Gradient.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Gradient.java @@ -22,36 +22,23 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="gradient") -@XmlAccessorType(XmlAccessType.FIELD) public class Gradient { - @XmlAttribute private String key; - @XmlAttribute private Integer color1; - @XmlAttribute private Integer color2; - @XmlAttribute private Float posX; - @XmlAttribute private Float posY; - @XmlAttribute private Float radius; /** @@ -95,4 +82,28 @@ public Float getPosY() { public Float getRadius() { return radius; } + + public void setKey(String key) { + this.key = key; + } + + public void setColor1(Integer color1) { + this.color1 = color1; + } + + public void setColor2(Integer color2) { + this.color2 = color2; + } + + public void setPosX(Float posX) { + this.posX = posX; + } + + public void setPosY(Float posY) { + this.posY = posY; + } + + public void setRadius(Float radius) { + this.radius = radius; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Image.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Image.java index 077f519f29..c8fd3b41df 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Image.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Image.java @@ -22,26 +22,17 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="image") -@XmlAccessorType(XmlAccessType.FIELD) public class Image { - @XmlAttribute private String name; - @XmlAttribute private String baseUrl; - @XmlAttribute private String type; /** @@ -64,4 +55,16 @@ public String getBaseUrl() { public String getType() { return type; } + + public void setName(String name) { + this.name = name; + } + + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl; + } + + public void setType(String type) { + this.type = type; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/L10n.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/L10n.java index 2db6026167..658c230d7e 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/L10n.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/L10n.java @@ -22,24 +22,15 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="l10n") -@XmlAccessorType(XmlAccessType.FIELD) public class L10n { - @XmlAttribute private String name; - @XmlElement private Lang[] lang; /** @@ -52,4 +43,12 @@ public String getName() { public Lang[] getLang() { return lang; } + + public void setName(String name) { + this.name = name; + } + + public void setLang(Lang[] lang) { + this.lang = lang; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Lang.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Lang.java index e64fb93955..a19d417369 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Lang.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Lang.java @@ -22,24 +22,15 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="lang") -@XmlAccessorType(XmlAccessType.FIELD) public class Lang { - @XmlAttribute private String name; - @XmlElement private Entry[] entry; /** @@ -52,4 +43,12 @@ public String getName() { public Entry[] getEntry() { return entry; } + + public void setName(String name) { + this.name = name; + } + + public void setEntry(Entry[] entry) { + this.entry = entry; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/LegacyFont.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/LegacyFont.java index 3863e4d5d7..59367f62e2 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/LegacyFont.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/LegacyFont.java @@ -22,21 +22,13 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="legacyFont") -@XmlAccessorType(XmlAccessType.FIELD) public class LegacyFont { - @XmlAttribute private String name; /** @@ -45,4 +37,8 @@ public class LegacyFont { public String getName() { return name; } + + public void setName(String name) { + this.name = name; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/ResourceFileXML.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/ResourceFileXML.java index 431f71125b..4d9e3a4817 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/ResourceFileXML.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/ResourceFileXML.java @@ -22,45 +22,29 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * A JAXB XML object for loading the resource file into RAM * * @author Shai Almog */ -@XmlRootElement(name="resource") -@XmlAccessorType(XmlAccessType.FIELD) public class ResourceFileXML { - @XmlAttribute private int majorVersion; - @XmlAttribute private int minorVersion; - @XmlElement private Theme[] theme; - @XmlElement private Ui[] ui; - @XmlElement private LegacyFont[] legacyFont; - @XmlElement private Data[] data; - @XmlElement private Image[] image; - @XmlElement private L10n[] l10n; - @XmlAttribute private boolean useXmlUI; /** @@ -70,6 +54,10 @@ public int getMajorVersion() { return majorVersion; } + public void setMajorVersion(int majorVersion) { + this.majorVersion = majorVersion; + } + /** * @return the minorVersion */ @@ -77,6 +65,10 @@ public int getMinorVersion() { return minorVersion; } + public void setMinorVersion(int minorVersion) { + this.minorVersion = minorVersion; + } + /** * @return the theme */ @@ -84,6 +76,10 @@ public Theme[] getTheme() { return theme; } + public void setTheme(Theme[] theme) { + this.theme = theme; + } + /** * @return the ui */ @@ -91,6 +87,10 @@ public Ui[] getUi() { return ui; } + public void setUi(Ui[] ui) { + this.ui = ui; + } + /** * @return the legacyFont */ @@ -98,6 +98,10 @@ public LegacyFont[] getLegacyFont() { return legacyFont; } + public void setLegacyFont(LegacyFont[] legacyFont) { + this.legacyFont = legacyFont; + } + /** * @return the data */ @@ -105,6 +109,10 @@ public Data[] getData() { return data; } + public void setData(Data[] data) { + this.data = data; + } + /** * @return the image */ @@ -112,6 +120,10 @@ public Image[] getImage() { return image; } + public void setImage(Image[] image) { + this.image = image; + } + /** * @return the l10n */ @@ -119,6 +131,10 @@ public L10n[] getL10n() { return l10n; } + public void setL10n(L10n[] l10n) { + this.l10n = l10n; + } + /** * @return the useXmlUI */ diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/SimpleXmlParser.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/SimpleXmlParser.java new file mode 100644 index 0000000000..78c730901e --- /dev/null +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/SimpleXmlParser.java @@ -0,0 +1,172 @@ +package com.codename1.ui.util.xml; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.File; +import java.lang.reflect.Array; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import javax.xml.parsers.DocumentBuilderFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Lightweight XML-to-bean parser used to avoid JAXB runtime dependencies. + */ +public final class SimpleXmlParser { + private SimpleXmlParser() { + } + + public static T parse(File xml, Class type) { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(false); + Document doc = factory.newDocumentBuilder().parse(xml); + Element root = doc.getDocumentElement(); + return parseElement(root, type); + } catch (Exception ex) { + throw new IllegalStateException("Failed to parse XML file " + xml, ex); + } + } + + @SuppressWarnings("unchecked") + private static T parseElement(Element element, Class type) throws Exception { + T instance = type.getDeclaredConstructor().newInstance(); + BeanInfo beanInfo = Introspector.getBeanInfo(type, Object.class); + Map properties = new HashMap(); + for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) { + if (pd.getWriteMethod() != null) { + properties.put(pd.getName(), pd); + } + } + + NamedNodeMap attrs = element.getAttributes(); + for (int i = 0; i < attrs.getLength(); i++) { + Node attr = attrs.item(i); + PropertyDescriptor pd = properties.get(attr.getNodeName()); + if (pd == null) { + continue; + } + invokeSetter(instance, pd.getWriteMethod(), convert(attr.getNodeValue(), pd.getPropertyType())); + } + + Map> childrenByTag = new HashMap>(); + NodeList children = element.getChildNodes(); + for (int i = 0; i < children.getLength(); i++) { + Node child = children.item(i); + if (child.getNodeType() != Node.ELEMENT_NODE) { + continue; + } + String tag = child.getNodeName(); + List list = childrenByTag.get(tag); + if (list == null) { + list = new ArrayList(); + childrenByTag.put(tag, list); + } + list.add((Element) child); + } + + for (PropertyDescriptor pd : properties.values()) { + Method setter = pd.getWriteMethod(); + Class propertyType = pd.getPropertyType(); + List propertyChildren = childrenByTag.get(pd.getName()); + + if (propertyType.isArray()) { + if (propertyChildren == null) { + continue; + } + Class componentType = propertyType.getComponentType(); + Object arr = Array.newInstance(componentType, propertyChildren.size()); + for (int i = 0; i < propertyChildren.size(); i++) { + Element child = propertyChildren.get(i); + Object value = isSimple(componentType) + ? convert(child.getTextContent(), componentType) + : parseElement(child, componentType); + Array.set(arr, i, value); + } + invokeSetter(instance, setter, arr); + continue; + } + + if (propertyChildren != null && !propertyChildren.isEmpty()) { + Element child = propertyChildren.get(0); + Object value = isSimple(propertyType) + ? convert(child.getTextContent(), propertyType) + : parseElement(child, propertyType); + invokeSetter(instance, setter, value); + continue; + } + + if ("value".equals(pd.getName()) && isSimple(propertyType)) { + String text = element.getTextContent(); + if (text != null) { + text = text.trim(); + } + if (text != null && text.length() > 0) { + invokeSetter(instance, setter, convert(text, propertyType)); + } + } + } + return instance; + } + + private static void invokeSetter(Object target, Method setter, Object value) throws Exception { + if (value == null && setter.getParameterTypes()[0].isPrimitive()) { + return; + } + setter.invoke(target, value); + } + + private static boolean isSimple(Class type) { + return type == String.class + || type == Integer.class || type == Integer.TYPE + || type == Long.class || type == Long.TYPE + || type == Boolean.class || type == Boolean.TYPE + || type == Float.class || type == Float.TYPE + || type == Double.class || type == Double.TYPE + || type == Short.class || type == Short.TYPE + || type == Byte.class || type == Byte.TYPE; + } + + private static Object convert(String value, Class type) { + if (value == null) { + return null; + } + String trimmed = value.trim(); + if (type == String.class) { + return value; + } + if (trimmed.length() == 0) { + return null; + } + if (type == Integer.class || type == Integer.TYPE) { + return Integer.valueOf(trimmed); + } + if (type == Long.class || type == Long.TYPE) { + return Long.valueOf(trimmed); + } + if (type == Boolean.class || type == Boolean.TYPE) { + return Boolean.valueOf(trimmed); + } + if (type == Float.class || type == Float.TYPE) { + return Float.valueOf(trimmed); + } + if (type == Double.class || type == Double.TYPE) { + return Double.valueOf(trimmed); + } + if (type == Short.class || type == Short.TYPE) { + return Short.valueOf(trimmed); + } + if (type == Byte.class || type == Byte.TYPE) { + return Byte.valueOf(trimmed); + } + return value; + } +} diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Theme.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Theme.java index 3bc916b402..6fe957fb73 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Theme.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Theme.java @@ -22,33 +22,21 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="theme") -@XmlAccessorType(XmlAccessType.FIELD) public class Theme { - @XmlAttribute private String name; - @XmlElement private Val[] val; - @XmlElement private Gradient[] gradient; - @XmlElement private Font[] font; - @XmlElement private Border[] border; /** @@ -85,4 +73,24 @@ public Font[] getFont() { public Border[] getBorder() { return border; } + + public void setName(String name) { + this.name = name; + } + + public void setVal(Val[] val) { + this.val = val; + } + + public void setGradient(Gradient[] gradient) { + this.gradient = gradient; + } + + public void setFont(Font[] font) { + this.font = font; + } + + public void setBorder(Border[] border) { + this.border = border; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Ui.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Ui.java index 5c086a5534..1dd496c588 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Ui.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Ui.java @@ -22,21 +22,13 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="ui") -@XmlAccessorType(XmlAccessType.FIELD) public class Ui { - @XmlAttribute private String name; @@ -46,4 +38,8 @@ public class Ui { public String getName() { return name; } + + public void setName(String name) { + this.name = name; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Val.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Val.java index a93edcab60..206a54aa2a 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/Val.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/Val.java @@ -22,24 +22,15 @@ */ package com.codename1.ui.util.xml; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * Parsed XML data * * @author Shai Almog */ -@XmlRootElement(name="val") -@XmlAccessorType(XmlAccessType.FIELD) public class Val { - @XmlAttribute private String key; - @XmlAttribute private String value; /** @@ -55,5 +46,13 @@ public String getKey() { public String getValue() { return value; } + + public void setKey(String key) { + this.key = key; + } + + public void setValue(String value) { + this.value = value; + } } diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/ArrayEntry.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/ArrayEntry.java index c41a2ea2a9..cbae312564 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/ArrayEntry.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/ArrayEntry.java @@ -23,20 +23,12 @@ package com.codename1.ui.util.xml.comps; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlValue; /** * * @author Shai Almog */ -@XmlRootElement(name="arr") -@XmlAccessorType(XmlAccessType.FIELD) public class ArrayEntry { - @XmlElement private StringEntry[] value; /** diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/CommandEntry.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/CommandEntry.java index cf8110f84c..180c571245 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/CommandEntry.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/CommandEntry.java @@ -23,44 +23,28 @@ package com.codename1.ui.util.xml.comps; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlValue; /** * * @author Shai Almog */ -@XmlRootElement(name="command") -@XmlAccessorType(XmlAccessType.FIELD) public class CommandEntry { - @XmlAttribute private String name; - @XmlAttribute private String icon; - @XmlAttribute private String rolloverIcon; - @XmlAttribute private String pressedIcon; - @XmlAttribute private String disabledIcon; - @XmlAttribute private int id; - @XmlAttribute private String action; - @XmlAttribute private String argument; - @XmlAttribute private boolean backCommand; /** diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/ComponentEntry.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/ComponentEntry.java index ef70dfcba3..6ef17b4f29 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/ComponentEntry.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/ComponentEntry.java @@ -24,313 +24,208 @@ package com.codename1.ui.util.xml.comps; import java.util.List; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * XML representation for a component in the UI tree * * @author Shai Almog */ -@XmlRootElement(name="component") -@XmlAccessorType(XmlAccessType.FIELD) public class ComponentEntry { - @XmlAttribute private String name; - @XmlElement private Custom[] custom; - @XmlElement private LayoutConstraint layoutConstraint; - @XmlElement private ComponentEntry[] component; - @XmlElement private StringEntry[] stringItem; - @XmlElement private MapItems[] mapItems; - @XmlAttribute private String type; - @XmlAttribute private String baseForm; - @XmlAttribute private String cloudBoundProperty; - @XmlAttribute private String cloudDestinationProperty; - @XmlAttribute private String embed; - @XmlAttribute private String uiid; - @XmlAttribute private Boolean focusable; - @XmlAttribute private Boolean enabled; - @XmlAttribute private Boolean rtl; - @XmlAttribute private Boolean scrollVisible; - @XmlAttribute private Boolean tensileDragEnabled; - @XmlAttribute private Boolean tactileTouch; - @XmlAttribute private Boolean snapToGrid; - @XmlAttribute private Boolean flatten; - @XmlAttribute private Boolean scrollableX; - @XmlAttribute private Boolean scrollableY; - @XmlAttribute private Integer tabPlacement; - @XmlAttribute private Integer tabTextPosition; - @XmlAttribute private String tabTitle; - @XmlAttribute private String layout; - @XmlAttribute private Boolean flowLayoutFillRows; - @XmlAttribute private Integer flowLayoutAlign; - @XmlAttribute private Integer flowLayoutValign; - @XmlAttribute private Boolean borderLayoutAbsoluteCenter; - @XmlAttribute private String borderLayoutSwapNorth; - @XmlAttribute private String borderLayoutSwapEast; - @XmlAttribute private String borderLayoutSwapWest; - @XmlAttribute private String borderLayoutSwapSouth; - @XmlAttribute private String borderLayoutSwapCenter; - @XmlAttribute private Integer gridLayoutRows; - @XmlAttribute private Integer gridLayoutColumns; - @XmlAttribute private String boxLayoutAxis; - @XmlAttribute private Integer tableLayoutRows; - @XmlAttribute private Integer tableLayoutColumns; - @XmlAttribute private String nextForm; - @XmlAttribute private String title; - @XmlAttribute private Boolean cyclicFocus; - @XmlAttribute private String dialogUIID; - @XmlAttribute private Boolean disposeWhenPointerOutOfBounds; - @XmlAttribute private String dialogPosition; - @XmlElement private CommandEntry[] command; - @XmlAttribute private String selectedRenderer; - @XmlAttribute private String unselectedRenderer; - @XmlAttribute private String selectedRendererEven; - @XmlAttribute private String unselectedRendererEven; - @XmlAttribute private String text; - @XmlAttribute private Integer alignment; - @XmlAttribute private String icon; - @XmlAttribute private String rolloverIcon; - @XmlAttribute private String pressedIcon; - @XmlAttribute private String disabledIcon; - @XmlAttribute private Boolean toggle; - @XmlAttribute private Boolean editable; - @XmlAttribute private Boolean infinite; - @XmlAttribute private String thumbImage; - @XmlAttribute private Integer progress; - @XmlAttribute private Boolean vertical; - @XmlAttribute private Integer increments; - @XmlAttribute private Integer maxValue; - @XmlAttribute private Integer minValue; - @XmlAttribute private Boolean renderPercentageOnTop; - @XmlAttribute private String group; - @XmlAttribute private Boolean selected; - @XmlAttribute private Integer gap; - @XmlAttribute private Integer verticalAlignment; - @XmlAttribute private Integer textPosition; - @XmlAttribute private Boolean growByContent; - @XmlAttribute private Integer constraint; - @XmlAttribute private Integer maxSize; - @XmlAttribute private String hint; - @XmlAttribute private String hintIcon; - @XmlAttribute private Integer columns; - @XmlAttribute private Integer rows; - @XmlAttribute private Integer itemGap; - @XmlAttribute private Integer fixedSelection; - @XmlAttribute private Integer orientation; - @XmlAttribute private String labelFor; - @XmlAttribute private String leadComponent; - @XmlAttribute private String nextFocusDown; - @XmlAttribute private String nextFocusUp; - @XmlAttribute private String nextFocusLeft; - @XmlAttribute private String nextFocusRight; - @XmlAttribute private String commandName; - @XmlAttribute private String commandIcon; - @XmlAttribute private String commandRolloverIcon; - @XmlAttribute private String commandPressedIcon; - @XmlAttribute private String commandDisabledIcon; - @XmlAttribute private Integer commandId; - @XmlAttribute private String commandAction; - @XmlAttribute private String commandArgument; - @XmlAttribute private Boolean commandBack; - @XmlAttribute private String clientProperties; /** diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/Custom.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/Custom.java index c0941598c7..85a2832494 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/Custom.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/Custom.java @@ -23,53 +23,34 @@ package com.codename1.ui.util.xml.comps; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; /** * * @author Shai Almog */ -@XmlRootElement(name="custom") -@XmlAccessorType(XmlAccessType.FIELD) public class Custom { - @XmlAttribute private String name; - @XmlAttribute private String type; - @XmlAttribute private int dimensions; - @XmlAttribute private String value; - @XmlElement private StringEntry[] str; - @XmlElement private ArrayEntry[] arr; - @XmlAttribute private String selectedRenderer; - @XmlAttribute private String unselectedRenderer; - @XmlAttribute private String selectedRendererEven; - @XmlAttribute private String unselectedRendererEven; - @XmlElement private MapItems[] mapItems; - @XmlElement private StringEntry[] stringItem; /** diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/LayoutConstraint.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/LayoutConstraint.java index aea56c1fac..e86bdd0452 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/LayoutConstraint.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/LayoutConstraint.java @@ -23,44 +23,29 @@ package com.codename1.ui.util.xml.comps; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlAttribute; -import javax.xml.bind.annotation.XmlRootElement; /** * * @author Shai Almog */ -@XmlRootElement(name="layoutConstraint") -@XmlAccessorType(XmlAccessType.FIELD) public class LayoutConstraint { - @XmlAttribute private String value; - @XmlAttribute private int row; - @XmlAttribute private int column; - @XmlAttribute private int height; - @XmlAttribute private int width; - @XmlAttribute private int align; - @XmlAttribute private int valign; - @XmlAttribute private int spanHorizontal; - @XmlAttribute private int spanVertical; /** diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/MapItems.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/MapItems.java index a1fc9a10dd..fa2efa74a4 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/MapItems.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/MapItems.java @@ -24,26 +24,16 @@ package com.codename1.ui.util.xml.comps; import com.codename1.ui.util.xml.Val; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlValue; /** * * @author Shai Almog */ -@XmlRootElement(name="mapItems") -@XmlAccessorType(XmlAccessType.FIELD) public class MapItems { - @XmlElement private Val[] imageItem; - @XmlElement private Val[] actionItem; - @XmlElement private Val[] stringItem; /** diff --git a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/StringEntry.java b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/StringEntry.java index 71efca3424..6596f44ba4 100644 --- a/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/StringEntry.java +++ b/CodenameOneDesigner/src/com/codename1/ui/util/xml/comps/StringEntry.java @@ -23,19 +23,12 @@ package com.codename1.ui.util.xml.comps; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlValue; /** * * @author Shai Almog */ -@XmlRootElement(name="str") -@XmlAccessorType(XmlAccessType.FIELD) public class StringEntry { - @XmlValue private String value; /** diff --git a/Ports/JavaSEWithSVGSupport/nbproject/project.properties b/Ports/JavaSEWithSVGSupport/nbproject/project.properties index 45deaac04e..9e35ff7367 100644 --- a/Ports/JavaSEWithSVGSupport/nbproject/project.properties +++ b/Ports/JavaSEWithSVGSupport/nbproject/project.properties @@ -46,7 +46,6 @@ file.reference.batik-transcoder.jar=../../../cn1-binaries/svg/batik-transcoder.j file.reference.batik-util.jar=../../../cn1-binaries/svg/batik-util.jar file.reference.batik-xml.jar=../../../cn1-binaries/svg/batik-xml.jar file.reference.js.jar=../../../cn1-binaries/svg/js.jar -file.reference.xalan-2.6.0.jar=../../../cn1-binaries/svg/xalan-2.6.0.jar file.reference.xerces_2_5_0.jar=../../../cn1-binaries/svg/xerces_2_5_0.jar file.reference.xml-apis-ext.jar=../../../cn1-binaries/svg/xml-apis-ext.jar file.reference.xml-apis.jar=../../../cn1-binaries/svg/xml-apis.jar @@ -74,7 +73,6 @@ javac.classpath=\ ${file.reference.batik-util.jar}:\ ${file.reference.batik-xml.jar}:\ ${file.reference.js.jar}:\ - ${file.reference.xalan-2.6.0.jar}:\ ${file.reference.xerces_2_5_0.jar}:\ ${file.reference.xml-apis-ext.jar}:\ ${file.reference.xml-apis.jar} diff --git a/maven/designer/pom.xml b/maven/designer/pom.xml index d41c565341..0745ea4749 100644 --- a/maven/designer/pom.xml +++ b/maven/designer/pom.xml @@ -78,26 +78,17 @@ sac 1.3 - - - javax.xml.bind - jaxb-api - - - - com.sun.xml.bind - jaxb-impl - - - - com.sun.xml.bind - jaxb-core - org.junit.jupiter junit-jupiter-engine test + + junit + junit + 4.13.2 + test + diff --git a/maven/designer/src/test/java/com/codename1/ui/util/xml/SimpleXmlParserTest.java b/maven/designer/src/test/java/com/codename1/ui/util/xml/SimpleXmlParserTest.java new file mode 100644 index 0000000000..0bc09e6312 --- /dev/null +++ b/maven/designer/src/test/java/com/codename1/ui/util/xml/SimpleXmlParserTest.java @@ -0,0 +1,159 @@ +package com.codename1.ui.util.xml; + +import com.codename1.ui.util.xml.comps.ArrayEntry; +import com.codename1.ui.util.xml.comps.CommandEntry; +import com.codename1.ui.util.xml.comps.ComponentEntry; +import com.codename1.ui.util.xml.comps.Custom; +import com.codename1.ui.util.xml.comps.LayoutConstraint; +import com.codename1.ui.util.xml.comps.MapItems; +import com.codename1.ui.util.xml.comps.StringEntry; +import java.io.File; +import java.io.FileWriter; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class SimpleXmlParserTest { + + @Test + public void parseResourceFileXml() throws Exception { + File xml = File.createTempFile("resource", ".xml"); + xml.deleteOnExit(); + try (FileWriter out = new FileWriter(xml)) { + out.write("\n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write("\n"); + } + + ResourceFileXML parsed = SimpleXmlParser.parse(xml, ResourceFileXML.class); + assertEquals(1, parsed.getMajorVersion()); + assertEquals(6, parsed.getMinorVersion()); + assertTrue(parsed.isUseXmlUI()); + + assertNotNull(parsed.getTheme()); + assertEquals("MainTheme", parsed.getTheme()[0].getName()); + assertEquals("Button.bgColor", parsed.getTheme()[0].getVal()[0].getKey()); + assertEquals("ff00ff", parsed.getTheme()[0].getVal()[0].getValue()); + + assertEquals(Integer.valueOf(111), parsed.getTheme()[0].getGradient()[0].getColor1()); + assertEquals(Integer.valueOf(222), parsed.getTheme()[0].getGradient()[0].getColor2()); + assertEquals(Float.valueOf(0.2f), parsed.getTheme()[0].getGradient()[0].getPosX()); + + Font font = parsed.getTheme()[0].getFont()[0]; + assertEquals("system", font.getType()); + assertEquals(Integer.valueOf(1), font.getFace()); + assertEquals(Float.valueOf(11.5f), font.getActualSize()); + + Border border = parsed.getTheme()[0].getBorder()[0]; + assertEquals(1234, border.getRoundBorderColor()); + + assertEquals("MyForm", parsed.getUi()[0].getName()); + assertEquals("bitmap.fnt", parsed.getLegacyFont()[0].getName()); + assertEquals("payload.dat", parsed.getData()[0].getName()); + assertEquals("logo.png", parsed.getImage()[0].getName()); + assertEquals("svg", parsed.getImage()[1].getType()); + + assertEquals("Strings", parsed.getL10n()[0].getName()); + assertEquals("en", parsed.getL10n()[0].getLang()[0].getName()); + assertEquals("hello", parsed.getL10n()[0].getLang()[0].getEntry()[0].getKey()); + assertEquals("Hello", parsed.getL10n()[0].getLang()[0].getEntry()[0].getValue()); + } + + @Test + public void parseComponentEntryXml() throws Exception { + File xml = File.createTempFile("component", ".xml"); + xml.deleteOnExit(); + try (FileWriter out = new FileWriter(xml)) { + out.write("\n"); + out.write(" \n"); + out.write(" Title\n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" customStr\n"); + out.write(" \n"); + out.write(" row1\n"); + out.write(" row2\n"); + out.write(" \n"); + out.write(" si1\n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write(" \n"); + out.write("\n"); + } + + ComponentEntry parsed = SimpleXmlParser.parse(xml, ComponentEntry.class); + assertEquals("Main", parsed.getName()); + assertEquals("Container", parsed.getType()); + assertEquals("FlowLayout", parsed.getLayout()); + assertTrue(parsed.isFocusable()); + assertFalse(parsed.isEnabled()); + assertEquals(Integer.valueOf(3), parsed.getColumns()); + assertEquals(Integer.valueOf(2), parsed.getRows()); + assertEquals(Integer.valueOf(1), parsed.getTabPlacement()); + + LayoutConstraint constraint = parsed.getLayoutConstraint(); + assertEquals(2, constraint.getRow()); + assertEquals(3, constraint.getColumn()); + assertEquals(10, constraint.getWidth()); + assertEquals(20, constraint.getHeight()); + assertEquals(4, constraint.getAlign()); + assertEquals(5, constraint.getValign()); + assertEquals(6, constraint.getSpanHorizontal()); + assertEquals(7, constraint.getSpanVertical()); + + assertEquals("Title", parsed.getStringItem()[0].getValue()); + + MapItems mapItems = parsed.getMapItems()[0]; + assertEquals("title", mapItems.getStringItem()[0].getKey()); + assertEquals("Hello", mapItems.getStringItem()[0].getValue()); + assertEquals("icon", mapItems.getImageItem()[0].getKey()); + assertEquals("tap", mapItems.getActionItem()[0].getKey()); + + Custom custom = parsed.getCustom()[0]; + assertEquals("items", custom.getName()); + assertEquals("String[]", custom.getType()); + assertEquals(1, custom.getDimensions()); + assertNotNull(custom.getValue()); + assertEquals("customStr", custom.getStr()[0].getValue()); + assertEquals("row1", custom.getArr()[0].getValue()[0].getValue()); + assertEquals("row2", custom.getArr()[0].getValue()[1].getValue()); + assertEquals("si1", custom.getStringItem()[0].getValue()); + assertEquals("k", custom.getMapItems()[0].getStringItem()[0].getKey()); + assertEquals("SelR", custom.getSelectedRenderer()); + assertEquals("UnselR", custom.getUnselectedRenderer()); + assertEquals("SelEven", custom.getSelectedRendererEven()); + assertEquals("UnselEven", custom.getUnselectedRendererEven()); + + CommandEntry command = parsed.getCommand()[0]; + assertEquals("Back", command.getName()); + assertEquals(9, command.getId()); + assertEquals("backAction", command.getAction()); + assertEquals("arg1", command.getArgument()); + assertTrue(command.isBackCommand()); + + assertEquals(1, parsed.getComponent().length); + assertEquals("ChildLabel", parsed.getComponent()[0].getName()); + assertEquals("Label", parsed.getComponent()[0].getType()); + assertEquals("Text", parsed.getComponent()[0].getText()); + } +} diff --git a/maven/javase-svg/pom.xml b/maven/javase-svg/pom.xml index 50cf22d878..2769ed6ab4 100644 --- a/maven/javase-svg/pom.xml +++ b/maven/javase-svg/pom.xml @@ -29,6 +29,16 @@ org.apache.xmlgraphics batik-transcoder 1.17 + + + xalan + xalan + + + serializer + serializer + +