List of usage examples for org.jdom2 Element getAttributeValue
public String getAttributeValue(final String attname)
This returns the attribute value for the attribute with the given name and within no namespace, null if there is no such attribute, and the empty string if the attribute value is empty.
From source file:com.ardor3d.extension.model.collada.jdom.ColladaNodeUtils.java
License:Open Source License
/** * Recursively parse the node hierarcy./*from w w w . j av a 2s.c om*/ * * @param dNode * @return a new Ardor3D node, created from the given <node> element */ @SuppressWarnings("unchecked") private Node buildNode(final Element dNode, JointNode jointNode) { final NodeType nodeType = getNodeType(dNode); final JointNode jointChildNode; if (nodeType == NodeType.JOINT) { String name = dNode.getAttributeValue("name"); if (name == null) { name = dNode.getAttributeValue("id"); } if (name == null) { name = dNode.getAttributeValue("sid"); } final Joint joint = new Joint(name); jointChildNode = new JointNode(joint); jointChildNode.setParent(jointNode); jointNode.getChildren().add(jointChildNode); jointNode = jointChildNode; _dataCache.getElementJointMapping().put(dNode, joint); } else { jointChildNode = null; } String nodeName = dNode.getAttributeValue("name", (String) null); if (nodeName == null) { // use id if name doesn't exist nodeName = dNode.getAttributeValue("id", dNode.getName()); } final Node node = new Node(nodeName); final List<Element> transforms = new ArrayList<Element>(); for (final Element child : dNode.getChildren()) { if (_dataCache.getTransformTypes().contains(child.getName())) { transforms.add(child); } } // process any transform information. if (!transforms.isEmpty()) { final Transform localTransform = getNodeTransforms(transforms); node.setTransform(localTransform); if (jointChildNode != null) { jointChildNode.setSceneNode(node); } } // process any instance geometries for (final Element instance_geometry : dNode.getChildren("instance_geometry")) { _colladaMaterialUtils.bindMaterials(instance_geometry.getChild("bind_material")); final Spatial mesh = _colladaMeshUtils.getGeometryMesh(instance_geometry); if (mesh != null) { node.attachChild(mesh); } _colladaMaterialUtils.unbindMaterials(instance_geometry.getChild("bind_material")); } // process any instance controllers for (final Element instanceController : dNode.getChildren("instance_controller")) { _dataCache.getControllers().add(new ControllerStore(node, instanceController)); } // process any instance nodes for (final Element in : dNode.getChildren("instance_node")) { final Node subNode = getNode(in, jointNode); if (subNode != null) { node.attachChild(subNode); if (nodeType == NodeType.JOINT && getNodeType( _colladaDOMUtil.findTargetWithId(in.getAttributeValue("url"))) == NodeType.NODE) { // make attachment createJointAttachment(jointChildNode, node, subNode); } } } // process any concrete child nodes. for (final Element n : dNode.getChildren("node")) { final Node subNode = buildNode(n, jointNode); if (subNode != null) { node.attachChild(subNode); if (nodeType == NodeType.JOINT && getNodeType(n) == NodeType.NODE) { // make attachment createJointAttachment(jointChildNode, node, subNode); } } } // Cache reference _dataCache.getElementSpatialMapping().put(dNode, node); return node; }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaNodeUtils.java
License:Open Source License
private NodeType getNodeType(final Element dNode) { if (dNode.getAttribute("type") != null) { return Enum.valueOf(NodeType.class, dNode.getAttributeValue("type")); } else {/*from www .j a va 2s.co m*/ return NodeType.NODE; } }
From source file:com.arrggh.eve.api.xml.parsers.ResponseParsers.java
static List<XmlApiCharacter> parseCharacterList(String text) { List<XmlApiCharacter> results = new LinkedList<>(); try {/* w ww . j a v a2 s . c om*/ SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(text)); List<Element> rows = document.getRootElement().getChild("result").getChild("rowset").getChildren("row"); for (Element row : rows) { XmlApiCharacter.XmlApiCharacterBuilder builder = XmlApiCharacter.builder(); builder.id(row.getAttributeValue("characterID")); builder.name(row.getAttributeValue("name")); builder.corporationName(row.getAttributeValue("corporationName")); builder.corporationId(row.getAttributeValue("corporationID")); builder.allianceId(row.getAttributeValue("allianceID")); builder.allianceName(row.getAttributeValue("allianceName")); builder.factionId(row.getAttributeValue("factionID")); builder.factionName(row.getAttributeValue("factionName")); results.add(builder.build()); } } catch (JDOMException | IOException e) { throw new ParserException("Cannot parse character list", e); } return results; }
From source file:com.arrggh.eve.api.xml.parsers.ResponseParsers.java
static List<XmlApiCharacterIndustryJob> parseIndustryJobs(String text) { List<XmlApiCharacterIndustryJob> results = new LinkedList<>(); try {// www.j a v a 2 s . c o m SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(text)); List<Element> rows = document.getRootElement().getChild("result").getChild("rowset").getChildren("row"); for (Element row : rows) { XmlApiCharacterIndustryJob.XmlApiCharacterIndustryJobBuilder builder = XmlApiCharacterIndustryJob .builder(); builder.jobID(getLong(row, "jobID")); builder.installerID(getLong(row, "installerID")); builder.installerName(row.getAttributeValue("installerName")); builder.facilityID(getLong(row, "facilityID")); builder.solarSystemID(getLong(row, "solarSystemID")); builder.solarSystemName(row.getAttributeValue("solarSystemName")); builder.stationID(getLong(row, "stationID")); builder.activityID(getLong(row, "activityID")); builder.blueprintID(getLong(row, "blueprintID")); builder.blueprintTypeID(getLong(row, "blueprintTypeID")); builder.blueprintTypeName(row.getAttributeValue("blueprintTypeName")); builder.blueprintLocationID(getLong(row, "blueprintLocationID")); builder.outputLocationID(getLong(row, "outputLocationID")); builder.runs(getLong(row, "runs")); builder.cost(row.getAttributeValue("cost")); builder.teamID(getLong(row, "teamID")); builder.licensedRuns(row.getAttributeValue("licensedRuns")); builder.probability(row.getAttributeValue("probability")); builder.productTypeID(getLong(row, "productTypeID")); builder.productTypeName(row.getAttributeValue("productTypeName")); builder.status(row.getAttributeValue("status")); builder.timeInSeconds(getLong(row, "timeInSeconds")); builder.startDate(row.getAttributeValue("startDate")); builder.endDate(row.getAttributeValue("endDate")); builder.pauseDate(row.getAttributeValue("pauseDate")); builder.completedDate(row.getAttributeValue("completedDate")); builder.completedCharacterID(getLong(row, "completedCharacterID")); builder.successfulRuns(row.getAttributeValue("successfulRuns")); results.add(builder.build()); } } catch (JDOMException | IOException e) { throw new ParserException("Cannot parse industry job", e); } return results; }
From source file:com.arrggh.eve.api.xml.parsers.ResponseParsers.java
static List<XmlApiOwnedBlueprint> parseBlueprints(String text) { List<XmlApiOwnedBlueprint> results = new LinkedList<>(); try {/*from w w w. j a v a2 s . c om*/ SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(text)); List<Element> rows = document.getRootElement().getChild("result").getChild("rowset").getChildren("row"); for (Element row : rows) { XmlApiOwnedBlueprint.XmlApiOwnedBlueprintBuilder builder = XmlApiOwnedBlueprint.builder(); builder.itemId(getLong(row, "itemID")); builder.typeName(row.getAttributeValue("typeName")); builder.typeId(getLong(row, "typeID")); builder.flagId(getLong(row, "flagID")); builder.quantity(row.getAttributeValue("quantity")); builder.runs(row.getAttributeValue("runs")); builder.locationId(getLong(row, "locationID")); builder.materialEfficiency(row.getAttributeValue("materialEfficiency")); builder.timeEfficiency(row.getAttributeValue("timeEfficiency")); results.add(builder.build()); } } catch (JDOMException | IOException e) { throw new ParserException("Cannot parse blueprints", e); } return results; }
From source file:com.arrggh.eve.api.xml.parsers.ResponseParsers.java
static List<XmlApiOwnedAsset> parseAssets(String text) { List<XmlApiOwnedAsset> results = new LinkedList<>(); try {// w w w . j a v a 2 s . co m SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(text)); List<Element> rows = document.getRootElement().getChild("result").getChild("rowset").getChildren("row"); for (Element row : rows) { XmlApiOwnedAsset.XmlApiOwnedAssetBuilder builder = XmlApiOwnedAsset.builder(); builder.itemID(getLong(row, "itemID")); builder.locationID(getLong(row, "locationID")); builder.typeID(getLong(row, "typeID")); builder.quantity(getLong(row, "quantity")); builder.flag(row.getAttributeValue("flag")); builder.singleton(row.getAttributeValue("singleton")); builder.rawQuantity(row.getAttributeValue("rawQuantity")); results.add(builder.build()); } } catch (JDOMException | IOException e) { throw new ParserException("Cannot parse assets", e); } return results; }
From source file:com.arrggh.eve.api.xml.parsers.ResponseParsers.java
static List<XmlApiEveLocation> parseLocations(String text) { List<XmlApiEveLocation> results = new LinkedList<>(); try {/*from w ww .j a v a2 s . c o m*/ SAXBuilder jdomBuilder = new SAXBuilder(); Document document = jdomBuilder.build(new StringReader(text)); List<Element> rows = document.getRootElement().getChild("result").getChild("rowset").getChildren("row"); for (Element row : rows) { XmlApiEveLocation.XmlApiEveLocationBuilder builder = XmlApiEveLocation.builder(); builder.itemID(getLong(row, "itemID")); builder.itemName(row.getAttributeValue("itemName")); builder.x(getDouble(row, "x")); builder.y(getDouble(row, "y")); builder.z(getDouble(row, "z")); results.add(builder.build()); } } catch (JDOMException | IOException e) { throw new ParserException("Cannot parse locations", e); } return results; }
From source file:com.astronomy.project.Alignment.java
/** * // w w w .jav a2 s . co m * @param e XML element * @throws ProcessException Format error */ public Alignment(Element e) throws ProcessException { pComments = new SimpleStringProperty(); for (Element el : e.getChildren()) { switch (el.getName()) { case "lugar": if (el.getAttributeValue("tipo").equals("origen")) { observatory = new ReferencePoint(el); pObservatory = new SimpleStringProperty(observatory.getName()); } else if (el.getAttributeValue("tipo").equals("referencia")) { foresight = new ReferencePoint(el); pForesight = new SimpleStringProperty(foresight.getName()); } break; case "direccion": orientation = new Orientation(el); pAzimuth = new SimpleStringProperty( String.format("%.1f", orientation.getAzimuth().getSignedValue()).replace(",", ".")); pAltitude = new SimpleStringProperty( String.format("%.1f", orientation.getAltitude().getSignedValue()).replace(",", ".")); break; case "descripcion": description = new Tag("descripcion", el); pComments.set(description.getValue()); break; case "imagen": imagenPath = new Tag("imagen", el); break; case "declinacion": declination = new Declination(el); pDeclination = new SimpleStringProperty( String.format("%.1f", getDeclination().getSignedValue()).replace(",", ".")); break; } } if (imagenPath == null) imagenPath = new Tag("imagen", ""); }
From source file:com.astronomy.project.Project.java
/** * Parse XML project/*from ww w. j av a 2s . c o m*/ * @param file XML file * @throws JDOMException XML error * @throws IOException IO error * @throws ProcessException Format error */ public void parseXML(File file) throws JDOMException, IOException, ProcessException { SAXBuilder saxBuilder = new SAXBuilder(); Document document = saxBuilder.build(file); Element raiz = document.getRootElement(); name = raiz.getAttributeValue("nombre"); List<Element> aa = raiz.getChild("alineamientos").getChildren(); data.clear(); for (Element e : aa) { data.add(new Alignment(e)); } }
From source file:com.astronomy.project.ReferencePoint.java
/** * //from w w w . j a v a 2 s. c o m * @param e Reference point as XML element * @throws ProcessException Format error */ public ReferencePoint(Element e) throws ProcessException { this.type = e.getAttributeValue("tipo"); this.name = e.getChild("nombre").getText(); try { coordinates = new Geographic( SexagesimalDegree.valueOf(e.getChild("coordenadas").getChild("latitud").getText()), SexagesimalDegree.valueOf(e.getChild("coordenadas").getChild("longitud").getText()), Double.valueOf(e.getChild("coordenadas").getChild("altitud").getText())); } catch (NullPointerException ex) { coordinates = null; } }