List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:hudson.plugins.ccm.parser.CcmParser.java
@Override public Collection<FileAnnotation> parse(InputStream file, String moduleName) throws InvocationTargetException { try {//from ww w. j a v a2 s . c o m Digester digester = new Digester(); digester.setValidating(false); digester.setClassLoader(CcmParser.class.getClassLoader()); String rootXPath = "ccm"; digester.addObjectCreate(rootXPath, Ccm.class); digester.addSetProperties(rootXPath); String fileMetric = "ccm/metric"; digester.addObjectCreate(fileMetric, Metric.class); digester.addSetProperties(fileMetric); digester.addBeanPropertySetter("ccm/metric/complexity"); digester.addBeanPropertySetter("ccm/metric/unit"); digester.addBeanPropertySetter("ccm/metric/classification"); digester.addBeanPropertySetter("ccm/metric/file"); digester.addBeanPropertySetter("ccm/metric/startLineNumber"); digester.addBeanPropertySetter("ccm/metric/endLineNumber"); digester.addSetNext(fileMetric, "addMetric", Metric.class.getName()); Ccm module = (Ccm) digester.parse(file); if (module == null) { throw new SAXException("Input stream is not a CCM file."); } return convert(module, moduleName); } catch (IOException exception) { throw new InvocationTargetException(exception); } catch (SAXException exception) { throw new InvocationTargetException(exception); } }
From source file:Main.java
/** * Parse string with XML content to {@link org.w3c.dom.Document}. * * @param xml/*from w w w . j a va 2s . c o m*/ * string with XML content * @return Document * @throws SAXException * if any parse errors occur */ public static Document getXMLDocument(final String xml) throws SAXException { try { return getNewDocumentBuilder().parse(new InputSource(new StringReader(xml))); } catch (IOException e) { throw new SAXException(e); } catch (ParserConfigurationException e) { throw new SAXException(e); } }
From source file:gov.nih.nci.cabig.caaers.esb.client.ESBMessageConsumerImpl.java
public void fatalError(SAXParseException exception) throws SAXException { // Bring things to a crashing halt log.warn("**Parsing Fatal Error**" + " Line: " + exception.getLineNumber() + "" + " URI: " + exception.getSystemId() + "" + " Message: " + exception.getMessage()); throw new SAXException("Fatal Error encountered"); }
From source file:com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb.JAXBPlistParser.java
private SAXSource createSAXSource(InputSource project, final InputSource dtd) throws SAXException, ParserConfigurationException { XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); xmlReader.setEntityResolver(new EntityResolver() { @Override/*from w w w . j av a2 s.c om*/ public InputSource resolveEntity(String pid, String sid) throws SAXException { if (sid.equals("http://www.apple.com/DTDs/PropertyList-1.0.dtd")) return dtd; throw new SAXException("unable to resolve remote entity, sid = " + sid); } }); SAXSource ss = new SAXSource(xmlReader, project); return ss; }
From source file:net.sf.ehcache.config.BeanHandler.java
/** * Creates a child element of an object. *//*w w w . ja v a 2 s . co m*/ private Object createChild(final ElementInfo parent, final String name) throws SAXException { try { // Look for a create<name> method final Class parentClass = parent.bean.getClass(); Method method = findCreateMethod(parentClass, name); if (method != null) { return method.invoke(parent.bean, new Object[] {}); } // Look for an add<name> method method = findSetMethod(parentClass, "add", name); if (method != null) { return createInstance(parent.bean, method.getParameterTypes()[0]); } } catch (final Exception e) { throw new SAXException(getLocation() + ": Could not create nested element <" + name + ">."); } throw new SAXException(getLocation() + ": Element <" + parent.elementName + "> does not allow nested <" + name + "> elements."); }
From source file:com.esri.geoevent.solutions.adapter.cot.MessageParser.java
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { try {/*www . j av a 2s . c o m*/ if (qName == null) return; if (messageLevel == MessageLevel.root && (qName.equalsIgnoreCase(MESSAGES) || qName.equalsIgnoreCase("geomessages"))) { messageLevel = MessageLevel.inMessages; } else if (messageLevel == MessageLevel.inMessages && (qName.equalsIgnoreCase(MESSAGE) || qName.equalsIgnoreCase("geomessage"))) { messageLevel = MessageLevel.inMessage; } else if (messageLevel == MessageLevel.inMessage) { messageLevel = MessageLevel.inAttribute; attribute = ""; attributeName = qName; } else if (messageLevel == MessageLevel.inAttribute) { throw new SAXException("Problem parsing message, cannot handle nested attributes. (" + qName + " inside " + attributeName + ")"); } else if (qName.equalsIgnoreCase("event")) { // Event element was found. Store all available CoT attributes. for (int i = 0; attributes.getLength() > i; i++) { String l = attributes.getLocalName(i); String q = attributes.getQName(i); String name = null; if (l.isEmpty()) { name = q; } else { name = l; } if (name.equalsIgnoreCase("how")) { this.how = attributes.getValue(i); } else if (name.equalsIgnoreCase("opex")) { this.opex = attributes.getValue(i); } else if (name.equalsIgnoreCase("qos")) { this.qos = attributes.getValue(i); } else if (name.equalsIgnoreCase("type")) { this.type = attributes.getValue(i); } else if (name.equalsIgnoreCase("uid")) { this.uid = attributes.getValue(i); } else if (name.equalsIgnoreCase("stale")) { this.stale = attributes.getValue(i); } else if (name.equalsIgnoreCase("start")) { this.start = attributes.getValue(i); } else if (name.equalsIgnoreCase("time")) { this.time = attributes.getValue(i); } else if (name.equalsIgnoreCase("version")) { this.version = attributes.getValue(i); } else if (name.equalsIgnoreCase("access")) { this.access = attributes.getValue(i); } } } else if (!inDetails && qName.equalsIgnoreCase("detail")) { // <detail> element started tabLevel++; inDetails = true; detail.append("\n" + makeTabs(tabLevel) + "<eventWrapper><detail"); // (NOTE: detail should NOT have any attributes but search just // in case) for (int i = 0; attributes.getLength() > i; i++) { detail.append("\n" + makeTabs(tabLevel + 1) + attributes.getLocalName(i) + "=" + "\"" + attributes.getValue(i) + "\""); } // close the tag detail.append(">"); } else if (inDetails && !qName.equalsIgnoreCase("detail")) { // some new child element inside the Detail section tabLevel++; detail.append("\n" + makeTabs(tabLevel) + "<" + qName); // search for any attributes for (int i = 0; attributes.getLength() > i; i++) { String l = attributes.getLocalName(i); String q = attributes.getQName(i); String name = null; if (l.isEmpty()) { name = q; } else { name = l; } detail.append( "\n" + makeTabs(tabLevel + 1) + name + "=" + "\"" + attributes.getValue(i) + "\""); } // close the tag detail.append(">"); } else if (!inDetails && qName.equalsIgnoreCase("point")) { // <point> element started tabLevel++; point.append("\n" + makeTabs(tabLevel) + "<point"); // search for any attributes for (int i = 0; attributes.getLength() > i; i++) { String l = attributes.getLocalName(i); String q = attributes.getQName(i); String name = null; if (l.isEmpty()) { name = q; } else { name = l; } point.append("\n" + makeTabs(tabLevel + 1) + name + "=" + "\"" + attributes.getValue(i) + "\""); } // close the tag point.append(" />"); tabLevel--; } } catch (Exception e) { LOG.error(e); LOG.error(e.getStackTrace()); } }
From source file:com.limegroup.gnutella.xml.LimeXMLDocument.java
/** * Constructs a LimeXMLDocument with the given string. *///www . j ava2s . c o m public LimeXMLDocument(String xml) throws SAXException, SchemaNotFoundException, IOException { if (xml == null || xml.equals("")) throw new SAXException("null or empty string"); InputSource doc = new InputSource(new StringReader(xml)); XMLParsingUtils.ParseResult result = XMLParsingUtils.parse(doc); if (result.isEmpty()) throw new IOException("No element present"); if (result.schemaURI == null) throw new SchemaNotFoundException("no schema"); this.fieldToValue = (Map) result.get(0); this.schemaUri = result.schemaURI; setFields(result.canonicalKeyPrefix); if (!isValid()) throw new IOException("Invalid XML: " + xml); }
From source file:net.sf.joost.trax.TrAXFilter.java
/** * Parses the <code>InputSource</code> * @param input A <code>InputSource</code> object. * @throws SAXException/*from ww w. ja v a 2s . c o m*/ * @throws IOException */ public void parse(InputSource input) throws SAXException, IOException { Transformer transformer = null; if (DEBUG) { if (log.isDebugEnabled()) log.debug("parsing InputSource " + input.getSystemId()); } try { // get a new Transformer transformer = this.templates.newTransformer(); if (transformer instanceof TransformerImpl) { this.processor = ((TransformerImpl) transformer).getStxProcessor(); } else { String msg = "An error is occured, because the given transformer is " + "not an instance of TransformerImpl"; if (log != null) log.fatal(msg); else System.err.println("Fatal error - " + msg); } XMLReader parent = this.getParent(); if (parent == null) { parent = XMLReaderFactory.createXMLReader(); setParent(parent); } ContentHandler handler = this.getContentHandler(); if (handler == null) { handler = parent.getContentHandler(); } if (handler == null) { throw new SAXException("no ContentHandler registered"); } //init StxEmitter StxEmitter out = null; //SAX specific Implementation out = new SAXEmitter(handler); if (this.processor != null) { this.processor.setContentHandler(out); this.processor.setLexicalHandler(out); } else { throw new SAXException("Joost-Processor is not correct configured."); } if (parent == null) { throw new SAXException("No parent for filter"); } parent.setContentHandler(this.processor); parent.setProperty("http://xml.org/sax/properties/lexical-handler", this.processor); parent.setEntityResolver(this); parent.setDTDHandler(this); parent.setErrorHandler(this); parent.parse(input); } catch (TransformerConfigurationException tE) { try { configErrListener.fatalError(tE); } catch (TransformerConfigurationException innerE) { throw new SAXException(innerE.getMessage(), innerE); } } catch (SAXException sE) { try { configErrListener.fatalError(new TransformerConfigurationException(sE.getMessage(), sE)); } catch (TransformerConfigurationException innerE) { throw new SAXException(innerE.getMessage(), innerE); } } catch (IOException iE) { try { configErrListener.fatalError(new TransformerConfigurationException(iE.getMessage(), iE)); } catch (TransformerConfigurationException innerE) { throw new IOException(innerE.getMessage()); } } }
From source file:hudson.plugins.debt.parser.DebtParser.java
/** {@inheritDoc} */ @Override//from w w w . ja va 2 s .c om public Collection<FileAnnotation> parse(final InputStream file, final String moduleName) throws InvocationTargetException { System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>entered DebtParser.parse()"); try { Digester digester = new Digester(); digester.setValidating(false); digester.setClassLoader(DebtParser.class.getClassLoader()); String rootXPath = "debt"; digester.addObjectCreate(rootXPath, Debt.class); digester.addSetProperties(rootXPath); String fileXPath = "debt/file"; digester.addObjectCreate(fileXPath, hudson.plugins.debt.parser.File.class); digester.addSetProperties(fileXPath); digester.addSetNext(fileXPath, "addFile", hudson.plugins.debt.parser.File.class.getName()); String bugXPath = "debt/file/violation"; digester.addObjectCreate(bugXPath, Violation.class); digester.addSetProperties(bugXPath); digester.addCallMethod(bugXPath, "setMessage", 0); digester.addSetNext(bugXPath, "addViolation", Violation.class.getName()); Debt module = (Debt) digester.parse(file); if (module == null) { throw new SAXException("Input stream is not a valid Debt file."); } return convert(module, moduleName); } catch (IOException exception) { throw new InvocationTargetException(exception); } catch (SAXException exception) { throw new InvocationTargetException(exception); } }
From source file:es.mityc.firmaJava.libreria.utilidades.AnalizadorFicheroFirma.java
public static void mostrarError(SAXParseException exc, String aviso) throws SAXException { log.error(aviso);//from w w w . ja v a 2 s .c o m log.error(LINE_DOS_PUNTOS + exc.getLineNumber()); log.error(URI_DOS_PUNTOS + exc.getSystemId()); log.error(I18n.getResource(LIBRERIA_UTILIDADES_ANALIZADOR_ERROR_3) + exc.getMessage()); throw new SAXException(aviso); }