List of usage examples for org.jdom2 Element getChildren
public List<Element> getChildren()
List
of all the child elements nested directly (one level deep) within this element, as Element
objects. From source file:com.ardor3d.extension.model.collada.jdom.ColladaMaterialUtils.java
License:Open Source License
/** * Convert a <texture> element to an Ardor3D representation and store in the given state. * /*from w w w.j a va 2 s. com*/ * @param mesh * the Ardor3D Mesh to add the Texture to. * @param daeTexture * our <texture> element * @param effect * our <instance_effect> element * @return the created Texture. */ private Texture populateTextureState(final Mesh mesh, final Element daeTexture, final Element effect, final HashMap<String, Texture> loadedTextures, final MaterialInfo info, String textureSlot) { // TODO: Use vert data to determine which texcoords and set to use. // final String uvName = daeTexture.getAttributeValue("texcoord"); TextureState tState = (TextureState) mesh.getLocalRenderState(RenderState.StateType.Texture); if (tState == null) { tState = new TextureState(); mesh.setRenderState(tState); } // Use texture attrib to find correct sampler final String textureReference = daeTexture.getAttributeValue("texture"); if (textureSlot == null) { // if we have no texture slot defined (like in the case of an "extra" texture), we'll use the // textureReference. textureSlot = textureReference; } /* only add the texture to the state once */ if (loadedTextures.containsKey(textureReference)) { final Texture tex = loadedTextures.get(textureReference); if (info != null) { info.setTextureSlot(textureSlot, textureReference, tex, null); } return tex; } Element node = _colladaDOMUtil.findTargetWithSid(textureReference); if (node == null) { // Not sure if this is quite right, but spec seems to indicate looking for global id node = _colladaDOMUtil.findTargetWithId("#" + textureReference); } if ("newparam".equals(node.getName())) { node = node.getChildren().get(0); } Element sampler = null; Element surface = null; Element image = null; Texture.MinificationFilter min = Texture.MinificationFilter.BilinearNoMipMaps; if ("sampler2D".equals(node.getName())) { sampler = node; if (sampler.getChild("minfilter") != null) { final String minfilter = sampler.getChild("minfilter").getText(); min = Enum.valueOf(SamplerTypes.MinFilterType.class, minfilter).getArdor3dFilter(); } // Use sampler to get correct surface node = _colladaDOMUtil.findTargetWithSid(sampler.getChild("source").getText()); // node = resolveSid(effect, sampler.getSource()); } if ("newparam".equals(node.getName())) { node = node.getChildren().get(0); } if ("surface".equals(node.getName())) { surface = node; // image(s) will come from surface. } else if ("image".equals(node.getName())) { image = node; } // Ok, a few possibilities here... Texture texture = null; String fileName = null; if (surface == null && image != null) { // Only an image found (no sampler). Assume 2d texture. Load. fileName = image.getChild("init_from").getText(); texture = loadTexture2D(fileName, min); } else if (surface != null) { // We have a surface, pull images from that. if ("2D".equals(surface.getAttributeValue("type"))) { // look for an init_from with lowest mip and use that. (usually 0) // TODO: mip? final Element lowest = surface.getChildren("init_from").get(0); // Element lowest = null; // for (final Element i : (List<Element>) surface.getChildren("init_from")) { // if (lowest == null || lowest.getMip() > i.getMip()) { // lowest = i; // } // } if (lowest == null) { logger.warning("surface given with no usable init_from: " + surface); return null; } image = _colladaDOMUtil.findTargetWithId("#" + lowest.getText()); // image = (DaeImage) root.resolveUrl("#" + lowest.getValue()); if (image != null) { fileName = image.getChild("init_from").getText(); texture = loadTexture2D(fileName, min); } // TODO: add support for mip map levels other than 0. } // TODO: add support for the other texture types. } else { // No surface OR image... warn. logger.warning("texture given with no matching <sampler*> or <image> found."); if (info != null) { info.setTextureSlot(textureSlot, textureReference, null, null); } return null; } if (texture != null) { if (sampler != null) { // Apply params from our sampler. applySampler(sampler, texture); } // Add to texture state. tState.setTexture(texture, tState.getNumberOfSetTextures()); loadedTextures.put(textureReference, texture); if (info != null) { info.setTextureSlot(textureSlot, textureReference, texture, fileName); } } else { logger.warning("unable to load texture: " + daeTexture); if (info != null) { info.setTextureSlot(textureSlot, textureReference, null, fileName); } } return texture; }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaMaterialUtils.java
License:Open Source License
@SuppressWarnings("unchecked") public void bindMaterials(final Element bindMaterial) { if (bindMaterial == null || bindMaterial.getChildren().isEmpty()) { return;/*from ww w.java 2s .c o m*/ } for (final Element instance : bindMaterial.getChild("technique_common").getChildren("instance_material")) { final Element matNode = _colladaDOMUtil.findTargetWithId(instance.getAttributeValue("target")); if (matNode != null && "material".equals(matNode.getName())) { _dataCache.bindMaterial(instance.getAttributeValue("symbol"), matNode); } else { logger.warning("instance material target not found: " + instance.getAttributeValue("target")); } // TODO: need to store bound vert data as local data. (also unstore on unbind.) } }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaMaterialUtils.java
License:Open Source License
@SuppressWarnings("unchecked") public void unbindMaterials(final Element bindMaterial) { if (bindMaterial == null || bindMaterial.getChildren().isEmpty()) { return;/* w w w. j a v a 2 s . c o m*/ } for (final Element instance : bindMaterial.getChild("technique_common").getChildren("instance_material")) { _dataCache.unbindMaterial(instance.getAttributeValue("symbol")); } }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaNodeUtils.java
License:Open Source License
/** * Parse an asset element into an AssetData object. * /*from w w w . ja v a 2 s . c om*/ * @param asset * @return */ @SuppressWarnings("unchecked") public AssetData parseAsset(final Element asset) { final AssetData assetData = new AssetData(); for (final Element child : asset.getChildren()) { if ("contributor".equals(child.getName())) { parseContributor(assetData, child); } else if ("created".equals(child.getName())) { assetData.setCreated(child.getText()); } else if ("keywords".equals(child.getName())) { assetData.setKeywords(child.getText()); } else if ("modified".equals(child.getName())) { assetData.setModified(child.getText()); } else if ("revision".equals(child.getName())) { assetData.setRevision(child.getText()); } else if ("subject".equals(child.getName())) { assetData.setSubject(child.getText()); } else if ("title".equals(child.getName())) { assetData.setTitle(child.getText()); } else if ("unit".equals(child.getName())) { final String name = child.getAttributeValue("name"); if (name != null) { assetData.setUnitName(name); } final String meter = child.getAttributeValue("meter"); if (meter != null) { assetData.setUnitMeter(Float.parseFloat(meter.replace(",", "."))); } } else if ("up_axis".equals(child.getName())) { final String axis = child.getText(); if ("X_UP".equals(axis)) { assetData.setUpAxis(new Vector3()); } else if ("Y_UP".equals(axis)) { assetData.setUpAxis(Vector3.UNIT_Y); } else if ("Z_UP".equals(axis)) { assetData.setUpAxis(Vector3.UNIT_Z); } } } return assetData; }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaNodeUtils.java
License:Open Source License
@SuppressWarnings("unchecked") private void parseContributor(final AssetData assetData, final Element contributor) { for (final Element child : contributor.getChildren()) { if ("author".equals(child.getName())) { assetData.setAuthor(child.getText()); } else if ("authoringTool".equals(child.getName())) { assetData.setCreated(child.getText()); } else if ("comments".equals(child.getName())) { assetData.setComments(child.getText()); } else if ("copyright".equals(child.getName())) { assetData.setCopyright(child.getText()); } else if ("source_data".equals(child.getName())) { assetData.setSourceData(child.getText()); }//from ww w. ja v a 2 s . c o m } }
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 a v a2 s .co m * * @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.plugin.GoogleEarthPlugin.java
License:Open Source License
@Override public boolean processExtra(final Element extra, final Object[] params) { if (params.length > 0 && params[0] instanceof Mesh) { final Mesh mesh = (Mesh) params[0]; // should have a child: <technique profile="GOOGLEEARTH"> final Element technique = extra.getChild("technique"); if (technique != null) { final Attribute profile = technique.getAttribute("profile"); if (profile != null && "GOOGLEEARTH".equalsIgnoreCase(profile.getValue())) { for (final Element child : technique.getChildren()) { // disable back face culling if it's been enabled. if ("double_sided".equalsIgnoreCase(child.getName()) && "1".equals(child.getTextTrim())) { final CullState cs = new CullState(); cs.setEnabled(false); mesh.setRenderState(cs); }//from w w w . ja v a 2 s. com } return true; } } } return false; }
From source file:com.astronomy.project.Alignment.java
/** * //from ww w . java 2 s . c om * @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.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * ? ?? Data setting (data class : PDFMetadataDefinition) * //from w w w . j av a2 s . c o m * @param root * @param rootData * @param upload * @throws Exception */ public static void setDynamicSection(Element root, PDFMetadataDefinition rootData, Upload upload) throws Exception { List<Element> childs = new ArrayList<Element>(); AnalyzeDefinition data = rootData.getEarDefinition(); setDynamicSection(root, data, upload); for (Element e : root.getChildren()) { if (e.getName().equals("section")) { if (e.getChild("war_child_deploy") != null) { //ear Web Applications childs = setChildDeployData(rootData, upload, "war"); } else if (e.getChild("jar_child_deploy") != null) { //ear EJB Applications childs = setChildDeployData(rootData, upload, "jar"); } else if (e.getChild("trans_application_xml_info") != null) { //?? - application Deployment Descriptor childs = setTransXmlData(rootData, upload, "application"); } else if (e.getChild("trans_web_xml_info") != null) { //?? - Web Deployment Descriptor childs = setTransXmlData(rootData, upload, "web"); } else if (e.getChild("trans_ejb_xml_info") != null) { //?? - EJB Deployment Descriptor childs = setTransXmlData(rootData, upload, "ejb"); } } for (Element child : childs) { e.addContent(child); } childs = new ArrayList<Element>(); } //?? ? start(chapter ? ?? section? ? ) for (Element e : root.getChildren()) { if (e.getName().equals("exception_info")) { childs = setExceptionData(rootData, upload); } } for (Element child : childs) { root.addContent(child); } childs = new ArrayList<Element>(); //?? ? end }
From source file:com.athena.chameleon.engine.core.PDFDocGenerator.java
License:Apache License
/** * ? ?? Data setting (data class : AnalyzeDefinition) * /*from w ww . j ava2 s.c o m*/ * @param root * @param data * @param upload */ public static void setDynamicSection(Element root, AnalyzeDefinition data, Upload upload) { List<Element> childs = new ArrayList<Element>(); int index = 0; for (Element e : root.getChildren()) { if (e.getName().equals("section")) { // Section ? setDynamicSection(e, data, upload); } else if (e.getName().equals("file_summary")) { // ? childs = setFileSummary(data); } else if (e.getName().equals("pattern_servlet")) { // Servlet ?? ? childs = setPatternData(data, "servlet"); } else if (e.getName().equals("pattern_ejb")) { // EJB ?? ? childs = setPatternData(data, "ejb"); } else if (e.getName().equals("dependency_java")) { // Java ? childs = setDependencyData(data, "java"); } else if (e.getName().equals("dependency_jsp")) { // jsp ? childs = setDependencyData(data, "jsp"); } else if (e.getName().equals("dependency_property")) { // Properties ? childs = setDependencyData(data, "property"); } else if (e.getName().equals("dependency_class")) { // Class ? childs = setDependencyData(data, "class"); } else if (e.getName().equals("jsp_analyze_result")) { // JSP ? ? childs = setJspAnalyzeData(data, upload); } else if (e.getName().equals("deploy_application_text")) { // ? ? childs = setDeployApplicationText(data, upload); index = 1; } else if (e.getName().equals("web_xml_info")) { // ? ? childs = setApplicationData(data, upload); } else if (e.getName().equals("jar_xml_info")) { // EJB ? ? childs = setApplicationData(data, upload); } else if (e.getName().equals("lib_list")) { // lib childs = setLibData(data, upload, ""); } else if (e.getName().equals("delete_lib_list")) { // ? lib childs = setLibData(data, upload, "D"); } else if (e.getName().equals("class_info")) { // classes childs = setClassData(data, upload); } else if (e.getName().equals("application_list")) { // ?? ? ? ? childs = setApplicationListData(data, upload); index = 2; } else if (e.getName().equals("application_info")) { // ?? ? ? childs = setApplicationData(data, upload); } else if (e.getName().equals("ejb_application_list")) { // ?? ?? EJB childs = setEjbApplicationData(data, upload); } else if (e.getName().equals("maven_dependency")) { // Maven Dependency childs = setMavenDependencyList(data, upload); } else if (e.getName().equals("convert_encoding")) { //? ? childs = setConvertEncodingData(data, upload); index = 7; } } //index 0? ? index ? ? if (index == 0) { root.addContent(childs); } else { root.addContent(index, childs); index = 0; } }