List of usage examples for org.jdom2 Element getValue
@Override
public String getValue()
From source file:jmri.managers.configurexml.AbstractAudioManagerConfigXML.java
License:Open Source License
/** * Utility method to load the individual Audio objects. If there's no * additional info needed for a specific Audio type, invoke this with the * parent of the set of Audio elements./*from w ww . j a v a2 s . c om*/ * * @param audio Element containing the Audio elements to load. */ @SuppressWarnings("unchecked") public void loadAudio(Element audio) { AudioManager am = InstanceManager.audioManagerInstance(); // Count number of loaded Audio objects int loadedObjects = 0; // Load buffers first List<Element> audioList = audio.getChildren("audiobuffer"); if (log.isDebugEnabled()) { log.debug("Found " + audioList.size() + " Audio Buffer objects"); } for (int i = 0; i < audioList.size(); i++) { Element e = audioList.get(i); String sysName = getSystemName(e); if (sysName == null) { log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes()); break; } String userName = getUserName(e); if (log.isDebugEnabled()) { log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")"); } try { AudioBuffer ab = (AudioBuffer) am.newAudio(sysName, userName); // load common parts loadCommon(ab, e); // load sub-type specific parts // Transient objects for reading child elements Element ce; String value; if ((ce = e.getChild("url")) != null) { ab.setURL(ce.getValue()); } if ((ce = e.getChild("looppoint")) != null) { if ((value = ce.getAttributeValue("start")) != null) { ab.setStartLoopPoint(Integer.parseInt(value)); } if ((value = ce.getAttributeValue("end")) != null) { ab.setEndLoopPoint(Integer.parseInt(value)); } } if ((ce = e.getChild("streamed")) != null) { ab.setStreamed(ce.getValue().equals("yes")); } } catch (AudioException ex) { log.error("Error loading AudioBuffer (" + sysName + "): " + ex); } } loadedObjects += audioList.size(); // Now load sources audioList = audio.getChildren("audiosource"); if (log.isDebugEnabled()) { log.debug("Found " + audioList.size() + " Audio Source objects"); } for (int i = 0; i < audioList.size(); i++) { Element e = audioList.get(i); String sysName = getSystemName(e); if (sysName == null) { log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes()); break; } String userName = getUserName(e); if (log.isDebugEnabled()) { log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")"); } try { AudioSource as = (AudioSource) am.newAudio(sysName, userName); // load common parts loadCommon(as, e); // load sub-type specific parts // Transient objects for reading child elements Element ce; String value; if ((ce = e.getChild("position")) != null) { as.setPosition(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z")))); } if ((ce = e.getChild("velocity")) != null) { as.setVelocity(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z")))); } if ((ce = e.getChild("assignedbuffer")) != null) { if (ce.getValue().length() != 0 && !ce.getValue().equals("null")) { as.setAssignedBuffer(ce.getValue()); } } if ((ce = e.getChild("gain")) != null && ce.getValue().length() != 0) { as.setGain(Float.parseFloat(ce.getValue())); } if ((ce = e.getChild("pitch")) != null && ce.getValue().length() != 0) { as.setPitch(Float.parseFloat(ce.getValue())); } if ((ce = e.getChild("distances")) != null) { if ((value = ce.getAttributeValue("ref")) != null) { as.setReferenceDistance(Float.parseFloat(value)); } if ((value = ce.getAttributeValue("max")) != null) { as.setMaximumDistance(Float.parseFloat(value)); } } if ((ce = e.getChild("loops")) != null) { if ((value = ce.getAttributeValue("min")) != null) { as.setMinLoops(Integer.parseInt(value)); } if ((value = ce.getAttributeValue("max")) != null) { as.setMaxLoops(Integer.parseInt(value)); } // if ((value = ce.getAttributeValue("mindelay"))!=null) // as.setMinLoopDelay(Integer.parseInt(value)); // if ((value = ce.getAttributeValue("maxdelay"))!=null) // as.setMaxLoopDelay(Integer.parseInt(value)); } if ((ce = e.getChild("fadetimes")) != null) { if ((value = ce.getAttributeValue("in")) != null) { as.setFadeIn(Integer.parseInt(value)); } if ((value = ce.getAttributeValue("out")) != null) { as.setFadeOut(Integer.parseInt(value)); } } if ((ce = e.getChild("dopplerfactor")) != null && ce.getValue().length() != 0) { as.setDopplerFactor(Float.parseFloat(ce.getValue())); } if ((ce = e.getChild("positionrelative")) != null) { as.setPositionRelative(ce.getValue().equals("yes")); } } catch (AudioException ex) { log.error("Error loading AudioSource (" + sysName + "): " + ex); } } loadedObjects += audioList.size(); // Finally, load Listeners if needed if (loadedObjects > 0) { audioList = audio.getChildren("audiolistener"); if (log.isDebugEnabled()) { log.debug("Found " + audioList.size() + " Audio Listener objects"); } for (int i = 0; i < audioList.size(); i++) { Element e = audioList.get(i); String sysName = getSystemName(e); if (sysName == null) { log.warn("unexpected null in systemName " + (e) + " " + (e).getAttributes()); break; } String userName = getUserName(e); if (log.isDebugEnabled()) { log.debug("create Audio: (" + sysName + ")(" + (userName == null ? "<null>" : userName) + ")"); } try { AudioListener al = (AudioListener) am.newAudio(sysName, userName); // load common parts loadCommon(al, e); // load sub-type specific parts // Transient object for reading child elements Element ce; if ((ce = e.getChild("position")) != null) { al.setPosition(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z")))); } if ((ce = e.getChild("velocity")) != null) { al.setVelocity(new Vector3f(Float.parseFloat(ce.getAttributeValue("x")), Float.parseFloat(ce.getAttributeValue("y")), Float.parseFloat(ce.getAttributeValue("z")))); } if ((ce = e.getChild("orientation")) != null) { al.setOrientation( new Vector3f(Float.parseFloat(ce.getAttributeValue("atX")), Float.parseFloat(ce.getAttributeValue("atY")), Float.parseFloat(ce.getAttributeValue("atZ"))), new Vector3f(Float.parseFloat(ce.getAttributeValue("upX")), Float.parseFloat(ce.getAttributeValue("upY")), Float.parseFloat(ce.getAttributeValue("upZ")))); } if ((ce = e.getChild("gain")) != null) { al.setGain(Float.parseFloat(ce.getValue())); } if ((ce = e.getChild("metersperunit")) != null) { al.setMetersPerUnit(Float.parseFloat((ce.getValue()))); } } catch (AudioException ex) { log.error("Error loading AudioListener (" + sysName + "): " + ex); } } Attribute a; if ((a = audio.getAttribute("distanceattenuated")) != null) { am.getActiveAudioFactory().setDistanceAttenuated(a.getValue().equals("yes")); } } }
From source file:Lectura.Archivo.java
public void leerXML(String path) { SAXBuilder builder = new SAXBuilder(); File xml = new File(path); try {/*from ww w.j a v a 2 s . c o m*/ Document doc = (Document) builder.build(xml); Element nodoRaiz = doc.getRootElement(); List dimensions = nodoRaiz.getChildren("dimension"); Element elemento = (Element) dimensions.get(0); dimension = elemento.getValue(); List dobles = nodoRaiz.getChildren("dobles"); Element doble = (Element) dobles.get(0); List casillas = doble.getChildren("casilla"); for (int i = 0; i < casillas.size(); i++) { Dimension dim; int x; int y; Element casilla = (Element) casillas.get(i); List posx = casilla.getChildren("x"); Element xx = (Element) posx.get(0); x = Integer.parseInt(xx.getValue()); List posy = casilla.getChildren("y"); Element yy = (Element) posy.get(0); y = Integer.parseInt(yy.getValue()); dim = new Dimension(x, y); listaCasillaDobles.add(dim); } List triples = nodoRaiz.getChildren("triples"); Element triple = (Element) triples.get(0); List casillas_t = triple.getChildren("casilla"); for (int i = 0; i < casillas_t.size(); i++) { Dimension dim; int x; int y; Element casilla_t = (Element) casillas_t.get(i); List posx = casilla_t.getChildren("x"); Element xx = (Element) posx.get(0); x = Integer.parseInt(xx.getValue()); List posy = casilla_t.getChildren("y"); Element yy = (Element) posy.get(0); y = Integer.parseInt(yy.getValue()); dim = new Dimension(x, y); listaCasillasTriples.add(dim); } List dic = nodoRaiz.getChildren("diccionario"); Element word = (Element) dic.get(0); List palabras = word.getChildren("palabra"); for (int i = 0; i < palabras.size(); i++) { Element palabra = (Element) palabras.get(i); getDiccionario().add(palabra.getValue()); } // } catch (Exception e) { } }
From source file:mammothkiosk.Bone.java
/** * Parses an xml file for the data not contained in the bones.xml bonerec. * This includes the xy min and max coordinates and coordinates for the * polylines to draw the bone./*from w w w . j a va 2 s . c om*/ * * @param root The root element to parse */ private void parseFile(Element root) { // Grab minimum X/Y values String parseMe = root.getChild("xymin").getValue(); int space = parseMe.substring(1).indexOf(" "); min = new Point2D.Float(Float.parseFloat(parseMe.substring(0, space)), Float.parseFloat(parseMe.substring(space + 1))); // Grab maximum X/Y values parseMe = root.getChild("xymax").getValue(); space = parseMe.substring(1).indexOf(" "); max = new Point2D.Float(Float.parseFloat(parseMe.substring(0, space)), Float.parseFloat(parseMe.substring(space + 1))); // Parse the shape Element shape = root.getChild("shape"); polylines = new ArrayList<>(); for (Element curElement : shape.getChildren("polyline")) { PolyLine polyline = new PolyLine(); for (Element coord : curElement.getChildren("xy")) { space = coord.getValue().substring(1).indexOf(" "); polyline.addX(Float.parseFloat(coord.getValue().substring(0, space))); polyline.addY(Float.parseFloat(coord.getValue().substring(space + 1))); } polylines.add(polyline); } }
From source file:me.iste.subsonicdialer.Factory.java
/** * @param document The XML {@link Document}. * @return Array of {@link Playlist}.// ww w.j a va 2 s. c o m */ public static Playlist[] createPlaylists(final Document document) { final Element searchResult = document.getRootElement().getChild("playlists", NS); final List<Element> playlistsElement = searchResult.getChildren("playlist", NS); final Playlist[] playlists = new Playlist[playlistsElement.size()]; int i = 0; for (final Element playlist : playlistsElement) { final List<Element> allowedUsersElement = playlist.getChildren("allowedUser", NS); final String[] allowedUsers = new String[allowedUsersElement.size()]; int j = 0; for (final Element allowedUser : allowedUsersElement) { allowedUsers[j++] = allowedUser.getValue(); } playlists[i++] = createPlaylist(playlist, allowedUsers, null); } return playlists; }
From source file:me.iste.subsonicdialer.Factory.java
/** * @param document The XML {@link Document}. * @return Array of {@link Child}./*from ww w. ja v a 2s . c om*/ */ public static Playlist createPlaylist(final Document document) { final Element playlist = document.getRootElement().getChild("playlist", NS); final List<Element> entries = playlist.getChildren("entry", NS); final Child[] childs = new Child[entries.size()]; int i = 0; for (final Element childElement : entries) { childs[i++] = createChild(childElement); } final List<Element> allowedUsersElement = playlist.getChildren("allowedUser", NS); final String[] allowedUsers = new String[allowedUsersElement.size()]; i = 0; for (final Element allowedUser : allowedUsersElement) { allowedUsers[i++] = allowedUser.getValue(); } return createPlaylist(playlist, allowedUsers, childs); }
From source file:me.iste.subsonicdialer.Factory.java
/** * @param document The XML {@link Document}. * @return The lyrics.//from w ww .ja v a 2s . c o m */ public static String createLyrics(final Document document) { final Element lyricsElement = document.getRootElement().getChild("lyrics", NS); return lyricsElement.getValue(); }
From source file:model.advertisement.AbstractAdvertisement.java
License:Open Source License
private boolean superHandleElement(Element e) { switch (e.getName()) { case "signature": setSignature(e.getValue()); return true; case "lastUpdated": lastUpdated = new Long(e.getValue()); return true; case "keyId": keyId = e.getValue();//from w w w .ja va 2 s . com return true; case "keys": if (e.getValue().isEmpty()) { keys = null; return true; } keys = new AsymKeysImpl(e.getValue()); return true; case "superPublicKey": return true; default: return handleElement(e); } }
From source file:model.data.contrat.Contrat.java
License:Open Source License
private void loadSignatories(Element e) { Element root = StringToElement.getElementFromString(e.getValue(), e.getName()); for (Element s : root.getChildren("signatory")) { addSignatory(s.getText());//www . j ava 2 s . co m } }
From source file:model.data.contrat.Contrat.java
License:Open Source License
private void loadItems(Element e) { Element root = StringToElement.getElementFromString(e.getValue(), e.getName()); for (Element i : root.getChildren()) { addItem(new Item(i)); }// w w w . j a v a 2 s. c o m }
From source file:model.data.contrat.Contrat.java
License:Open Source License
private void loadRules(Element e) { Element root = StringToElement.getElementFromString(e.getValue(), e.getName()); for (Element r : root.getChildren("rule")) { Element itemKeyElement = r.getChild("itemKey"); Element receiverElement = r.getChild("receiver"); if (itemKeyElement == null || receiverElement == null) continue; String itemKey = itemKeyElement.getText(); String receiver = receiverElement.getText(); if (!rules.containsKey(itemKey)) rules.put(itemKey, receiver); }/*from w ww .j ava 2s. c o m*/ }