List of usage examples for org.jdom2 Attribute getValue
public String getValue()
Attribute
. From source file:com.archimatetool.editor.model.compatibility.Archimate2To3Converter.java
License:Open Source License
private Element getModelFolder(String folderType) { for (Element elementFolder : rootElement.getChildren("folder")) { Attribute attType = elementFolder.getAttribute("type"); if (attType != null && folderType.equals(attType.getValue())) { return elementFolder; }// www . ja v a 2s . c om } return null; }
From source file:com.archimatetool.templates.impl.model.ArchimateTemplateManager.java
License:Open Source License
@Override protected boolean isValidTemplateFile(File file) throws IOException { if (file == null || !file.exists()) { return false; }/* w w w. j av a2s . c om*/ // Ensure the template is of the right kind String xmlString = ZipUtils.extractZipEntry(file, ZIP_ENTRY_MANIFEST); if (xmlString == null) { return false; } // If the attribute "type" exists then return true if its value is "model". // If the attribute doesn't exist it was from an older version (before 2.1) try { Document doc = JDOMUtils.readXMLString(xmlString); Element root = doc.getRootElement(); Attribute attType = root.getAttribute(ITemplateXMLTags.XML_TEMPLATE_ATTRIBUTE_TYPE); if (attType != null) { return ArchimateModelTemplate.XML_TEMPLATE_ATTRIBUTE_TYPE_MODEL.equals(attType.getValue()); } } catch (JDOMException ex) { return false; } return true; }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaAnimUtils.java
License:Open Source License
/** * Gather up all animation channels based on what nodes they affect. * /* w w w . j av a 2 s .c o m*/ * @param channelMap * @param animationRoot * @param animationItemRoot */ @SuppressWarnings("unchecked") private void parseAnimations(final Multimap<Element, TargetChannel> channelMap, final Element animationRoot, final AnimationItem animationItemRoot) { if (animationRoot.getChild("animation") != null) { Attribute nameAttribute = animationRoot.getAttribute("name"); if (nameAttribute == null) { nameAttribute = animationRoot.getAttribute("id"); } final String name = nameAttribute != null ? nameAttribute.getValue() : "Default"; final AnimationItem animationItem = new AnimationItem(name); animationItemRoot.getChildren().add(animationItem); for (final Element animationElement : animationRoot.getChildren("animation")) { parseAnimations(channelMap, animationElement, animationItem); } } if (animationRoot.getChild("channel") != null) { if (logger.isLoggable(Level.FINE)) { logger.fine("\n-- Parsing animation channels --"); } final List<Element> channels = animationRoot.getChildren("channel"); for (final Element channel : channels) { final String source = channel.getAttributeValue("source"); final String targetString = channel.getAttributeValue("target"); if (targetString == null || targetString.isEmpty()) { return; } final Target target = processTargetString(targetString); if (logger.isLoggable(Level.FINE)) { logger.fine("channel source: " + target.toString()); } final Element targetNode = findTargetNode(target); if (targetNode == null || !_dataCache.getTransformTypes().contains(targetNode.getName())) { // TODO: pass with warning or exception or nothing? // throw new ColladaException("No target transform node found for target: " + target, target); continue; } if ("rotate".equals(targetNode.getName())) { target.accessorType = AccessorType.Vector; target.accessorIndexX = 3; } channelMap.put(targetNode.getParentElement(), new TargetChannel(target, targetNode, source, animationItemRoot)); } } }
From source file:com.ardor3d.extension.model.collada.jdom.ColladaAnimUtils.java
License:Open Source License
@SuppressWarnings("unchecked") private static void getElementString(final Element e, final StringBuilder str, final int depth, final int maxDepth, final boolean showDots) { addSpacing(str, depth);//from w w w .ja v a2s . c o m str.append('<'); str.append(e.getName()); str.append(' '); final List<Attribute> attrs = e.getAttributes(); for (int i = 0; i < attrs.size(); i++) { final Attribute attr = attrs.get(i); str.append(attr.getName()); str.append("=\""); str.append(attr.getValue()); str.append('"'); if (i < attrs.size() - 1) { str.append(' '); } } if (!e.getChildren().isEmpty() || !"".equals(e.getText())) { str.append('>'); if (depth < maxDepth) { str.append('\n'); for (final Element child : (List<Element>) e.getChildren()) { getElementString(child, str, depth + 1, maxDepth, showDots); } if (!"".equals(e.getText())) { addSpacing(str, depth + 1); str.append(e.getText()); str.append('\n'); } } else if (showDots) { str.append('\n'); addSpacing(str, depth + 1); str.append("..."); str.append('\n'); } addSpacing(str, depth); str.append("</"); str.append(e.getName()); str.append('>'); } else { str.append("/>"); } str.append('\n'); }
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 ww.j a va 2s . c o m*/ } return true; } } } return false; }
From source file:com.c4om.utils.xmlutils.XPathUtils.java
License:Apache License
/** * Given a {@link List} of {@link Attribute}, this generates a XPath condition that describes it. * That condition is of the form: <code>./@attr1QName='value1' and /@attr2QName='value2' and ... and /@attrNQName='valueN' and count(./@*)=N</code> * @param attributes the list of attributes (as a {@link List} of {@link Attribute} objects) * @return the XPath condition/*from w ww . j a v a 2 s .c om*/ */ public static String generateAttributesFilter(List<Attribute> attributes) { StringBuilder builder = new StringBuilder(); for (Attribute attribute : attributes) { builder.append("./@" + attribute.getQualifiedName() + "='" + attribute.getValue() + "' and "); } builder.append("count(./@*)=" + attributes.size()); String result = builder.toString(); return result; }
From source file:com.googlesource.gerrit.plugins.manifest.CustomOutputter.java
License:Apache License
@Override protected void printAttribute(java.io.Writer out, FormatStack fstack, Attribute attribute) throws java.io.IOException { // Do not print attributes that use default values for (DTDAttribute dtdAttribute : dtdAttributes) { if (attribute.getName().equals(dtdAttribute.getAttributeName()) && attribute.getParent().getName().equals(dtdAttribute.getElementName()) && attribute.getAttributeType().toString().equals(dtdAttribute.getType()) && attribute.getValue().equals(dtdAttribute.getValue())) { return; }/*from ww w .j ava 2s . c o m*/ } out.append(fstack.getLineSeparator()); String indent = fstack.getIndent(); out.append(fstack.getLevelIndent()); out.append(indent); // super.printAttribute() indents with an extra space, this will offset that out.append(indent.substring(0, indent.length() - 1)); super.printAttribute(out, fstack, attribute); }
From source file:com.init.octo.schema.XSDElementTypeComplex.java
License:Open Source License
/** * This method builds a complex type//from ww w . j a v a 2s .co m * * @param root - the complexType element that defines this element * @param cache - a list of pre-defined XML types */ public boolean build(Element root, XSDCache cache, String parentName) { log.debug("" + indent + ": " + "Build representation of a ComplexType"); /** get the complex types attributes **/ id = root.getAttributeValue(XSDSchema.ID_ATT); name = root.getAttributeValue(XSDSchema.NAME_ATT); abstractAtt = root.getAttributeValue(XSDSchema.ABSTRACT_ATT); mixed = root.getAttributeValue(XSDSchema.MIXED_ATT); block = root.getAttributeValue(XSDSchema.BLOCK_ATT); finalAtt = root.getAttributeValue(XSDSchema.FINAL_ATT); log.debug("" + indent + ": ComplexType <" + name + ">"); for (Element rootChild : root.getChildren()) { String elementName = rootChild.getName(); if (elementName.equals(XSDSchema.ANNOTATION)) { annotation = rootChild.getTextTrim(); } else if (elementName.equals(XSDSchema.SIMPLECONTENT)) { } else if (elementName.equals(XSDSchema.COMPLEXCONTENT)) { for (Element child : rootChild.getChildren()) { Attribute baseTypeAtt = child.getAttribute(XSDSchema.BASE_ATT); if (baseTypeAtt == null) { throw new XmlSchemaException("No base attribute for element [" + elementName + "]"); } XSDElementTypeComplex cachedObject = cache.getElementTypeComplex(baseTypeAtt.getValue()); if (cachedObject != null) { baseType = cachedObject; } processComplexTypeChildren(child, cache); } } else if (elementName.equals(XSDSchema.GROUP)) { if (elementGroup != null) { throw new XmlSchemaException("Cannot define a grouping element more than once"); } elementGroup = new XSDElementGroup(indent); elementGroup.build(rootChild, cache, parentName); } else if (elementName.equals(XSDSchema.ALL)) { if (elementGroup != null) { throw new XmlSchemaException("Cannot define a grouping element more than once"); } elementGroup = new XsdAll(indent); elementGroup.build(rootChild, cache, parentName); } else if (elementName.equals(XSDSchema.CHOICE)) { if (elementGroup != null) { throw new XmlSchemaException("Cannot define a grouping element more than once"); } elementGroup = new XSDChoice(indent); elementGroup.build(rootChild, cache, parentName); } else if (elementName.equals(XSDSchema.SEQUENCE)) { if (elementGroup != null) { log.error("Cannot define a grouping element more than once"); return (false); } elementGroup = new XSDSequence(indent); if (elementGroup.build(rootChild, cache, parentName) != true) { log.error("Error building a sequence object"); return (false); } } else if (elementName.equals(XSDSchema.ATTRIBUTE)) { XSDAttribute attribute = new XSDAttribute(); if (attribute.build(rootChild, cache, parentName) != true) { log.error("Error building an attribute object"); return (false); } attributeList.add(attribute); } else if (elementName.equals(XSDSchema.ATTRIBUTEGROUP)) { XSDAttributeGroup group = new XSDAttributeGroup(); if (group.build(rootChild, cache, parentName) != true) { log.error("Error building an attribute group object"); return (false); } attributeList.addAll(group.getAllAttributes()); } else { log.warn("" + indent + ": " + "Unexpected element <" + elementName + "> found and ignored"); } } // end for all child elements of this <element> tag log.debug("" + indent + ": " + "ComplexType built"); return (true); }
From source file:com.izforge.izpack.util.xmlmerge.matcher.AbstractAttributeMatcher.java
License:Open Source License
@Override public boolean matches(Element originalElement, Element patchElement) { if (super.matches(originalElement, patchElement)) { List<Attribute> origAttList = originalElement.getAttributes(); List<Attribute> patchAttList = patchElement.getAttributes(); if (origAttList.size() == 0 && patchAttList.size() == 0) { return true; }//from w w w . j a v a 2 s. co m if (origAttList.size() != patchAttList.size()) { return false; } for (Attribute origAttribute : origAttList) { if (getAttributeName() == null || (getAttributeName() != null && equalsString(origAttribute.getQualifiedName(), getAttributeName(), ignoreCaseAttributeName()))) { for (Attribute patchAttribute : patchAttList) { if (ignoreCaseAttributeName()) { if (origAttribute.getQualifiedName() .equalsIgnoreCase(patchAttribute.getQualifiedName())) { return equalsString(origAttribute.getValue(), patchAttribute.getValue(), ignoreCaseAttributeValue()); } } else { if (origAttribute.getQualifiedName().equals(patchAttribute.getQualifiedName())) { return equalsString(origAttribute.getValue(), patchAttribute.getValue(), ignoreCaseAttributeValue()); } } } } } } return false; }
From source file:com.kixeye.scout.eureka.EurekaServiceInstanceDescriptor.java
License:Apache License
/** * Creates a descriptor from a parent and a raw element. * //from w ww . j av a 2 s .c om * @param parent * @param instanceElement */ protected EurekaServiceInstanceDescriptor(EurekaApplication parent, Element instanceElement) { this.parent = parent; this.app = instanceElement.getChildText("app"); this.ipAddress = instanceElement.getChildText("ipAddr"); this.hostname = instanceElement.getChildText("hostName"); this.vipAddress = instanceElement.getChildText("vipAddress"); int lastUpdatedTimestampRaw; try { lastUpdatedTimestampRaw = Integer.parseInt(instanceElement.getChildText("lastUpdatedTimestamp")); } catch (Exception e) { lastUpdatedTimestampRaw = -11; } this.lastUpdatedTimestamp = lastUpdatedTimestampRaw; int lastDirtyTimestampRaw; try { lastDirtyTimestampRaw = Integer.parseInt(instanceElement.getChildText("lastDirtyTimestamp")); } catch (Exception e) { lastDirtyTimestampRaw = -11; } this.lastDirtyTimestamp = lastDirtyTimestampRaw; Element port = instanceElement.getChild("port"); if (port != null) { this.isPortEnabled = Boolean.valueOf(port.getAttributeValue("enabled", "true")); this.port = Integer.valueOf(port.getTextTrim()); } else { this.isPortEnabled = false; this.port = -1; } Element securePort = instanceElement.getChild("securePort"); if (securePort != null) { this.isSecurePortEnabled = Boolean.valueOf(securePort.getAttributeValue("enabled", "true")); this.securePort = Integer.valueOf(securePort.getTextTrim()); } else { this.isSecurePortEnabled = false; this.securePort = -1; } Element statusElement = instanceElement.getChild("status"); ServiceStatus status = null; if (statusElement != null) { switch (statusElement.getTextTrim()) { case "UP": status = ServiceStatus.UP; break; case "DOWN": status = ServiceStatus.DOWN; break; default: status = ServiceStatus.UNKNOWN; } } this.status = status; Element overridenStatusElement = instanceElement.getChild("overriddenstatus"); ServiceStatus overridenStatus = null; if (overridenStatusElement != null) { switch (overridenStatusElement.getTextTrim()) { case "UP": overridenStatus = ServiceStatus.UP; break; case "DOWN": overridenStatus = ServiceStatus.DOWN; break; default: overridenStatus = ServiceStatus.UNKNOWN; } } this.overridenStatus = overridenStatus; Element metadata = instanceElement.getChild("metadata"); if (metadata != null) { for (Element element : metadata.getChildren()) { this.metadata.put(element.getName(), element.getText()); } } Element dataCenterInfo = instanceElement.getChild("dataCenterInfo"); if (dataCenterInfo != null) { Attribute dataCenterInfoClass = instanceElement.getAttribute("class"); if (dataCenterInfoClass != null && dataCenterInfoClass.getValue() != null) { switch (dataCenterInfoClass.getValue()) { case EurekaServiceAmazonDataCenterInfo.DATA_CENTER_INFO_CLASS: this.dataCenterInfo = new EurekaServiceAmazonDataCenterInfo(this, dataCenterInfo); break; default: this.dataCenterInfo = null; } } else { this.dataCenterInfo = null; } } else { this.dataCenterInfo = null; } }