List of usage examples for org.xml.sax InputSource InputSource
public InputSource(Reader characterStream)
From source file:nl.flotsam.hamcrest.schema.relaxng.ResourceValidator.java
public boolean validate(Verifier verifier, Resource verifiable) throws SAXException, IOException { InputSource source = new InputSource(verifiable.getInputStream()); source.setSystemId(verifiable.getURI().toASCIIString()); return new InputSourceValidator().validate(verifier, source); }
From source file:Main.java
/** * <p>//from w w w .j a v a 2 s . c om * Parses an XML document from a reader. * </p> * <p> * Note that use of this method is discouraged. It ignores the character * encoding that is defined within the XML document itself, and should only * be used if the encoding is undefined or if the encoding needs to be * ignored for whatever reason. The {@link #toDocument(InputStream)} method * should be used instead, since it takes the XML document's character * encoding into account when parsing. * </p> * @param reader the reader * @return the parsed DOM * @throws SAXException if the XML is not valid * @throws IOException if there is a problem reading from the reader * @see <a * href="http://stackoverflow.com/q/3482494/13379">http://stackoverflow.com/q/3482494/13379</a> */ public static Document toDocument(Reader reader) throws SAXException, IOException { return toDocument(new InputSource(reader)); }
From source file:Main.java
public static final boolean isWellFormedXml(final InputStream in) throws Exception { return isWellFormedXml(new InputSource(in)); }
From source file:de.ii.xtraplatform.ogc.api.gml.parser.GMLDictionaryParser.java
public void parse(HttpEntity entity) { try {/*from w ww. j a va 2 s . c o m*/ InputSource is = new InputSource(entity.getContent()); parse(is); } catch (IOException ex) { // TODO: move to analyzer for XtraProxy //LOGGER.error(FrameworkMessages.ERROR_PARSING_WFS_CAPABILITIES); //throw new SchemaParseException(FrameworkMessages.ERROR_PARSING_WFS_CAPABILITIES); analyzer.analyzeFailed(ex); } finally { EntityUtils.consumeQuietly(entity); } }
From source file:Main.java
public static Document parse(Reader input) throws SAXException, ParserConfigurationException { return parse(new InputSource(input), null); }
From source file:XMLTreeView.java
public XMLTreeView(JFrame frame) { frame.getContentPane().setLayout(new BorderLayout()); DefaultMutableTreeNode top = new DefaultMutableTreeNode(file); // DefaultMutableTreeNode top = new DefaultMutableTreeNode("XML Document"); saxTree = new SAXTreeBuilder(top); try {/*from w ww. j av a2 s. co m*/ SAXParser saxParser = new SAXParser(); saxParser.setContentHandler(saxTree); saxParser.parse(new InputSource(new FileInputStream(file))); } catch (Exception ex) { top.add(new DefaultMutableTreeNode(ex.getMessage())); } JTree tree = new JTree(saxTree.getTree()); JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add("Center", scrollPane); frame.setVisible(true); }
From source file:Utils.java
public static Document newDocumentFromString(String xmlString) { DocumentBuilderFactory factory = null; DocumentBuilder builder = null; Document ret = null;/* w ww . ja va 2s . com*/ try { factory = DocumentBuilderFactory.newInstance(); builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { e.printStackTrace(); } try { ret = builder.parse(new InputSource(new StringReader(xmlString))); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return ret; }
From source file:de.nava.informa.parsers.OPMLParser.java
public static Collection parse(Reader reader) throws IOException, ParseException { return parse(new InputSource(reader), null); }
From source file:Main.java
public void process() { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(true);// www .j av a2 s .c o m spf.setValidating(true); System.out.println("Parser will " + (spf.isNamespaceAware() ? "" : "not ") + "be namespace aware"); System.out.println("Parser will " + (spf.isValidating() ? "" : "not ") + "validate XML"); try { parser = spf.newSAXParser(); System.out.println("Parser object is: " + parser); } catch (SAXException e) { e.printStackTrace(System.err); System.exit(1); } catch (ParserConfigurationException e) { e.printStackTrace(System.err); System.exit(1); } try { parser.parse(new InputSource(new StringReader(getXMLData())), this); } catch (IOException e) { e.printStackTrace(System.err); } catch (SAXException e) { e.printStackTrace(System.err); } }
From source file:uk.ac.ebi.intact.dataexchange.psimi.solr.util.IntactSolrUtils.java
public static SchemaInfo retrieveSchemaInfo(SolrServer solrServer) throws IOException { SchemaInfo schemaInfo = new SchemaInfo(); if (solrServer instanceof CommonsHttpSolrServer) { final CommonsHttpSolrServer solr = (CommonsHttpSolrServer) solrServer; final String url = solr.getBaseURL() + "/admin/file/?file=schema.xml"; final GetMethod method = new GetMethod(url); final int code = solr.getHttpClient().executeMethod(method); XPath xpath = XPathFactory.newInstance().newXPath(); String expression = "/schema/fields/field"; InputStream stream = method.getResponseBodyAsStream(); InputSource inputSource = new InputSource(stream); try {//from w ww. j a v a 2 s . co m NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { final String fieldName = nodes.item(i).getAttributes().getNamedItem("name").getNodeValue(); schemaInfo.addFieldName(fieldName); } } catch (XPathExpressionException e) { e.printStackTrace(); } finally { stream.close(); } } else if (solrServer instanceof HttpSolrServer) { final HttpSolrServer solr = (HttpSolrServer) solrServer; final String url = solr.getBaseURL() + "/admin/file/?file=schema.xml"; final HttpUriRequest method = new HttpGet(url); final HttpResponse response = solr.getHttpClient().execute(method); XPath xpath = XPathFactory.newInstance().newXPath(); String expression = "/schema/fields/field"; InputStream stream = response.getEntity().getContent(); InputSource inputSource = new InputSource(stream); try { NodeList nodes = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET); for (int i = 0; i < nodes.getLength(); i++) { final String fieldName = nodes.item(i).getAttributes().getNamedItem("name").getNodeValue(); schemaInfo.addFieldName(fieldName); } } catch (XPathExpressionException e) { e.printStackTrace(); } finally { stream.close(); } } else { throw new IllegalArgumentException( "Cannot get schema for SolrServer with class: " + solrServer.getClass().getName()); } return schemaInfo; }