List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:com.mirth.connect.plugins.datatypes.hl7v2.ER7Reader.java
public void parse(InputSource source) throws SAXException, IOException { String message = getMessageFromSource(source); ContentHandler contentHandler = getContentHandler(); contentHandler.startDocument();/*from www . ja v a 2s. c o m*/ // first tokenize the segments if ((message == null) || (message.length() < 6)) { throw new SAXException("Unable to parse message. It is NULL or too short. " + message); } // usually | String fieldSeparator = DEFAULT_FIELD_SEPARATOR; String componentSeparator = DEFAULT_COMPONENT_SEPARATOR; String repetitionSeparator = DEFAULT_REPETITION_SEPARATOR; String escapeCharacter = DEFAULT_ESCAPE_CHARACTER; String subcomponentSeparator = DEFAULT_SUBCOMPONENT_TERMINATOR; // if we have a header, grab the actual separators from the message String firstSegment = message.substring(0, 3); if (firstSegment.equalsIgnoreCase("MSH") || firstSegment.equalsIgnoreCase("FHS") || firstSegment.equalsIgnoreCase("BHS")) { fieldSeparator = new String(new char[] { message.charAt(3) }); int nextDelimiter = message.indexOf(message.charAt(3), 4); if (nextDelimiter == -1) { // If the message is just MSH|^~\&, we still want to extract the encoding characters nextDelimiter = message.length(); } if (nextDelimiter > 4) { // usually ^ componentSeparator = new String(new char[] { message.charAt(4) }); } if (nextDelimiter > 5) { // usually ~ repetitionSeparator = new String(new char[] { message.charAt(5) }); } if (nextDelimiter > 6) { // usually \ escapeCharacter = new String(new char[] { message.charAt(6) }); } if (nextDelimiter > 7) { // usually & subcomponentSeparator = new String(new char[] { message.charAt(7) }); } } // replace the special case of ^~& with ^~\& (MIRTH-1544) if (message.length() >= 8 && "^~&|".equals(message.substring(4, 8))) { escapeCharacter = "\\"; subcomponentSeparator = "&"; repetitionSeparator = "~"; componentSeparator = "^"; } // tokenize the segments first String[] segments = StringUtils.split(message, segmentDelimiter); String documentHead = handleSegments("", contentHandler, fieldSeparator, componentSeparator, subcomponentSeparator, repetitionSeparator, escapeCharacter, segments); contentHandler.endElement("", documentHead, ""); contentHandler.endDocument(); }
From source file:net.ontopia.xml.ContentWriter.java
@Override public void endDocument() throws SAXException { try {/* w ww .j ava2s.c o m*/ out.close(); } catch (IOException e) { throw new SAXException(e); } }
From source file:hudson.util.TableNestChecker.java
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { String tagName = localName.toUpperCase(); // make sure that this tag occurs in the proper context if (!elements.peek().isAllowed(tagName)) throw new SAXException(tagName + " is not allowed inside " + tagNames.peek()); Checker next = CHECKERS.get(tagName); if (next == null) next = ALL_ALLOWED;/* w w w . j a va 2 s. com*/ elements.push(next); tagNames.push(tagName); super.startElement(uri, localName, qName, atts); }
From source file:gov.nih.nci.cabig.caaers.esb.client.ESBMessageConsumerImpl.java
public void warning(SAXParseException exception) throws SAXException { // Bring things to a crashing halt log.warn("**Parsing Warning**" + " Line: " + exception.getLineNumber() + "" + " URI: " + exception.getSystemId() + "" + " Message: " + exception.getMessage()); throw new SAXException("Warning encountered"); }
From source file:io.github.msdk.io.mzdata.MzDataSaxHandler.java
/** {@inheritDoc} */ public void startElement(String namespaceURI, String lName, String qName, Attributes attrs) throws SAXException { if (canceled) throw new SAXException("Parsing Cancelled"); // <spectrumList> if (qName.equals("spectrumList")) { String s = attrs.getValue("count"); if (s != null) totalScans = Integer.parseInt(s); }//from w w w .j ava 2s . c o m // <spectrum> if (qName.equalsIgnoreCase("spectrum")) { msLevel = 1; retentionTime = null; polarity = PolarityType.UNKNOWN; precursorMz = null; precursorCharge = null; scanNumber = Integer.parseInt(attrs.getValue("id")); } // <spectrumInstrument> 1.05 version, <acqInstrument> 1.04 version if ((qName.equalsIgnoreCase("spectrumInstrument")) || (qName.equalsIgnoreCase("acqInstrument"))) { msLevel = Integer.parseInt(attrs.getValue("msLevel")); spectrumInstrumentFlag = true; } // <cvParam> /* * The terms time.min, time.sec & mz belongs to mzData 1.04 standard. */ if (qName.equalsIgnoreCase("cvParam")) { if (spectrumInstrumentFlag) { if ((attrs.getValue("accession").equals(MzDataCV.cvPolarity)) || (attrs.getValue("name").equals("Polarity"))) { if (attrs.getValue("value").toLowerCase().equals("positive")) polarity = PolarityType.POSITIVE; else if (attrs.getValue("value").toLowerCase().equals("negative")) polarity = PolarityType.NEGATIVE; else polarity = PolarityType.UNKNOWN; } if ((attrs.getValue("accession").equals(MzDataCV.cvTimeMin)) || (attrs.getValue("name").equals("time.min"))) { retentionTime = Float.parseFloat(attrs.getValue("value")) * 60f; } if ((attrs.getValue("accession").equals(MzDataCV.cvTimeSec)) || (attrs.getValue("name").equals("time.sec"))) { retentionTime = Float.parseFloat(attrs.getValue("value")); } } if (precursorFlag) { if ((attrs.getValue("accession").equals(MzDataCV.cvPrecursorMz)) || (attrs.getValue("name").equals("mz"))) { precursorMz = Double.parseDouble(attrs.getValue("value")); } if (attrs.getValue("accession").equals(MzDataCV.cvPrecursorCharge)) { precursorCharge = Integer.parseInt(attrs.getValue("value")); } } } // <mzArrayBinary> if (qName.equalsIgnoreCase("mzArrayBinary")) { // clean the current char buffer for the new element mzArrayBinaryFlag = true; } // <intenArrayBinary> if (qName.equalsIgnoreCase("intenArrayBinary")) { // clean the current char buffer for the new element intenArrayBinaryFlag = true; } // <data> if (qName.equalsIgnoreCase("data")) { // clean the current char buffer for the new element charBuffer.setLength(0); if (mzArrayBinaryFlag) { endian = attrs.getValue("endian"); precision = attrs.getValue("precision"); String len = attrs.getValue("length"); if (len != null) peaksCount = Integer.parseInt(len); } if (intenArrayBinaryFlag) { endian = attrs.getValue("endian"); precision = attrs.getValue("precision"); String len = attrs.getValue("length"); if (len != null) peaksCount = Integer.parseInt(len); } } // <precursor> if (qName.equalsIgnoreCase("precursor")) { precursorFlag = true; } }
From source file:gov.nih.nci.cabig.caaers.esb.client.ESBMessageConsumerImpl.java
public void error(SAXParseException exception) throws SAXException { // Bring things to a crashing halt log.warn("**Parsing Error**" + " Line: " + exception.getLineNumber() + "" + " URI: " + exception.getSystemId() + "" + " Message: " + exception.getMessage()); throw new SAXException("Error encountered"); }
From source file:net.sf.joost.plugins.saxfilter.THResolver.java
/** * If given method is @SAX_METHOD return cached (or new) * Trax compatible instance.//from w ww . jav a 2 s. c o m * otherwise return null. */ private TransformerHandler resolve(String method, String href, String base, XMLReader reader, Hashtable params) throws SAXException { if (Constants.DEBUG) log.debug("sax-filter : resolve '" + method + "'"); if (!available(method)) throw new SAXException("Not supported filter-method!"); if ((reader != null) || (href != null)) throw new SAXException("Attribute 'filter-src' not allowed for method '" + method + "'"); return new SAXWrapperHandler(); }
From source file:net.sf.joost.plugins.httppostfilter.THResolver.java
/** * actual business logic related to POST. Used by both resolve methods. *//* www . j a v a 2 s .co m*/ private TransformerHandler resolve(String method, String href, String base, XMLReader reader, Hashtable params) throws SAXException { if (Constants.DEBUG) log.debug("hppt-post-filter : resolve '" + method + "'"); if (!available(method)) throw new SAXException("Not supported filter-method!"); if ((reader != null) || (href != null)) throw new SAXException("Attribute 'filter-src' not allowed for method '" + method + "'"); String v = String.valueOf(params.get("target")); if (v == null) throw new SAXException("Missing parameter 'target' for filter " + "method '" + method + "'"); return new HttpPostHandler(v); }
From source file:net.sf.firemox.xml.XmlParser.java
/** * Constructor./* w w w . j a va 2 s.com*/ * * @param validation * validation flag. * @throws SAXException */ public XmlParser(boolean validation) throws SAXException { try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(validation); parser = factory.newSAXParser(); if (validation) { parser.setProperty(JAXP_SCHEMA_LANGUAGE, XMLConstants.W3C_XML_SCHEMA_NS_URI); parser.setProperty(JAXP_SCHEMA_SOURCE, MToolKit.getFile(MP_XML_SCHEMA)); } } catch (Exception e) { throw new SAXException(e.toString()); } }
From source file:ambit.data.qmrf.Qmrf_Xml_Pdf.java
public Qmrf_Xml_Pdf(String ttffont) { super();/* w w w . ja v a2s. c om*/ try { this.ttffont = ttffont; docBuilder = docBuilderFactory.newDocumentBuilder(); nodeBuilder = docBuilderFactory.newDocumentBuilder(); nodeBuilder.setErrorHandler(new ErrorHandler() { public void error(SAXParseException arg0) throws SAXException { throw new SAXException(arg0); } public void fatalError(SAXParseException arg0) throws SAXException { throw new SAXException(arg0); } public void warning(SAXParseException arg0) throws SAXException { } }); //PRIndirectReference pri; //pri. try { baseFont = BaseFont.createFont(ttffont, //"c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); System.out.println(ttffont); } catch (Exception x) { x.printStackTrace(); baseFont = BaseFont.createFont("c:\\windows\\fonts\\times.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); System.out.println("Default font c:\\windows\\fonts\\times.ttf"); } font = new Font(baseFont, 12); bfont = new Font(baseFont, 12, Font.BOLD); } catch (Exception x) { docBuilder = null; } }