List of usage examples for org.w3c.dom Element setAttributeNS
public void setAttributeNS(String namespaceURI, String qualifiedName, String value) throws DOMException;
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
/** * add triggers to use the repeat elements (allow to add an element, ...) *//*from www . j av a2 s. co m*/ private void createTriggersForRepeat(final Document xformsDocument, final Element rootGroup, final String repeatId, final String nodeset, final String bindId) { //xforms:at = xforms:index from the "id" attribute on the repeat element //trigger insert Element action = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":insert"); action.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":nodeset", nodeset); action.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":position", "before"); action.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":at", "1"); final Element trigger_insert_before = this.createTrigger(xformsDocument, repeatId + "-insert_before", bindId, "insert at beginning", action); action = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":insert"); action.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":nodeset", nodeset); action.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":position", "after"); action.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":at", NamespaceConstants.XFORMS_PREFIX + ":index('" + repeatId + "')"); final Element trigger_insert_after = this.createTrigger(xformsDocument, repeatId + "-insert_after", bindId, "insert after selected", action); //trigger delete action = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":delete"); action.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":nodeset", nodeset); action.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":at", NamespaceConstants.XFORMS_PREFIX + ":index('" + repeatId + "')"); final Element trigger_delete = this.createTrigger(xformsDocument, repeatId != null ? repeatId + "-delete" : null, bindId, "delete selected", action); //add the triggers rootGroup.appendChild(trigger_insert_before); rootGroup.appendChild(trigger_insert_after); rootGroup.appendChild(trigger_delete); }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
private Element createSubmissionElement(final Document xformDocument, final String id, final boolean validate) { final Element result = xformDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":submission"); this.setXFormsId(result, id); result.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":validate", validate ? "true" : "false"); result.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":action", this.action == null ? "" : this.base + this.action); result.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":method", (this.submitMethod != null ? this.submitMethod : Schema2XForms.SubmitMethod.POST).toString()); result.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":encoding", "UTF-8"); return result; }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
private Element createSubmitControl(final Document xformsDocument, final Element submission, final String id, final String label) { final Element result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":submit"); result.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":submission", submission.getAttributeNS(null, "id")); this.setXFormsId(result, id); result.appendChild(this.createLabel(xformsDocument, label)); return result; }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
private Element createBind(final Document xformsDocument, final String nodeset) { final Element result = xformsDocument.createElementNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":bind"); final String id = this.setXFormsId(result); result.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":nodeset", nodeset); if (LOGGER.isDebugEnabled()) LOGGER.debug("[createBind] created bind " + id + " for nodeset " + nodeset); return result; }
From source file:org.apache.axis.utils.XMLUtils.java
/** * Return a string for a particular QName, mapping a new prefix * if necessary.//from ww w .ja va 2s. co m */ public static String getStringForQName(QName qname, Element e) { String uri = qname.getNamespaceURI(); String prefix = getPrefix(uri, e); if (prefix == null) { int i = 1; prefix = "ns" + i; while (getNamespace(prefix, e) != null) { i++; prefix = "ns" + i; } e.setAttributeNS(Constants.NS_URI_XMLNS, "xmlns:" + prefix, uri); } return prefix + ":" + qname.getLocalPart(); }
From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java
private Element createNewSchemaWithElement(Element newElement, Map namespacePrefixMap, Map namespaceImportsMap, String targetNamespace, Document document, String xsdPrefix) { Element schemaElement = document.createElementNS(XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":" + XML_SCHEMA_LOCAL_NAME); // loop through the namespace declarations first String[] nameSpaceDeclarationArray = (String[]) namespacePrefixMap.keySet() .toArray(new String[namespacePrefixMap.size()]); for (int i = 0; i < nameSpaceDeclarationArray.length; i++) { String s = nameSpaceDeclarationArray[i]; schemaElement.setAttributeNS(XML_NAMESPACE_URI, NAMESPACE_DECLARATION_PREFIX + namespacePrefixMap.get(s).toString(), s); }//from w w w . j av a2 s . c o m if (schemaElement.getAttributeNS(XML_NAMESPACE_URI, xsdPrefix).length() == 0) { schemaElement.setAttributeNS(XML_NAMESPACE_URI, NAMESPACE_DECLARATION_PREFIX + xsdPrefix, XMLSCHEMA_NAMESPACE_URI); } // add the targetNamespace schemaElement.setAttributeNS(XML_NAMESPACE_URI, XMLNS_AXIS2WRAPPED, targetNamespace); schemaElement.setAttribute(XSD_TARGETNAMESPACE, targetNamespace); schemaElement.setAttribute(XSD_ELEMENT_FORM_DEFAULT, XSD_UNQUALIFIED); // add imports Element[] namespaceImports = (Element[]) namespaceImportsMap.values() .toArray(new Element[namespaceImportsMap.size()]); for (int i = 0; i < namespaceImports.length; i++) { schemaElement.appendChild(namespaceImports[i]); } schemaElement.appendChild(newElement); return schemaElement; }
From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java
/** * @param part/*from w ww. j a v a 2s . co m*/ * @param document * @param xsdPrefix * @param namespaceImportsMap * @param namespacePrefixMap * @param cmplxTypeSequence * @param isOutMessage (true is part is referenced by the output clause) * @param boe BindingOperationEntry that caused the creation of this part. */ private void addPartToElement(Part part, Document document, String xsdPrefix, Map namespaceImportsMap, Map namespacePrefixMap, Element cmplxTypeSequence, boolean isOutMessage, BindingOperationEntry boe) { Element child; String elementName = part.getName(); // the type name QName schemaTypeName = part.getTypeName(); if (schemaTypeName != null) { child = document.createElementNS(XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":" + XML_SCHEMA_ELEMENT_LOCAL_NAME); // always child attribute should be in no namespace child.setAttribute("form", "unqualified"); child.setAttribute("nillable", "true"); String prefix; if (XMLSCHEMA_NAMESPACE_URI.equals(schemaTypeName.getNamespaceURI())) { prefix = xsdPrefix; if (log.isDebugEnabled()) { log.debug( "Unable to find a namespace for " + xsdPrefix + ". Creating a new namespace attribute"); } cmplxTypeSequence.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + xsdPrefix, XMLSCHEMA_NAMESPACE_URI); } else { // this schema is a third party one. So we need to have // an import statement in our generated schema String uri = schemaTypeName.getNamespaceURI(); if (!namespaceImportsMap.containsKey(uri)) { // create Element for namespace import Element namespaceImport = document.createElementNS(XMLSCHEMA_NAMESPACE_URI, xsdPrefix + ":" + XML_SCHEMA_IMPORT_LOCAL_NAME); namespaceImport.setAttribute(NAMESPACE_URI, uri); // add this to the map namespaceImportsMap.put(uri, namespaceImport); // we also need to associate this uri with a prefix // and include that prefix // in the schema's namspace declarations. So add // theis particular namespace to the // prefix map as well prefix = getTemporaryNamespacePrefix(); namespacePrefixMap.put(uri, prefix); } else { // this URI should be already in the namspace prefix // map prefix = (String) namespacePrefixMap.get(uri); } } child.setAttribute(XSD_NAME, elementName); child.setAttribute(XSD_TYPE, prefix + ":" + schemaTypeName.getLocalPart()); cmplxTypeSequence.appendChild(child); } else { String bindingOperationName = boe.getBindingOperation().getName(); String partName = part.getName(); if (boe.isRPC()) { // see the basic profile 4.4.1 for rpc-literal. // messages parts can have only types throw new WSDLProcessingException("The binding operation " + bindingOperationName + " is RPC/literal. " + "The message parts for this operation must use the type " + "attribute as specificed by " + "WS-I Basic Profile specification (4.4.1). Message part, " + partName + ", violates" + "this rule. Please remove the element attribute " + "and use the type attribute."); } else { // The presense of an element means that a wrapper xsd element is not needed. boe.setWrappedOutput(false); if (log.isDebugEnabled()) { log.debug("The binding operation " + bindingOperationName + " references message part " + partName + ". This part does not use the " + "type attribute, so a wrappering element is not added."); } } } }
From source file:org.apache.axis2.description.WSDL11ToAxisServiceBuilder.java
/** * @param prefixMap/*from w w w . j a va2s .co m*/ */ private void checkAndAddNamespaceDeclarations(String namespace, Map prefixMap, Element schemaElement) { // get the attribute for the current namespace String prefix = (String) prefixMap.get(namespace); // A prefix must be found at this point! String existingURL = schemaElement.getAttributeNS(XML_NAMESPACE_URI, NAMESPACE_DECLARATION_PREFIX + prefix); if (existingURL == null || existingURL.length() == 0) { // there is no existing URL by that prefix - declare a new namespace schemaElement.setAttributeNS(XML_NAMESPACE_URI, NAMESPACE_DECLARATION_PREFIX + prefix, namespace); } else if (existingURL.equals(namespace)) { // this namespace declaration is already there with the same prefix // ignore it } else { // there is a different namespace declared in the given prefix // change the prefix in the prefix map to a new one and declare it // create a prefix String generatedPrefix = "ns" + prefixCounter++; while (prefixMap.containsKey(generatedPrefix)) { generatedPrefix = "ns" + prefixCounter++; } schemaElement.setAttributeNS(XML_NAMESPACE_URI, NAMESPACE_DECLARATION_PREFIX + generatedPrefix, namespace); // add to the map prefixMap.put(namespace, generatedPrefix); } }
From source file:org.apache.camel.component.xmlsecurity.api.XAdESSignatureProperties.java
protected void setAttribute(Element element, String attrName, String value) { // element.setAttribute(name, value); did cause NullPointerException in santuario 2.02 element.setAttributeNS("", attrName, value); }
From source file:org.apache.cocoon.webapps.session.context.RequestSessionContext.java
/** * Build cookies XML//from w ww. j a va 2s . c o m */ private void buildCookiesXML(Element root) { Document doc = root.getOwnerDocument(); Element cookiesElement = doc.createElementNS(null, "cookies"); root.appendChild(cookiesElement); Cookie[] cookies = this.request.getCookies(); if (cookies != null) { Cookie current; Element node; Element parent; for (int i = 0; i < cookies.length; i++) { current = cookies[i]; parent = doc.createElementNS(null, "cookie"); parent.setAttributeNS(null, "name", current.getName()); cookiesElement.appendChild(parent); node = doc.createElementNS(null, "comment"); node.appendChild(this.createTextNode(doc, current.getComment())); parent.appendChild(node); node = doc.createElementNS(null, "domain"); node.appendChild(this.createTextNode(doc, current.getDomain())); parent.appendChild(node); node = doc.createElementNS(null, "maxAge"); node.appendChild(this.createTextNode(doc, "" + current.getMaxAge())); parent.appendChild(node); node = doc.createElementNS(null, "name"); node.appendChild(this.createTextNode(doc, current.getName())); parent.appendChild(node); node = doc.createElementNS(null, "path"); node.appendChild(this.createTextNode(doc, current.getPath())); parent.appendChild(node); node = doc.createElementNS(null, "secure"); node.appendChild(doc.createTextNode(BooleanUtils.toStringTrueFalse(current.getSecure()))); parent.appendChild(node); node = doc.createElementNS(null, "value"); node.appendChild(this.createTextNode(doc, current.getValue())); parent.appendChild(node); node = doc.createElementNS(null, "version"); node.appendChild(this.createTextNode(doc, "" + current.getVersion())); parent.appendChild(node); } } }