elementproxy.java
来自「JAVA 所有包」· Java 代码 · 共 544 行 · 第 1/2 页
JAVA
544 行
} } /** * Method setVal * * @param bi * @param localname */ public void addBigIntegerElement(BigInteger bi, String localname) { if (bi != null) { Element e = XMLUtils.createElementInSignatureSpace(this._doc, localname); Base64.fillElementWithBigInteger(e, bi); this._constructionElement.appendChild(e); XMLUtils.addReturnToElement(this._constructionElement); } } /** * Method addBase64Element * * @param bytes * @param localname */ public void addBase64Element(byte[] bytes, String localname) { if (bytes != null) { Element e = Base64.encodeToElement(this._doc, localname, bytes); this._constructionElement.appendChild(e); this._constructionElement.appendChild(this._doc.createTextNode("\n")); } } /** * Method addTextElement * * @param text * @param localname */ public void addTextElement(String text, String localname) { Element e = XMLUtils.createElementInSignatureSpace(this._doc, localname); Text t = this._doc.createTextNode(text); e.appendChild(t); this._constructionElement.appendChild(e); XMLUtils.addReturnToElement(this._constructionElement); } /** * Method addBase64Text * * @param bytes */ public void addBase64Text(byte[] bytes) { if (bytes != null) { Text t = this._doc.createTextNode("\n" + Base64.encode(bytes) + "\n"); this._constructionElement.appendChild(t); } } /** * Method addText * * @param text */ public void addText(String text) { if (text != null) { Text t = this._doc.createTextNode(text); this._constructionElement.appendChild(t); } } /** * Method getVal * * @param localname * @param namespace * @return The biginter contained in the given element * @throws Base64DecodingException */ public BigInteger getBigIntegerFromChildElement( String localname, String namespace) throws Base64DecodingException { return Base64.decodeBigIntegerFromText( XMLUtils.selectNodeText(this._constructionElement.getFirstChild(), namespace,localname,0)); } /** * Method getBytesFromChildElement * * @param localname * @param namespace * @return the bytes * @throws XMLSecurityException */ public byte[] getBytesFromChildElement(String localname, String namespace) throws XMLSecurityException { Element e = XMLUtils.selectNode( this._constructionElement.getFirstChild(), namespace, localname, 0); return Base64.decode(e); } /** * Method getTextFromChildElement * * @param localname * @param namespace * @return the Text of the textNode */ public String getTextFromChildElement(String localname, String namespace) { Text t = (Text) XMLUtils.selectNode( this._constructionElement.getFirstChild(), namespace, localname, 0).getFirstChild(); return t.getData(); } /** * Method getBytesFromTextChild * * @return The base64 bytes from the first text child of this element * @throws XMLSecurityException */ public byte[] getBytesFromTextChild() throws XMLSecurityException { Text t = (Text)this._constructionElement.getFirstChild(); return Base64.decode(t.getData()); } /** * Method getTextFromTextChild * * @return the Text obtained concatening all the the text nodes of this element */ public String getTextFromTextChild() { return XMLUtils.getFullTextChildrenFromElement(this._constructionElement); } /** * Method length * * @param namespace * @param localname * @return the number of elements {namespace}:localname under this element */ public int length(String namespace, String localname) { int number=0; Node sibling=this._constructionElement.getFirstChild(); while (sibling!=null) { if (localname.equals(sibling.getLocalName()) && namespace.equals(sibling.getNamespaceURI())) { number++; } sibling=sibling.getNextSibling(); } return number; } /** * Adds an xmlns: definition to the Element. This can be called as follows: * * <PRE> * // set namespace with ds prefix * xpathContainer.setXPathNamespaceContext("ds", "http://www.w3.org/2000/09/xmldsig#"); * xpathContainer.setXPathNamespaceContext("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#"); * </PRE> * * @param prefix * @param uri * @throws XMLSecurityException */ public void setXPathNamespaceContext(String prefix, String uri) throws XMLSecurityException { String ns; if ((prefix == null) || (prefix.length() == 0)) { throw new XMLSecurityException("defaultNamespaceCannotBeSetHere"); } else if (prefix.equals("xmlns")) { throw new XMLSecurityException("defaultNamespaceCannotBeSetHere"); } else if (prefix.startsWith("xmlns:")) { ns = prefix;//"xmlns:" + prefix.substring("xmlns:".length()); } else { ns = "xmlns:" + prefix; } Attr a = this._constructionElement.getAttributeNodeNS(Constants.NamespaceSpecNS, ns); if (a != null) { if (!a.getNodeValue().equals(uri)) { Object exArgs[] = { ns, this._constructionElement.getAttributeNS(null, ns) }; throw new XMLSecurityException("namespacePrefixAlreadyUsedByOtherURI", exArgs); } return; } this._constructionElement.setAttributeNS(Constants.NamespaceSpecNS, ns, uri); } /** Field _prefixMappings */ static HashMap _prefixMappings = new HashMap(); /** * Method setDefaultPrefix * * @param namespace * @param prefix * @throws XMLSecurityException */ public static void setDefaultPrefix(String namespace, String prefix) throws XMLSecurityException { if (ElementProxy._prefixMappings.containsValue(prefix)) { Object storedNamespace=ElementProxy._prefixMappings.get(namespace); if (!storedNamespace.equals(prefix)) { Object exArgs[] = { prefix, namespace, storedNamespace }; throw new XMLSecurityException("prefix.AlreadyAssigned", exArgs); } } ElementProxy._prefixMappings.put(namespace, prefix); } /** * Method getDefaultPrefix * * @param namespace * @return the default prefix bind to this element. */ public static String getDefaultPrefix(String namespace) { String prefix = (String) ElementProxy._prefixMappings.get(namespace); return prefix; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?