List of usage examples for org.jdom2 Document getRootElement
public Element getRootElement()
Element
for this Document
From source file:com.globalsight.dispatcher.controller.TranslateXLFController.java
License:Apache License
private String parseXLF(JobBO p_job, File p_srcFile) { if (p_srcFile == null || !p_srcFile.exists()) return "File not exits."; String srcLang, trgLang;//from w w w .j a v a2 s . c o m List<String> srcSegments = new ArrayList<String>(); try { SAXBuilder builder = new SAXBuilder(); Document read_doc = builder.build(p_srcFile); // Get Root Element Element root = read_doc.getRootElement(); Namespace namespace = root.getNamespace(); Element fileElem = root.getChild("file", namespace); // Get Source/Target Language srcLang = fileElem.getAttributeValue(XLF_SOURCE_LANGUAGE); trgLang = fileElem.getAttributeValue(XLF_TARGET_LANGUAGE); XPathFactory xFactory = XPathFactory.instance(); XPathExpression<Element> expr = xFactory.compile("//trans-unit", Filters.element(), null, namespace); List<Element> list = expr.evaluate(fileElem.getChild("body", namespace)); for (int i = 0; i < list.size(); i++) { Element tuElem = (Element) list.get(i); Element srcElem = tuElem.getChild("source", namespace); // Get Source Segment if (srcElem != null && srcElem.getContentSize() > 0) { String source = getInnerXMLString(srcElem); srcSegments.add(source); } } p_job.setSourceLanguage(srcLang); p_job.setTargetLanguage(trgLang); p_job.setSourceSegments(srcSegments); } catch (Exception e) { String msg = "Parse XLIFF file error."; logger.error(msg, e); return msg; } return null; }
From source file:com.gmapp.comun.LeerPathFromXML.java
public String cargarXml(String tipoPathBuscado) { //System.out.println("Buscando path para \"" + tipoPathBuscado + "\" ..."); String pathBuscado = ""; //Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); InputStream xmlFile = getClass().getResourceAsStream("/xml/pathFiles.xml"); try {/* www.j av a 2 s. co m*/ //Se crea el documento a traves del archivo Document document = (Document) builder.build(xmlFile); //Se obtiene la raiz 'Sistemas' Element rootNode = document.getRootElement(); //Se obtiene la lista de hijos de la raiz 'Sistemas' List list = rootNode.getChildren("Sistema"); //Se recorre la lista de hijos de 'Sistemas' for (int i = 0; i < list.size(); i++) { //Se obtiene el elemento 'Sistema' Element sistema = (Element) list.get(i); //Se obtiene el atributo 'nombre' que esta en el tag 'Sistema' String nombreSistema = sistema.getAttributeValue("nombre"); if (SysOper.contains(nombreSistema)) { //System.out.println("Sistema: " + nombreSistema ); //Se obtiene la lista de hijos del tag 'Sistema~nombre ' List lista_registros = sistema.getChildren(); //Se recorre la lista de campos for (int j = 0; j < lista_registros.size(); j++) { //Se obtiene el elemento 'campo' Element campo = (Element) lista_registros.get(j); //Se obtienen los valores que estan entre los tags '<campo></campo>' //Se obtiene el valor que esta entre los tags '<nombre></nombre>' String nombre = campo.getChildTextTrim("nombrePath"); if (nombre.equals(tipoPathBuscado)) { //Se obtiene el valor que esta entre los tags '<valor></valor>' pathBuscado = campo.getChildTextTrim("path"); //System.out.println( "\t"+nombre+"\t"+pathBuscado); } } } } } catch (IOException io) { System.out.println(io.getMessage()); } catch (JDOMException jdomex) { System.out.println(jdomex.getMessage()); } return pathBuscado; }
From source file:com.googlecode.mipnp.extension.rhythmbox.RhythmboxExtension.java
License:Open Source License
private List<MusicTrack> getMusicTracks() { List<MusicTrack> tracks = new ArrayList<MusicTrack>(); Map<String, MusicAlbum> albums = new HashMap<String, MusicAlbum>(); try {//from ww w .ja va 2s.c o m Document document = builder.build(db); Element rootNode = document.getRootElement(); List<Element> list = rootNode.getChildren("entry"); for (Element entry : list) { if (entry.getAttribute("type").getValue().equals("song")) { try { MusicTrack track = new MusicTrack(); track.setTitle(entry.getChildText("title")); track.setArtist(entry.getChildText("artist")); track.setGenre(entry.getChildText("genre")); track.setDuration(Integer.parseInt(entry.getChildText("duration")) * 1000); track.setTrackNumber(Integer.parseInt(entry.getChildText("track-number"))); track.setBitRate(Integer.parseInt(entry.getChildText("bitrate"))); track.setFile(new File(new URI(entry.getChildText("location")))); String strAlbum = entry.getChildText("album"); MusicAlbum album = albums.get(strAlbum); if (album == null) { album = new MusicAlbum(strAlbum, entry.getChildText("album-artist")); albums.put(strAlbum, album); } track.setAlbum(album); tracks.add(track); } catch (NumberFormatException ex) { System.err.println("ERROR: " + ex.getMessage()); } catch (URISyntaxException ex) { System.err.println("ERROR: " + ex.getMessage()); } } } } catch (JDOMException ex) { System.err.println("ERROR: " + ex.getMessage()); } catch (IOException ex) { System.err.println("ERROR: " + ex.getMessage()); } return tracks; }
From source file:com.hack23.cia.service.external.common.impl.XmlAgentImpl.java
License:Apache License
/** * Sets the name space on xml stream.//from w ww.j av a 2 s.c om * * @param in * the in * @param nameSpace * the name space * @return the source * @throws Exception * the exception */ private static Source setNameSpaceOnXmlStream(final InputStream in, final String nameSpace) throws Exception { final SAXBuilder sb = new SAXBuilder(new XMLReaderSAX2Factory(false)); final Document doc = sb.build(in); doc.getRootElement().setNamespace(Namespace.getNamespace(nameSpace)); return new JDOMSource(doc); }
From source file:com.hotaviano.tableexporter.csv.CSVExporter.java
License:Open Source License
private void createBody(Document doc, PrintWriter writer) { Element tbody = doc.getRootElement().getChild("tbody"); for (Element tr : tbody.getChildren()) { String line = ""; for (Element td : tr.getChildren()) { line += td.getText() + ","; }/* w w w .j av a 2 s.c om*/ writer.println(line.substring(0, line.length() - 1)); } }
From source file:com.hotaviano.tableexporter.csv.CSVExporter.java
License:Open Source License
private void createHeader(Document doc, PrintWriter writer) { Element thead = doc.getRootElement().getChild("thead").getChildren().get(0); String header = ""; for (Element elem : thead.getChildren()) { header += elem.getText() + ","; }/* w ww. j av a 2 s . c om*/ writer.println(header.subSequence(0, header.length() - 1)); }
From source file:com.hotaviano.tableexporter.docx.DOCXExporter.java
License:Open Source License
private void createHeaderTable(XWPFTable table, Document document) { List<Element> elements = document.getRootElement().getChild("thead").getChildren().get(0).getChildren(); int i = 0;//from w w w. j av a 2 s.co m for (Element element : elements) { table.getRow(0).getCell(i++).setText(element.getText()); } }
From source file:com.hotaviano.tableexporter.docx.DOCXExporter.java
License:Open Source License
private void createBodyTable(XWPFTable table, Document document) { List<Element> elements = document.getRootElement().getChild("tbody").getChildren(); int row = 1;//from www .j a v a 2 s . c om for (Element element : elements) { XWPFTableRow tableRow = table.getRow(row++); int col = 0; for (Element td : element.getChildren()) { tableRow.getCell(col++).setText(td.getText()); } } }
From source file:com.hotaviano.tableexporter.docx.DOCXExporter.java
License:Open Source License
private int getHeaderSize(Document doc) { return doc.getRootElement().getChild("thead").getChild("tr").getChildren().size(); }
From source file:com.hotaviano.tableexporter.docx.DOCXExporter.java
License:Open Source License
private int getBodySize(Document doc) { return doc.getRootElement().getChild("tbody").getChildren().size(); }