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));
}
}
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);
}
Aggregations