/** * {@inheritDoc} * * @throws DOMException If thrown by method invoked on the underlying DOM document */ public void attribute(String name, String value) throws DOMException { if (!this.isNude) throw new IllegalArgumentException("Cannot write attribute: too late!"); Attr att = this.document.createAttribute(name); att.setValue(value); this.currentElement.appendChild(att); }
if ((atts.getLocalName(i) == null) || (atts.getLocalName(i).length() == 0)) { attr = doc.createAttribute(atts.getQName(i)); attr.setNodeValue(atts.getValue(i)); ((Element)top).setAttributeNode(attr);
/** If the child node or attribute doesn't exist, it is created. Usage example: Node property = * getFirstChildByAttrValue(properties, "property", "name"); */ private static Node getFirstChildByNameAttrValue (Node node, String childName, String attr, String value) { NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { if (childNodes.item(i).getNodeName().equals(childName)) { NamedNodeMap attributes = childNodes.item(i).getAttributes(); Node attribute = attributes.getNamedItem(attr); if (attribute.getNodeValue().equals(value)) return childNodes.item(i); } } Node newNode = node.getOwnerDocument().createElement(childName); NamedNodeMap attributes = newNode.getAttributes(); Attr nodeAttr = node.getOwnerDocument().createAttribute(attr); nodeAttr.setNodeValue(value); attributes.setNamedItem(nodeAttr); if (childNodes.item(0) != null) { return node.insertBefore(newNode, childNodes.item(0)); } else { return node.appendChild(newNode); } }
private static void setProperty (Document doc, Node parent, String name, String value) { Node properties = getFirstChildNodeByName(parent, "properties"); Node property = getFirstChildByNameAttrValue(properties, "property", "name", name); NamedNodeMap attributes = property.getAttributes(); Node valueNode = attributes.getNamedItem("value"); if (valueNode == null) { valueNode = doc.createAttribute("value"); valueNode.setNodeValue(value); attributes.setNamedItem(valueNode); } else { valueNode.setNodeValue(value); } }
private static void setProperty (Document doc, Node parent, String name, String value) { Node properties = getFirstChildNodeByName(parent, "properties"); Node property = getFirstChildByNameAttrValue(properties, "property", "name", name); NamedNodeMap attributes = property.getAttributes(); Node valueNode = attributes.getNamedItem("value"); if (valueNode == null) { valueNode = doc.createAttribute("value"); valueNode.setNodeValue(value); attributes.setNamedItem(valueNode); } else { valueNode.setNodeValue(value); } }
/** If the child node or attribute doesn't exist, it is created. Usage example: Node property = * getFirstChildByAttrValue(properties, "property", "name"); */ private static Node getFirstChildByNameAttrValue (Node node, String childName, String attr, String value) { NodeList childNodes = node.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { if (childNodes.item(i).getNodeName().equals(childName)) { NamedNodeMap attributes = childNodes.item(i).getAttributes(); Node attribute = attributes.getNamedItem(attr); if (attribute.getNodeValue().equals(value)) return childNodes.item(i); } } Node newNode = node.getOwnerDocument().createElement(childName); NamedNodeMap attributes = newNode.getAttributes(); Attr nodeAttr = node.getOwnerDocument().createAttribute(attr); nodeAttr.setNodeValue(value); attributes.setNamedItem(nodeAttr); if (childNodes.item(0) != null) { return node.insertBefore(newNode, childNodes.item(0)); } else { return node.appendChild(newNode); } }
public static void putAt(Element self, String property, Object value) { if (property.startsWith("@")) { String attributeName = property.substring(1); Document doc = self.getOwnerDocument(); Attr newAttr = doc.createAttribute(attributeName); newAttr.setValue(value.toString()); self.setAttributeNode(newAttr); return; } InvokerHelper.setProperty(self, property, value); }
private Attr createAttribute(Node node, String name, String value) { Attr attr = node.getOwnerDocument().createAttribute(name); attr.setNodeValue(value); return attr; }
Node delayNode = gceNode.getAttributes().getNamedItem(delayNodeName); if (delayNode == null) { delayNode = tree.getOwnerDocument().createAttribute(delayNodeName); gceNode.appendChild(delayNode); Node transparencyFlagNode = gceNode.getAttributes().getNamedItem(transparencyFlagNodeName); if (transparencyFlagNode == null) { transparencyFlagNode = tree.getOwnerDocument().createAttribute(transparencyFlagNodeName); gceNode.appendChild(transparencyFlagNode); Node transparencyIndexNode = gceNode.getAttributes().getNamedItem(transparencyIndexNodeName); if (transparencyIndexNode == null) { transparencyIndexNode = tree.getOwnerDocument().createAttribute(transparencyIndexNodeName); gceNode.appendChild(transparencyIndexNode);
Attr attr = doc.createAttribute("id"); attr.setValue("1"); staff.setAttributeNode(attr);
@Test public void testExclusiveSplitXPathAdvanced2() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-ExclusiveSplitXPath-advanced-vars-not-signaled.bpmn2"); ksession = createKnowledgeSession(kbase); ksession.getWorkItemManager().registerWorkItemHandler("Email", new SystemOutWorkItemHandler()); Map<String, Object> params = new HashMap<String, Object>(); Document doc = DocumentBuilderFactory.newInstance() .newDocumentBuilder().newDocument(); Element hi = doc.createElement("hi"); Element ho = doc.createElement("ho"); hi.appendChild(ho); Attr attr = doc.createAttribute("value"); ho.setAttributeNode(attr); attr.setValue("a"); params.put("x", hi); params.put("y", "Second"); ProcessInstance processInstance = ksession.startProcess( "com.sample.test", params); assertProcessInstanceCompleted(processInstance); }
@Test public void testExclusiveSplitXPathAdvanced() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-ExclusiveSplitXPath-advanced.bpmn2"); ksession = createKnowledgeSession(kbase); ksession.getWorkItemManager().registerWorkItemHandler("Email", new SystemOutWorkItemHandler()); Map<String, Object> params = new HashMap<String, Object>(); Document doc = DocumentBuilderFactory.newInstance() .newDocumentBuilder().newDocument(); Element hi = doc.createElement("hi"); Element ho = doc.createElement("ho"); hi.appendChild(ho); Attr attr = doc.createAttribute("value"); ho.setAttributeNode(attr); attr.setValue("a"); params.put("x", hi); params.put("y", "Second"); ProcessInstance processInstance = ksession.startProcess( "com.sample.test", params); assertProcessInstanceCompleted(processInstance); }
@Test public void testExclusiveSplitXPathAdvancedWithVars() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-ExclusiveSplitXPath-advanced-with-vars.bpmn2"); ksession = createKnowledgeSession(kbase); ksession.getWorkItemManager().registerWorkItemHandler("Email", new SystemOutWorkItemHandler()); Map<String, Object> params = new HashMap<String, Object>(); Document doc = DocumentBuilderFactory.newInstance() .newDocumentBuilder().newDocument(); Element hi = doc.createElement("hi"); Element ho = doc.createElement("ho"); hi.appendChild(ho); Attr attr = doc.createAttribute("value"); ho.setAttributeNode(attr); attr.setValue("a"); params.put("x", hi); params.put("y", "Second"); ProcessInstance processInstance = ksession.startProcess( "com.sample.test", params); assertProcessInstanceCompleted(processInstance); }
/** * Append the specified key/value pair of attributes to the <code>Node</code>. * @param node Node * @param name String * @param value String */ public static void appendAttribute(Node node, String name, String value) { if (value != null) { Node attribute = node.getOwnerDocument().createAttribute(name); attribute.setNodeValue(value); node.getAttributes().setNamedItem(attribute); } } }
Attr attr = doc.createAttribute("id"); attr.setValue("1"); staff.setAttributeNode(attr);
private Document buildModuleConfig() throws ParserConfigurationException { DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element rootElement = doc.createElement("module"); doc.appendChild(rootElement); Element dwr = doc.createElement("dwr"); dwr.appendChild(doc.createTextNode("")); rootElement.appendChild(dwr); Element allow = doc.createElement("allow"); allow.appendChild(doc.createTextNode("")); dwr.appendChild(allow); Attr attr = doc.createAttribute("moduleId"); attr.setValue("mymodule"); allow.setAttributeNode(attr); Element create = doc.createElement("create"); allow.appendChild(create); return doc; }
/** * @todo: How Axis will maintain the Attribute representation ? */ public Attr createAttribute(String name) throws DOMException { return delegate.createAttribute(name); }
public static void putAt(Element self, String property, Object value) { if (property.startsWith("@")) { String attributeName = property.substring(1); Document doc = self.getOwnerDocument(); Attr newAttr = doc.createAttribute(attributeName); newAttr.setValue(value.toString()); self.setAttributeNode(newAttr); return; } InvokerHelper.setProperty(self, property, value); }
public void postProcess(ParserContext unused, BeanAssembler assembler, Element element) { Attr attribute = element.getOwnerDocument().createAttribute(name); attribute.setNodeValue(value); assembler.extendTarget(attribute); }
public void setAttribute( String name, String value ) throws DOMException { if (value.equals( getAttribute( name ))) return; Attr attribute = getOwnerDocument().createAttribute( name ); attribute.setValue( value ); setAttributeNode( attribute ); reportPropertyChanged( name ); }