Added a new property, characterEncoding, to MessageFactory, IsoMessage, FieldParseInfo and IsoValue. This helps in parsing messages from byte buffers containing extended characters in encodings other than the default for the JVM. Tested with UTF8 on a Mac (which has default Mac OS Roman) and worked fine.
Several methods now have an additional encoding parameter (just a String, not directly a Charset), but the default is always the JVM's default encoding (taken from the property 'file.encoding'). git-svn-id: https://j8583.svn.sourceforge.net/svnroot/j8583/j8583@70 db60a039-f72e-0410-b1d2-baa000846441
This commit is contained in:
@@ -139,6 +139,7 @@ public class ConfigParser {
|
||||
NodeList fields = elem.getElementsByTagName("field");
|
||||
IsoMessage m = new IsoMessage();
|
||||
m.setType(type);
|
||||
m.setCharacterEncoding(mfact.getCharacterEncoding());
|
||||
for (int j = 0; j < fields.getLength(); j++) {
|
||||
Element f = (Element)fields.item(j);
|
||||
int num = Integer.parseInt(f.getAttribute("num"));
|
||||
@@ -172,7 +173,7 @@ public class ConfigParser {
|
||||
if (f.getAttribute("length").length() > 0) {
|
||||
length = Integer.parseInt(f.getAttribute("length"));
|
||||
}
|
||||
parseMap.put(num, FieldParseInfo.getInstance(itype, length));
|
||||
parseMap.put(num, FieldParseInfo.getInstance(itype, length, mfact.getCharacterEncoding()));
|
||||
}
|
||||
mfact.setParseMap(type, parseMap);
|
||||
}
|
||||
@@ -189,6 +190,17 @@ public class ConfigParser {
|
||||
}
|
||||
}
|
||||
|
||||
/** This method attempts to open a stream from the XML configuration in the specified URL and
|
||||
* configure the message factory from that config. */
|
||||
public static void configureFromUrl(MessageFactory mfact, URL url) throws IOException {
|
||||
InputStream stream = url.openStream();
|
||||
try {
|
||||
parse(mfact, stream);
|
||||
} finally {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
||||
/** Configures a MessageFactory using the configuration file at the path specified (will be searched
|
||||
* within the classpath using the MessageFactory's ClassLoader). This is useful for configuring
|
||||
* Spring-bound instances of MessageFactory for example. */
|
||||
|
||||
Reference in New Issue
Block a user