|
From: Pelle B. <pe...@us...> - 2004-04-17 19:21:50
|
Update of /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29052/src/java/org/neuclear/xml/xmlsec Modified Files: HTMLSignature.java SignedElement.java Log Message: HTMLSignature can now process an Dom4j document as well. SignedElement is now ensured that it has a Document SignedElement also now automatically uses HTMLSignature if it senses the document is html. Index: HTMLSignature.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec/HTMLSignature.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** HTMLSignature.java 17 Apr 2004 17:26:14 -0000 1.2 --- HTMLSignature.java 17 Apr 2004 19:21:27 -0000 1.3 *************** *** 54,58 **** */ public HTMLSignature(String name, Signer signer, InputStream is) throws XMLSecurityException, UserCancellationException, NonExistingSignerException { ! super(name, signer); Tidy tidy = new Tidy(); tidy.setXmlOut(true); --- 54,61 ---- */ public HTMLSignature(String name, Signer signer, InputStream is) throws XMLSecurityException, UserCancellationException, NonExistingSignerException { ! this(name, signer, parseHTML(is)); ! } ! ! private static Document parseHTML(InputStream is) { Tidy tidy = new Tidy(); tidy.setXmlOut(true); *************** *** 60,63 **** --- 63,71 ---- DOMReader reader = new DOMReader(); Document doc = reader.read(dom); + return doc; + } + + public HTMLSignature(String name, Signer signer, Document doc) throws XMLSecurityException, UserCancellationException, NonExistingSignerException { + super(name, signer); Element html = doc.getRootElement(); createHTMLBadge(html); *************** *** 96,108 **** */ public HTMLSignature(BrowsableSigner signer, InputStream is) throws XMLSecurityException, UserCancellationException { super(new SignedInfo(SignedInfo.SIG_ALG_RSA, 1)); - Tidy tidy = new Tidy(); - tidy.setXmlOut(true); - org.w3c.dom.Document dom = tidy.parseDOM(is, null); - DOMReader reader = new DOMReader(); - Document doc = reader.read(dom); Element html = doc.getRootElement(); createHTMLBadge(html); - // si.getElement().addAttribute("id", "dsdigestvalue"); si.getElement().addAttribute("style", DIGESTSTYLE); si.setEnvelopedReference(html); --- 104,114 ---- */ public HTMLSignature(BrowsableSigner signer, InputStream is) throws XMLSecurityException, UserCancellationException { + this(signer, parseHTML(is)); + } + + public HTMLSignature(BrowsableSigner signer, Document doc) throws XMLSecurityException, UserCancellationException { super(new SignedInfo(SignedInfo.SIG_ALG_RSA, 1)); Element html = doc.getRootElement(); createHTMLBadge(html); si.getElement().addAttribute("style", DIGESTSTYLE); si.setEnvelopedReference(html); *************** *** 121,125 **** * Uses the provided KeyPair to sign it. * ! * @param kp * @param elem * @throws XMLSecurityException --- 127,131 ---- * Uses the provided KeyPair to sign it. * ! * @param kp * @param elem * @throws XMLSecurityException Index: SignedElement.java =================================================================== RCS file: /cvsroot/neuclear/neuclear-xmlsig/src/java/org/neuclear/xml/xmlsec/SignedElement.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** SignedElement.java 12 Apr 2004 15:00:42 -0000 1.13 --- SignedElement.java 17 Apr 2004 19:21:27 -0000 1.14 *************** *** 1,4 **** --- 1,9 ---- /* $Id$ * $Log$ + * Revision 1.14 2004/04/17 19:21:27 pelle + * HTMLSignature can now process an Dom4j document as well. + * SignedElement is now ensured that it has a Document + * SignedElement also now automatically uses HTMLSignature if it senses the document is html. + * * Revision 1.13 2004/04/12 15:00:42 pelle * Now have a slightly better way of handling the waiting for input using the WaitForInput class. *************** *** 157,160 **** --- 162,166 ---- */ + import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.Namespace; *************** *** 169,180 **** public abstract class SignedElement extends AbstractElementProxy { ! private EnvelopedSignature sig; public SignedElement(final QName qname) { super(qname); } public SignedElement(final Element elem) throws XMLSecurityException { super(elem); final Element sigElement = getElement().element(XMLSecTools.createQName("Signature")); if (sigElement != null) --- 175,196 ---- public abstract class SignedElement extends AbstractElementProxy { ! private XMLSignature sig; public SignedElement(final QName qname) { super(qname); + if (getElement().getDocument() == null) + DocumentHelper.createDocument(getElement()); + } + + protected SignedElement(final String name) { + super(name); + if (getElement().getDocument() == null) + DocumentHelper.createDocument(getElement()); } public SignedElement(final Element elem) throws XMLSecurityException { super(elem); + if (getElement().getDocument() == null) + DocumentHelper.createDocument(getElement()); final Element sigElement = getElement().element(XMLSecTools.createQName("Signature")); if (sigElement != null) *************** *** 191,198 **** --- 207,218 ---- public SignedElement(final String name, final Namespace ns) { super(name, ns); + if (getElement().getDocument() == null) + DocumentHelper.createDocument(getElement()); } public SignedElement(final String name, final String prefix, final String nsURI) { super(name, prefix, nsURI); + if (getElement().getDocument() == null) + DocumentHelper.createDocument(getElement()); } *************** *** 246,250 **** public final void sign(final String name, final Signer signer) throws XMLSecurityException, UserCancellationException, NonExistingSignerException { preSign(); ! sig = new EnvelopedSignature(name, signer, getElement()); postSign(); } --- 266,273 ---- public final void sign(final String name, final Signer signer) throws XMLSecurityException, UserCancellationException, NonExistingSignerException { preSign(); ! if (getElement().getName().equals("html")) { ! sig = new HTMLSignature(name, signer, getElement().getDocument()); ! } else ! sig = new EnvelopedSignature(name, signer, getElement()); postSign(); } *************** *** 252,256 **** public final void sign(final BrowsableSigner signer) throws XMLSecurityException, UserCancellationException { preSign(); ! sig = new EnvelopedSignature(signer, getElement()); postSign(); } --- 275,282 ---- public final void sign(final BrowsableSigner signer) throws XMLSecurityException, UserCancellationException { preSign(); ! if (getElement().getName().equals("html")) ! sig = new HTMLSignature(signer, getElement().getDocument()); ! else ! sig = new EnvelopedSignature(signer, getElement()); postSign(); } |