List of usage examples for org.xml.sax SAXException SAXException
public SAXException(Exception e)
From source file:net.sf.joost.plugins.traxfilter.THResolver.java
/** * @see net.sf.joost.TransformerHandlerResolver#resolve(java.lang.String, * org.xml.sax.XMLReader, javax.xml.transform.URIResolver, * javax.xml.transform.ErrorListener, java.util.Hashtable) */// w w w . j ava2 s . com public TransformerHandler resolve(String method, XMLReader reader, URIResolver uriResolver, ErrorListener errorListener, Hashtable params) throws SAXException { if (!available(method)) throw new SAXException("Not supported filter-method:" + method); if (DEBUG) log.debug("resolve(buffer)"); if (reader == null) throw new SAXException("method-src must be url() or buffer()"); setFilterAttributes(params); TransformerHandler th = null; // reuse th if available th = getReusableXmlReaderTH(method); // new transformer if non available if (th == null) { // prepare the source if (DEBUG) log.debug("resolve(buffer): new source out of buffer"); Source source = new SAXSource(reader, new InputSource()); th = newTHOutOfTrAX(method, source, params, errorListener, uriResolver); // cache the instance if required cacheBufferTH(method, th); } prepareTh(th, params); return th; }
From source file:com.sfs.jbtimporter.JBTProcessor.java
/** * Parses the xml index.//from w w w . j a va2 s .c o m * * @return the list * @throws SAXException the SAX exception * @throws IOException Signals that an I/O exception has occurred. */ public final List<JBTIssue> parseXmlIndex() throws SAXException, IOException { final List<JBTIssue> issues = new ArrayList<JBTIssue>(); final File file = new File(this.getExportBase() + "index.xml"); final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; try { db = dbf.newDocumentBuilder(); } catch (ParserConfigurationException pce) { throw new SAXException("Error configuring XML parser: " + pce.getMessage()); } final Document doc = db.parse(file); doc.getDocumentElement().normalize(); final NodeList bugList = doc.getElementsByTagName("bug"); for (int s = 0; s < bugList.getLength(); s++) { final Node bugNode = bugList.item(s); if (bugNode.getNodeType() == Node.ELEMENT_NODE) { final JBTIssue issue = new JBTIssue(this); final Element bugElmnt = (Element) bugNode; issue.setId(bugElmnt.getAttribute("id")); issue.setBase(bugElmnt.getAttribute("base")); NodeList fileElmntLst = bugNode.getChildNodes(); for (int t = 0; t < fileElmntLst.getLength(); t++) { final Node fileNode = fileElmntLst.item(t); if (fileNode.getNodeType() == Node.ELEMENT_NODE) { final Element fileElmnt = (Element) fileNode; final NodeList chldFile = fileElmnt.getChildNodes(); final Node filenameNode = (Node) chldFile.item(0); if (StringUtils.equals(fileElmnt.getAttribute("primary"), "true")) { issue.setFileName(filenameNode.getNodeValue()); // Add the issue to the array issues.add(issue); } } } } } return issues; }
From source file:io.github.msdk.io.mzdata.MzDataSaxHandler.java
/** * {@inheritDoc}//from w ww. ja va2 s .co m * * characters() * @see org.xml.sax.ContentHandler#characters(char[], int, int) */ public void characters(char buf[], int offset, int len) throws SAXException { if (canceled) throw new SAXException("Parsing Cancelled"); charBuffer.append(buf, offset, len); }
From source file:com.amalto.core.util.Util.java
public static Map<String, XSElementDecl> getConceptMap(String xsd) throws Exception { XSOMParser reader = new XSOMParser(); reader.setAnnotationParser(new DomAnnotationParserFactory()); reader.setEntityResolver(new SecurityEntityResolver()); SAXErrorHandler seh = new SAXErrorHandler(); reader.setErrorHandler(seh);/*from w ww .j ava 2s . c o m*/ reader.parse(new StringReader(xsd)); XSSchemaSet xss = reader.getResult(); String errors = seh.getErrors(); if (errors.length() > 0) { throw new SAXException("DataModel parsing error -> " + errors); } Collection xssList = xss.getSchemas(); Map<String, XSElementDecl> mapForAll = new HashMap<>(); Map<String, XSElementDecl> map; for (Object xmlSchema : xssList) { XSSchema schema = (XSSchema) xmlSchema; map = schema.getElementDecls(); mapForAll.putAll(map); } return mapForAll; }
From source file:org.esco.grouper.parsing.SGSParsingUtil.java
/** * Resolve relative path.//from www .j a v a 2s . c om * @param tag The current processed tag. * @param path The path to resolve. * @return The resolved path. * @throws SAXException If the path can't be resolved. */ protected String resolvePath(final String tag, final String path) throws SAXException { // Resolves the paths with ../../../reference/to/a/folder/ if (path.startsWith(UP_IN_PATH)) { // Error the current path is not set. String relativePath = path; String currentReference = current.getPath(); while (relativePath.startsWith(UP_IN_PATH)) { final int index = currentReference.lastIndexOf(Stem.DELIM); // Error can't go up. if (index < 0) { final String msg = "Error while resolving path: " + path + " - too much \"" + UP_IN_PATH + "\"(Tag " + tag + " - line " + locator.getLineNumber() + ")."; LOGGER.fatal(msg); throw new SAXException(msg); } currentReference = currentReference.substring(0, index); relativePath = relativePath.replaceFirst(UP_IN_PATH, ""); } if (!relativePath.startsWith(Stem.DELIM)) { relativePath = Stem.DELIM + relativePath; } return currentReference + relativePath; } // The path is relative and referes to the current path. if (path.startsWith(CURRENT_PATH)) { String resolvedPath = path.replaceFirst(CURRENT_PATH, current.getPath()); return resolvedPath.replaceAll(ESC_CURRENT_PATH, ""); } // The path is absolute. return path; }
From source file:io.github.msdk.io.mzdata.MzDataSaxHandler.java
/** * <p>/*from w w w. j av a 2s . c o m*/ * endDocument. * </p> * * @throws org.xml.sax.SAXException * if any. */ public void endDocument() throws SAXException { if (canceled) throw new SAXException("Parsing Cancelled"); }
From source file:net.sf.joost.emitter.XmlEmitter.java
/** * SAX2-Callback - Outputs a PI// ww w. j av a2 s. c om */ public void processingInstruction(String target, String data) throws SAXException { processLastElement(false); if (supportDisableOutputEscaping) { if (Result.PI_DISABLE_OUTPUT_ESCAPING.equals(target)) { disabledOutputEscaping = true; return; } else if (Result.PI_ENABLE_OUTPUT_ESCAPING.equals(target)) { disabledOutputEscaping = false; return; } } try { writer.write("<?"); writer.write(target); if (!data.equals("")) { writer.write(" "); writer.write(data); } writer.write("?>"); } catch (IOException ex) { if (log != null) log.error(ex); throw new SAXException(ex); } }
From source file:net.sf.joost.emitter.XmlEmitter.java
/** * SAX2-Callback - Notify the start of a CDATA section *///from www . j ava 2 s.co m public void startCDATA() throws SAXException { processLastElement(false); try { writer.write("<![CDATA["); } catch (IOException ex) { if (log != null) log.error(ex); throw new SAXException(ex); } insideCDATA = true; }
From source file:com.amalto.core.util.Util.java
public static Map<String, XSType> getConceptTypeMap(String xsd) throws Exception { XSOMParser reader = new XSOMParser(); reader.setAnnotationParser(new DomAnnotationParserFactory()); reader.setEntityResolver(new SecurityEntityResolver()); SAXErrorHandler seh = new SAXErrorHandler(); reader.setErrorHandler(seh);/* w w w . j ava 2 s.c om*/ reader.parse(new StringReader(xsd)); XSSchemaSet xss = reader.getResult(); String errors = seh.getErrors(); if (errors.length() > 0) { throw new SAXException("DataModel parsing error -> " + errors); } Collection xssList = xss.getSchemas(); Map<String, XSType> mapForAll = new HashMap<>(); Map<String, XSType> map; for (Object aXssList : xssList) { XSSchema schema = (XSSchema) aXssList; map = schema.getTypes(); mapForAll.putAll(map); } return mapForAll; }
From source file:net.sf.joost.emitter.XmlEmitter.java
/** * SAX2-Callback - Notify the end of a CDATA section *///from w w w.j ava 2 s . co m public void endCDATA() throws SAXException { insideCDATA = false; try { writer.write("]]>"); } catch (IOException ex) { if (log != null) log.error(ex); throw new SAXException(ex); } }