List of usage examples for org.jdom2 Element getAttribute
public Attribute getAttribute(final String attname)
This returns the attribute for this element with the given name and within no namespace, or null if no such attribute exists.
From source file:neon.server.entity.Map.java
License:Open Source License
private void initEntities(Element entities) { long base = (long) uid << 32; // load creatures for (Element entity : entities.getChildren("creature")) { try {/* w w w. jav a 2 s . co m*/ long uid = base | Integer.parseInt(entity.getAttributeValue("uid")); RCreature rc = resources.getResource("creatures", entity.getAttributeValue("id")); Entity creature = tracker.createEntity(uid, rc); // check if the creature has dialog if (entity.getAttribute("dialog") != null) { String dialog = entity.getAttributeValue("dialog"); creature.setComponent(new Dialog(uid, dialog)); } // check if the creature provides any services if (!entity.getChildren("service").isEmpty()) { Provider services = new Provider(uid); for (Element service : entity.getChildren("service")) { services.addService( Provider.Service.valueOf(service.getAttributeValue("id").toUpperCase())); } creature.setComponent(services); } // check if the creature is member of any factions CreatureInfo info = creature.getComponent(CreatureInfo.class); for (Element faction : entity.getChildren("faction")) { info.addFaction(faction.getAttributeValue("id")); } initEntity(entity, creature.getComponent(Shape.class), map); } catch (ResourceException e) { logger.severe("unknown creature on map " + map.id + ": " + entity.getAttributeValue("id")); } } // load items for (Element entity : entities.getChildren("item")) { try { Entity item = loadItem(entity, base); Inventory contents = item.getComponent(Inventory.class); for (Element child : entity.getChildren("item")) { contents.addItem(loadItem(child, base).uid); } initEntity(entity, item.getComponent(Shape.class), map); } catch (ResourceException e) { logger.severe("unknown item on map " + map.id + ": " + entity.getAttributeValue("id")); } } }
From source file:neon.systems.conversation.DialogLoader.java
License:Open Source License
private PlayerNode loadPlayerNode(Element node, RDialog dialog) { NodeType type = NodeType.NONE;//from w ww .j a v a 2 s .c o m if (node.getAttribute("type") != null) { type = NodeType.valueOf(node.getAttributeValue("type").toUpperCase()); } ArrayList<String> nodes = new ArrayList<>(); if (type == NodeType.LINK) { nodes.add(node.getAttributeValue("link")); } else { for (Element child : node.getChildren("cnode")) { nodes.add(loadCreatureNode(child, dialog).id); } } PlayerNode pnode = new PlayerNode(node.getAttributeValue("id"), node.getChildText("text"), nodes, type); dialog.addNode(pnode); return pnode; }
From source file:neon.ui.graphics.svg.SVGLoader.java
License:Open Source License
public static JVShape loadShape(Element shape) { Color color = ColorFactory.getColor(shape.getAttributeValue("fill")); if (shape.getAttribute("opacity") != null) { int opacity = (int) (Float.parseFloat(shape.getAttributeValue("opacity")) * 255); color = new Color(color.getRed(), color.getGreen(), color.getBlue(), opacity); }/*from w ww . jav a 2s .com*/ // DitherPaint paint = new DitherPaint(color, Float.parseFloat(shape.getAttributeValue("opacity"))); if (shape.getName().equals("circle")) { int radius = Integer.parseInt(shape.getAttributeValue("r")); return new JVEllipse(radius, color); } else { return new JVRectangle(null, null); } }
From source file:net.psexton.libuti.UtiDb.java
License:Open Source License
/** * Adds UTI mappings to the DB from an XML source * @param in InputStream containing XML data * @throws IOException if there was a problem reading the InputStream * @throws JDOMException if there was a problem parsing the XML *//*from www .jav a 2s .com*/ public final void importXmlData(InputStream in) throws IOException, JDOMException { // Parse the input stream and rip out a usable Element from the Document Document doc = new SAXBuilder().build(in); Element root = doc.detachRootElement(); // root element is <uti-list> // Iterate over all <uti> children for (Object o : root.getChildren("uti")) { Element uti = (Element) o; // UTI's name is in a <name> child String name = uti.getChildText("name"); conformances.addVertex(name); // Add UTI to graph // File suffixes are in <suffix> children // Iterate over them for (Object o2 : uti.getChildren("suffix")) { Element suffix = (Element) o2; if (suffix.getAttribute("preferred") != null && suffix.getAttribute("preferred").getBooleanValue()) { reverseSuffixTable.put(name, suffix.getText()); // Add UTI->suffix to reverseSuffixTable } suffixTable.put(suffix.getText(), name); // Add suffix->UTI to suffixTable } // Conformances are in <conforms-to> children // Iterate over them for (Object o2 : uti.getChildren("conforms-to")) { Element conformsTo = (Element) o2; String parentUtiName = conformsTo.getText(); String edgeName = name + "->" + parentUtiName; conformances.addEdge(edgeName, name, parentUtiName, EdgeType.DIRECTED); } } }
From source file:no.imr.stox.functions.utils.JDOMUtils.java
public static String getNodeValue(Element node, String nodeName, String missingStr) { String res;/*from www . j av a 2 s . c o m*/ if (node == null) { return null; } Attribute a = node.getAttribute(nodeName); if (a != null) { res = a.getValue(); } else { res = node.getChildText(nodeName, node.getNamespace()); if (res == null || res.isEmpty()) { res = missingStr; } } return res; }
From source file:odml.core.Reader.java
License:Open Source License
/** * Converts the DOM representation of the metadata-file to the tree like odML structure. * //from www .j av a 2s. c o m * @param dom - {@link Document}: the document to parse */ public void createTree(Document dom) { root = new Section(); if (dom == null) { return; } Element rootElement = dom.getRootElement(); String odmlVersion = rootElement.getAttribute("version").getValue(); if (Float.parseFloat(odmlVersion) != 1.0) { System.out.println("Can not handle odmlVersion: " + odmlVersion + " stopping further processing!"); return; } String author = rootElement.getChildText("author"); root.setDocumentAuthor(author); Date date; String temp = rootElement.getChildText("date"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); try { date = sdf.parse(temp); } catch (Exception e) { date = null; } root.setDocumentDate(date); String version = rootElement.getChildText("version"); root.setDocumentVersion(version); URL url = null; temp = rootElement.getChildText("repository"); if (temp != null && !temp.isEmpty()) { try { url = new URL(temp); } catch (Exception e) { System.out.println("Reader.parseSection.repository: " + e); } } root.setRepository(url); root.setFileUrl(this.fileUrl); for (Element domSection : rootElement.getChildren("section")) { if (rootElement.isAncestor(domSection)) { root.add(parseSection(domSection)); } } confirmLinks(root); }
From source file:org.apache.marmotta.ucuenca.wk.provider.orcid.ORCIDRawProvider.java
License:Apache License
private List<String> getAtt(Document dc, String qr, String fl) { List<String> ls = new ArrayList<>(); List<Element> queryElements = queryElements(dc, qr); for (Element e : queryElements) { ls.add(e.getAttribute(fl).getValue()); }/*w w w. j a v a 2 s . c o m*/ return ls; }
From source file:org.artifactory.mime.version.converter.v7.ArchiveMimeTypeConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); List mimetypes = rootElement.getChildren("mimetype", namespace); log.info("updating mime-types: application/x-gzip and application/x-tar , setting archive value to true"); for (Object mimetype : mimetypes) { Element mimeTypeElement = (Element) mimetype; String type = mimeTypeElement.getAttributeValue("type", namespace); // update gzip and tar archive attribute to true if ("application/x-gzip".equals(type) || "application/x-tar".equals(type)) { // set archive attribute to true mimeTypeElement.getAttribute("archive").setValue("true"); }/*w ww . j ava 2 s . c o m*/ } }
From source file:org.artifactory.update.md.MetadataVersion.java
License:Open Source License
/** * Find the version from the format of the metadata folder * * @param metadataFolder//from w w w . j a v a2 s.c o m */ public static MetadataVersion findVersion(File metadataFolder) { if (!metadataFolder.exists()) { throw new IllegalArgumentException( "Cannot find metadata version of non existent file " + metadataFolder.getAbsolutePath()); } if (!metadataFolder.isDirectory()) { // For v125rc0 to v130beta2, the folder is actually a file return v1; } File[] mdFiles = metadataFolder.listFiles(); for (File mdFile : mdFiles) { String mdFileName = mdFile.getName(); if (mdFileName.equalsIgnoreCase(FILE_MD_NAME_V130_BETA_3) || mdFileName.equalsIgnoreCase(FOLDER_MD_NAME_V130_BETA_3)) { return v2; } if (mdFileName.equalsIgnoreCase(FILE_MD_NAME_V130_BETA_6) || mdFileName.equalsIgnoreCase(FOLDER_MD_NAME_V130_BETA_6)) { // here we don't know if it's beta6 or rc1+ so we must read the xml and decide by the content // must improve this in the future. Document doc; try { doc = buildDocFromFile(mdFile); } catch (Exception e) { // log and try the next file log.warn("Failed to read file '" + mdFile + "' as xml", e); continue; } Element root = doc.getRootElement(); Element extension = root.getChild("extension"); if (extension != null) { return v3; } else { Element repoPath = root.getChild("repoPath"); if (repoPath.getAttribute("class") != null) { return v5; } return v6; } } } log.warn("Metadata folder " + metadataFolder.getAbsolutePath() + " does not contain any recognizable metadata files! Trying to use the latest metadata layout."); return v6; }
From source file:org.artifactory.update.md.v230.BaseRepoPathClassConverter.java
License:Open Source License
@Override public void convert(Document doc) { Element rootElement = doc.getRootElement(); Element repoPath = rootElement.getChild("repoPath"); if (repoPath != null) { if (repoPath.getAttribute("class") != null) { repoPath.removeAttribute("class"); }/*w w w .j a v a 2 s .co m*/ } }