List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.OperatorNormalizer.java
License:Apache License
@Override public void execute(final Document doc) { if (doc == null) { throw new NullPointerException("doc"); }/* www .j a v a2 s .c om*/ final Element root = doc.getRootElement(); // TODO: convert Unicode superscripts (supX entities) to msup etc. final String normalizerFormStr = getProperty(NORMALIZATION_FORM); if (normalizerFormStr.isEmpty()) { LOGGER.fine("Unicode text normalization is switched off"); } else { try { Normalizer.Form normalizerForm = Normalizer.Form.valueOf(normalizerFormStr); normalizeUnicode(root, normalizerForm); } catch (IllegalArgumentException ex) { throw new IllegalArgumentException("Invalid configuration value: " + NORMALIZATION_FORM, ex); } } unifyOperators(root); }
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.ScriptNormalizer.java
License:Apache License
@Override public void execute(final Document doc) { if (doc == null) { throw new NullPointerException("doc"); }/* w ww . ja va 2s . co m*/ final Element root = doc.getRootElement(); if (isEnabled(UNIFY_SCRIPTS)) { final Map<String, String> replaceMap = new HashMap<String, String>(); replaceMap.put(UNDERSCRIPT, SUBSCRIPT); replaceMap.put(OVERSCRIPT, SUPERSCRIPT); replaceMap.put(UNDEROVER, SUBSUP); replaceDescendants(root, replaceMap); } else { // TODO: normalize unconverted munder/mover/munderover } // TODO: convert multiscript where possible if (isEnabled(SWAP_SCRIPTS)) { normalizeSupInSub(root); } Collection<String> chosenElements = getPropertySet(SPLIT_SCRIPTS_ELEMENTS); if (chosenElements.isEmpty()) { LOGGER.fine("Msubsup conversion is switched off"); } else { normalizeMsubsup(root, chosenElements); } // TODO: convert sub/sup combination with not chosen elements to subsup }
From source file:cz.muni.fi.mir.mathmlcanonicalization.modules.UnaryOperatorRemover.java
License:Apache License
@Override public void execute(final Document doc) { if (doc == null) { throw new NullPointerException("doc"); }/*from w w w . j a v a 2s . com*/ final Element root = doc.getRootElement(); removeUnaryOperator(root); }
From source file:cz.muni.fi.pb138.scxml2voicexmlj.voicexml.XsltStateStackConverter.java
@Override public String convert(InputStream scxmlContent, GrammarReference srgsReferences) { Document vxml = emptyVxmlDocument(); Document scxml = helper.parseStream(scxmlContent); Element form = vxml.getRootElement().getChild("form", NS_VXML); appendGrammarFile(form, srgsReferences); List<Element> states = new ArrayList<>(scxml.getRootElement().getChildren("state", NS_SCXML)); states.addAll(scxml.getRootElement().getChildren("final", NS_SCXML)); String initialName = helper.extractAttribute(scxml.getRootElement(), "initial"); List<Element> transformedVxmlStates = transformStates(assignTransformationsToStates(states, initialName), srgsReferences);//from ww w . j av a 2s . c o m form.addContent(transformedVxmlStates); return helper.render(vxml); }
From source file:cz.muni.fi.pb138.scxml2voicexmlj.XmlHelper.java
public String render(Document xml) { return render(xml.getRootElement()); }
From source file:cz.pecina.retro.memory.Snapshot.java
License:Open Source License
/** * Reads snapshot from a file and sets hardware accordingly. * * @param file input file//from w w w. ja v a2s .c o m */ public void read(final File file) { log.fine("Reading snapshot from a file, file: " + file.getName()); try { SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(new StreamSource( getClass().getResourceAsStream("snapshot-" + SNAPSHOT_XML_FILE_VERSION + ".xsd"))) .newValidator().validate(new StreamSource(file)); } catch (final Exception exception) { log.fine("Error, validation failed, exception: " + exception.getMessage()); throw Application.createError(this, "validation"); } Document doc; Element snapshot; try { doc = new SAXBuilder().build(file); } catch (final JDOMException exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(this, "parsing"); } catch (final Exception exception) { log.fine("Error, reading failed, exception: " + exception.getMessage()); throw Application.createError(this, "XMLRead"); } try { snapshot = doc.getRootElement(); } catch (final Exception exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(this, "parsing"); } if (!snapshot.getName().equals("snapshot")) { log.fine("Error, parsing failed, no <snapshot> tag"); throw Application.createError(this, "parsing"); } if (!SNAPSHOT_XML_FILE_VERSION.equals(snapshot.getAttributeValue("version"))) { log.fine("Version mismatch"); throw Application.createError(this, "version"); } hardware.unmarshal(snapshot); log.fine("Reading completed"); }
From source file:cz.pecina.retro.memory.XML.java
License:Open Source License
/** * Reads XML data from a file and stores it in memory. * * @param file input file * @param destinationAddress destination address ({@code -1} = none) * @return info record/*from ww w . jav a 2 s.c o m*/ */ public Info read(final File file, final int destinationAddress) { log.fine(String.format("Reading XML data from a file, file: %s, destination address: %04x", file.getName(), destinationAddress)); try { SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(new StreamSource( getClass().getResourceAsStream("memory-" + MEMORY_XML_FILE_VERSION + ".xsd"))) .newValidator().validate(new StreamSource(file)); } catch (final Exception exception) { log.fine("Error, validation failed, exception: " + exception.getMessage()); throw Application.createError(this, "validation"); } Document doc; try { doc = new SAXBuilder().build(file); } catch (final JDOMException exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(this, "parsing"); } catch (final Exception exception) { log.fine("Error, reading failed, exception: " + exception.getMessage()); throw Application.createError(this, "XMLRead"); } Element tag; try { tag = doc.getRootElement(); } catch (final Exception exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(this, "parsing"); } if (!tag.getName().equals("memory")) { log.fine("Error, parsing failed, no <memory> tag"); throw Application.createError(this, "parsing"); } if (!MEMORY_XML_FILE_VERSION.equals(tag.getAttributeValue("version"))) { log.fine("Version mismatch"); throw Application.createError(this, "version"); } final Info info = Snapshot.processBlockElement(destinationMemory, tag, destinationAddress); if (info.number == 0) { log.fine("Reading completed, with info: number: 0"); } else { log.fine(String.format("Reading completed, with info: number: %d, min: %04x, max: %04x", info.number, info.minAddress, info.maxAddress)); } return info; }
From source file:cz.pecina.retro.trec.XML.java
License:Open Source License
/** * Reads the tape from an XML file./* ww w. j a v a2s .co m*/ * * @param file input file */ public void read(final File file) { log.fine("Reading tape data from an XML file, file: " + file); try { SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) .newSchema(new StreamSource( getClass().getResourceAsStream("tape-" + TAPE_XML_FILE_VERSION + ".xsd"))) .newValidator().validate(new StreamSource(file)); } catch (final Exception exception) { log.fine("Error, validation failed, exception: " + exception.getMessage()); throw Application.createError(this, "validation"); } Document doc; try { doc = new SAXBuilder().build(file); } catch (final JDOMException exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(this, "parsing"); } catch (final Exception exception) { log.fine("Error, reading failed, exception: " + exception.getMessage()); throw Application.createError(this, "XMLRead"); } Element tag; try { tag = doc.getRootElement(); } catch (final Exception exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(this, "parsing"); } if (!tag.getName().equals("tape")) { log.fine("Error, parsing failed, no <tape> tag"); throw Application.createError(this, "noTape"); } if (!TAPE_XML_FILE_VERSION.equals(tag.getAttributeValue("version"))) { log.fine("Version mismatch"); throw Application.createError(this, "version"); } if (!"per sec".equals(tag.getAttributeValue("unit"))) { log.fine("Unsupported sample rate"); throw Application.createError(this, "XMLSampleRate"); } tape.clear(); try { long currPos = -1; for (Element pulse : tag.getChildren("pulse")) { final long start = Long.parseLong(pulse.getAttributeValue("start")); final long duration = Long.parseLong(pulse.getAttributeValue("duration")); if ((start <= currPos) || (duration <= 0)) { log.fine("Error in XML file"); throw Application.createError(this, "XML"); } tape.put(start, duration); log.finest(String.format("Read: (%d, %d)", start, duration)); currPos = start; } } catch (final Exception exception) { log.fine("Error, parsing failed, exception: " + exception.getMessage()); throw Application.createError(this, "parsing"); } log.fine("Reading completed"); }
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 w w w.java 2 s . co m*/ 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 {// w w 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(); } }