List of usage examples for org.jdom2 Element getNamespace
public Namespace getNamespace(final String prefix)
From source file:com.tactfactory.harmony.generator.androidxml.ManifestUpdater.java
License:Open Source License
/** * Get all services from the manifest.// w ww . j a va 2s . co m * @return List of service name. */ public List<String> getServices() { List<String> result = new ArrayList<String>(); // Load Root element final Element rootNode = this.getDocument().getRootElement(); final Element appElem = rootNode.getChild(ManifestConstants.ELEMENT_APPLICATION); // Load Name space (required for manipulate attributes) final Namespace ns = rootNode.getNamespace(ManifestConstants.NAMESPACE_ANDROID); for (Element elem : appElem.getChildren(ManifestConstants.ELEMENT_SERVICE)) { result.add(elem.getAttributeValue(ManifestConstants.ATTRIBUTE_NAME, ns)); } return result; }
From source file:de.dfki.iui.mmds.core.emf.persistence.EmfPersistence.java
License:Creative Commons License
/** * Update member contents with resolved data * /*ww w . ja v a 2s . c om*/ * @param node * @param memberReference * @param memberDocument * @return * @throws Exception */ private static Element updateMember(Element node, EReference memberReference, int id, EObject memberObject, Document memberDocument) throws Exception { Namespace namespace = node.getNamespace(modelMetaData.getNamespace(memberReference)); List<Element> children = null; if (namespace == null) { children = node.getChildren(modelMetaData.getName(memberReference)); } else throw new IllegalArgumentException(); if (id < children.size()) { // Inserting resolved contents to the member Element element = children.get(id); Element clone = memberDocument.getRootElement().clone(); clone.setName(memberReference.getName()); node.setContent(node.indexOf(element), clone); // Setting xsi:type clone.setAttribute("type", memberObject.eClass().getEPackage().getName() + ":" + memberObject.eClass().getName(), node.getNamespace("xsi")); } return node; }
From source file:de.nava.informa.utils.ParserUtils.java
License:Open Source License
public static Namespace getNamespace(Element element, String prefix) { // Namespace ns = null; // Iterator it = element.getAdditionalNamespaces().iterator(); // while (it.hasNext()) { // Namespace curNS = (Namespace) it.next(); // if (curNS.getPrefix().equals(prefix)) { // ns = curNS; // break; // }/*from w ww.jav a 2 s. c o m*/ // } return (prefix == null) ? element.getNamespace("") : element.getNamespace(prefix); }
From source file:de.nava.informa.utils.XmlPathUtils.java
License:Open Source License
/** * Returns the Namespace corresponding to an element and a prefix. * * @param element the element.//www .jav a2s . c om * @param prefix the prefix. * @return the Namespace. */ private static Namespace getNamespace(final Element element, final String prefix) { Namespace namespace = (prefix == null) ? element.getNamespace("") : element.getNamespace(prefix); return (namespace == null) ? Namespace.NO_NAMESPACE : namespace; }
From source file:ilarkesto.integration.jdom.JDom.java
License:Open Source License
public static Element getChild(Element parent, String name) { Namespace ns = null;/*from w ww.j av a 2 s.c o m*/ int idx = name.indexOf(':'); if (idx > 0) { String prefix = name.substring(0, idx); name = name.substring(idx + 1); ns = parent.getNamespace(prefix); } return parent.getChild(name, ns); }
From source file:net.instantcom.mm7.MM7Error.java
License:Open Source License
@Override public void load(Element element) { Element body = element.getChild("Body", MM7Message.ENVELOPE); Element e = (Element) body.getChildren().get(0); this.faultCode = e.getChildTextTrim("faultcode"); this.faultMessage = e.getChildTextTrim("faultstring"); try {// w ww. j a va 2s . co m Element detail; if (element.getNamespace("") != null) { detail = (Element) e.getChild("detail", element.getNamespace("")).getChildren().get(0); } else { detail = (Element) e.getChild("detail").getChildren().get(0); } String message = detail.getName(); // Instantiate correct status type Class<?> clazz = Class.forName("net.instantcom.mm7." + message); this.response = (MM7Response) clazz.newInstance(); this.response.load(element); } catch (Throwable t) { // Ignored XMLOutputter outp = new XMLOutputter(); String s = outp.outputString(element); System.err.println("Failed to instantiate a correct response type" + s); t.printStackTrace(); } }
From source file:net.instantcom.mm7.MM7Response.java
License:Open Source License
@Override public void load(Element element) { super.load(element); Element body = element.getChild("Body", MM7Message.ENVELOPE); Element child = (Element) body.getChildren().get(0); // Handle SOAP faults, status will be found in a Fault detail element if ("Fault".equals(child.getName())) { //child = (Element) child.getChild("detail").getChildren().get(0); if (element.getNamespace("") != null) { child = (Element) child.getChild("detail", element.getNamespace("")).getChildren().get(0); } else {//from w ww. jav a 2 s . co m child = (Element) child.getChild("detail").getChildren().get(0); } } Element status = child.getChild("Status", namespace); if (status != null) { setStatusCode(Integer.parseInt(status.getChildTextTrim("StatusCode", namespace))); setStatusText(status.getChildTextTrim("StatusText", namespace)); } }
From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java
License:Open Source License
private YDecomposition createDecomposition(Element decompElem) { Namespace schemaInstanceNS = decompElem.getNamespace("xsi"); String xsiType = _decompElem.getAttributeValue("type", schemaInstanceNS); String id = _decompElem.getAttributeValue("id"); String elementName = _decompElem.getName(); if ("NetFactsType".equals(xsiType) || "rootNet".equals(elementName)) { _decomposition = new YNet(id, _specificationParser.getSpecification()); parseNet((YNet) _decomposition, decompElem); } else if ("WebServiceGatewayFactsType".equals(xsiType)) { _decomposition = new YAWLServiceGateway(id, _specificationParser.getSpecification()); parseWebServiceGateway((YAWLServiceGateway) _decomposition, decompElem); }/*w w w .j a v a 2 s .c om*/ /** * AJH: Added to support XML attribute pass-thru from specification into task output data doclet. * Load element attributes */ for (Attribute attr : decompElem.getAttributes()) { String attname = attr.getName(); boolean isXsiNS = attr.getNamespace() == schemaInstanceNS; //don't add the standard YAWL schema attributes to the pass through list. if (!("id".equals(attname) || ("type".equals(attname) && isXsiNS))) { String value = attr.getValue(); if (value.startsWith("dynamic{")) { _decomposition.setAttribute(attr.getName(), new DynamicValue(value, _decomposition)); } else _decomposition.setAttribute(attr.getName(), value); } } parseDecompositionRoles(_decomposition, decompElem); _decomposition.setLogPredicate(parseLogPredicate(decompElem, _yawlNS)); // added for resourcing parseExternalInteraction(_decomposition, decompElem); parseCodelet(_decomposition, decompElem); return _decomposition; }
From source file:org.yawlfoundation.yawl.unmarshal.YDecompositionParser.java
License:Open Source License
private void parseExternalTaskRoles(Element externalTaskElem, YTask externalTask) { _removeSetIDs.put(externalTask, parseRemoveSet(externalTaskElem)); _removeSetForFlows.put(externalTask, parseRemoveSetFromFlow(externalTaskElem)); _postsetIDs.add(externalTask.getID(), parsePostset(externalTaskElem)); Element startingMappings = externalTaskElem.getChild("startingMappings", _yawlNS); if (startingMappings != null) { externalTask.setDataMappingsForTaskStarting(parseMappings(startingMappings, true)); }/*from www .ja va 2s. co m*/ Element completedMappings = externalTaskElem.getChild("completedMappings", _yawlNS); if (completedMappings != null) { externalTask.setDataMappingsForTaskCompletion(parseMappings(completedMappings, false)); } Element enablementMappings = externalTaskElem.getChild("enablementMappings", _yawlNS); if (enablementMappings != null && externalTask instanceof YAtomicTask) { ((YAtomicTask) externalTask).setDataMappingsForEnablement(parseMappings(enablementMappings, true)); } String taskType = externalTaskElem.getAttributeValue("type", externalTaskElem.getNamespace("xsi")); if ("MultipleInstanceExternalTaskFactsType".equals(taskType)) { externalTask.setUpMultipleInstanceAttributes(externalTaskElem.getChildText("minimum", _yawlNS), externalTaskElem.getChildText("maximum", _yawlNS), externalTaskElem.getChildText("threshold", _yawlNS), externalTaskElem.getChild("creationMode", _yawlNS).getAttributeValue("code")); String expression = externalTaskElem.getChild("miDataInput", _yawlNS).getChild("expression", _yawlNS) .getAttributeValue("query"); String processingExpressionForInput = externalTaskElem.getChild("miDataInput", _yawlNS) .getChild("splittingExpression", _yawlNS).getAttributeValue("query"); String remoteVarName = externalTaskElem.getChild("miDataInput", _yawlNS) .getChildText("formalInputParam", _yawlNS); externalTask.setDataBindingForInputParam(expression, remoteVarName); externalTask.setMultiInstanceInputDataMappings(remoteVarName, processingExpressionForInput); Element miDataOutputElem = externalTaskElem.getChild("miDataOutput", _yawlNS); if (miDataOutputElem != null) { String remoteExpressionName = miDataOutputElem.getChild("formalOutputExpression", _yawlNS) .getAttributeValue("query"); String aggregationQuery = miDataOutputElem.getChild("outputJoiningExpression", _yawlNS) .getAttributeValue("query"); String localVarName = miDataOutputElem.getChildText("resultAppliedToLocalVariable", _yawlNS); externalTask.setDataBindingForOutputExpression(remoteExpressionName, localVarName); externalTask.setMultiInstanceOutputDataMappings(remoteExpressionName, aggregationQuery); } } }
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); }// ww w. j a va 2s .co m } 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); }