List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java
License:Apache License
/** * TextElement /*from w ww . jav a 2 s . c o m*/ * * @param doc - Document ? * @param addNDName - ? Elememt * @param list - TextElement * @param path * @throws TransformerException * @throws TransformerConfigurationException * @throws FileNotFoundException */ public void addTextElement(Document doc, String addNDName, List<?> list, String path) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException { StreamResult sTResult = null; FileOutputStream fos = null; Element root = doc.getRootElement(); addTextNode(root, addNDName, list); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer serializer = transformerFactory.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "euc-kr"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); if (path != null) { fos = new FileOutputStream(path); sTResult = new StreamResult(fos); serializer.transform(new JDOMSource(doc), sTResult); fos.close(); } else { fos = new FileOutputStream(savedPath + "addElement.xml"); sTResult = new StreamResult(fos); serializer.transform(new JDOMSource(doc), sTResult); fos.close(); } }
From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java
License:Apache License
/** * TextElement Update/* w ww. ja v a 2 s. co m*/ * * @param doc - Document ? * @param list - update TextNode * @param path - ? XML * @throws TransformerException * @throws TransformerConfigurationException * @throws FileNotFoundException */ public void updTextElement(Document doc, List<?> list, String path) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException { StreamResult sTResult = null; FileOutputStream fos = null; Element root = doc.getRootElement(); updTextNode(root, list); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer serializer = transformerFactory.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "euc-kr"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); if (path != null) { fos = new FileOutputStream(path); sTResult = new StreamResult(fos); serializer.transform(new JDOMSource(doc), sTResult); fos.close(); } else { fos = new FileOutputStream(savedPath + "updTEXT.xml"); sTResult = new StreamResult(fos); serializer.transform(new JDOMSource(doc), sTResult); fos.close(); } }
From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java
License:Apache License
/** * Element /*from w ww. j a v a 2 s .c o m*/ * * @param doc - document ? * @param nodeName - * @param path - ? XML * @throws TransformerException * @throws TransformerConfigurationException * @throws FileNotFoundException */ public void delElement(Document doc, String nodeName, String path) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException { StreamResult sTResult = null; FileOutputStream fos = null; Element element = doc.getRootElement(); removeNode(element, nodeName); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer serializer = transformerFactory.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "euc-kr"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); if (path != null) { fos = new FileOutputStream(path); sTResult = new StreamResult(fos); serializer.transform(new JDOMSource(doc), sTResult); fos.close(); } else { fos = new FileOutputStream(savedPath + "delXML.xml"); sTResult = new StreamResult(fos); serializer.transform(new JDOMSource(doc), sTResult); fos.close(); } }
From source file:egovframework.rte.fdl.xml.AbstractXMLUtility.java
License:Apache License
/** * Element Update//from w ww . jav a 2s . c o m * * @param doc - document ? * @param oldNodename - * @param newNodeName - * @param path - ? XML * @throws TransformerException * @throws TransformerConfigurationException * @throws FileNotFoundException */ public void updElement(Document doc, String oldNodename, String newNodeName, String path) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException { StreamResult sTResult = null; FileOutputStream fos = null; Element root = doc.getRootElement(); chgNode(root, oldNodename, newNodeName); TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer serializer = transformerFactory.newTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, "euc-kr"); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); if (path != null) { fos = new FileOutputStream(path); sTResult = new StreamResult(fos); serializer.transform(new JDOMSource(doc), sTResult); fos.close(); } else { fos = new FileOutputStream(savedPath + "updElement.xml"); sTResult = new StreamResult(fos); serializer.transform(new JDOMSource(doc), sTResult); fos.close(); } }
From source file:engine.Engine.java
License:Open Source License
public void loadLevel(String filePath) throws JDOMException, IOException { SAXBuilder sax = new SAXBuilder(); Document doc; doc = sax.build(new File(filePath)); Element root = doc.getRootElement(); List<Element> listElem = root.getChildren(); for (Element elem : listElem) { Entity entity = null;//from www . j a va 2s . c om switch (elem.getName()) { case "BreakableBlock": entity = new BreakableBlock(this); break; case "SolidBlock": entity = new SolidBlock(this); break; case "Bomb": entity = new Bomb(this); break; case "Fire": entity = new Fire(this); break; case "Bomberman": entity = new Bomberman(this); break; case "Bonus": Bonus bonus = new Bonus(this); bonus.setBomb(elem.getAttribute("bomb").getIntValue()); bonus.setPower(elem.getAttribute("power").getIntValue()); bonus.setSpeed(elem.getAttribute("speed").getIntValue()); entity = bonus; break; case "SpeedBonus": entity = new SpeedBonus(this); break; case "PowerBonus": entity = new PowerBonus(this); break; case "BombBonus": entity = new BombBonus(this); break; case "KickBonus": entity = new KickBonus(this); break; case "FutureBonus": futureBonus(elem); continue; default: this.log.warn("loadLevel: unknown type object -> " + elem.getName()); continue; } Vector2f position = new Vector2f(); position.x = elem.getAttribute("x").getIntValue() * 1000; position.y = elem.getAttribute("y").getIntValue() * 1000; entity.setPosition(position); entity.setDirection(elem.getAttribute("dir").getIntValue()); addEntity(entity); } this.collisionManager.addHandler(new BombermanBlockCH(this.collisionManager)); this.collisionManager.addHandler(new BombermanBonusCH()); this.collisionManager.addHandler(new BombermanFireCH()); this.collisionManager.addHandler(new BombFireCH()); this.collisionManager.addHandler(new BonusFireCH()); this.collisionManager.addHandler(new BlockFireCH()); this.collisionManager.addHandler(new BombBlockCH()); BombermanBombCH han = new BombermanBombCH(this.collisionManager); addListener(han); this.collisionManager.addHandler(han); this.loaded = true; }
From source file:es.ucm.fdi.ac.Analysis.java
License:Open Source License
/** * Reads an analysis from a file//from w w w . j av a2 s . c o m * * @param f the file to read from * @throws IOException on any error (may wrap invalid internal XML errors) */ public void loadFromFile(File f) throws IOException { try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(f); loadFromXML(doc.getRootElement()); } catch (Exception e) { throw new IOException("Error loading from '" + f.getAbsolutePath() + "' xml save file", e); } }
From source file:es.ucm.fdi.ac.gui.MainGui.java
License:Open Source License
/** * Load a test help file, adhering to the following structure: * <helppairs>/* w w w . j a va 2 s. c o m*/ * <testhelp> * <testname>...</testname> * <helpcontent>...</helpcontent> * </testhelp> * ... * </helppairs> * Notice that 'helpcontent' should be XHTML: old-fashioned HTML may fail to * validate. */ public HashMap<String, String> loadTestHelpFile(String fileName) throws IOException { HashMap<String, String> m = new HashMap<String, String>(); XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); URL url = getClass().getClassLoader().getResource(fileName); try { Document doc = (new SAXBuilder()).build(url); for (Element th : doc.getRootElement().getChildren()) { m.put(th.getChildTextTrim("testname"), outputter.outputString(th.getChild("helpcontent"))); } } catch (JDOMException | NullPointerException e) { throw new IOException("Impossible to read XML file for " + url, e); } return m; }
From source file:es.ucm.fdi.clover.gui.CloverSave.java
License:Open Source License
/** * Restores the CloverSave to a different XML file; totally changes the * 'views' (it is basically recreated) output array; *//* w ww .ja v a2 s. co m*/ public static ArrayList<ClusterView> restore(BaseGraph base, ClusterViewFactory vf, File f) throws IOException { if (vf == null) { vf = new DefaultClusterViewFactory(); } ArrayList<ClusterView> views = new ArrayList<ClusterView>(); HashMap<String, Filter> filters = new HashMap<String, Filter>(); HashMap<String, ClusterHierarchy> hierarchies = new HashMap<String, ClusterHierarchy>(); SAXBuilder builder = new SAXBuilder(); ClassLoader loader = base.getClass().getClassLoader(); try { Document doc = builder.build(f.getAbsolutePath()); Element root = doc.getRootElement(); Element sharedElems = (Element) root.getChildren().get(0); for (Element e : (List<Element>) sharedElems.getChildren()) { if (e.getName().equals("filter")) { String className = e.getAttributeValue("filterClass"); Filter filter = (Filter) loader.loadClass(className).newInstance(); filter.restore(e); filters.put(e.getAttributeValue("id"), filter); } else if (e.getName().equals("hierarchy")) { Element cluster = (Element) e.getChildren().get(0); Element clusterer = (Element) e.getChildren().get(1); String className = clusterer.getAttributeValue("engineClass"); ClusteringEngine engine = (ClusteringEngine) loader.loadClass(className).newInstance(); engine.restore(clusterer); BaseGraph hb = base; if (e.getAttribute("filterId") != null) { Filter filter = filters.get(e.getAttributeValue("filterId")); hb = new FilteredGraph(base, filter); } ClusterHierarchy h = new ClusterHierarchy(e, hb, engine); hierarchies.put(e.getAttributeValue("id"), h); } } for (Element e : (List<Element>) root.getChildren()) { if (!e.getName().equals("view")) continue; // build view String hid = e.getAttributeValue("hierarchyId"); ClusterView view = vf.createClusterView(hierarchies.get(hid), e); view.restore(e); Element layoutCache = (Element) e.getChildren().get(0); view.getAnimator().getLayoutCache().restore(layoutCache, view.getBase()); Element animatorProps = (Element) e.getChildren().get(1); view.getAnimator().restore(animatorProps); views.add(view); } } // indicates a well-formedness error catch (JDOMException jde) { log.warn("Document is not well-formed XML"); jde.printStackTrace(); } catch (IOException ioe) { System.out.println(ioe); ioe.printStackTrace(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); } return views; }
From source file:es.upm.dit.xsdinferencer.extraction.extractorImpl.JSONTypesExtractorImpl.java
License:Apache License
/** * Method that performs the conversion between JSON and XML * @param jsonRoot the root of the JSON document. It must be either a {@link JSONObject} or a {@link JSONArray} * @param namespaceRoot the namespace of the resulting root element * @return a JDOM2 {@link Document} representing the obtained XML. * @throws JDOMException/*from w ww .ja v a 2s.co m*/ * @throws IOException */ protected Document convertJSONToXML(Object jsonRoot, Namespace namespaceRoot) throws JDOMException, IOException { if (!(jsonRoot instanceof JSONArray || jsonRoot instanceof JSONObject)) { throw new IllegalArgumentException("'jsonRoot' must be either a JSONObject or a JSONArray"); } quoteStringsAtJSON(jsonRoot); addPrefixToJSONKeysEndingsRecursive(jsonRoot, XSDInferenceConfiguration.ARRAY_ELEMENT_NAME, XSDInferenceConfiguration.ARRAY_ELEMENT_ESCAPING_PREFIX); encapsulateArraysAtJSONRecursive(jsonRoot); String xmlString = "<" + XSDInferenceConfiguration.XML_ROOT_NAME + ">" + XML.toString(jsonRoot) + "</" + XSDInferenceConfiguration.XML_ROOT_NAME + ">"; SAXBuilder saxBuilder = new SAXBuilder(); Document xmlDocument = saxBuilder.build(new StringReader(xmlString)); setNamespaceToElementsByName(XSDInferenceConfiguration.ARRAY_ELEMENT_NAME, xmlDocument.getRootElement(), XSDInferenceConfiguration.NAMESPACE_ARRAY_ELEMENT); removePrefixToElementNameEndings(xmlDocument.getRootElement(), XSDInferenceConfiguration.ARRAY_ELEMENT_NAME, XSDInferenceConfiguration.ARRAY_ELEMENT_ESCAPING_PREFIX); xmlDocument.getRootElement().setNamespace(namespaceRoot); sortElementsRecursive(xmlDocument.getRootElement()); return xmlDocument; }
From source file:es.uvigo.ei.sing.rubioseq.gui.view.models.configuration.ConfigProgramPathsChipSeq.java
License:Open Source License
public void loadDataFromFile(File editFile) { loadDefaultParameters(editFile);// w ww .ja v a 2 s . c om SAXBuilder saxBuilder = new SAXBuilder(); try { Document document = saxBuilder.build(editFile); Element configData = document.getRootElement(); Element bwaPath = configData.getChild(BWA_PATH); if (validElement(bwaPath)) { this.setBwaPath(Utils.getRUbioSeqFile(bwaPath.getValue())); } Element samtoolsPath = configData.getChild(SAMTOOLS_PATH); if (validElement(samtoolsPath)) { this.setSamtoolsPath(Utils.getRUbioSeqFile(samtoolsPath.getValue())); } Element picardPath = configData.getChild(PICARD_PATH); if (validElement(picardPath)) { this.setPicardPath(Utils.getRUbioSeqFile(picardPath.getValue())); } Element MACSPath = configData.getChild(MACS_PATH); if (validElement(MACSPath)) { this.setMacsPath(Utils.getRUbioSeqFile(MACSPath.getValue())); } Element PythonPath = configData.getChild(PYTHON_PATH); if (validElement(PythonPath)) { this.setPythonPath(Utils.getRUbioSeqFile(PythonPath.getValue())); } Element fastqcPath = configData.getChild(FASTQC_PATH); if (validElement(fastqcPath)) { this.setFastqcPath(Utils.getRUbioSeqFile(fastqcPath.getValue())); } Element BEDToolsPath = configData.getChild(BED_TOOLS_PATH); if (validElement(BEDToolsPath)) { this.setBedtoolsPath(Utils.getRUbioSeqFile(BEDToolsPath.getValue())); } Element BedgraphtoWigPath = configData.getChild(BGTW_PATH); if (validElement(BedgraphtoWigPath)) { this.setBedgraphtobigwigPath(Utils.getRUbioSeqFile(BedgraphtoWigPath.getValue())); } Element IDRPath = configData.getChild(IDR_PATH); if (validElement(IDRPath)) { this.setIdrPath(Utils.getRUbioSeqFile(IDRPath.getValue())); } Element PeakAnnotatorPath = configData.getChild(PEAKANNOTATOR_PATH); if (validElement(PeakAnnotatorPath)) { this.setPeakannotatorPath(Utils.getRUbioSeqFile(PeakAnnotatorPath.getValue())); } Element CCATPath = configData.getChild(CCAT_PATH); if (validElement(CCATPath)) { this.setCcatPath(Utils.getRUbioSeqFile(CCATPath.getValue())); } Element nthr = configData.getChild(NTHR); if (validElement(nthr)) { try { this.setNthr(Integer.valueOf(nthr.getValue())); } catch (Exception e) { } } Element javaRam = configData.getChild(JAVA_RAM); if (validElement(javaRam)) { this.setJavaRam(javaRam.getValue()); } Element queueSystem = configData.getChild(QUEUE_SYSTEM); System.err.println("\n\n\t QUEUE_SYSTEM = " + queueSystem + "\n"); if (validElement(queueSystem)) { String queueSystemValue = queueSystem.getValue().toUpperCase(); if (queueSystemValue.equals("SGE")) { this.setQueueSystem(QueueSystem.SGE); } else if (queueSystemValue.equals("PBS")) { this.setQueueSystem(QueueSystem.PBS); } else if (queueSystemValue.equals("NONE")) { this.setQueueSystem(QueueSystem.NONE); } } Element queueName = configData.getChild(QUEUE_NAME); if (validElement(queueName)) { this.setQueueName(queueName.getValue()); } Element multicoreName = configData.getChild(MULTICORE_NAME); if (validElement(multicoreName)) { this.setMulticoreName(multicoreName.getValue()); } Element multicoreNumber = configData.getChild(MULTICORE_NUMBER); if (validElement(multicoreNumber)) { try { this.setMulticoreNumber(Integer.valueOf(multicoreNumber.getValue())); } catch (Exception e) { } } } catch (JDOMException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }