List of usage examples for org.w3c.dom Element getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;
NodeList
of all the descendant Elements
with a given local name and namespace URI in document order. From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
private void addAttributeSet(Document xForm, Element modelSection, Element formSection, XSComplexTypeDefinition controlType, XSElementDeclaration owner, String pathToRoot, boolean checkIfExtension) { XSObjectList attrUses = controlType.getAttributeUses(); if (attrUses != null) { int nbAttr = attrUses.getLength(); for (int i = 0; i < nbAttr; i++) { XSAttributeUse currentAttributeUse = (XSAttributeUse) attrUses.item(i); XSAttributeDeclaration currentAttribute = currentAttributeUse.getAttrDeclaration(); //test if extended ! if (checkIfExtension && this.doesAttributeComeFromExtension(currentAttributeUse, controlType)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(/*from w w w . j av a2 s.c o m*/ "This attribute comes from an extension: recopy form controls. \n Model section: "); DOMUtil.prettyPrintDOM(modelSection); } String attributeName = currentAttributeUse.getName(); if (attributeName == null || attributeName.equals("")) attributeName = currentAttributeUse.getAttrDeclaration().getName(); //find the existing bind Id //(modelSection is the enclosing bind of the element) NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind"); int j = 0; int nb = binds.getLength(); String bindId = null; while (j < nb && bindId == null) { Element bind = (Element) binds.item(j); String nodeset = bind.getAttributeNS(XFORMS_NS, "nodeset"); if (nodeset != null) { String name = nodeset.substring(1); //remove "@" in nodeset if (name.equals(attributeName)) bindId = bind.getAttributeNS(XFORMS_NS, "id"); } j++; } //find the control Element control = null; if (bindId != null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("bindId found: " + bindId); JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument()); Pointer pointer = context .getPointer("//*[@" + this.getXFormsNSPrefix() + "bind='" + bindId + "']"); if (pointer != null) control = (Element) pointer.getNode(); } //copy it if (control == null) { LOGGER.warn("Corresponding control not found"); } else { Element newControl = (Element) control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); formSection.appendChild(newControl); } } else { String newPathToRoot; if ((pathToRoot == null) || pathToRoot.equals("")) { newPathToRoot = "@" + currentAttribute.getName(); } else if (pathToRoot.endsWith("/")) { newPathToRoot = pathToRoot + "@" + currentAttribute.getName(); } else { newPathToRoot = pathToRoot + "/@" + currentAttribute.getName(); } XSSimpleTypeDefinition simpleType = currentAttribute.getTypeDefinition(); //TODO SRA: UrType ? /*if(simpleType==null){ simpleType=new UrType(); }*/ addSimpleType(xForm, modelSection, formSection, simpleType, currentAttributeUse, newPathToRoot); } } } }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
/** * add an element to the XForms document: the bind + the control * (only the control if "withBind" is false) *///from w w w. j a va 2 s. c om private void addElement(Document xForm, Element modelSection, Element formSection, XSElementDeclaration elementDecl, XSTypeDefinition controlType, String pathToRoot) { if (controlType == null) { // TODO!!! Figure out why this happens... for now just warn... // seems to happen when there is an element of type IDREFS LOGGER.warn("WARNING!!! controlType is null for " + elementDecl + ", " + elementDecl.getName()); return; } switch (controlType.getTypeCategory()) { case XSTypeDefinition.SIMPLE_TYPE: { addSimpleType(xForm, modelSection, formSection, (XSSimpleTypeDefinition) controlType, elementDecl, pathToRoot); break; } case XSTypeDefinition.COMPLEX_TYPE: { if (controlType.getName() != null && controlType.getName().equals("anyType")) { addAnyType(xForm, modelSection, formSection, (XSComplexTypeDefinition) controlType, elementDecl, pathToRoot); break; } else { // find the types which are compatible(derived from) the parent type. // // This is used if we encounter a XML Schema that permits the xsi:type // attribute to specify subtypes for the element. // // For example, the <address> element may be typed to permit any of // the following scenarios: // <address xsi:type="USAddress"> // </address> // <address xsi:type="CanadianAddress"> // </address> // <address xsi:type="InternationalAddress"> // </address> // // What we want to do is generate an XForm' switch element with cases // representing any valid non-abstract subtype. // // <xforms:select1 xforms:bind="xsi_type_13" // <xforms:label>Address</xforms:label> // <xforms:choices> // <xforms:item> // <xforms:label>US Address Type</xforms:label> // <xforms:value>USAddressType</xforms:value> // <xforms:action ev:event="xforms-select"> // <xforms:toggle xforms:case="USAddressType-case"/> // </xforms:action> // </xforms:item> // <xforms:item> // <xforms:label>Canadian Address Type</xforms:label> // <xforms:value>CanadianAddressType</xforms:value> // <xforms:action ev:event="xforms-select"> // <xforms:toggle xforms:case="CanadianAddressType-case"/> // </xforms:action> // </xforms:item> // <xforms:item> // <xforms:label>International Address Type</xforms:label> // <xforms:value>InternationalAddressType</xforms:value> // <xforms:action ev:event="xforms-select"> // <xforms:toggle xforms:case="InternationalAddressType-case"/> // </xforms:action> // </xforms:item> // // </xforms:choices> // <xforms:select1> // <xforms:trigger> // <xforms:label>validate Address type</xforms:label> // <xforms:action> // <xforms:dispatch id="dispatcher" xforms:name="xforms-activate" xforms:target="select1_0"/> // </xforms:action> //</xforms:trigger> // // <xforms:switch id="address_xsi_type_switch"> // <xforms:case id="USAddressType-case" selected="false"> // <!-- US Address Type sub-elements here--> // </xforms:case> // <xforms:case id="CanadianAddressType-case" selected="false"> // <!-- US Address Type sub-elements here--> // </xforms:case> // ... // </xforms:switch> // // + change bindings to add: // - a bind for the "@xsi:type" attribute // - for each possible element that can be added through the use of an inheritance, add a "relevant" attribute: // ex: xforms:relevant="../@xsi:type='USAddress'" // look for compatible types // String typeName = controlType.getName(); boolean relative = true; if (typeName != null) { TreeSet compatibleTypes = (TreeSet) typeTree.get(controlType.getName()); //TreeSet compatibleTypes = (TreeSet) typeTree.get(controlType); if (compatibleTypes != null) { relative = false; if (LOGGER.isDebugEnabled()) { LOGGER.debug("compatible types for " + typeName + ":"); Iterator it1 = compatibleTypes.iterator(); while (it1.hasNext()) { //String name = (String) it1.next(); XSTypeDefinition compType = (XSTypeDefinition) it1.next(); LOGGER.debug(" compatible type name=" + compType.getName()); } } Element control = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "select1"); String select1_id = this.setXFormsId(control); Element choices = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "choices"); this.setXFormsId(choices); //get possible values Vector enumValues = new Vector(); //add the type (if not abstract) if (!((XSComplexTypeDefinition) controlType).getAbstract()) enumValues.add(controlType); //enumValues.add(typeName); //add compatible types Iterator it = compatibleTypes.iterator(); while (it.hasNext()) { enumValues.add(it.next()); } if (enumValues.size() > 1) { String caption = createCaption(elementDecl.getName() + " Type"); Element controlCaption = (Element) control .appendChild(xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "label")); this.setXFormsId(controlCaption); controlCaption.appendChild(xForm.createTextNode(caption)); // multiple compatible types for this element exist // in the schema - allow the user to choose from // between compatible non-abstract types Element bindElement = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "bind"); String bindId = this.setXFormsId(bindElement); bindElement.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "nodeset", pathToRoot + "/@xsi:type"); modelSection.appendChild(bindElement); control.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "bind", bindId); //add the "element" bind, in addition Element bindElement2 = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "bind"); String bindId2 = this.setXFormsId(bindElement2); bindElement2.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "nodeset", pathToRoot); modelSection.appendChild(bindElement2); if (enumValues.size() < Long.parseLong(getProperty(SELECTONE_LONG_LIST_SIZE_PROP))) { control.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "appearance", getProperty(SELECTONE_UI_CONTROL_SHORT_PROP)); } else { control.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "appearance", getProperty(SELECTONE_UI_CONTROL_LONG_PROP)); // add the "Please select..." instruction item for the combobox // and set the isValid attribute on the bind element to check for the "Please select..." // item to indicate that is not a valid value // String pleaseSelect = "[Select1 " + caption + "]"; Element item = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "item"); this.setXFormsId(item); choices.appendChild(item); Element captionElement = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "label"); this.setXFormsId(captionElement); item.appendChild(captionElement); captionElement.appendChild(xForm.createTextNode(pleaseSelect)); Element value = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "value"); this.setXFormsId(value); item.appendChild(value); value.appendChild(xForm.createTextNode(pleaseSelect)); // not(purchaseOrder/state = '[Choose State]') //String isValidExpr = "not(" + bindElement.getAttributeNS(XFORMS_NS, "nodeset") + " = '" + pleaseSelect + "')"; // ->no, not(. = '[Choose State]') String isValidExpr = "not( . = '" + pleaseSelect + "')"; //check if there was a constraint String constraint = bindElement.getAttributeNS(XFORMS_NS, "constraint"); if ((constraint != null) && !constraint.equals("")) { constraint = constraint + " && " + isValidExpr; } else { constraint = isValidExpr; } bindElement.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "constraint", constraint); } Element choicesControlWrapper = _wrapper.createControlsWrapper(choices); control.appendChild(choicesControlWrapper); Element controlWrapper = _wrapper.createControlsWrapper(control); formSection.appendChild(controlWrapper); ///////////////// /////////////// // add content to select1 HashMap case_types = new HashMap(); addChoicesForSelectSwitchControl(xForm, choices, enumValues, case_types); ///////////////// //add a trigger for this control (is there a way to not need it ?) Element trigger = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "trigger"); formSection.appendChild(trigger); this.setXFormsId(trigger); Element label_trigger = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "label"); this.setXFormsId(label_trigger); trigger.appendChild(label_trigger); String trigger_caption = createCaption("validate choice"); label_trigger.appendChild(xForm.createTextNode(trigger_caption)); Element action_trigger = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "action"); this.setXFormsId(action_trigger); trigger.appendChild(action_trigger); Element dispatch_trigger = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "dispatch"); this.setXFormsId(dispatch_trigger); action_trigger.appendChild(dispatch_trigger); dispatch_trigger.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "name", "DOMActivate"); dispatch_trigger.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "target", select1_id); ///////////////// //add switch Element switchElement = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "switch"); this.setXFormsId(switchElement); Element switchControlWrapper = _wrapper.createControlsWrapper(switchElement); formSection.appendChild(switchControlWrapper); //formSection.appendChild(switchElement); /////////////// add this type ////////////// Element firstCaseElement = (Element) case_types.get(controlType.getName()); switchElement.appendChild(firstCaseElement); addComplexType(xForm, modelSection, firstCaseElement, (XSComplexTypeDefinition) controlType, elementDecl, pathToRoot, true, false); /////////////// add sub types ////////////// it = compatibleTypes.iterator(); // add each compatible type within // a case statement while (it.hasNext()) { /*String compatibleTypeName = (String) it.next(); //WARNING: order of parameters inversed from the doc for 2.6.0 !!! XSTypeDefinition type =getSchema().getTypeDefinition( compatibleTypeName, targetNamespace);*/ XSTypeDefinition type = (XSTypeDefinition) it.next(); String compatibleTypeName = type.getName(); if (LOGGER.isDebugEnabled()) { if (type == null) LOGGER.debug(">>>addElement: compatible type is null!! type=" + compatibleTypeName + ", targetNamespace=" + targetNamespace); else LOGGER.debug(" >>>addElement: adding compatible type " + type.getName()); } if (type != null && type.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) { //Element caseElement = (Element) xForm.createElementNS(XFORMS_NS,getXFormsNSPrefix() + "case"); //caseElement.setAttributeNS(XFORMS_NS,getXFormsNSPrefix() + "id",bindId + "_" + type.getName() +"_case"); //String case_id=this.setXFormsId(caseElement); Element caseElement = (Element) case_types.get(type.getName()); switchElement.appendChild(caseElement); addComplexType(xForm, modelSection, caseElement, (XSComplexTypeDefinition) type, elementDecl, pathToRoot, true, true); ////// // modify bind to add a "relevant" attribute that checks the value of @xsi:type // if (LOGGER.isDebugEnabled()) DOMUtil.prettyPrintDOM(bindElement2); NodeList binds = bindElement2.getElementsByTagNameNS(XFORMS_NS, "bind"); Element thisBind = null; int nb_binds = binds.getLength(); int i = 0; while (i < nb_binds && thisBind == null) { Element subBind = (Element) binds.item(i); String name = subBind.getAttributeNS(XFORMS_NS, "nodeset"); if (LOGGER.isDebugEnabled()) LOGGER.debug("Testing sub-bind with nodeset " + name); if (this.isElementDeclaredIn(name, (XSComplexTypeDefinition) type, false) || this.isAttributeDeclaredIn(name, (XSComplexTypeDefinition) type, false)) { if (LOGGER.isDebugEnabled()) LOGGER.debug("Element/Attribute " + name + " declared in type " + type.getName() + ": adding relevant attribute"); //test sub types of this type TreeSet subCompatibleTypes = (TreeSet) typeTree.get(type.getName()); //TreeSet subCompatibleTypes = (TreeSet) typeTree.get(type); String newRelevant = null; if (subCompatibleTypes == null || subCompatibleTypes.isEmpty()) { //just add ../@xsi:type='type' newRelevant = "../@xsi:type='" + type.getName() + "'"; } else { //add ../@xsi:type='type' or ../@xsi:type='otherType' or ... newRelevant = "../@xsi:type='" + type.getName() + "'"; Iterator it_ct = subCompatibleTypes.iterator(); while (it_ct.hasNext()) { //String otherTypeName = (String) it_ct.next(); XSTypeDefinition otherType = (XSTypeDefinition) it_ct.next(); String otherTypeName = otherType.getName(); newRelevant = newRelevant + " or ../@xsi:type='" + otherTypeName + "'"; } } //change relevant attribute String relevant = subBind.getAttributeNS(XFORMS_NS, "relevant"); if (relevant != null && !relevant.equals("")) { newRelevant = "(" + relevant + ") and " + newRelevant; } if (newRelevant != null && !newRelevant.equals("")) subBind.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "relevant", newRelevant); } i++; } } } /*if (LOGGER.isDebugEnabled()) { LOGGER.debug( "###addElement for derived type: bind created:"); DOMUtil.prettyPrintDOM(bindElement2); }*/ // we're done // break; } else if (enumValues.size() == 1) { // only one compatible type, set the controlType value // and fall through // //controlType = getSchema().getComplexType((String)enumValues.get(0)); controlType = getSchema().getTypeDefinition((String) enumValues.get(0), targetNamespace); } } else if (LOGGER.isDebugEnabled()) LOGGER.debug("No compatible type found for " + typeName); //name not null but no compatibleType? relative = true; } if (relative) //create the bind in case it is a repeat { if (LOGGER.isDebugEnabled()) LOGGER.debug(">>>Adding empty bind for " + typeName); // create the <xforms:bind> element and add it to the model. Element bindElement = xForm.createElementNS(XFORMS_NS, getXFormsNSPrefix() + "bind"); String bindId = this.setXFormsId(bindElement); bindElement.setAttributeNS(XFORMS_NS, getXFormsNSPrefix() + "nodeset", pathToRoot); modelSection.appendChild(bindElement); } else if (LOGGER.isDebugEnabled()) { LOGGER.debug("addElement: bind is not relative for " + elementDecl.getName()); } //addComplexType(xForm,modelSection, formSection,(ComplexType)controlType,elementDecl,pathToRoot, relative); addComplexType(xForm, modelSection, formSection, (XSComplexTypeDefinition) controlType, elementDecl, pathToRoot, true, false); break; } } default: // TODO: add wildcard support LOGGER.warn("\nWARNING!!! - Unsupported type [" + elementDecl.getType() + "] for node [" + controlType.getName() + "]"); } }
From source file:org.chiba.tools.schemabuilder.AbstractSchemaFormBuilder.java
/** * checkIfExtension: if false, addElement is called wether it is an extension or not * if true, if it is an extension, element is recopied (and no additional bind) *//*from w ww. j av a 2s . c o m*/ private void addGroup(Document xForm, Element modelSection, Element formSection, XSModelGroup group, XSComplexTypeDefinition controlType, XSElementDeclaration owner, String pathToRoot, int minOccurs, int maxOccurs, boolean checkIfExtension) { if (group != null) { Element repeatSection = addRepeatIfNecessary(xForm, modelSection, formSection, owner.getTypeDefinition(), minOccurs, maxOccurs, pathToRoot); Element repeatContentWrapper = repeatSection; if (repeatSection != formSection) { //selector -> no more needed? //this.addSelector(xForm, repeatSection); //group wrapper repeatContentWrapper = _wrapper.createGroupContentWrapper(repeatSection); } if (LOGGER.isDebugEnabled()) LOGGER.debug( "addGroup from owner=" + owner.getName() + " and controlType=" + controlType.getName()); XSObjectList particles = group.getParticles(); for (int counter = 0; counter < particles.getLength(); counter++) { XSParticle currentNode = (XSParticle) particles.item(counter); XSTerm term = currentNode.getTerm(); if (LOGGER.isDebugEnabled()) LOGGER.debug(" : next term = " + term.getName()); int childMaxOccurs = currentNode.getMaxOccurs(); if (currentNode.getMaxOccursUnbounded()) childMaxOccurs = -1; int childMinOccurs = currentNode.getMinOccurs(); if (term instanceof XSModelGroup) { if (LOGGER.isDebugEnabled()) LOGGER.debug(" term is a group"); addGroup(xForm, modelSection, repeatContentWrapper, ((XSModelGroup) term), controlType, owner, pathToRoot, childMinOccurs, childMaxOccurs, checkIfExtension); } else if (term instanceof XSElementDeclaration) { XSElementDeclaration element = (XSElementDeclaration) term; if (LOGGER.isDebugEnabled()) LOGGER.debug(" term is an element declaration: " + term.getName()); //special case for types already added because used in an extension //do not add it when it comes from an extension !!! //-> make a copy from the existing form control if (checkIfExtension && this.doesElementComeFromExtension(element, controlType)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug( "This element comes from an extension: recopy form controls.\n Model Section="); DOMUtil.prettyPrintDOM(modelSection); } //find the existing bind Id //(modelSection is the enclosing bind of the element) NodeList binds = modelSection.getElementsByTagNameNS(XFORMS_NS, "bind"); int i = 0; int nb = binds.getLength(); String bindId = null; while (i < nb && bindId == null) { Element bind = (Element) binds.item(i); String nodeset = bind.getAttributeNS(XFORMS_NS, "nodeset"); if (nodeset != null && nodeset.equals(element.getName())) bindId = bind.getAttributeNS(XFORMS_NS, "id"); i++; } //find the control Element control = null; if (bindId != null) { if (LOGGER.isDebugEnabled()) LOGGER.debug("bindId found: " + bindId); JXPathContext context = JXPathContext.newContext(formSection.getOwnerDocument()); Pointer pointer = context .getPointer("//*[@" + this.getXFormsNSPrefix() + "bind='" + bindId + "']"); if (pointer != null) control = (Element) pointer.getNode(); } //copy it if (control == null) { LOGGER.warn("Corresponding control not found"); } else { Element newControl = (Element) control.cloneNode(true); //set new Ids to XForm elements this.resetXFormIds(newControl); repeatContentWrapper.appendChild(newControl); } } else { //add it normally String elementName = getElementName(element, xForm); String path = pathToRoot + "/" + elementName; if (pathToRoot.equals("")) { //relative path = elementName; } addElement(xForm, modelSection, repeatContentWrapper, element, element.getTypeDefinition(), path); } } else { //XSWildcard -> ignore ? //LOGGER.warn("XSWildcard found in group from "+owner.getName()+" for pathToRoot="+pathToRoot); } } if (LOGGER.isDebugEnabled()) LOGGER.debug("--- end of addGroup from owner=" + owner.getName()); } }
From source file:org.chiba.xml.xforms.test.ChibaBeanTest.java
/** * Tests instance element assignment./* w w w . j a v a2 s . c o m*/ * * @throws Exception in any error occurred during the test. */ public void testSetInstanceElement() throws Exception { this.processor.setXMLContainer(this.form); this.processor.setInstanceElement("instance-1", this.instance.getDocumentElement()); Element instance = (Element) this.processor.getXMLContainer() .getElementsByTagNameNS(NamespaceCtx.XFORMS_NS, "instance").item(1); Element data = (Element) instance.getElementsByTagNameNS(null, "data").item(0); assertNotNull(data); assertTrue(getComparator().compare(this.instance.getDocumentElement(), data)); }
From source file:org.chiba.xml.xforms.test.ChibaBeanTest.java
/** * Tests default instance element assignment. * * @throws Exception in any error occurred during the test. */// w ww . j av a 2 s. c om public void testSetInstanceElementDefault() throws Exception { this.processor.setXMLContainer(this.form); this.processor.setInstanceElement("", this.instance.getDocumentElement()); Element instance = (Element) this.processor.getXMLContainer() .getElementsByTagNameNS(NamespaceCtx.XFORMS_NS, "instance").item(0); Element data = (Element) instance.getElementsByTagNameNS(null, "data").item(0); assertNotNull(data); assertTrue(getComparator().compare(this.instance.getDocumentElement(), data)); }
From source file:org.commonjava.maven.galley.maven.parse.XMLInfrastructure.java
public Element createElement(final Node in, final String relativePath, final Map<String, String> leafElements) { final Document doc; final Element below; if (in instanceof Document) { doc = (Document) in;//from w w w .j av a 2 s . c o m below = doc.getDocumentElement(); } else if (in instanceof Element) { below = (Element) in; doc = below.getOwnerDocument(); } else { throw new IllegalArgumentException("Cannot create nodes/content under a node of type: " + in); } Element insertionPoint = below; if (relativePath != null && relativePath.length() > 0 && !"/".equals(relativePath)) { final String[] intermediates = relativePath.split("/"); // DO NOT traverse last "intermediate"...this will be the new element! for (int i = 0; i < intermediates.length - 1; i++) { final NodeList nl = insertionPoint.getElementsByTagNameNS(below.getNamespaceURI(), intermediates[i]); if (nl != null && nl.getLength() > 0) { insertionPoint = (Element) nl.item(0); } else { final Element e = doc.createElementNS(below.getNamespaceURI(), intermediates[i]); insertionPoint.appendChild(e); insertionPoint = e; } } final Element e = doc.createElementNS(below.getNamespaceURI(), intermediates[intermediates.length - 1]); insertionPoint.appendChild(e); insertionPoint = e; } for (final Entry<String, String> entry : leafElements.entrySet()) { final String key = entry.getKey(); final String value = entry.getValue(); final Element e = doc.createElementNS(below.getNamespaceURI(), key); insertionPoint.appendChild(e); e.setTextContent(value); } return insertionPoint; }
From source file:org.dhatim.yaml.KeyMapDigester.java
public static HashMap<String, String> digest(Element keyMapElement) { HashMap<String, String> keyMap = new HashMap<String, String>(); NodeList keys = keyMapElement.getElementsByTagNameNS("*", KEY_MAP_KEY_ELEMENT); for (int i = 0; keys != null && i < keys.getLength(); i++) { Element keyElement = (Element) keys.item(i); String from = DomUtils.getAttributeValue(keyElement, KEY_MAP_KEY_ELEMENT_FROM_ATTRIBUTE); if (StringUtils.isBlank(from)) { throw new SmooksConfigurationException("The '" + KEY_MAP_KEY_ELEMENT_FROM_ATTRIBUTE + "' attribute isn't defined or is empty for the key element: " + keyElement); }/*ww w. j a v a 2 s.c o m*/ from = from.trim(); String value = DomUtils.getAttributeValue(keyElement, KEY_MAP_KEY_ELEMENT_TO_ATTRIBUTE); if (value == null) { value = DomUtils.getAllText(keyElement, true); if (StringUtils.isBlank(value)) { value = null; } } keyMap.put(from, value); } return keyMap; }
From source file:org.eclipse.smila.datamodel.record.dom.RecordParser.java
/** * parse attachment elements./*from w w w. ja v a 2s. c om*/ * * @param record * record to attach to * @param recordElement * element ro parse from. */ private void parseAttachments(final Record record, final Element recordElement) { final NodeList attachmentElements = recordElement.getElementsByTagNameNS(NAMESPACE_RECORD, TAG_ATTACHMENT); if (attachmentElements != null && attachmentElements.getLength() > 0) { for (int i = 0; i < attachmentElements.getLength(); i++) { final Element attachmentElement = (Element) attachmentElements.item(i); final String attachmentName = attachmentElement.getTextContent(); record.setAttachment(attachmentName, null); } } }
From source file:org.eclipse.smila.processing.bpel.ExtensionManager.java
/** * find element with given local name (proc: namespace) and return value of given attribute. return null, if not * found./* w w w.j a va 2 s . c o m*/ * * @param content * an element to search in. * @param localName * local name of element to look for. * @param attribute * attribute name. * @return attribute value if found, else null. */ public String getAttributeOfElement(final Element content, final String localName, final String attribute) { String attributeValue = null; final NodeList nodes = content.getElementsByTagNameNS(ODEWorkflowProcessor.NAMESPACE_PROCESSOR, localName); if (nodes.getLength() > 0) { attributeValue = ((Element) nodes.item(0)).getAttribute(attribute); if (StringUtils.isBlank(attributeValue)) { attributeValue = null; } } return attributeValue; }
From source file:org.eclipse.smila.processing.bpel.ExtensionManager.java
/** * parse annotations from given element and attach them to annotatble object. * /* ww w .ja v a2s .c o m*/ * @param content * DOM objects to search for annotations * @param annotatable * object to attach annotations to. */ public void parseAnnotations(final Element content, final AnnotatableImpl annotatable) { final NodeList annotations = content.getElementsByTagNameNS(ODEWorkflowProcessor.NAMESPACE_PROCESSOR, TAG_SETANNOTATIONS); if (annotations != null && annotations.getLength() > 0) { for (int j = 0; j < annotations.getLength(); j++) { final Element setAnnotations = (Element) annotations.item(j); final NodeList childs = setAnnotations.getChildNodes(); for (int i = 0; i < childs.getLength(); i++) { final Node child = childs.item(i); if (child instanceof Element) { final Element element = (Element) child; if (RecordParser.TAG_ANNOTATION.equals(element.getLocalName())) { RECORD_PARSER.parseAnnotation(annotatable, element); } } } } } }