List of usage examples for org.jdom2.input SAXBuilder build
@Override public Document build(final String systemId) throws JDOMException, IOException
This builds a document from the supplied URI.
From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java
License:Apache License
public static void loadFromString(final String document) { SAXBuilder builder = new SAXBuilder(); try {/*from w ww . j a v a 2 s. c o m*/ loadFromDocument(builder.build(new StringReader(document))); } catch (JDOMException e) { LOG.error("The string isn't parsable: " + document, e); throw new RuntimeException("The string isn't parsable: " + document, e); } catch (IOException e) { LOG.error("The string can't be opend as StringReader: " + document, e); throw new RuntimeException("The string cant be opend as StringReader: " + document, e); } }
From source file:cz.lbenda.dbapp.rc.SessionConfiguration.java
License:Apache License
private void loadExtendedConfigurationFromFile() { SAXBuilder builder = new SAXBuilder(); try {//from w w w.j a v a 2 s . c om File file = new File(extendedConfigurationPath); Document document = builder.build(new FileReader(file)); Element root = document.getRootElement(); loadSchemas(root.getChild("schemas")); tableOfKeysSQLFromElement(root.getChild("tableOfKeySQLs")); tableDescriptionExtensionsFromElement(root.getChild("tableDescriptionExtensions")); } catch (JDOMException e) { LOG.error("The file isn't parsable: " + extendedConfigurationPath, e); throw new RuntimeException("The file isn't parsable: " + extendedConfigurationPath, e); } catch (IOException e) { LOG.error("The file can't be opend as StringReader: " + extendedConfigurationPath, e); throw new RuntimeException("The file cant be opend as StringReader: " + extendedConfigurationPath, e); } }
From source file:cz.muni.fi.mir.mathmlcanonicalization.MathMLCanonicalizer.java
License:Apache License
/** * Canonicalize an input MathML stream.//from w ww . ja va 2 s .co m * * @param in input stream to be canonicalized * @param out canonical output stream of input * @throws JDOMException problem with DOM * @throws IOException problem with streams * @throws ModuleException some module cannot canonicalize the input */ public void canonicalize(final InputStream in, final OutputStream out) throws JDOMException, IOException, ModuleException, XMLStreamException { if (in == null) { throw new NullPointerException("in"); } if (out == null) { throw new NullPointerException("out"); } InputStream inputStream = in; if (enforcingXHTMLPlusMathMLDTD) { inputStream = DTDManipulator.injectXHTMLPlusMathMLDTD(in); } ByteArrayOutputStream outputStream = null; // calling stream modules for (StreamModule module : streamModules) { outputStream = module.execute(inputStream); if (outputStream == null) { throw new IOException("Module " + module + "returned null."); } inputStream = new ByteArrayInputStream(outputStream.toByteArray()); } if (enforcingXHTMLPlusMathMLDTD) { inputStream = DTDManipulator.removeDTD(inputStream); } // do not create the JDOM representation if there are no modules if (domModules.isEmpty()) { if (streamModules.isEmpty()) { throw new IOException("There are no modules added."); } assert outputStream != null; // nonempty streamModules + nothing thrown in for outputStream.writeTo(out); return; } // creating the JDOM representation from the stream final SAXBuilder builder = Settings.setupSAXBuilder(); final Document document = builder.build(inputStream); // calling JDOM modules for (DOMModule module : domModules) { module.execute(document); } // convertong the JDOM representation back to stream final XMLOutputter serializer = new XMLOutputter(); serializer.output(document, out); }
From source file:cz.muni.fi.pb138.scxml2voicexmlj.XmlHelper.java
public Document parseStream(InputStream xml) { try {//from w w w. j a v a2 s . co m SAXBuilder builder = new SAXBuilder(); return builder.build(xml); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:datalab.upo.ladonspark.controller.Loaddata.java
public List<Host> loadXml(String url, String interfaz) throws JDOMException, IOException, InterruptedException { System.out.println("\n\ncargando datos xml\n\n"); List<Host> hostfind = new ArrayList<>(); String name = ""; String ip = ""; String myIp = findMyIp(interfaz); boolean type = false; FileReader xmlFile = new FileReader(url + "nmapData.xml"); System.out.println("pasa file"); SAXBuilder builder = new SAXBuilder(); Document document = (Document) builder.build(xmlFile); Element rootNode = document.getRootElement(); /*//from ww w.j av a 2 s . c om obtain the host list in XML file sacamos la lista de Host del fichero XML */ List<Element> hosts = rootNode.getChildren("host"); // hosts=hosts.get(0).getChildren("host"); for (int i = 0; i < hosts.size(); i++) { Element host = hosts.get(i); /* Obtain the hostname list in list host and obtain the address list in self list host */ List<Element> hostnames = host.getChildren("hostnames"); List<Element> address = host.getChildren("address"); if (hostnames.get(0).getChild("hostname") != null) { name = hostnames.get(0).getChild("hostname").getAttributeValue("name"); ip = address.get(0).getAttributeValue("addr"); } else { name = "unamed"; ip = address.get(0).getAttributeValue("addr"); } if (ip.equals(myIp)) { type = true; } else { type = false; } hostfind.add(new Host(name, ip, type)); } hostfind.remove(hostfind.get(0)); this.setHostfind(hostfind); return hostfind; }
From source file:dblp.xml.DBLPParserFirstSchema.java
public static void parse() { createDir("data/" + outputDir); DBLPParserFirstSchema parser = new DBLPParserFirstSchema(); try {// ww w. ja v a 2s .c o m title_year_writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(title_year_path), "utf-8")); title_conf_writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(title_conf_path), "utf-8")); title_author_writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(title_author_path), "utf-8")); SAXBuilder builder = new SAXBuilder(); String path = "data/dblp.xml"; Document jdomDocument = builder.build(path); Element root = jdomDocument.getRootElement(); // List<String> types = Arrays.asList("incollection", "article", "inproceedings", "proceedings"); List<String> types = Arrays.asList("inproceedings"); for (String type : types) { System.out.println("extractElements for " + type); parser.extractElements(root, type); } titlesCollection.writeToFile(title_path); authorsCollection.writeToFile(author_path); confsCollection.writeToFile(conf_path); yearsCollection.writeToFile(year_path); } catch (Exception e) { e.printStackTrace(); } }
From source file:dblp.xml.DBLPParserSecondSchema.java
public static void parse() { createDir("data/" + outputDir); DBLPParserSecondSchema parser = new DBLPParserSecondSchema(); try {/*from www . ja va2 s . co m*/ title_author_writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(title_author_path), "utf-8")); author_conf_writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(author_conf_path), "utf-8")); title_year_writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(title_year_path), "utf-8")); conf_year_writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(conf_year_path), "utf-8")); SAXBuilder builder = new SAXBuilder(); String path = "data/dblp.xml"; Document jdomDocument = builder.build(path); Element root = jdomDocument.getRootElement(); // List<String> types = Arrays.asList("incollection", "article", "inproceedings", "proceedings"); List<String> types = Arrays.asList("inproceedings"); for (String type : types) { parser.extractElements(root, type); } titlesCollection.writeToFile(title_path); authorsCollection.writeToFile(author_path); confsCollection.writeToFile(conf_path); yearConfsCollection.writeToFile(year_with_conf_path); yearConfsCollection.writeToFileJustFirsToken(year_path); } catch (Exception e) { e.printStackTrace(); } }
From source file:dblp.xml.DBLPParserThirdSchema.java
public static void parse() { createDir("data/" + outputDir); DBLPParserThirdSchema parser = new DBLPParserThirdSchema(); try {/*from www .j ava 2s .c o m*/ title_author_writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(title_author_path), "utf-8")); title_conf_writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(title_conf_path), "utf-8")); conf_year_writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(conf_year_path), "utf-8")); SAXBuilder builder = new SAXBuilder(); String path = "data/dblp.xml"; Document jdomDocument = builder.build(path); Element root = jdomDocument.getRootElement(); // List<String> types = Arrays.asList("incollection", "article", "inproceedings", "proceedings"); List<String> types = Arrays.asList("inproceedings"); for (String type : types) { parser.extractElements(root, type); } titlesCollection.writeToFile(title_path); authorsCollection.writeToFile(author_path); confsCollection.writeToFile(conf_path); yearConfsCollection.writeToFile(year_with_conf_path); yearConfsCollection.writeToFileJustFirsToken(year_path); } catch (Exception e) { e.printStackTrace(); } }
From source file:DBWorkers.DBFiller.java
/** * HashMap Xml/*w w w . j av a2 s . c om*/ * @param xml * @return Hash map Xml */ protected HashMap<String, Object> parsePersonXML(String xml) { HashMap<String, Object> personData = new HashMap<String, Object>(); try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new InputSource(new StringReader(xml))); Element root = doc.getRootElement(); Element user = root.getChild("user"); personData.put("uid", getOneField("uid", user)); personData.put("first_name", getOneField("first_name", user)); personData.put("last_name", getOneField("last_name", user)); personData.put("sex", getOneField("sex", user)); personData.put("bdate", getOneField("bdate", user)); personData.put("city", getOneField("city", user)); personData.put("can_post", getOneField("can_post", user)); personData.put("status", getOneField("status", user)); personData.put("relation", getOneField("relation", user)); personData.put("nickname", getOneField("nickname", user)); personData.put("interests", getOneField("interests", user)); personData.put("movies", getOneField("movies", user)); personData.put("tv", getOneField("tv", user)); personData.put("books", getOneField("books", user)); personData.put("games", getOneField("games", user)); personData.put("about", getOneField("about", user)); personData.put("counters", getOneField("counters", user)); } catch (JDOMException ex) { Logger.getLogger(DBCreator.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(DBCreator.class.getName()).log(Level.SEVERE, null, ex); } return personData; }
From source file:de.altimos.util.asset.ext.XmlDocumentLoader.java
License:Apache License
@Override public Object loadAsset(AssetManager mgr, AssetInfo info) throws IOException { try {//from w w w .j ava 2 s . c om SAXBuilder builder = new SAXBuilder(); return new XmlDocument(info.getKey(), builder.build(info.openStream())); } catch (Exception e) { throw new IOException(e.getMessage(), e); } }