Java Code Examples for org.jdom2.Element#getValue()
The following examples show how to use
org.jdom2.Element#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameRulesModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@Override public GameRulesModule parse(MapFactory factory, Logger logger, Document doc) throws InvalidXMLException { Map<String, String> gameRules = new HashMap<>(); for (Element gameRulesElement : doc.getRootElement().getChildren("gamerules")) { for (Element gameRuleElement : gameRulesElement.getChildren()) { String rule = gameRuleElement.getName(); String value = gameRuleElement.getValue(); if (value == null) { throw new InvalidXMLException("Missing value for gamerule " + rule, gameRuleElement); } else if (gameRules.containsKey(rule)) { throw new InvalidXMLException(rule + " has already been specified", gameRuleElement); } gameRules.put(rule, value); } } return new GameRulesModule(gameRules); }
Example 2
Source File: GameRulesModule.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
public static GameRulesModule parse(MapModuleContext context, Logger logger, Document doc) throws InvalidXMLException { Map<GameRule, Boolean> gameRules = new HashMap<>(); for (Element gameRulesElement : doc.getRootElement().getChildren("gamerules")) { for (Element gameRuleElement : gameRulesElement.getChildren()) { GameRule gameRule = GameRule.forName(gameRuleElement.getName()); String value = gameRuleElement.getValue(); if (gameRule == null) { throw new InvalidXMLException(gameRuleElement.getName() + " is not a valid gamerule", gameRuleElement); } if (value == null) { throw new InvalidXMLException("Missing value for gamerule " + gameRule.getValue(), gameRuleElement); } else if (!(value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false"))) { throw new InvalidXMLException(gameRuleElement.getValue() + " is not a valid gamerule value", gameRuleElement); } if (gameRules.containsKey(gameRule)){ throw new InvalidXMLException(gameRule.getValue() + " has already been specified", gameRuleElement); } gameRules.put(gameRule, Boolean.valueOf(value)); } } return new GameRulesModule(gameRules); }
Example 3
Source File: EntityXMLreader.java From JedAIToolkit with Apache License 2.0 | 6 votes |
private void readXMLdoc(Document document) throws IOException { final Element classElement = document.getRootElement(); final List<Element> dblpRoot = classElement.getChildren(); for (final Element profile : dblpRoot) { final String profName = profile.getName(); EntityProfile entityProfile = urlToEntity.get(profName); if (entityProfile == null) { entityProfile = new EntityProfile(profName); urlToEntity.put(profName, entityProfile); entityProfiles.add(entityProfile); } final List<Element> profAttributes = profile.getChildren(); for (final Element attr : profAttributes) { String attName = attr.getName(); if (attributesToExclude.contains(attName)) { continue; } final String attValue = attr.getValue(); entityProfile.addAttribute(attName, attValue); } } }
Example 4
Source File: ISBNRange.java From wpcleaner with Apache License 2.0 | 6 votes |
/** * Analyze RangeMessage.xml file Rules. * * @param node Current node. * @param rangeElement Range element. * @throws JDOMException */ private static void analyzeRules(Element node, Range rangeElement) throws JDOMException { XPathExpression<Element> xpa = XPathFactory.instance().compile( "./Rules/Rule", Filters.element()); List<Element> results = xpa.evaluate(node); Iterator<Element> iter = results.iterator(); while (iter.hasNext()) { Element ruleNode = iter.next(); Element rangeNode = ruleNode.getChild("Range"); String range = (rangeNode != null) ? rangeNode.getValue() : null; Element lengthNode = ruleNode.getChild("Length"); String length = (lengthNode != null) ? lengthNode.getValue() : null; if ((range != null) && (length != null)) { String[] rangeElements = range.split("\\-"); if ((rangeElements != null) && (rangeElements.length == 2)) { Rule rule = new Rule(rangeElements[0], rangeElements[1], Integer.parseInt(length)); rangeElement.addRule(rule); } } } }
Example 5
Source File: ApiXmlAllMessagesResult.java From wpcleaner with Apache License 2.0 | 6 votes |
/** * Execute message request. * * @param properties Properties defining request. * @return Message. * @throws APIException Exception thrown by the API. */ @Override public String executeMessage( Map<String, String> properties) throws APIException { try { Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS); // Retrieve general information XPathExpression<Element> xpa = XPathFactory.instance().compile( "/api/query/allmessages/message", Filters.element()); Element generalNode = xpa.evaluateFirst(root); if (generalNode != null) { return generalNode.getValue(); } return null; } catch (JDOMException e) { log.error("Error loading messages", e); throw new APIException("Error parsing XML", e); } }
Example 6
Source File: ISBNRange.java From wpcleaner with Apache License 2.0 | 6 votes |
/** * Analyze RangeMessage.xml file for Ranges. * * @param root Root of RangeMessage.xml file. * @param ranges Current list of ranges. * @param xpath XPath selector. * @throws JDOMException */ private static void analyzeRanges(Element root, List<Range> ranges, String xpath) throws JDOMException { XPathExpression<Element> xpa = XPathFactory.instance().compile(xpath, Filters.element()); List<Element> results = xpa.evaluate(root); Iterator<Element> iter = results.iterator(); while (iter.hasNext()) { Element node = iter.next(); Element prefixNode = node.getChild("Prefix"); String prefix = (prefixNode != null) ? prefixNode.getValue() : null; Element agencyNode = node.getChild("Agency"); String agency = (agencyNode != null) ? agencyNode.getValue() : null; Range range = new Range(prefix, agency); analyzeRules(node, range); ranges.add(range); } }
Example 7
Source File: YWorkItem.java From yawl with GNU Lesser General Public License v3.0 | 5 votes |
private YLogDataItemList assembleLogDataItemList(Element data, boolean input) { YLogDataItemList result = new YLogDataItemList(); if (data != null) { Map<String, YParameter> params = _engine.getParameters(_specID, getTaskID(), input) ; String descriptor = (input ? "Input" : "Output") + "VarAssignment"; for (Element child : data.getChildren()) { String name = child.getName(); String value = child.getValue(); YParameter param = params.get(name); if (param != null) { String dataType = param.getDataTypeNameUnprefixed(); // if a complex type, store the structure with the value if (child.getContentSize() > 1) { value = JDOMUtil.elementToString(child); } result.add(new YLogDataItem(descriptor, name, value, dataType)); // add any configurable logging predicates for this parameter YLogDataItem dataItem = getDataLogPredicate(param, input); if (dataItem != null) result.add(dataItem); } } } return result; }
Example 8
Source File: LolStatus.java From League-of-Legends-XMPP-Chat-Library with MIT License | 5 votes |
private String get(XMLProperty p) { final Element child = getElement(p); if (child == null) { return ""; } return child.getValue(); }
Example 9
Source File: ConvertXmlToJsonService.java From cs-actions with Apache License 2.0 | 5 votes |
private JsonObject addJsonObjectsAndPrimitives(final JsonObject jsonObject, final List<Element> elements, final boolean includeAttributes, final String textPropName) { for (final Element element : elements) { final JsonElement jsonElement = isPrimitiveElement(element) ? new JsonPrimitive(element.getValue()) : convertXmlElementsToJsonObject(Collections.singletonList(element), includeAttributes, textPropName); jsonObject.add(getElementFullName(element), jsonElement); } return jsonObject; }
Example 10
Source File: XMLUpdate.java From Flashtool with GNU General Public License v3.0 | 5 votes |
public XMLUpdate(File xmlsource) throws IOException, JDOMException { SAXBuilder builder = new SAXBuilder(); FileInputStream fin = new FileInputStream(xmlsource); Document document = builder.build(fin); fin.close(); Iterator i = document.getRootElement().getChildren().iterator(); while (i.hasNext()) { Element element = (Element)i.next(); if (element.getName().equals("NOERASE") || element.getName().equals("FACTORY_ONLY")) noerase = noerase + element.getValue() + ","; } }
Example 11
Source File: XMLFwInfo.java From Flashtool with GNU General Public License v3.0 | 5 votes |
public XMLFwInfo(File xmlsource) throws IOException, JDOMException { SAXBuilder builder = new SAXBuilder(); FileInputStream fin = new FileInputStream(xmlsource); Document document = builder.build(fin); fin.close(); Iterator i = document.getRootElement().getChildren().iterator(); while (i.hasNext()) { Element element = (Element)i.next(); if (element.getName().equals("project")) project = element.getValue(); if (element.getName().equals("product")) product = element.getValue(); if (element.getName().equals("model")) model = element.getValue(); if (element.getName().equals("cda")) cda = element.getValue(); if (element.getName().equals("market")) market = element.getValue(); if (element.getName().equals("operator")) operator = element.getValue(); if (element.getName().equals("network")) network = element.getValue(); if (element.getName().equals("swVer")) swVer = element.getValue(); if (element.getName().equals("cdfVer")) cdfVer = element.getValue(); } }
Example 12
Source File: KitParser.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public ItemStack parseItem(Element el, boolean allowAir) throws InvalidXMLException { if (el == null) return null; org.jdom2.Attribute attrMaterial = el.getAttribute("material"); String name = attrMaterial != null ? attrMaterial.getValue() : el.getValue(); Material type = Materials.parseMaterial(name); if (type == null || (type == Material.AIR && !allowAir)) { throw new InvalidXMLException("Invalid material type '" + name + "'", el); } return parseItem(el, type); }
Example 13
Source File: FeedUtils.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
public static String getForeignValue(SyndEntry entry, String name) { if (entry == null) { return null; } Element element = getForeignValue(entry.getForeignMarkup(), name); return element != null ? element.getValue() : null; }
Example 14
Source File: IOProcessorImpl.java From n2o-framework with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void childrenToStringMap(Element element, String sequences, String childrenName, String keyName, String valueName, Supplier<Map<String, String>> getter, Consumer<Map<String, String>> setter) { if (r) { Map<String, String> result = new HashMap<>(); Element seqE; if (sequences != null) { seqE = element.getChild(sequences, element.getNamespace()); if (seqE == null) return; } else { seqE = element; } for (Object child : seqE.getChildren(childrenName, seqE.getNamespace())) { Element childE = (Element) child; String key = process(childE.getAttribute(keyName).getValue()); String value = valueName == null ? childE.getValue() : childE.getAttribute(valueName).getValue(); result.put(key, value); } setter.accept(result); } else { persistChildrenMap(element, sequences, childrenName, keyName, valueName, getter); } }
Example 15
Source File: IOProcessorImpl.java From n2o-framework with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void childrenToMap(Element element, String sequences, String childrenName, String keyName, String valueName, Supplier<Map<String, Object>> getter, Consumer<Map<String, Object>> setter) { if (r) { Map<String, Object> result = new HashMap<>(); Element seqE; if (sequences != null) { seqE = element.getChild(sequences, element.getNamespace()); if (seqE == null) return; } else { seqE = element; } for (Object child : seqE.getChildren(childrenName, seqE.getNamespace())) { Element childE = (Element) child; String key = process(childE.getAttribute(keyName).getValue()); String value = valueName == null ? childE.getValue() : childE.getAttribute(valueName).getValue(); Object objValue = DomainProcessor.getInstance().doDomainConversion(null, value); result.put(key, objValue); } setter.accept(result); } else { persistChildrenMap(element, sequences, childrenName, keyName, valueName, getter); } }
Example 16
Source File: DamageParser.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
public DamageCause parseDamageCause(Element el) throws InvalidXMLException { DamageCause cause = DamageCause.valueOf(el.getTextNormalize().toUpperCase().replace(" ", "_")); if (cause == null) { throw new InvalidXMLException("Invalid damage cause '" + el.getValue() + "'.", el); } return cause; }
Example 17
Source File: ZonarAvlModule.java From core with GNU General Public License v3.0 | 4 votes |
@Override protected Collection<AvlReport> extractAvlData(Document doc) throws NumberFormatException { logger.info("Extracting data from xml file"); // Get root of doc Element rootNode = doc.getRootElement(); // The return value for the method Collection<AvlReport> avlReportsReadIn = new ArrayList<AvlReport>(); List<Element> assets = rootNode.getChildren("asset"); for (Element asset : assets) { String vehicleId = asset.getAttributeValue("id"); // Only need 5 digits of precision for lat & lon. Anything more // than that is silly. String latStr = asset.getChild("lat").getValue(); double lat = MathUtils.round(Double.parseDouble(latStr), 5); String lonStr = asset.getChild("long").getValue(); double lon = MathUtils.round(Double.parseDouble(lonStr), 5); String headingStr = asset.getChild("heading").getValue(); float heading = Float.parseFloat(headingStr); Element speedElement = asset.getChild("speed"); String speedStr = speedElement.getValue(); float speed = Float.parseFloat(speedStr); String unitsStr = speedElement.getAttributeValue("unit"); if (unitsStr.equals("Km/Hour")) { speed *= KM_PER_HOUR_TO_METERS_PER_SEC; } else { logger.error("Cannot handle units of \"{}\" for Zonar feed.", unitsStr); } String timeStr = asset.getChild("time").getValue(); long time = Long.parseLong(timeStr) * Time.MS_PER_SEC; // Power and odometer are currently not used but are processed // here just in case they are helpful in the future @SuppressWarnings("unused") String power = asset.getChild("power").getValue(); // on or off @SuppressWarnings("unused") String odometer = asset.getChild("odometer").getValue(); // Create and process the AVL report. AvlReport avlReport = new AvlReport(vehicleId, time, MathUtils.round(lat, 5), MathUtils.round(lon, 5), speed, heading, "Zonar"); avlReportsReadIn.add(avlReport); } return avlReportsReadIn; }