Skip to content
This repository was archived by the owner on May 26, 2020. It is now read-only.

Commit b73e4f2

Browse files
committed
Code coverage work for the transformers
git-svn-id: https://svn.apache.org/repos/asf/santuario/xml-security-java/trunk@1877660 13f79535-47bb-0310-9956-ffa450edef68
1 parent 094a1ea commit b73e4f2

8 files changed

Lines changed: 21 additions & 715 deletions

File tree

src/main/java/org/apache/xml/security/transforms/implementations/TransformC14N.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.OutputStream;
2424

2525
import org.apache.xml.security.c14n.CanonicalizationException;
26+
import org.apache.xml.security.c14n.implementations.Canonicalizer20010315;
2627
import org.apache.xml.security.c14n.implementations.Canonicalizer20010315OmitComments;
2728
import org.apache.xml.security.signature.XMLSignatureInput;
2829
import org.apache.xml.security.transforms.TransformSpi;
@@ -53,7 +54,7 @@ protected XMLSignatureInput enginePerformTransform(
5354
String baseURI, boolean secureValidation
5455
) throws CanonicalizationException {
5556

56-
Canonicalizer20010315OmitComments c14n = new Canonicalizer20010315OmitComments();
57+
Canonicalizer20010315 c14n = getCanonicalizer();
5758

5859
if (os == null) {
5960
try (ByteArrayOutputStream writer = new ByteArrayOutputStream()) {
@@ -73,4 +74,8 @@ protected XMLSignatureInput enginePerformTransform(
7374
return output;
7475
}
7576
}
77+
78+
protected Canonicalizer20010315 getCanonicalizer() {
79+
return new Canonicalizer20010315OmitComments();
80+
}
7681
}

src/main/java/org/apache/xml/security/transforms/implementations/TransformC14N11.java

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,15 @@
1818
*/
1919
package org.apache.xml.security.transforms.implementations;
2020

21-
import java.io.ByteArrayOutputStream;
22-
import java.io.IOException;
23-
import java.io.OutputStream;
24-
25-
import org.apache.xml.security.c14n.CanonicalizationException;
2621
import org.apache.xml.security.c14n.implementations.Canonicalizer11_OmitComments;
27-
import org.apache.xml.security.signature.XMLSignatureInput;
28-
import org.apache.xml.security.transforms.TransformSpi;
22+
import org.apache.xml.security.c14n.implementations.Canonicalizer20010315;
2923
import org.apache.xml.security.transforms.Transforms;
30-
import org.w3c.dom.Element;
3124

3225
/**
3326
* Implements the <CODE>http://www.w3.org/2006/12/xml-c14n11</CODE>
3427
* (C14N 1.1) transform.
35-
*
3628
*/
37-
public class TransformC14N11 extends TransformSpi {
29+
public class TransformC14N11 extends TransformC14N {
3830

3931
/**
4032
* {@inheritDoc}
@@ -48,29 +40,8 @@ protected String engineGetURI() {
4840
* {@inheritDoc}
4941
*/
5042
@Override
51-
protected XMLSignatureInput enginePerformTransform(
52-
XMLSignatureInput input, OutputStream os, Element transformElement,
53-
String baseURI, boolean secureValidation
54-
) throws CanonicalizationException {
55-
56-
Canonicalizer11_OmitComments c14n = new Canonicalizer11_OmitComments();
57-
58-
if (os == null) {
59-
try (ByteArrayOutputStream writer = new ByteArrayOutputStream()) {
60-
c14n.engineCanonicalize(input, writer, secureValidation);
61-
writer.flush();
62-
XMLSignatureInput output = new XMLSignatureInput(writer.toByteArray());
63-
output.setSecureValidation(secureValidation);
64-
return output;
65-
} catch (IOException ex) {
66-
throw new CanonicalizationException("empty", new Object[] {ex.getMessage()});
67-
}
68-
} else {
69-
c14n.engineCanonicalize(input, os, secureValidation);
70-
XMLSignatureInput output = new XMLSignatureInput((byte[])null);
71-
output.setSecureValidation(secureValidation);
72-
output.setOutputStream(os);
73-
return output;
74-
}
43+
protected Canonicalizer20010315 getCanonicalizer() {
44+
return new Canonicalizer11_OmitComments();
7545
}
46+
7647
}

src/main/java/org/apache/xml/security/transforms/implementations/TransformC14N11_WithComments.java

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,16 @@
1818
*/
1919
package org.apache.xml.security.transforms.implementations;
2020

21-
import java.io.ByteArrayOutputStream;
22-
import java.io.IOException;
23-
import java.io.OutputStream;
24-
25-
import org.apache.xml.security.c14n.CanonicalizationException;
2621
import org.apache.xml.security.c14n.implementations.Canonicalizer11_WithComments;
27-
import org.apache.xml.security.signature.XMLSignatureInput;
28-
import org.apache.xml.security.transforms.TransformSpi;
22+
import org.apache.xml.security.c14n.implementations.Canonicalizer20010315;
2923
import org.apache.xml.security.transforms.Transforms;
30-
import org.w3c.dom.Element;
3124

3225
/**
3326
* Implements the <CODE>http://www.w3.org/2006/12/xml-c14n-11#WithComments</CODE>
3427
* (C14N 1.1 With Comments) transform.
3528
*
3629
*/
37-
public class TransformC14N11_WithComments extends TransformSpi {
30+
public class TransformC14N11_WithComments extends TransformC14N {
3831

3932
/**
4033
* {@inheritDoc}
@@ -48,28 +41,7 @@ protected String engineGetURI() {
4841
* {@inheritDoc}
4942
*/
5043
@Override
51-
protected XMLSignatureInput enginePerformTransform(
52-
XMLSignatureInput input, OutputStream os, Element transformElement,
53-
String baseURI, boolean secureValidation
54-
) throws CanonicalizationException {
55-
56-
Canonicalizer11_WithComments c14n = new Canonicalizer11_WithComments();
57-
if (os == null) {
58-
try (ByteArrayOutputStream writer = new ByteArrayOutputStream()) {
59-
c14n.engineCanonicalize(input, writer, secureValidation);
60-
writer.flush();
61-
XMLSignatureInput output = new XMLSignatureInput(writer.toByteArray());
62-
output.setSecureValidation(secureValidation);
63-
return output;
64-
} catch (IOException ex) {
65-
throw new CanonicalizationException("empty", new Object[] {ex.getMessage()});
66-
}
67-
} else {
68-
c14n.engineCanonicalize(input, os, secureValidation);
69-
XMLSignatureInput output = new XMLSignatureInput((byte[])null);
70-
output.setSecureValidation(secureValidation);
71-
output.setOutputStream(os);
72-
return output;
73-
}
44+
protected Canonicalizer20010315 getCanonicalizer() {
45+
return new Canonicalizer11_WithComments();
7446
}
7547
}

src/main/java/org/apache/xml/security/transforms/implementations/TransformC14NWithComments.java

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,15 @@
1818
*/
1919
package org.apache.xml.security.transforms.implementations;
2020

21-
import java.io.ByteArrayOutputStream;
22-
import java.io.IOException;
23-
import java.io.OutputStream;
24-
25-
import org.apache.xml.security.c14n.CanonicalizationException;
21+
import org.apache.xml.security.c14n.implementations.Canonicalizer20010315;
2622
import org.apache.xml.security.c14n.implementations.Canonicalizer20010315WithComments;
27-
import org.apache.xml.security.signature.XMLSignatureInput;
28-
import org.apache.xml.security.transforms.TransformSpi;
2923
import org.apache.xml.security.transforms.Transforms;
30-
import org.w3c.dom.Element;
3124

3225
/**
3326
* Implements the <CODE>http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments</CODE>
3427
* transform.
35-
*
3628
*/
37-
public class TransformC14NWithComments extends TransformSpi {
29+
public class TransformC14NWithComments extends TransformC14N {
3830

3931
/**
4032
* {@inheritDoc}
@@ -48,29 +40,8 @@ protected String engineGetURI() {
4840
* {@inheritDoc}
4941
*/
5042
@Override
51-
protected XMLSignatureInput enginePerformTransform(
52-
XMLSignatureInput input, OutputStream os, Element transformElement,
53-
String baseURI, boolean secureValidation
54-
) throws CanonicalizationException {
55-
56-
Canonicalizer20010315WithComments c14n = new Canonicalizer20010315WithComments();
57-
58-
if (os == null) {
59-
try (ByteArrayOutputStream writer = new ByteArrayOutputStream()) {
60-
c14n.engineCanonicalize(input, writer, secureValidation);
61-
writer.flush();
62-
XMLSignatureInput output = new XMLSignatureInput(writer.toByteArray());
63-
output.setSecureValidation(secureValidation);
64-
return output;
65-
} catch (IOException ex) {
66-
throw new CanonicalizationException("empty", new Object[] {ex.getMessage()});
67-
}
68-
} else {
69-
c14n.engineCanonicalize(input, os, secureValidation);
70-
XMLSignatureInput output = new XMLSignatureInput((byte[])null);
71-
output.setSecureValidation(secureValidation);
72-
output.setOutputStream(os);
73-
return output;
74-
}
43+
protected Canonicalizer20010315 getCanonicalizer() {
44+
return new Canonicalizer20010315WithComments();
7545
}
46+
7647
}

src/main/java/org/apache/xml/security/transforms/implementations/TransformXPath2Filter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ protected XMLSignatureInput enginePerformTransform(
9090
inputDoc = XMLUtils.getOwnerDocument(input.getNodeSet());
9191
}
9292

93+
XPathFactory xpathFactory = XPathFactory.newInstance();
9394
for (int i = 0; i < xpathElements.length; i++) {
9495
Element xpathElement = xpathElements[i];
9596

@@ -99,7 +100,6 @@ protected XMLSignatureInput enginePerformTransform(
99100
String str =
100101
XMLUtils.getStrFromNode(xpathContainer.getXPathFilterTextNode());
101102

102-
XPathFactory xpathFactory = XPathFactory.newInstance();
103103
XPathAPI xpathAPIInstance = xpathFactory.newXPathAPI();
104104

105105
NodeList subtreeRoots =

src/main/java/org/apache/xml/security/transforms/implementations/TransformXPointer.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)