You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2011/01/24 12:31:02 UTC
svn commit: r1062736 [2/2] - in
/santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples:
keys/ transforms/
Modified: santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/transforms/SampleTransformXPathHereFunc.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/transforms/SampleTransformXPathHereFunc.java?rev=1062736&r1=1062735&r2=1062736&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/transforms/SampleTransformXPathHereFunc.java (original)
+++ santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/transforms/SampleTransformXPathHereFunc.java Mon Jan 24 11:31:01 2011
@@ -17,8 +17,6 @@
*/
package org.apache.xml.security.samples.transforms;
-
-
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.samples.SampleUtils;
import org.apache.xml.security.transforms.Transforms;
@@ -28,7 +26,6 @@ import org.apache.xpath.XPathAPI;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
-
/**
* This class demonstrates the use of a Transform for XSLT. The
* <CODE>xsl:stylesheet</CODE> is directly embedded in the <CODE>ds:Transform</CODE>,
@@ -39,58 +36,57 @@ import org.w3c.dom.Node;
*/
public class SampleTransformXPathHereFunc {
- /**
- * Method main
- *
- * @param args
- * @throws Exception
- */
- public static void main(String args[]) throws Exception {
- //J-
- String inputStr =
- "<?xml version=\"1.0\"?>" + "\n"
- + "<Document>" + "\n"
- + " <Data attr='attrValue'>text in Data</Data>" + "\n"
- + "<Signature xmlns='http://www.w3.org/2000/09/xmldsig#'>" + "\n"
- + " <SignedInfo>" + "\n"
- + " <Reference>" + "\n"
- + " <Transforms>" + "\n"
- + " <Transform xmlns:ds='http://www.w3.org/2000/09/xmldsig#' Algorithm='http://www.w3.org/TR/1999/REC-xpath-19991116'>" + "\n"
- + " <XPath>count(ancestor-or-self::ds:Signature | here()/ancestor::ds:Signature[1]) > count(ancestor-or-self::ds:Signature)</XPath>" + "\n"
- + " </Transform>" + "\n"
- + " <Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' />" + "\n"
- + " <Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' />" + "\n"
- + " <Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' />" + "\n"
- + " <Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' />" + "\n"
- + " <Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' />" + "\n"
- + " </Transforms>" + "\n"
- + " </Reference>" + "\n"
- + " </SignedInfo>" + "\n"
- + " </Signature>"
- + "</Document>"
- ;
- //J+
- javax.xml.parsers.DocumentBuilderFactory dbf =
- javax.xml.parsers.DocumentBuilderFactory.newInstance();
-
- dbf.setNamespaceAware(true);
-
- javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
- org.w3c.dom.Document doc =
- db.parse(new java.io.ByteArrayInputStream(inputStr.getBytes()));
- Element nscontext = SampleUtils.createDSctx(doc, "ds", Constants.SignatureSpecNS);
-
- Element transformsElem = (Element) XPathAPI.selectSingleNode(
- doc,
- "/Document/ds:Signature[1]/ds:SignedInfo/ds:Reference[1]/ds:Transforms",
- nscontext);
- Transforms transforms = new Transforms(transformsElem, "memory://");
- XMLSignatureInput input = new XMLSignatureInput((Node) doc);
-
- // input.setCanonicalizerURI(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
-
- XMLSignatureInput result = transforms.performTransforms(input);
-
- System.out.println(new String(result.getBytes()));
- }
+ /**
+ * Method main
+ *
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String args[]) throws Exception {
+ String inputStr =
+ "<?xml version=\"1.0\"?>" + "\n"
+ + "<Document>" + "\n"
+ + " <Data attr='attrValue'>text in Data</Data>" + "\n"
+ + "<Signature xmlns='http://www.w3.org/2000/09/xmldsig#'>" + "\n"
+ + " <SignedInfo>" + "\n"
+ + " <Reference>" + "\n"
+ + " <Transforms>" + "\n"
+ + " <Transform xmlns:ds='http://www.w3.org/2000/09/xmldsig#' Algorithm='http://www.w3.org/TR/1999/REC-xpath-19991116'>" + "\n"
+ + " <XPath>count(ancestor-or-self::ds:Signature | here()/ancestor::ds:Signature[1]) > count(ancestor-or-self::ds:Signature)</XPath>" + "\n"
+ + " </Transform>" + "\n"
+ + " <Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' />" + "\n"
+ + " <Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' />" + "\n"
+ + " <Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' />" + "\n"
+ + " <Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' />" + "\n"
+ + " <Transform Algorithm='http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments' />" + "\n"
+ + " </Transforms>" + "\n"
+ + " </Reference>" + "\n"
+ + " </SignedInfo>" + "\n"
+ + " </Signature>"
+ + "</Document>"
+ ;
+ javax.xml.parsers.DocumentBuilderFactory dbf =
+ javax.xml.parsers.DocumentBuilderFactory.newInstance();
+
+ dbf.setNamespaceAware(true);
+
+ javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
+ org.w3c.dom.Document doc =
+ db.parse(new java.io.ByteArrayInputStream(inputStr.getBytes()));
+ Element nscontext = SampleUtils.createDSctx(doc, "ds", Constants.SignatureSpecNS);
+
+ Element transformsElem =
+ (Element) XPathAPI.selectSingleNode(
+ doc, "/Document/ds:Signature[1]/ds:SignedInfo/ds:Reference[1]/ds:Transforms", nscontext
+ );
+ Transforms transforms = new Transforms(transformsElem, "memory://");
+ XMLSignatureInput input = new XMLSignatureInput((Node) doc);
+
+ // input.setCanonicalizerURI(Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS);
+
+ XMLSignatureInput result = transforms.performTransforms(input);
+
+ System.out.println(new String(result.getBytes()));
+ }
+
}
Modified: santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/transforms/SampleTransformXSLT.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/transforms/SampleTransformXSLT.java?rev=1062736&r1=1062735&r2=1062736&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/transforms/SampleTransformXSLT.java (original)
+++ santuario/xml-security-java/trunk/samples/org/apache/xml/security/samples/transforms/SampleTransformXSLT.java Mon Jan 24 11:31:01 2011
@@ -18,11 +18,9 @@
package org.apache.xml.security.samples.transforms;
-
import org.apache.xml.security.signature.XMLSignatureInput;
import org.apache.xml.security.transforms.Transforms;
-
/**
* This class demonstrates the use of a Transform for XSLT. The
* <CODE>xsl:stylesheet</CODE> is directly embedded in the <CODE>ds:Transform</CODE>,
@@ -33,111 +31,110 @@ import org.apache.xml.security.transform
*/
public class SampleTransformXSLT {
- /**
- * Method main
- *
- * @param args
- * @throws Exception
- */
- public static void main(String args[]) throws Exception {
- org.apache.xml.security.Init.init();
-
- //J-
- String transformStr =
- "<?xml version=\"1.0\"?>\n"
- + "<ds:Transforms xmlns:ds='http://www.w3.org/2000/09/xmldsig#'>\n"
- + "<ds:Transform Algorithm='http://www.w3.org/TR/1999/REC-xslt-19991116'>\n"
- + "<xsl:stylesheet version=\"1.0\"\n"
- + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n"
- + "<xsl:output method=\"xml\" indent=\"yes\"/>\n"
-
- + "<xsl:template match=\"Class\">\n"
- + "<BirdInfo>\n"
- + " <xsl:apply-templates select=\"Order\"/>\n"
- + "</BirdInfo>\n"
- + "</xsl:template>\n"
-
- + "<xsl:template match=\"Order\">\n"
- + "Order is: <xsl:value-of select=\"@Name\"/>\n"
- + " <xsl:apply-templates select=\"Family\"/><xsl:text>\n"
- + "</xsl:text>\n"
- + "</xsl:template>\n"
-
- + "<xsl:template match=\"Family\">\n"
- + " Family is: <xsl:value-of select=\"@Name\"/>\n"
- + " <xsl:apply-templates select=\"Species | SubFamily | text()\"/>\n"
- + "</xsl:template>\n"
- + "<xsl:template match=\"SubFamily\">\n"
- + " SubFamily is <xsl:value-of select=\"@Name\"/>\n"
- + " <xsl:apply-templates select=\"Species | text()\"/>\n"
- + "</xsl:template>\n"
-
- + "<xsl:template match=\"Species\">\n"
- + " <xsl:choose>\n"
- + " <xsl:when test=\"name(..)='SubFamily'\">\n"
- + " <xsl:text> </xsl:text><xsl:value-of select=\".\"/><xsl:text> </xsl:text><xsl:value-of select=\"@Scientific_Name\"/>\n"
- + " </xsl:when>\n"
- + " <xsl:otherwise>\n"
- + " <xsl:value-of select=\".\"/><xsl:text> </xsl:text><xsl:value-of select=\"@Scientific_Name\"/>\n"
- + " </xsl:otherwise>\n"
- + " </xsl:choose>\n"
- + "</xsl:template>\n"
-
- + "</xsl:stylesheet>\n"
- + "</ds:Transform>\n"
- + "</ds:Transforms>\n"
- ;
-
- String inputStr =
- "<?xml version=\"1.0\"?>\n"
- + "<Class>\n"
- + "<Order Name=\"TINAMIFORMES\">\n"
- + " <Family Name=\"TINAMIDAE\">\n"
- + " <Species Scientific_Name=\"Tinamus major\"> Great Tinamou.</Species>\n"
- + " <Species Scientific_Name=\"Nothocercus\">Highland Tinamou.</Species>\n"
- + " <Species Scientific_Name=\"Crypturellus soui\">Little Tinamou.</Species>\n"
- + " <Species Scientific_Name=\"Crypturellus cinnamomeus\">Thicket Tinamou.</Species>\n"
- + " <Species Scientific_Name=\"Crypturellus boucardi\">Slaty-breasted Tinamou.</Species>\n"
- + " <Species Scientific_Name=\"Crypturellus kerriae\">Choco Tinamou.</Species>\n"
- + " </Family>\n"
- + " </Order>\n"
- + " <Order Name=\"GAVIIFORMES\">\n"
- + " <Family Name=\"GAVIIDAE\">\n"
- + " <Species Scientific_Name=\"Gavia stellata\">Red-throated Loon.</Species>\n"
- + " <Species Scientific_Name=\"Gavia arctica\">Arctic Loon.</Species>\n"
- + " <Species Scientific_Name=\"Gavia pacifica\">Pacific Loon.</Species>\n"
- + " <Species Scientific_Name=\"Gavia immer\">Common Loon.</Species>\n"
- + " <Species Scientific_Name=\"Gavia adamsii\">Yellow-billed Loon.</Species>\n"
- + " </Family>\n"
- + " </Order>\n"
- + " <Order Name=\"PODICIPEDIFORMES\">\n"
- + " <Family Name=\"PODICIPEDIDAE\">\n"
- + " <Species Scientific_Name=\"Tachybaptus dominicus\">Least Grebe.</Species>\n"
- + " <Species Scientific_Name=\"Podilymbus podiceps\">Pied-billed Grebe.</Species>\n"
- + " <Species Scientific_Name=\"\">Atitlan Grebe.</Species>\n"
- + " <Species Scientific_Name=\"\">Horned Grebe.</Species>\n"
- + " <Species Scientific_Name=\"\">Red-necked Grebe.</Species>\n"
- + " <Species Scientific_Name=\"\">Eared Grebe.</Species>\n"
- + " <Species Scientific_Name=\"\">Western Grebe.</Species>\n"
- + " <Species Scientific_Name=\"\">Clark's Grebe.</Species>\n"
- + " </Family>\n"
- + " </Order>\n"
- + "</Class>\n"
- ;
- //J+
- javax.xml.parsers.DocumentBuilderFactory dbf =
- javax.xml.parsers.DocumentBuilderFactory.newInstance();
-
- dbf.setNamespaceAware(true);
-
- javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
- org.w3c.dom.Document doc =
- db.parse(new java.io.ByteArrayInputStream(transformStr.getBytes()));
-
- Transforms t = new Transforms(doc.getDocumentElement(), "memory://");
- XMLSignatureInput result =
- t.performTransforms(new XMLSignatureInput(inputStr.getBytes()));
-
- System.out.println(new String(result.getBytes()));
- }
+ /**
+ * Method main
+ *
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String args[]) throws Exception {
+ org.apache.xml.security.Init.init();
+
+ String transformStr =
+ "<?xml version=\"1.0\"?>\n"
+ + "<ds:Transforms xmlns:ds='http://www.w3.org/2000/09/xmldsig#'>\n"
+ + "<ds:Transform Algorithm='http://www.w3.org/TR/1999/REC-xslt-19991116'>\n"
+ + "<xsl:stylesheet version=\"1.0\"\n"
+ + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n"
+ + "<xsl:output method=\"xml\" indent=\"yes\"/>\n"
+
+ + "<xsl:template match=\"Class\">\n"
+ + "<BirdInfo>\n"
+ + " <xsl:apply-templates select=\"Order\"/>\n"
+ + "</BirdInfo>\n"
+ + "</xsl:template>\n"
+
+ + "<xsl:template match=\"Order\">\n"
+ + "Order is: <xsl:value-of select=\"@Name\"/>\n"
+ + " <xsl:apply-templates select=\"Family\"/><xsl:text>\n"
+ + "</xsl:text>\n"
+ + "</xsl:template>\n"
+
+ + "<xsl:template match=\"Family\">\n"
+ + " Family is: <xsl:value-of select=\"@Name\"/>\n"
+ + " <xsl:apply-templates select=\"Species | SubFamily | text()\"/>\n"
+ + "</xsl:template>\n"
+ + "<xsl:template match=\"SubFamily\">\n"
+ + " SubFamily is <xsl:value-of select=\"@Name\"/>\n"
+ + " <xsl:apply-templates select=\"Species | text()\"/>\n"
+ + "</xsl:template>\n"
+
+ + "<xsl:template match=\"Species\">\n"
+ + " <xsl:choose>\n"
+ + " <xsl:when test=\"name(..)='SubFamily'\">\n"
+ + " <xsl:text> </xsl:text><xsl:value-of select=\".\"/><xsl:text> </xsl:text><xsl:value-of select=\"@Scientific_Name\"/>\n"
+ + " </xsl:when>\n"
+ + " <xsl:otherwise>\n"
+ + " <xsl:value-of select=\".\"/><xsl:text> </xsl:text><xsl:value-of select=\"@Scientific_Name\"/>\n"
+ + " </xsl:otherwise>\n"
+ + " </xsl:choose>\n"
+ + "</xsl:template>\n"
+
+ + "</xsl:stylesheet>\n"
+ + "</ds:Transform>\n"
+ + "</ds:Transforms>\n"
+ ;
+
+ String inputStr =
+ "<?xml version=\"1.0\"?>\n"
+ + "<Class>\n"
+ + "<Order Name=\"TINAMIFORMES\">\n"
+ + " <Family Name=\"TINAMIDAE\">\n"
+ + " <Species Scientific_Name=\"Tinamus major\"> Great Tinamou.</Species>\n"
+ + " <Species Scientific_Name=\"Nothocercus\">Highland Tinamou.</Species>\n"
+ + " <Species Scientific_Name=\"Crypturellus soui\">Little Tinamou.</Species>\n"
+ + " <Species Scientific_Name=\"Crypturellus cinnamomeus\">Thicket Tinamou.</Species>\n"
+ + " <Species Scientific_Name=\"Crypturellus boucardi\">Slaty-breasted Tinamou.</Species>\n"
+ + " <Species Scientific_Name=\"Crypturellus kerriae\">Choco Tinamou.</Species>\n"
+ + " </Family>\n"
+ + " </Order>\n"
+ + " <Order Name=\"GAVIIFORMES\">\n"
+ + " <Family Name=\"GAVIIDAE\">\n"
+ + " <Species Scientific_Name=\"Gavia stellata\">Red-throated Loon.</Species>\n"
+ + " <Species Scientific_Name=\"Gavia arctica\">Arctic Loon.</Species>\n"
+ + " <Species Scientific_Name=\"Gavia pacifica\">Pacific Loon.</Species>\n"
+ + " <Species Scientific_Name=\"Gavia immer\">Common Loon.</Species>\n"
+ + " <Species Scientific_Name=\"Gavia adamsii\">Yellow-billed Loon.</Species>\n"
+ + " </Family>\n"
+ + " </Order>\n"
+ + " <Order Name=\"PODICIPEDIFORMES\">\n"
+ + " <Family Name=\"PODICIPEDIDAE\">\n"
+ + " <Species Scientific_Name=\"Tachybaptus dominicus\">Least Grebe.</Species>\n"
+ + " <Species Scientific_Name=\"Podilymbus podiceps\">Pied-billed Grebe.</Species>\n"
+ + " <Species Scientific_Name=\"\">Atitlan Grebe.</Species>\n"
+ + " <Species Scientific_Name=\"\">Horned Grebe.</Species>\n"
+ + " <Species Scientific_Name=\"\">Red-necked Grebe.</Species>\n"
+ + " <Species Scientific_Name=\"\">Eared Grebe.</Species>\n"
+ + " <Species Scientific_Name=\"\">Western Grebe.</Species>\n"
+ + " <Species Scientific_Name=\"\">Clark's Grebe.</Species>\n"
+ + " </Family>\n"
+ + " </Order>\n"
+ + "</Class>\n"
+ ;
+ javax.xml.parsers.DocumentBuilderFactory dbf =
+ javax.xml.parsers.DocumentBuilderFactory.newInstance();
+
+ dbf.setNamespaceAware(true);
+
+ javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
+ org.w3c.dom.Document doc =
+ db.parse(new java.io.ByteArrayInputStream(transformStr.getBytes()));
+
+ Transforms t = new Transforms(doc.getDocumentElement(), "memory://");
+ XMLSignatureInput result =
+ t.performTransforms(new XMLSignatureInput(inputStr.getBytes()));
+
+ System.out.println(new String(result.getBytes()));
+ }
+
}