List of usage examples for org.jdom2 Attribute getValue
public String getValue()
Attribute
. From source file:io.wcm.handler.link.Link.java
License:Apache License
/** * @return Map with all attributes of the anchor element. Returns null if anchor element is null. *//*from w w w . j a va2s . c om*/ public Map<String, String> getAnchorAttributes() { if (getAnchor() == null) { return null; } Map<String, String> attributes = new HashMap<>(); for (Attribute attribute : getAnchor().getAttributes()) { attributes.put(attribute.getName(), attribute.getValue()); } return attributes; }
From source file:io.wcm.handler.richtext.impl.RichTextRewriteContentHandlerImpl.java
License:Apache License
/** * Support data structures where link metadata is stored in mutliple HTML5 data-* attributes. * @param pResourceProps Valuemap to write link metadata to * @param element Link element//from www.ja v a2 s . co m * @return true if any metadata attribute was found */ private boolean getAnchorMetadataFromData(ValueMap pResourceProps, Element element) { boolean foundAny = false; List<Attribute> attributes = element.getAttributes(); for (Attribute attribute : attributes) { if (DataPropertyUtil.isHtml5DataName(attribute.getName())) { String value = attribute.getValue(); if (StringUtils.isNotEmpty(value)) { String property = DataPropertyUtil.toHeadlessCamelCaseName(attribute.getName()); if (StringUtils.startsWith(value, "[") && StringUtils.endsWith(value, "]")) { try { JSONArray jsonArray = new JSONArray(value); String[] values = new String[jsonArray.length()]; for (int i = 0; i < jsonArray.length(); i++) { values[i] = jsonArray.optString(i); } pResourceProps.put(property, values); } catch (JSONException ex) { // ignore } } else { // decode if required value = decodeIfEncoded(value); pResourceProps.put(property, value); } foundAny = true; } } } return foundAny; }
From source file:io.wcm.handler.richtext.impl.RichTextRewriteContentHandlerImpl.java
License:Apache License
/** * Support legacy data structures where link metadata is stored as JSON fragment in single HTML5 data attribute. * @param pResourceProps Valuemap to write link metadata to * @param element Link element/*from w w w . j a va 2 s.c om*/ */ private boolean getAnchorLegacyMetadataFromSingleData(ValueMap pResourceProps, Element element) { boolean foundAny = false; JSONObject metadata = null; Attribute dataAttribute = element.getAttribute("data"); if (dataAttribute != null) { String metadataString = dataAttribute.getValue(); if (StringUtils.isNotEmpty(metadataString)) { try { metadata = new JSONObject(metadataString); } catch (JSONException ex) { RichTextHandlerImpl.log.debug("Invalid link metadata: " + metadataString, ex); } } } if (metadata != null) { JSONArray names = metadata.names(); for (int i = 0; i < names.length(); i++) { String name = names.optString(i); pResourceProps.put(name, metadata.opt(name)); foundAny = true; } } return foundAny; }
From source file:io.wcm.maven.plugins.contentpackage.unpacker.OneAttributePerLineXmlProcessor.java
License:Apache License
@Override protected void printAttribute(Writer out, FormatStack fstack, Attribute attribute) throws IOException { if (!attribute.isSpecified() && fstack.isSpecifiedAttributesOnly()) { return;// ww w. j a va 2s . c om } write(out, StringUtils.defaultString(fstack.getLineSeparator())); write(out, StringUtils.defaultString(fstack.getLevelIndent())); write(out, StringUtils.defaultString(fstack.getIndent())); write(out, StringUtils.defaultString(fstack.getIndent())); write(out, attribute.getQualifiedName()); write(out, "="); write(out, "\""); attributeEscapedEntitiesFilter(out, fstack, attribute.getValue()); write(out, "\""); }
From source file:jmri.jmrit.vsdecoder.VSDecoderPreferences.java
License:Open Source License
public void load(org.jdom2.Element e) { if (e == null) { return;/*from w w w .j a va2s . co m*/ } org.jdom2.Attribute a; org.jdom2.Element c; if ((a = e.getAttribute("isAutoStartingEngine")) != null) { setAutoStartEngine(a.getValue().compareTo("true") == 0); } if ((a = e.getAttribute("isAutoLoadingDefaultVSDFile")) != null) { setAutoLoadDefaultVSDFile(a.getValue().compareTo("true") == 0); } if ((c = e.getChild("DefaultVSDFilePath")) != null) { setDefaultVSDFilePath(c.getValue()); } if ((c = e.getChild("DefaultVSDFileName")) != null) { setDefaultVSDFileName(c.getValue()); } if ((c = e.getChild("ListenerPosition")) != null) { _listenerPosition = new ListeningSpot(c); } else { _listenerPosition = new ListeningSpot(); } if ((c = e.getChild("AudioMode")) != null) { setAudioMode(c.getValue()); } }
From source file:jmri.jmrix.loconet.cmdstnconfig.XmlConfig.java
License:Open Source License
@SuppressWarnings("unchecked") static void dumpNode(Element node, int depth) { int leader;/*from w ww . j a va2 s . c o m*/ for (leader = 0; leader < depth; leader++) { System.out.print('\t'); } System.out.print(node.getName()); Iterator<Attribute> attributes = node.getAttributes().iterator(); Attribute attribute; while (attributes.hasNext()) { attribute = attributes.next(); System.out.print(" " + attribute.getName() + " = " + attribute.getValue()); } System.out.println(); Iterator<Element> children = node.getChildren().iterator(); depth++; while (children.hasNext()) { dumpNode(children.next(), depth); } }
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./*ww w .j a v a2 s .c o m*/ * * @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:jodtemplate.pptx.preprocessor.PicPreprocessor.java
License:Apache License
public Document process(final Map<String, Object> context, final Document document, final Slide slide, final Resources resources, final Configuration configuration) throws JODTemplateException { final ExpressionHandler expressionHandler = configuration.getExpressionHandler(); final IteratorIterable<Element> picElements = document .getDescendants(Filters.element(PPTXDocument.PIC_ELEMENT, getPresentationmlNamespace())); final List<Element> picElementsList = new ArrayList<>(); while (picElements.hasNext()) { picElementsList.add(picElements.next()); }/*from w w w.j a v a 2 s . co m*/ for (Element pic : picElementsList) { final Attribute descr = pic.getChild(PPTXDocument.NVPICPR_ELEMENT, getPresentationmlNamespace()) .getChild(PPTXDocument.CNVPR_ELEMENT, getPresentationmlNamespace()) .getAttribute(PPTXDocument.DESCR_ATTR); if (descr != null && expressionHandler.isExpression(descr.getValue())) { final VariableExpression expression = expressionHandler.createVariableExpression(descr.getValue()); Object value; try { value = PropertyUtils.getNestedProperty(context, expression.getVariable()); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new JODTemplateException("Unable to get value: " + expression.getVariable()); } if (value instanceof ImageField) { final ImageField imageField = (ImageField) value; imageService.insertImage(imageField, slide, resources, pic); } else { throw new JODTemplateException("Field " + expression.getVariable() + " should contain image."); } } } return document; }
From source file:jworkspace.ui.plaf.XPlafConnector.java
License:Open Source License
/** * Sets look and feel, this class is connected to, along with * currently selected theme.//w w w . ja va2 s . c o m */ void setLookAndFeel() { /* * We use only metal themes by now */ Class[] argsTypes = new Class[] { MetalTheme.class }; /* * Instantiate method */ try { Class lafClazz = Class.forName(info.getClassName()); /* * Invoke method */ if (method != null) { Attribute nameAttr = method.getAttribute(NAME_ATTRIBUTE); Attribute staticAttr = method.getAttribute("static"); Method setTheme = lafClazz.getMethod(nameAttr.getValue(), argsTypes); /* * Only for static invocation by now */ if (currentTheme != null && staticAttr.getValue().equals("true")) { setTheme.invoke(null, currentTheme); } } UIManager.setLookAndFeel(info.getClassName()); } catch (Exception e) { LOG.error("Can't set look and feel", e); } }
From source file:neon.core.GameLoader.java
License:Open Source License
private void loadPlayer(Element playerData, Atlas atlas) { // player aanmaken RCreature species = (RCreature) Engine.getResources().getResource(playerData.getAttributeValue("race")); Player player = new Player(new RCreature(species.toElement()), playerData.getAttributeValue("name"), Gender.valueOf(playerData.getAttributeValue("gender").toUpperCase()), Player.Specialisation.valueOf(playerData.getAttributeValue("spec")), playerData.getAttributeValue("prof")); engine.startGame(/* ww w . j av a 2 s . c om*/ new Game(player, engine.getFileSystem(), engine.getScriptEngine(), engine.getPhysicsEngine())); Rectangle bounds = player.getShapeComponent(); bounds.setLocation(Integer.parseInt(playerData.getAttributeValue("x")), Integer.parseInt(playerData.getAttributeValue("y"))); player.setSign(playerData.getAttributeValue("sign")); player.species.text = "@"; // start map int mapUID = Integer.parseInt(playerData.getAttributeValue("map")); atlas.setMap(atlas.getMap(mapUID)); int level = Integer.parseInt(playerData.getAttributeValue("l")); atlas.setCurrentZone(level); // stats Stats stats = player.getStatsComponent(); stats.addStr(Integer.parseInt(playerData.getChild("stats").getAttributeValue("str")) - stats.getStr()); stats.addCon(Integer.parseInt(playerData.getChild("stats").getAttributeValue("con")) - stats.getCon()); stats.addDex(Integer.parseInt(playerData.getChild("stats").getAttributeValue("dex")) - stats.getDex()); stats.addInt(Integer.parseInt(playerData.getChild("stats").getAttributeValue("int")) - stats.getInt()); stats.addWis(Integer.parseInt(playerData.getChild("stats").getAttributeValue("wis")) - stats.getWis()); stats.addCha(Integer.parseInt(playerData.getChild("stats").getAttributeValue("cha")) - stats.getCha()); // skills for (Attribute skill : (List<Attribute>) playerData.getChild("skills").getAttributes()) { player.setSkill(Skill.valueOf(skill.getName()), Integer.parseInt(skill.getValue())); } // items for (Element e : playerData.getChildren("item")) { long uid = Long.parseLong(e.getAttributeValue("uid")); player.getInventoryComponent().addItem(uid); } // spells for (Element e : playerData.getChildren("spell")) { player.getMagicComponent().addSpell(SpellFactory.getSpell(e.getText())); } // feats for (Element e : playerData.getChildren("feat")) { player.getCharacteristicsComponent().addFeat(Feat.valueOf(e.getText())); } // geld player.getInventoryComponent().addMoney(Integer.parseInt(playerData.getChildText("money"))); }