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:mammothkiosk.Bone.java
/** * Constructor that takes a JDOM element as an argument. Parses the data from * bones.xml found in the element, then parses its specific id.xml file for * further data.//from w ww. j a v a 2s. c om * * @param boneRec The bone record to parse for information */ public Bone(Element boneRec) { // Retrieve info from boneRec (bones.xml file) Element temp; id = (temp = boneRec.getChild("uniqueid")) != null ? temp.getTextTrim() : null; year = (temp = boneRec.getChild("year")) != null ? temp.getTextTrim() : null; objectnum = (temp = boneRec.getChild("objectnum")) != null ? temp.getTextTrim() : null; part = (temp = boneRec.getChild("part")) != null ? temp.getTextTrim() : null; previous = (temp = boneRec.getChild("previous")) != null ? temp.getTextTrim() : null; taxon = (temp = boneRec.getChild("taxon")) != null ? temp.getTextTrim() : null; element = (temp = boneRec.getChild("element")) != null ? temp.getTextTrim() : null; subelement = (temp = boneRec.getChild("subelement")) != null ? temp.getTextTrim() : null; side = (temp = boneRec.getChild("side")) != null ? temp.getTextTrim() : null; portion = (temp = boneRec.getChild("portion")) != null ? temp.getTextTrim() : null; completeness = (temp = boneRec.getChild("completeness")) != null ? temp.getTextTrim() : null; expside = (temp = boneRec.getChild("expside")) != null ? temp.getTextTrim() : null; crack = (temp = boneRec.getChild("crack")) != null ? temp.getTextTrim() : null; articulate = (temp = boneRec.getChild("articulate")) != null ? temp.getTextTrim() : null; gender = (temp = boneRec.getChild("gender")) != null ? temp.getTextTrim() : null; remarks = (temp = boneRec.getChild("remarks")) != null ? temp.getTextTrim() : null; datefound = (temp = boneRec.getChild("datefound")) != null ? temp.getTextTrim() : null; foundby = (temp = boneRec.getChild("foundby")) != null ? temp.getTextTrim() : null; elevation = (temp = boneRec.getChild("elevation")) != null ? temp.getTextTrim() : null; updates = (temp = boneRec.getChild("updates")) != null ? temp.getTextTrim() : null; mappic = (temp = boneRec.getChild("mappic")) != null ? temp.getTextTrim() : null; fieldnotes = (temp = boneRec.getChild("fieldnotes")) != null ? temp.getTextTrim() : null; removed = (temp = boneRec.getChild("removed")) != null ? temp.getTextTrim() : null; removedby = (temp = boneRec.getChild("removedby")) != null ? temp.getTextTrim() : null; azimuth = (temp = boneRec.getChild("azimuth")) != null ? temp.getTextTrim() : null; incline = (temp = boneRec.getChild("incline")) != null ? temp.getTextTrim() : null; labrec = (temp = boneRec.getChild("labrec")) != null ? temp.getTextTrim() : null; objectid = (temp = boneRec.getChild("objectid")) != null ? temp.getTextTrim() : null; shapelength = (temp = boneRec.getChild("shapelength")) != null ? temp.getTextTrim() : null; min = null; max = null; polylines = null; boneImage = null; // Retrieve info for drawing bone from respective bone-shape file SAXBuilder saxBuild = new SAXBuilder(); Document doc; try { doc = saxBuild.build("../bonexml/" + id + ".xml"); Element rootElement = doc.getRootElement(); parseFile(rootElement); } catch (Exception ex) { System.out.println("Exception in Bone Constructor: " + ex.getMessage()); } }
From source file:mammothkiosk.MainWindow.java
/** * Parses bones.xml and creates an instance of the Bone class for each bone * record found within./*from ww w . ja v a2 s .c o m*/ * * @return the list of Bone objects specified by bones.xml */ private List<Bone> getBones() { List<Bone> temp = new ArrayList<>(); SAXBuilder saxBuild = new SAXBuilder(); Document doc; try { doc = saxBuild.build("../bonexml/bones.xml"); Element rootElement = doc.getRootElement(); for (Element bone : rootElement.getChildren("bonerec")) { temp.add(new Bone(bone)); } } catch (Exception ex) { System.out.println("Exception in Get Bones: " + ex.getMessage()); } return temp; }
From source file:mammothkiosk.Walkway.java
/** * Default constructor./*from w ww .j a v a2 s . c om*/ */ public Walkway() { // Retrieve info for drawing bone from respective bone-shape file SAXBuilder saxBuild = new SAXBuilder(); Document doc; try { doc = saxBuild.build("../bonexml/walkway.xml"); Element rootElement = doc.getRootElement(); parseFile(rootElement); } catch (Exception ex) { System.out.println("Exception in Bone Constructor: " + ex.getMessage()); } }
From source file:MCHelper.ToTree.java
private static void open(URL document) { SAXBuilder sxb = new SAXBuilder(); try {/*from w ww. j av a2 s . c o m*/ doc = sxb.build(document); root = doc.getRootElement(); } catch (Exception e) { System.out.println("Erreur : " + e); } }
From source file:me.iste.subsonicdialer.SubsonicDialer.java
License:Open Source License
/** * @param methode the methode.// w w w . j ava 2s . co m * @param parameters a {@link List} of {@link Parameter}. * @return The {@link Document}. * @throws JDOMException * @throws IOException * @throws SubsonicException */ public Document send(final String methode, final List<Parameter> parameters) throws JDOMException, IOException, SubsonicException { final HttpURLConnection httpConnection = this.connection.post(methode, parameters); final InputStream inputStream = httpConnection.getInputStream(); final SAXBuilder saxBuilder = new SAXBuilder(); final Document document = saxBuilder.build(inputStream); inputStream.close(); httpConnection.disconnect(); Factory.checkError(document); this.serverVersion = Factory.getVersion(document); return document; }
From source file:media.jplaylistparser.ASXPlaylistParser.java
License:Apache License
private String validateXML(String xml, SAXBuilder builder) throws JDOMException, IOException { Reader in;/*from w ww . ja va 2 s . com*/ int i = 0; xml = xml.replaceAll("\\&", "&"); while (i < 5) { in = new StringReader(xml); try { builder.build(in); break; } catch (JDOMParseException e) { String message = e.getMessage(); if (message.matches("^.*.The element type.*.must be terminated by the matching end-tag.*")) { String tag = message.substring(message.lastIndexOf("type") + 6, message.lastIndexOf("must") - 2); xml = xml.replaceAll("(?i)</" + tag + ">", "</" + tag + ">"); } else { break; } i++; } } return xml; }
From source file:media.jplaylistparser.ASXPlaylistParser.java
License:Apache License
private void parseXML(String xml, Playlist playlist) { SAXBuilder builder = new SAXBuilder(); Reader in;// w w w .j ava 2s . co m Document doc = null; Element root = null; try { xml = validateXML(xml, builder); in = new StringReader(xml); doc = builder.build(in); root = doc.getRootElement(); List<Element> children = castList(Element.class, root.getChildren()); for (int i = 0; i < children.size(); i++) { String tag = children.get(i).getName(); if (tag != null && tag.equalsIgnoreCase(ENTRY_ELEMENT)) { List<Element> children2 = castList(Element.class, children.get(i).getChildren()); buildPlaylistEntry(children2, playlist); } else if (tag != null && tag.equalsIgnoreCase(ENTRYREF_ELEMENT)) { URL url; HttpURLConnection conn = null; InputStream is = null; try { String href = children.get(i).getAttributeValue(HREF_ATTRIBUTE); if (href == null) { href = children.get(i).getAttributeValue(HREF_ATTRIBUTE.toUpperCase()); } if (href == null) { href = children.get(i).getValue(); } url = new URL(href); conn = (HttpURLConnection) url.openConnection(); conn.setConnectTimeout(6000); conn.setReadTimeout(6000); conn.setRequestMethod("GET"); String contentType = conn.getContentType(); is = conn.getInputStream(); AutoDetectParser parser = new AutoDetectParser(); //parser.parse(url.toString(), contentType, is, playlist); } catch (MalformedURLException e) { } catch (IOException e) { } finally { if (conn != null) { conn.disconnect(); } if (is != null) { try { is.close(); } catch (IOException e) { } } } } } } catch (JDOMException e) { } catch (IOException e) { } catch (Exception e) { } }
From source file:media.jplaylistparser.XSPFPlaylistParser.java
License:Apache License
private void parseXML(String xml, Playlist playlist) { SAXBuilder builder = new SAXBuilder(); Reader in;/* w w w. ja v a 2 s. c om*/ Document doc = null; Element root = null; try { in = new StringReader(xml); doc = builder.build(in); root = doc.getRootElement(); List<Element> children = castList(Element.class, root.getChildren()); for (int i = 0; i < children.size(); i++) { String tag = children.get(i).getName(); if (tag != null && tag.equalsIgnoreCase(TRACKLIST_ELEMENT)) { List<Element> children2 = castList(Element.class, children.get(i).getChildren()); for (int j = 0; j < children2.size(); j++) { String attributeName = children2.get(j).getName(); if (attributeName.equalsIgnoreCase(TRACK_ELEMENT)) { List<Element> children3 = castList(Element.class, children2.get(j).getChildren()); buildPlaylistEntry(children3, playlist); } } } } } catch (JDOMException e) { } catch (IOException e) { } catch (Exception e) { } }
From source file:mgbean.Listing.java
public Listing() { SAXBuilder builder = new SAXBuilder(); File f = new File("/home/joci/Joci/Java_Tanfolyam/cd_catalog.xml"); try {//w w w . j av a 2 s.com Document document = builder.build(f); Element root = document.getRootElement(); List<Element> elements = root.getChildren(); cds = new ArrayList<>(); for (Element oneCD : elements) { CD cd = new CD(oneCD.getChildText("ARTIST"), oneCD.getChildText("TITLE"), oneCD.getChildText("COMPANY"), oneCD.getChildText("COUNTRY"), Double.parseDouble(oneCD.getChildText("PRICE")), Integer.parseInt(oneCD.getChildText("YEAR"))); cds.add(cd); } } catch (JDOMException | IOException ex) { System.out.println(ex); } }
From source file:middleware.Reserva.java
public static void EliminarReserva(String reservaEliminar) { try {//ww w . jav a 2 s .com //Se crea un SAXBuilder para poder parsear el archivo SAXBuilder builder = new SAXBuilder(); //archivo que tiene las reservas File xmlFile = new File("reserva.xml"); //objeto que caragra el archivo tipo document Document doc = (Document) builder.build(xmlFile); //se obtiene el padre del xml Element rootNode = doc.getRootElement(); //se obtiene el hijo "reserva" List reservas = rootNode.getChildren("reserva"); //se declara un iterator para recorrer el archivo Iterator iter = reservas.iterator(); //se recorre el archivo while (iter.hasNext()) { Element reserva = (Element) iter.next(); //se elimina la reserva ya pagada if (reserva.getAttributeValue("clave").equals(reservaEliminar)) { iter.remove(); } } XMLOutputter xmlOutput = new XMLOutputter(); // display nice nice xmlOutput.setFormat(Format.getPrettyFormat()); //se guardan los cambios xmlOutput.output(doc, new FileWriter("reserva.xml")); } catch (IOException io) { io.printStackTrace(); } catch (JDOMException e) { e.printStackTrace(); } }