/** * Returns a String representing the encoding of the given message, if the * encoding is recognized. For example if the given message appears to be * encoded using HL7 2.x XML rules then "XML" would be returned. If the * encoding is not recognized then null is returned. That this method * returns a specific encoding does not guarantee that the message is * correctly encoded (e.g. well formed XML) - just that it is not encoded * using any other encoding than the one returned. */ public String getEncoding(String message) { return EncodingDetector.isEr7Encoded(message) ? getDefaultEncoding() : null; }
/** * Returns a String representing the encoding of the given message, if the * encoding is recognized. For example if the given message appears to be * encoded using HL7 2.x XML rules then "XML" would be returned. If the * encoding is not recognized then null is returned. That this method * returns a specific encoding does not guarantee that the message is * correctly encoded (e.g. well formed XML) - just that it is not encoded * using any other encoding than the one returned. */ public String getEncoding(String message) { return EncodingDetector.isEr7Encoded(message) ? getDefaultEncoding() : null; }
/** * Gets selected fields from a message, as with String[] arg version but * using DatumPaths. */ private static String[] getFields(String theMessageText, DatumPath[] thePaths) throws HL7Exception { String[] fields = new String[thePaths.length]; Properties props = new Properties(); List<DatumPath> mask = Arrays.asList(thePaths); boolean OK = false; if (EncodingDetector.isEr7Encoded(theMessageText)) { OK = ER7.parseMessage(props, mask, theMessageText); } else if (EncodingDetector.isXmlEncoded(theMessageText)) { OK = XML.parseMessage(props, theMessageText, null); } else { throw new HL7Exception("Message encoding is not recognized"); } if (!OK) { throw new HL7Exception("Parse failed"); } for (int i = 0; i < fields.length; i++) { fields[i] = props.getProperty(thePaths[i].toString()); } return fields; }
/** * Gets selected fields from a message, as with String[] arg version but * using DatumPaths. */ private static String[] getFields(String theMessageText, DatumPath[] thePaths) throws HL7Exception { String[] fields = new String[thePaths.length]; Properties props = new Properties(); List<DatumPath> mask = Arrays.asList(thePaths); boolean OK = false; if (EncodingDetector.isEr7Encoded(theMessageText)) { OK = ER7.parseMessage(props, mask, theMessageText); } else if (EncodingDetector.isXmlEncoded(theMessageText)) { OK = XML.parseMessage(props, theMessageText, null); } else { throw new HL7Exception("Message encoding is not recognized"); } if (!OK) { throw new HL7Exception("Parse failed"); } for (int i = 0; i < fields.length; i++) { fields[i] = props.getProperty(thePaths[i].toString()); } return fields; }