Search in sources :

Example 76 with JDOMException

use of org.jdom2.JDOMException in project jPOS by jpos.

the class FSDMsg method unpack.

protected void unpack(InputStreamReader r, Element schema) throws IOException, JDOMException {
    String keyOff = "";
    String defaultKey = "";
    for (Element elem : (List<Element>) schema.getChildren("field")) {
        String id = elem.getAttributeValue("id");
        int length = Integer.parseInt(elem.getAttributeValue("length"));
        String type = elem.getAttributeValue("type").toUpperCase();
        String separator = elem.getAttributeValue("separator");
        if (type != null && separator == null) {
            separator = getSeparatorType(type);
        }
        boolean key = "true".equals(elem.getAttributeValue("key"));
        Map properties = key ? loadProperties(elem) : Collections.EMPTY_MAP;
        String value = readField(r, id, length, type, separator);
        if (key) {
            keyOff = keyOff + normalizeKeyValue(value, properties);
            defaultKey += elem.getAttributeValue("default-key");
        }
        if ("K".equals(type) && !value.equals(elem.getText()))
            throw new IllegalArgumentException("Field " + id + " value='" + value + "' expected='" + elem.getText() + "'");
    }
    if (keyOff.length() > 0) {
        unpack(r, getSchema(getId(schema), keyOff, defaultKey));
    }
}
Also used : Element(org.jdom2.Element) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 77 with JDOMException

use of org.jdom2.JDOMException in project jPOS by jpos.

the class FSDMsg method pack.

protected void pack(Element schema, StringBuilder sb) throws JDOMException, IOException, ISOException {
    String keyOff = "";
    String defaultKey = "";
    for (Element elem : (List<Element>) schema.getChildren("field")) {
        String id = elem.getAttributeValue("id");
        int length = Integer.parseInt(elem.getAttributeValue("length"));
        String type = elem.getAttributeValue("type");
        // For backward compatibility, look for a separator at the end of the type attribute, if no separator has been defined.
        String separator = elem.getAttributeValue("separator");
        if (type != null && separator == null) {
            separator = getSeparatorType(type);
        }
        boolean key = "true".equals(elem.getAttributeValue("key"));
        Map properties = key ? loadProperties(elem) : Collections.EMPTY_MAP;
        String defValue = elem.getText();
        // If properties were specified, then the defValue contains lots of \n and \t in it. It should just be set to the empty string, or null.
        if (!properties.isEmpty()) {
            defValue = defValue.replace("\n", "").replace("\t", "").replace("\r", "");
        }
        String value = get(id, type, length, defValue, separator);
        sb.append(value);
        if (isSeparated(separator)) {
            char c = getSeparator(separator);
            if (c > 0)
                sb.append(c);
        }
        if (key) {
            String v = isBinary(type) ? ISOUtil.hexString(value.getBytes(charset)) : value;
            keyOff = keyOff + normalizeKeyValue(v, properties);
            defaultKey += elem.getAttributeValue("default-key");
        }
    }
    if (keyOff.length() > 0)
        pack(getSchema(getId(schema), keyOff, defaultKey), sb);
}
Also used : Element(org.jdom2.Element) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Element (org.jdom2.Element)60 JDOMException (org.jdom2.JDOMException)34 IOException (java.io.IOException)29 Document (org.jdom2.Document)24 File (java.io.File)22 SAXBuilder (org.jdom2.input.SAXBuilder)22 XmlFile (jmri.jmrit.XmlFile)12 ArrayList (java.util.ArrayList)9 List (java.util.List)8 URL (java.net.URL)7 FileNotFoundException (java.io.FileNotFoundException)6 HashMap (java.util.HashMap)5 BufferedInputStream (java.io.BufferedInputStream)4 FileInputStream (java.io.FileInputStream)4 NoProcessSpecifiedException (de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NoProcessSpecifiedException)3 NotAuthorizedToOverrideException (de.hpi.bpt.scylla.creation.SimulationConfiguration.SimulationConfigurationCreator.NotAuthorizedToOverrideException)3 HeadlessException (java.awt.HeadlessException)3 Attribute (org.jdom2.Attribute)3 ScalingFileChooser (de.hpi.bpt.scylla.GUI.ScalingFileChooser)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2