/** * This method creates an Element in a given namespace with a given localname. * It uses the {@link ElementProxy#getDefaultPrefix} method to decide whether * a particular prefix is bound to that namespace. * <p></p> * This method was refactored out of the constructor. * * @param doc * @param namespace * @param localName * @return The element created. */ public static Element createElementForFamily(Document doc, String namespace, String localName) { Element result = null; String prefix = ElementProxy.getDefaultPrefix(namespace); if (namespace == null) { result = doc.createElementNS(null, localName); } else { if (prefix == null || prefix.length() == 0) { result = doc.createElementNS(namespace, localName); result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace); } else { result = doc.createElementNS(namespace, prefix + ":" + localName); result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace); } } return result; }
protected Element createElementForFamilyLocal( String namespace, String localName ) { Document doc = getDocument(); Element result = null; if (namespace == null) { result = doc.createElementNS(null, localName); } else { String baseName = this.getBaseNamespace(); String prefix = ElementProxy.getDefaultPrefix(baseName); if (prefix == null || prefix.length() == 0) { result = doc.createElementNS(namespace, localName); result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns", namespace); } else { result = doc.createElementNS(namespace, prefix + ":" + localName); result.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, namespace); } } return result; }
/** * Constructor KeyInfo * @param doc */ public KeyInfo(Document doc) { super(doc); addReturnToSelf(); String prefix = ElementProxy.getDefaultPrefix(this.getBaseNamespace()); if (prefix != null && prefix.length() > 0) { getElement().setAttributeNS(Constants.NamespaceSpecNS, "xmlns:" + prefix, this.getBaseNamespace()); } }
digestElement.setAttributeNS( Constants.NamespaceSpecNS, "xmlns:" + ElementProxy.getDefaultPrefix(Constants.SignatureSpecNS), Constants.SignatureSpecNS ); mgfElement.setAttributeNS( Constants.NamespaceSpecNS, "xmlns:" + ElementProxy.getDefaultPrefix(EncryptionConstants.EncryptionSpec11NS), EncryptionConstants.EncryptionSpec11NS );