/** * Constructor ElementProxy * * @param doc */ public ElementProxy(Document doc) { if (doc == null) { throw new RuntimeException("Document is null"); } this.wrappedDoc = doc; this.wrappedElement = createElementForFamilyLocal(this.getBaseNamespace(), this.getBaseLocalName()); }
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; }
/** * Method guaranteeThatElementInCorrectSpace * * @throws XMLSecurityException */ void guaranteeThatElementInCorrectSpace() throws XMLSecurityException { String expectedLocalName = this.getBaseLocalName(); String expectedNamespaceUri = this.getBaseNamespace(); String actualLocalName = getElement().getLocalName(); String actualNamespaceUri = getElement().getNamespaceURI(); if(!expectedNamespaceUri.equals(actualNamespaceUri) && !expectedLocalName.equals(actualLocalName)) { Object exArgs[] = { actualNamespaceUri + ":" + actualLocalName, expectedNamespaceUri + ":" + expectedLocalName}; throw new XMLSecurityException("xml.WrongElement", exArgs); } }