List of usage examples for org.xml.sax SAXParseException getSystemId
public String getSystemId()
From source file:MainClass.java
static void fail(SAXException e) { if (e instanceof SAXParseException) { SAXParseException spe = (SAXParseException) e; System.err.printf("%s:%d:%d: %s%n", spe.getSystemId(), spe.getLineNumber(), spe.getColumnNumber(), spe.getMessage());/*w w w. j av a2s.c o m*/ } else { System.err.println(e.getMessage()); } System.exit(1); }
From source file:Main.java
/** * Builds a prettier exception message.// w ww . j a v a 2 s.c o m * * @param ex the SAXParseException * @return an easier to read exception message */ public static String getPrettyParseExceptionInfo(SAXParseException ex) { final StringBuilder sb = new StringBuilder(); if (ex.getSystemId() != null) { sb.append("systemId=").append(ex.getSystemId()).append(", "); } if (ex.getPublicId() != null) { sb.append("publicId=").append(ex.getPublicId()).append(", "); } if (ex.getLineNumber() > 0) { sb.append("Line=").append(ex.getLineNumber()); } if (ex.getColumnNumber() > 0) { sb.append(", Column=").append(ex.getColumnNumber()); } sb.append(": ").append(ex.getMessage()); return sb.toString(); }
From source file:Main.java
/** * Parse the XML file and create Document * @param fileName//from w ww . j a v a 2 s. c om * @return Document */ public static Document parse(InputStream fs) { Document document = null; // Initiate DocumentBuilderFactory DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); // To get a validating parser factory.setValidating(false); // To get one that understands namespaces factory.setNamespaceAware(true); try { // Get DocumentBuilder DocumentBuilder builder = factory.newDocumentBuilder(); // Parse and load into memory the Document //document = builder.parse( new File(fileName)); document = builder.parse(fs); return document; } catch (SAXParseException spe) { // Error generated by the parser System.err.println("\n** Parsing error , line " + spe.getLineNumber() + ", uri " + spe.getSystemId()); System.err.println(" " + spe.getMessage()); // Use the contained exception, if any Exception x = spe; if (spe.getException() != null) x = spe.getException(); x.printStackTrace(); } catch (SAXException sxe) { // Error generated during parsing Exception x = sxe; if (sxe.getException() != null) x = sxe.getException(); x.printStackTrace(); } catch (ParserConfigurationException pce) { // Parser with specified options can't be built pce.printStackTrace(); } catch (IOException ioe) { // I/O error ioe.printStackTrace(); } return null; }
From source file:Main.java
public static Element loadDocument(File location) { Document doc = null;/*from w ww . j a v a2 s . c o m*/ try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = docBuilderFactory.newDocumentBuilder(); doc = parser.parse(location); Element root = doc.getDocumentElement(); root.normalize(); return root; } catch (SAXParseException err) { System.err.println("URLMappingsXmlDAO ** Parsing error, line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.err.println("URLMappingsXmlDAO error: " + err.getMessage()); } catch (SAXException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (MalformedURLException mfx) { System.err.println("URLMappingsXmlDAO error: " + mfx); } catch (IOException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (Exception pce) { System.err.println("URLMappingsXmlDAO error: " + pce); } return null; }
From source file:Main.java
public static Element loadDocument(Reader target) { Document doc = null;/*from w w w . j a va 2 s . c o m*/ try { InputSource xmlInp = new InputSource(target); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = docBuilderFactory.newDocumentBuilder(); doc = parser.parse(xmlInp); Element root = doc.getDocumentElement(); root.normalize(); return root; } catch (SAXParseException err) { System.err.println("URLMappingsXmlDAO ** Parsing error, line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.err.println("URLMappingsXmlDAO error: " + err.getMessage()); } catch (SAXException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (MalformedURLException mfx) { System.err.println("URLMappingsXmlDAO error: " + mfx); } catch (IOException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (Exception pce) { System.err.println("URLMappingsXmlDAO error: " + pce); } return null; }
From source file:Main.java
public static Element loadDocument(Reader target) { Document doc = null;//from www .java 2s .co m try { InputSource xmlInp = new InputSource(target); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = docBuilderFactory.newDocumentBuilder(); doc = parser.parse(xmlInp); Element root = doc.getDocumentElement(); root.normalize(); return root; } catch (SAXParseException err) { System.err.println("URLMappingsXmlDAO ** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.err.println("URLMappingsXmlDAO error: " + err.getMessage()); } catch (SAXException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (java.net.MalformedURLException mfx) { System.err.println("URLMappingsXmlDAO error: " + mfx); } catch (java.io.IOException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (Exception pce) { System.err.println("URLMappingsXmlDAO error: " + pce); } return null; }
From source file:Main.java
public static Element loadDocument(String location) { Document doc = null;//w w w . j a v a 2 s . c o m try { URL url = new URL(location); InputSource xmlInp = new InputSource(url.openStream()); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = docBuilderFactory.newDocumentBuilder(); doc = parser.parse(xmlInp); Element root = doc.getDocumentElement(); root.normalize(); return root; } catch (SAXParseException err) { System.err.println("URLMappingsXmlDAO ** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.err.println("URLMappingsXmlDAO error: " + err.getMessage()); } catch (SAXException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (java.net.MalformedURLException mfx) { System.err.println("URLMappingsXmlDAO error: " + mfx); } catch (java.io.IOException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (Exception pce) { System.err.println("URLMappingsXmlDAO error: " + pce); } return null; }
From source file:Main.java
public static Element loadDocument(String value, String type) { Document doc = null;// w w w . j av a2 s.c o m InputSource xmlInp = null; try { if (type.equals("location")) { URL url = new URL(value); xmlInp = new InputSource(url.openStream()); } else { xmlInp = new InputSource(new StringReader(value)); } DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = docBuilderFactory.newDocumentBuilder(); doc = parser.parse(xmlInp); Element root = doc.getDocumentElement(); root.normalize(); return root; } catch (SAXParseException err) { System.err.println("URLMappingsXmlDAO ** Parsing error, line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.err.println("URLMappingsXmlDAO error: " + err.getMessage()); } catch (SAXException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (MalformedURLException mfx) { System.err.println("URLMappingsXmlDAO error: " + mfx); } catch (IOException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (Exception pce) { System.err.println("URLMappingsXmlDAO error: " + pce); } return null; }
From source file:Main.java
public static Element loadDocument(File location) { Document doc = null;/* w w w . j a va 2 s .c om*/ try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = docBuilderFactory.newDocumentBuilder(); doc = parser.parse(location); Element root = doc.getDocumentElement(); root.normalize(); /* * //Output to standard output ; use Sun's reference imple for now * XmlDocument xdoc = (XmlDocument) doc; xdoc.write(new * OutputStreamWriter(System.out)); */ return root; } catch (SAXParseException err) { System.err.println("URLMappingsXmlDAO ** Parsing error" + ", line " + err.getLineNumber() + ", uri " + err.getSystemId()); System.err.println("URLMappingsXmlDAO error: " + err.getMessage()); } catch (SAXException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (java.net.MalformedURLException mfx) { System.err.println("URLMappingsXmlDAO error: " + mfx); } catch (java.io.IOException e) { System.err.println("URLMappingsXmlDAO error: " + e); } catch (Exception pce) { System.err.println("URLMappingsXmlDAO error: " + pce); } return null; }
From source file:es.mityc.firmaJava.libreria.utilidades.AnalizadorFicheroFirma.java
public static void mostrarError(SAXParseException exc, String aviso) throws SAXException { log.error(aviso);// w w w.j ava 2s .com 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); }