List of usage examples for org.jdom2 Element getAttribute
public Attribute getAttribute(final String attname, final Namespace ns)
This returns the attribute for this element with the given name and within the given Namespace, or null if no such attribute exists.
From source file:ditatools.translate.DitaTranslator.java
License:Apache License
protected void translateTopicXML(Document doc, File outputXmlFile) throws JDOMException, IOException { // caller should have verified that root element // is a DITA topic: concept, task, or reference Element rootElement = doc.getRootElement(); // XXX handle case where xml:lang attr is not present rootElement.getAttribute("lang", Namespace.XML_NAMESPACE).setValue(language); process(rootElement);/*from w ww . j a v a2 s.com*/ XMLOutputter xmlOutput = new XMLOutputter(); // force use of UTF-8 in output FileOutputStream fos = null; OutputStreamWriter osw = null; try { fos = new FileOutputStream(outputXmlFile); osw = new OutputStreamWriter(fos, "UTF-8"); xmlOutput.output(doc, osw); } finally { if (osw != null) { try { osw.close(); } catch (Exception x) { } } if (fos != null) { try { fos.close(); } catch (Exception x) { } } } }
From source file:org.artifactory.mime.version.converter.v1.XmlIndexedConverter.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); // make sure there are no more 'xml' attributes for (Object mimetype : mimetypes) { Element mimeTypeElement = (Element) mimetype; Attribute xmlAttribute = mimeTypeElement.getAttribute("xml", namespace); if (xmlAttribute != null) { // rename to index xmlAttribute.setName("index"); // change to false unless maven of ivy String type = mimeTypeElement.getAttributeValue("type"); if (!"application/x-maven-pom+xml".equals(type) && !"application/x-ivy+xml".equals(type)) { xmlAttribute.setValue("false"); }/*from w w w . j a v a 2 s . c om*/ } } }
From source file:org.mycore.datamodel.metadata.MCRBase.java
License:Open Source License
protected void setUp() { if (jdom_document == null) { throw new MCRException("The JDOM document is null or empty."); }// w w w . j av a 2s .c o m org.jdom2.Element rootElement = jdom_document.getRootElement(); setId(MCRObjectID.getInstance(rootElement.getAttributeValue("ID"))); setLabel(rootElement.getAttributeValue("label")); setVersion(rootElement.getAttributeValue("version")); setSchema(rootElement.getAttribute("noNamespaceSchemaLocation", XSI_NAMESPACE).getValue()); // get the service data of the object Element serviceElement = rootElement.getChild("service"); if (serviceElement != null) { mcr_service.setFromDOM(serviceElement); } }
From source file:org.plasma.xml.uml.DefaultUMLModelAssembler.java
License:Open Source License
private Element buildProperty(Package pkg, Class clss, Property property, Element parentElem) { if (log.isDebugEnabled()) log.debug("creating property " + property.getName()); Element ownedAttribute = new Element("ownedAttribute"); parentElem.addContent(ownedAttribute); ownedAttribute.setAttribute(new Attribute("type", "uml:Property", xmiNs)); ownedAttribute.setAttribute(new Attribute("id", property.getId(), xmiNs)); ownedAttribute.setAttribute(new Attribute("name", property.getName())); if (property.getVisibility() != null) ownedAttribute.setAttribute(new Attribute("visibility", property.getVisibility().value())); if (property.getDocumentations() != null) for (Documentation doc : property.getDocumentations()) { if (doc.getBody() != null) addOwnedComment(ownedAttribute, property.getId(), doc.getBody().getValue()); }/*from w w w . j a v a 2s . co m*/ Element upperValue = new Element("upperValue"); ownedAttribute.addContent(upperValue); upperValue.setAttribute(new Attribute("type", "uml:LiteralUnlimitedNatural", xmiNs)); upperValue.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); upperValue.setAttribute(new Attribute("visibility", "public")); if (property.isMany()) upperValue.setAttribute(new Attribute("value", "*")); else upperValue.setAttribute(new Attribute("value", "1")); Element lowerValue = new Element("lowerValue"); ownedAttribute.addContent(lowerValue); lowerValue.setAttribute(new Attribute("type", "uml:LiteralInteger", xmiNs)); lowerValue.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); lowerValue.setAttribute(new Attribute("visibility", "public")); if (property.isNullable()) lowerValue.setAttribute(new Attribute("value", "0")); else lowerValue.setAttribute(new Attribute("value", "1")); if (property.getType() instanceof DataTypeRef) { Element type = new Element("type"); ownedAttribute.addContent(type); type.setAttribute(new Attribute("type", "uml:DataType", xmiNs)); //type.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); type.setAttribute( new Attribute("href", this.dataTypeHRefPrefix + ((DataTypeRef) property.getType()).getName())); } else { // set reference specific attribs ClassRef targetClassRef = (ClassRef) property.getType(); Class targetClass = classMap.get(targetClassRef.getUri() + "#" + targetClassRef.getName()); ownedAttribute.setAttribute(new Attribute("type", targetClass.getId())); } // add stereotypes in order of "priority" in terms of how we // would like them to appear in UML tools if (property.getKey() != null) { Element keyStereotype = new Element(SDOKey.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(keyStereotype); keyStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); keyStereotype.setAttribute(new Attribute(SDOKey.BASE__PROPERTY, property.getId())); keyStereotype.setAttribute(new Attribute(SDOKey.TYPE, // provisioning key-type is JAXB generated and upper-case property.getKey().getType().name().toLowerCase())); } if (property.getUniqueConstraint() != null) { Element uniqueStereotype = new Element(SDOUniqueConstraint.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(uniqueStereotype); uniqueStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); uniqueStereotype.setAttribute(new Attribute(SDOUniqueConstraint.BASE__PROPERTY, property.getId())); uniqueStereotype.setAttribute( new Attribute(SDOUniqueConstraint.GROUP, property.getUniqueConstraint().getGroup())); } if (property.getAlias() != null) { addAlias(property.getAlias(), property.getId()); } if (property.getSort() != null) { Element sequenceStereotype = new Element(SDOSort.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(sequenceStereotype); sequenceStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); sequenceStereotype.setAttribute(new Attribute(SDOSort.BASE__PROPERTY, property.getId())); sequenceStereotype .setAttribute(new Attribute(SDOSort.KEY, String.valueOf(property.getSort().getKey()))); } if (property.getXmlProperty() != null) { Element xmlPropertyStereotype = new Element(SDOXmlProperty.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(xmlPropertyStereotype); xmlPropertyStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); xmlPropertyStereotype.setAttribute(new Attribute(SDOXmlProperty.BASE__PROPERTY, property.getId())); xmlPropertyStereotype.setAttribute(new Attribute(SDOXmlProperty.NODE_TYPE, property.getXmlProperty().getNodeType().name().toLowerCase())); } if (property.getValueConstraint() != null) { Element valueContStereotype = new Element(SDOValueConstraint.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(valueContStereotype); valueContStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); valueContStereotype.setAttribute(new Attribute(SDOValueConstraint.BASE__PROPERTY, property.getId())); ValueConstraint vc = property.getValueConstraint(); if (vc.getTotalDigits() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.TOTAL_DIGITS, String.valueOf(vc.getTotalDigits()))); if (vc.getFractionDigits() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.FRACTION_DIGITS, String.valueOf(vc.getFractionDigits()))); if (vc.getMaxInclusive() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MAX_INCLUSIVE, String.valueOf(vc.getMaxInclusive()))); if (vc.getMaxExclusive() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MAX_EXCLUSIVE, String.valueOf(vc.getMaxExclusive()))); if (vc.getMaxLength() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MAX_LENGTH, String.valueOf(vc.getMaxLength()))); if (vc.getMinInclusive() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MIN_INCLUSIVE, String.valueOf(vc.getMinInclusive()))); if (vc.getMinExclusive() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MIN_EXCLUSIVE, String.valueOf(vc.getMinExclusive()))); if (vc.getMinLength() != null) valueContStereotype.setAttribute( new Attribute(SDOValueConstraint.MIN_LENGTH, String.valueOf(vc.getMinLength()))); if (vc.getPattern() != null) valueContStereotype .setAttribute(new Attribute(SDOValueConstraint.PATTERN, String.valueOf(vc.getPattern()))); } if (property.getEnumerationConstraint() != null) { Element enumConstraintStereotype = new Element(SDOEnumerationConstraint.class.getSimpleName(), plasmaNs); this.xmiElem.addContent(enumConstraintStereotype); enumConstraintStereotype.setAttribute(new Attribute("id", UUID.randomUUID().toString(), xmiNs)); enumConstraintStereotype .setAttribute(new Attribute(SDOUniqueConstraint.BASE__PROPERTY, property.getId())); EnumerationConstraint constraint = property.getEnumerationConstraint(); EnumerationRef enumRef = constraint.getValue(); String enumRefId = enumRef.getUri() + "#" + enumRef.getName(); Element enumeration = this.enumElementMap.get(enumRefId); if (enumeration == null) { enumeration = this.buildEnumeration(constraint); Element pkgElement = this.elementMap.get(pkg.getId()); pkgElement.addContent(enumeration); this.enumElementMap.put(enumRefId, enumeration); } Attribute enumId = enumeration.getAttribute("id", xmiNs); enumConstraintStereotype.setAttribute(new Attribute(SDOEnumerationConstraint.VALUE, enumId.getValue())); } return ownedAttribute; }
From source file:org.rometools.feed.module.content.io.ContentModuleParser.java
License:Open Source License
public com.sun.syndication.feed.module.Module parse(org.jdom2.Element element) { boolean foundSomething = false; ContentModule cm = new ContentModuleImpl(); List encodeds = element.getChildren("encoded", CONTENT_NS); ArrayList contentStrings = new ArrayList(); ArrayList encodedStrings = new ArrayList(); if (encodeds.size() > 0) { foundSomething = true;//from ww w.ja v a2 s. c o m for (int i = 0; i < encodeds.size(); i++) { Element encodedElement = (Element) encodeds.get(i); encodedStrings.add(encodedElement.getText()); contentStrings.add(encodedElement.getText()); } } ArrayList contentItems = new ArrayList(); List items = element.getChildren("items", CONTENT_NS); for (int i = 0; i < items.size(); i++) { foundSomething = true; List lis = ((Element) items.get(i)).getChild("Bag", RDF_NS).getChildren("li", RDF_NS); for (int j = 0; j < lis.size(); j++) { ContentItem ci = new ContentItem(); Element li = (Element) lis.get(j); Element item = li.getChild("item", CONTENT_NS); Element format = item.getChild("format", CONTENT_NS); Element encoding = item.getChild("encoding", CONTENT_NS); Element value = item.getChild("value", RDF_NS); if (value != null) { if (value.getAttributeValue("parseType", RDF_NS) != null) { ci.setContentValueParseType(value.getAttributeValue("parseType", RDF_NS)); } if ((ci.getContentValueParseType() != null) && ci.getContentValueParseType().equals("Literal")) { ci.setContentValue(getXmlInnerText(value)); contentStrings.add(getXmlInnerText(value)); ci.setContentValueNamespaces(value.getAdditionalNamespaces()); } else { ci.setContentValue(value.getText()); contentStrings.add(value.getText()); } ci.setContentValueDOM(((Element) value.clone()).getContent()); } if (format != null) { ci.setContentFormat(format.getAttribute("resource", RDF_NS).getValue()); } if (encoding != null) { ci.setContentEncoding(encoding.getAttribute("resource", RDF_NS).getValue()); } if (item != null) { Attribute about = item.getAttribute("about", RDF_NS); if (about != null) { ci.setContentAbout(about.getValue()); } } contentItems.add(ci); } } cm.setEncodeds(encodedStrings); cm.setContentItems(contentItems); cm.setContents(contentStrings); return (foundSomething) ? cm : null; }
From source file:org.xflatdb.xflat.db.ElementTable.java
License:Apache License
private String getId(Element element) { Attribute a = element.getAttribute("id", XFlatConstants.xFlatNs); if (a != null) { return a.getValue(); }//from w w w.ja va 2 s .c o m return null; }
From source file:org.yawlfoundation.yawl.unmarshal.YSpecificationParser.java
License:Open Source License
private void parseSpecification(Element specificationElem, YSchemaVersion version) throws YSyntaxException { List<Element> decompositionElems = specificationElem.getChildren("decomposition", _yawlNS); for (Element decompositionElem : decompositionElems) { Namespace xsiNameSpc = decompositionElem.getNamespace("xsi"); String decompID = decompositionElem.getAttributeValue("id"); Attribute type = decompositionElem.getAttribute("type", xsiNameSpc); if (type != null) { String decompType = type.getValue(); _decompAndTypeMap.put(decompID, decompType); }//from ww w .jav a 2s . c om } String uriString = specificationElem.getAttributeValue("uri"); _specification = new YSpecification(uriString); _specification.setVersion(version); _specification.setMetaData(parseMetaData(specificationElem)); String name = specificationElem.getChildText("name", _yawlNS); String documentation = specificationElem.getChildText("documentation", _yawlNS); // if name and doco fields missing from spec, see if they are in metadata if (name == null) name = _specification.getMetaData().getTitle(); if (documentation == null) documentation = _specification.getMetaData().getDescription(); _specification.setName(name); _specification.setDocumentation(documentation); Namespace schema4SchemaNS = Namespace.getNamespace(_schema4SchemaURI); Element schemaElem = specificationElem.getChild("schema", schema4SchemaNS); if (null != schemaElem) { extractEmptyComplexTypeFlagTypeNames(schemaElem); _specification.setSchema(JDOMUtil.elementToString(schemaElem)); } else { // if the spec has no schema definition insert a default one so that a // DataValidator gets created _specification.setSchema(_defaultSchema); } //If is version beta2 we loop through in a slightly different way. if (isBeta2Version()) { _decompositionParser = new YDecompositionParser[decompositionElems.size() + 1]; Element rootNetElem = specificationElem.getChild("rootNet", _yawlNS); _decompositionParser[0] = new YDecompositionParser(rootNetElem, this, _specification.getSchemaVersion()); YNet rootNet = (YNet) _decompositionParser[0].getDecomposition(); _specification.setRootNet(rootNet); for (int i = 1; i <= decompositionElems.size(); i++) { Element decompositionElem = decompositionElems.get(i - 1); _decompositionParser[i] = new YDecompositionParser(decompositionElem, this, _specification.getSchemaVersion()); YDecomposition decomposition = _decompositionParser[i].getDecomposition(); _specification.addDecomposition(decomposition); } } else {//must be beta3 or greater _decompositionParser = new YDecompositionParser[decompositionElems.size()]; for (int i = 0; i < decompositionElems.size(); i++) { Element decompositionElem = decompositionElems.get(i); _decompositionParser[i] = new YDecompositionParser(decompositionElem, this, _specification.getSchemaVersion()); YDecomposition decomposition = _decompositionParser[i].getDecomposition(); _specification.addDecomposition(decomposition); } } addSchema(specificationElem); }
From source file:uk.ac.ox.oucs.vle.xcri.daisy.Identifier.java
License:Educational Community License
@Override public void fromXml(Element element) throws InvalidElementException { super.fromXml(element); if (null != element.getAttribute("type", DaisyNamespace.DAISY_NAMESPACE_NS)) { this.setType(element.getAttributeValue("type", DaisyNamespace.DAISY_NAMESPACE_NS)); }/*from ww w .ja va 2 s.c om*/ }