List of usage examples for org.w3c.dom Element getAttributeNS
public String getAttributeNS(String namespaceURI, String localName) throws DOMException;
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
/** * This method is invoked after an xforms:bind element is created for the specified SimpleType. * The implementation is responsible for setting setting any/all bind attributes * except for <b>id</b> and <b>ref</b> - these have been automatically set * by the caller (and should not be touched by implementation of startBindElement) * prior to invoking startBindElement.//from w w w . j a v a 2 s .c om * The caller automatically adds the returned element to the model section of * the form. * * @param bindElement The bindElement being processed. * @param schema XML Schema type of the element/attribute this bind is for. * @param controlType * @param owner * @param o * @return The bind Element to use in the XForm - bindElement or a replacement. */ public Element startBindElement(final Element bindElement, final XSModel schema, final XSTypeDefinition controlType, final XSObject owner, final SchemaUtil.Occurrence o) { // START WORKAROUND // Due to a Chiba bug, anyType is not a recognized type name. // so, if this is an anyType, then we'll just skip the type // setting. // // type.getName() may be 'null' for anonymous types, so compare against // static string (see bug #1172541 on sf.net) final List<String> constraints = new LinkedList<String>(); if (controlType instanceof XSSimpleTypeDefinition && ((XSSimpleTypeDefinition) controlType).getBuiltInKind() != XSConstants.ANYSIMPLETYPE_DT) { String typeName = this.getXFormsTypeName(bindElement.getOwnerDocument(), schema, controlType); if (typeName != null && typeName.length() != 0) { bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":type", typeName); } typeName = SchemaUtil.getBuiltInTypeName(controlType); if (typeName != null && typeName.length() != 0) { bindElement.setAttributeNS(NamespaceService.ALFRESCO_URI, NamespaceService.ALFRESCO_PREFIX + ":builtInType", typeName); } final StringList lexicalPatterns = ((XSSimpleTypeDefinition) controlType).getLexicalPattern(); // NOTE: from glen.johnson@alfresco.com // Workaround to fix issue WCM-952 // // I added expression '&& !typeName.equals(SchemaSymbols.ATTVAL_INTEGER') // onto the end of loop condition expression below. // // This is to stop the pattern matching constraint (using deprecated chiba:match() function) // from being generated into binding elements that are linked to "xs:integer" // elements (in the xform instance) // // If this pattern match constraint is indeed added to the binding element linked to // a "xs:integer" element in the xform instance, then a value is always required // for that element - even if the corresponding schema has minOccurs="0" for // that element i.e. it causes a value to be required for "optional" xs:integer // elements. // // Note that the chiba:match() function is unsupported and will be removed from Chiba // in the future, so a solution enabling its complete removal will need to be found. // I do not see why it has been included here. The Schema inside the xform // model should take care of most validation needs. // In the past, when I have completely removed this constraint (see CHK-2333), restrictions // using <xs:pattern> in the Schema fail to get enforced - // Causing the failure of org.alfresco.web.forms.xforms.Schema2XFormsTest.testConstraint() // for (int i = 0; lexicalPatterns != null && i < lexicalPatterns.getLength() && !SchemaSymbols.ATTVAL_INTEGER.equals(typeName); i++) { String pattern = lexicalPatterns.item(i); if (o.isOptional()) { pattern = "(" + pattern + ")?"; } constraints.add("chiba:match(., '" + pattern + "',null)"); } XSSimpleTypeDefinition simpleControlType = ((XSSimpleTypeDefinition) controlType); if (simpleControlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MAXLENGTH)) { constraints.add("string-length(.) <= " + simpleControlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MAXLENGTH)); } if (simpleControlType.isDefinedFacet(XSSimpleTypeDefinition.FACET_MINLENGTH)) { constraints.add("string-length(.) >= " + simpleControlType.getLexicalFacetValue(XSSimpleTypeDefinition.FACET_MINLENGTH)); } } final short constraintType = (owner != null && owner instanceof XSElementDeclaration ? ((XSElementDeclaration) owner).getConstraintType() : (owner != null && owner instanceof XSAttributeDeclaration ? ((XSAttributeDeclaration) owner).getConstraintType() : (owner != null && owner instanceof XSAttributeUse ? ((XSAttributeUse) owner).getConstraintType() : XSConstants.VC_NONE))); bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":readonly", (constraintType == XSConstants.VC_FIXED) + "()"); if (controlType instanceof XSSimpleTypeDefinition) { bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":required", (o.minimum != 0) + "()"); } else if (controlType instanceof XSComplexTypeDefinition) { // make all complex types not required since it helps with validation - otherwise // chiba seems to expect a nodevalue for the container element bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":required", "false()"); } //no more minOccurs & maxOccurs element: add a constraint if maxOccurs>1: //count(.) <= maxOccurs && count(.) >= minOccurs final String nodeset = bindElement.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset"); if (o.minimum > 1) { //if 0 or 1 -> no constraint (managed by "required") constraints.add("count(../" + nodeset + ") >= " + o.minimum); } bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":minOccurs", String.valueOf(o.minimum)); if (o.maximum > 1) { //if 1 or unbounded -> no constraint constraints.add("count(../" + nodeset + ") <= " + o.maximum); } bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":maxOccurs", o.isUnbounded() ? "unbounded" : String.valueOf(o.maximum)); if (constraints.size() != 0) { bindElement.setAttributeNS(NamespaceConstants.XFORMS_NS, NamespaceConstants.XFORMS_PREFIX + ":constraint", StringUtils.join((String[]) constraints.toArray(new String[constraints.size()]), " and ")); } return bindElement; }
From source file:org.alfresco.web.forms.xforms.Schema2XForms.java
private void createTriggersForRepeats(final Document xformsDocument, final Element rootGroup) { if (LOGGER.isDebugEnabled()) LOGGER.debug("[createTriggersForRepeats] start"); final HashMap<String, Element> bindIdToBind = new HashMap<String, Element>(); final NodeList binds = xformsDocument.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "bind"); for (int i = 0; i < binds.getLength(); i++) { final Element b = (Element) binds.item(i); bindIdToBind.put(b.getAttributeNS(null, "id"), b); }// w w w . j av a 2 s . c o m final NodeList repeats = xformsDocument.getElementsByTagNameNS(NamespaceConstants.XFORMS_NS, "repeat"); final HashMap<Element, Element> bindToRepeat = new HashMap<Element, Element>(); for (int i = 0; i < repeats.getLength(); i++) { Element r = (Element) repeats.item(i); if (LOGGER.isDebugEnabled()) LOGGER.debug("[createTriggersForRepeats] processing repeat " + r.getAttributeNS(null, "id")); Element bind = bindIdToBind.get(r.getAttributeNS(NamespaceConstants.XFORMS_NS, "bind")); bindToRepeat.put(bind, r); String xpath = ""; do { if (xpath.length() != 0) { xpath = '/' + xpath; } if (LOGGER.isDebugEnabled()) LOGGER.debug("[createTriggersForRepeats] walking bind " + bind.getAttributeNS(null, "id")); String s = bind.getAttributeNS(NamespaceConstants.XFORMS_NS, "nodeset"); s = s.replaceAll("^([^\\[]+).*$", "$1"); if (bindToRepeat.containsKey(bind) && !r.equals(bindToRepeat.get(bind))) { s += "[index(\'" + bindToRepeat.get(bind).getAttributeNS(null, "id") + "\')]"; } xpath = s + xpath; bind = ((NamespaceConstants.XFORMS_PREFIX + ":bind").equals(bind.getParentNode().getNodeName()) ? (Element) bind.getParentNode() : null); } while (bind != null); this.createTriggersForRepeat(xformsDocument, rootGroup, r.getAttributeNS(null, "id"), xpath, r.getAttributeNS(NamespaceConstants.XFORMS_NS, "bind")); } }
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.XFormsBean.java
private Node getEventLog() { final Document result = XMLUtil.newDocument(); final Element eventsElement = result.createElement("events"); result.appendChild(eventsElement);//ww w. ja va 2 s. co m for (XMLEvent xfe : this.getXformsSession().getEventLog()) { final String type = xfe.getType(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("adding event " + type + " to the event log"); } final Element target = (Element) xfe.getTarget(); final Element eventElement = result.createElement(type); eventsElement.appendChild(eventElement); eventElement.setAttribute("targetId", target.getAttributeNS(null, "id")); eventElement.setAttribute("targetName", target.getLocalName()); final Collection properties = xfe.getPropertyNames(); if (properties != null) { for (Object name : properties) { final Object value = xfe.getContextInfo((String) name); if (LOGGER.isDebugEnabled()) { LOGGER.debug("adding property {" + name + ":" + value + "} to event " + type); } final Element propertyElement = result.createElement("property"); eventElement.appendChild(propertyElement); propertyElement.setAttribute("name", name.toString()); propertyElement.setAttribute("value", value != null ? value.toString() : null); } } if (LOGGER.isDebugEnabled() && XFormsEventNames.SUBMIT_ERROR.equals(type)) { // debug for figuring out which elements aren't valid for submit LOGGER.debug("performing full revalidate"); try { final Model model = this.getXformsSession().getChibaBean().getContainer().getDefaultModel(); final Instance instance = model.getDefaultInstance(); model.getValidator().validate(instance, "/", new DefaultValidatorMode()); final Iterator<ModelItem> it = instance.iterateModelItems("/"); while (it.hasNext()) { final ModelItem modelItem = it.next(); if (!modelItem.isValid()) { LOGGER.debug("model node " + modelItem.getNode() + " is invalid"); } if (modelItem.isRequired() && modelItem.getValue().length() == 0) { LOGGER.debug("model node " + modelItem.getNode() + " is empty and required"); } } } catch (final XFormsException xfe2) { LOGGER.debug("error performing revaliation", xfe2); } } } this.xformsSession.eventLog.clear(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("generated event log:\n" + XMLUtil.toString(result)); } return result; }
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); }/* w w w . j a v 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 prefixMap//from www. j ava 2s . com */ 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.rampart.util.RampartUtil.java
public static void handleEncryptedSignedHeaders(Vector encryptedParts, Vector signedParts, Document doc) { //TODO Is there a more efficient way to do this ? better search algorithm for (int i = 0; i < signedParts.size(); i++) { WSEncryptionPart signedPart = (WSEncryptionPart) signedParts.get(i); //This signed part is not a header if (signedPart.getNamespace() == null || signedPart.getName() == null) { continue; }/* w ww .j av a2s.co m*/ for (int j = 0; j < encryptedParts.size(); j++) { WSEncryptionPart encryptedPart = (WSEncryptionPart) encryptedParts.get(j); if (encryptedPart.getNamespace() == null || encryptedPart.getName() == null) { continue; } if (signedPart.getName().equals(encryptedPart.getName()) && signedPart.getNamespace().equals(encryptedPart.getNamespace())) { String encDataID = encryptedPart.getEncId(); Element encDataElem = WSSecurityUtil.findElementById(doc.getDocumentElement(), encDataID, null); if (encDataElem != null) { Element encHeader = (Element) encDataElem.getParentNode(); String encHeaderId = encHeader.getAttributeNS(WSConstants.WSU_NS, "Id"); //For some reason the id might not be available // so the part/element with empty/null id won't be recognized afterwards. if (encHeaderId != null && !"".equals(encHeaderId.trim())) { signedParts.remove(signedPart); WSEncryptionPart encHeaderToSign = new WSEncryptionPart(encHeaderId); signedParts.add(encHeaderToSign); } } } } } }
From source file:org.apache.servicemix.jbi.runtime.impl.AbstractComponentContext.java
/** * <p>//from w ww . ja va 2s . c o m * Resolve an internal JBI EPR conforming to the format defined in the JBI specification. * </p> * * <p>The EPR would look like: * <pre> * <jbi:end-point-reference xmlns:jbi="http://java.sun.com/xml/ns/jbi/end-point-reference" * jbi:end-point-name="endpointName" * jbi:service-name="foo:serviceName" * xmlns:foo="urn:FooNamespace"/> * </pre> * </p> * * @author Maciej Szefler m s z e f l e r @ g m a i l . c o m * @param epr EPR fragment * @return internal service endpoint corresponding to the EPR, or <code>null</code> * if the EPR is not an internal EPR or if the EPR cannot be resolved */ public ServiceEndpoint resolveInternalEPR(DocumentFragment epr) { if (epr == null) { throw new NullPointerException("resolveInternalEPR(epr) called with null epr."); } NodeList nl = epr.getChildNodes(); for (int i = 0; i < nl.getLength(); ++i) { Node n = nl.item(i); if (n.getNodeType() != Node.ELEMENT_NODE) { continue; } Element el = (Element) n; // Namespace should be "http://java.sun.com/jbi/end-point-reference" if (el.getNamespaceURI() == null || !el.getNamespaceURI().equals(ServiceEndpointImpl.JBI_NAMESPACE)) { continue; } if (el.getLocalName() == null || !el.getLocalName().equals(ServiceEndpointImpl.JBI_ENDPOINT_REFERENCE)) { continue; } String serviceName = el.getAttributeNS(el.getNamespaceURI(), ServiceEndpointImpl.JBI_SERVICE_NAME); // Now the DOM pain-in-the-you-know-what: we need to come up with QName for this; // fortunately, there is only one place where the xmlns:xxx attribute could be, on // the end-point-reference element! QName serviceQName = DOMUtil.createQName(el, serviceName); String endpointName = el.getAttributeNS(el.getNamespaceURI(), ServiceEndpointImpl.JBI_ENDPOINT_NAME); return getEndpoint(serviceQName, endpointName); } return null; }
From source file:org.apache.ws.security.message.EnvelopeIdResolver.java
/** * This is the workhorse method used to resolve resources. * <p/>/*from w ww . j a v a 2 s. c o m*/ * * @param * @param BaseURI * @return TODO * @throws ResourceResolverException */ public XMLSignatureInput engineResolve(Attr uri, String BaseURI) throws ResourceResolverException { doDebug = log.isDebugEnabled(); String uriNodeValue = uri.getNodeValue(); if (doDebug) { log.debug("enter engineResolve, look for: " + uriNodeValue); } Document doc = uri.getOwnerDocument(); /* * URI="#chapter1" * Identifies a node-set containing the element with ID attribute * value 'chapter1' of the XML resource containing the signature. * XML Signature (and its applications) modify this node-set to * include the element plus all descendants including namespaces and * attributes -- but not comments. */ /* * First check to see if the element that we require is a SecurityTokenReference * that is stored in WSDocInfo. */ String id = uriNodeValue.substring(1); Element selectedElem = null; if (wsDocInfo != null) { selectedElem = wsDocInfo.getSecurityTokenReference(id); } /* * Then lookup the SOAP Body element (processed by default) and * check if it contains a matching Id */ if (selectedElem == null) { SOAPConstants sc = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement()); selectedElem = WSSecurityUtil.findBodyElement(doc, sc); if (selectedElem == null) { throw new ResourceResolverException("generic.EmptyMessage", new Object[] { "Body element not found" }, uri, BaseURI); } String cId = selectedElem.getAttributeNS(WSConstants.WSU_NS, "Id"); /* * If Body Id match fails, look for a generic Id (without a namespace) * that matches the URI. If that lookup fails, try to get a namespace * qualified Id that matches the URI. */ if (!id.equals(cId)) { cId = null; if ((selectedElem = WSSecurityUtil.getElementByWsuId(doc, uriNodeValue)) != null) { cId = selectedElem.getAttributeNS(WSConstants.WSU_NS, "Id"); } else if ((selectedElem = WSSecurityUtil.getElementByGenId(doc, uriNodeValue)) != null) { cId = selectedElem.getAttribute("Id"); } if (cId == null) { throw new ResourceResolverException("generic.EmptyMessage", new Object[] { "Id not found" }, uri, BaseURI); } } } XMLSignatureInput result = new XMLSignatureInput(selectedElem); result.setMIMEType("text/xml"); try { URI uriNew = new URI(new URI(BaseURI), uri.getNodeValue()); result.setSourceURI(uriNew.toString()); } catch (URI.MalformedURIException ex) { result.setSourceURI(BaseURI); } if (doDebug) { log.debug("exit engineResolve, result: " + result); } return result; }
From source file:org.apache.ws.security.message.TestMessageTransformer.java
public static Element duplicateEncryptedDataInWsseHeader(Element saaj, boolean moveReferenceList) { if (moveReferenceList) { moveReferenceList(saaj);/* w ww. j ava2s . c o m*/ } Element body = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"), true); Element encData = getFirstChildElement(body, new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedData"), true); Element newEncData = createNewEncryptedData(encData); Element sh = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Header"), true); Element wsseHeader = getFirstChildElement(sh, new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security"), true); Node newWsseHeader = wsseHeader.cloneNode(false); Node cur = wsseHeader.getFirstChild(); String newId = newEncData.getAttributeNS(null, "Id"); while (cur != null) { cur = copyHeadersAndUpdateRefList(cur, newWsseHeader, newId); } newWsseHeader.appendChild(newEncData); if (!moveReferenceList) { updateEncryptedKeyRefList(newWsseHeader, newId); } Node parent = wsseHeader.getParentNode(); parent.removeChild(wsseHeader); parent.appendChild(newWsseHeader); print(saaj.getOwnerDocument()); return newEncData; }