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

Commit f1a6c5e

Browse files
committed
SANTUARIO-522 - Remove unused methods from Serializer
git-svn-id: https://svn.apache.org/repos/asf/santuario/xml-security-java/trunk@1873204 13f79535-47bb-0310-9956-ffa450edef68
1 parent d1ddf18 commit f1a6c5e

2 files changed

Lines changed: 3 additions & 116 deletions

File tree

src/main/java/org/apache/xml/security/encryption/AbstractSerializer.java

Lines changed: 2 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,6 @@ public void setCanonicalizer(Canonicalizer canon) {
4545
this.canon = canon;
4646
}
4747

48-
/**
49-
* Returns a <code>String</code> representation of the specified
50-
* <code>Element</code>.
51-
* <p></p>
52-
* Refer also to comments about setup of format.
53-
*
54-
* @param element the <code>Element</code> to serialize.
55-
* @return the <code>String</code> representation of the serilaized
56-
* <code>Element</code>.
57-
* @throws Exception
58-
*/
59-
public String serialize(Element element) throws Exception {
60-
return canonSerialize(element);
61-
}
62-
6348
/**
6449
* Returns a <code>byte[]</code> representation of the specified
6550
* <code>Element</code>.
@@ -70,39 +55,9 @@ public String serialize(Element element) throws Exception {
7055
* @throws Exception
7156
*/
7257
public byte[] serializeToByteArray(Element element) throws Exception {
73-
return canonSerializeToByteArray(element);
74-
}
75-
76-
/**
77-
* Returns a <code>String</code> representation of the specified
78-
* <code>NodeList</code>.
79-
* <p></p>
80-
* This is a special case because the NodeList may represent a
81-
* <code>DocumentFragment</code>. A document fragment may be a
82-
* non-valid XML document (refer to appropriate description of
83-
* W3C) because it my start with a non-element node, e.g. a text
84-
* node.
85-
* <p></p>
86-
* The methods first converts the node list into a document fragment.
87-
* Special care is taken to not destroy the current document, thus
88-
* the method clones the nodes (deep cloning) before it appends
89-
* them to the document fragment.
90-
* <p></p>
91-
* Refer also to comments about setup of format.
92-
*
93-
* @param content the <code>NodeList</code> to serialize.
94-
* @return the <code>String</code> representation of the serialized
95-
* <code>NodeList</code>.
96-
* @throws Exception
97-
*/
98-
public String serialize(NodeList content) throws Exception {
9958
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
100-
for (int i = 0; i < content.getLength(); i++) {
101-
canon.canonicalizeSubtree(content.item(i), baos);
102-
}
103-
String ret = baos.toString(StandardCharsets.UTF_8.name());
104-
baos.reset();
105-
return ret;
59+
canon.canonicalizeSubtree(element, baos);
60+
return baos.toByteArray();
10661
}
10762
}
10863

@@ -124,34 +79,6 @@ public byte[] serializeToByteArray(NodeList content) throws Exception {
12479
}
12580
}
12681

127-
/**
128-
* Use the Canonicalizer to serialize the node
129-
* @param node
130-
* @return the canonicalization of the node
131-
* @throws Exception
132-
*/
133-
public String canonSerialize(Node node) throws Exception {
134-
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
135-
canon.canonicalizeSubtree(node, baos);
136-
String ret = baos.toString(StandardCharsets.UTF_8.name());
137-
baos.reset();
138-
return ret;
139-
}
140-
}
141-
142-
/**
143-
* Use the Canonicalizer to serialize the node
144-
* @param node
145-
* @return the (byte[]) canonicalization of the node
146-
* @throws Exception
147-
*/
148-
public byte[] canonSerializeToByteArray(Node node) throws Exception {
149-
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
150-
canon.canonicalizeSubtree(node, baos);
151-
return baos.toByteArray();
152-
}
153-
}
154-
15582
protected static byte[] createContext(byte[] source, Node ctx) throws XMLEncryptionException {
15683
// Create the context to parse the document against
15784
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
@@ -195,36 +122,4 @@ protected static byte[] createContext(byte[] source, Node ctx) throws XMLEncrypt
195122
}
196123
}
197124

198-
protected static String createContext(String source, Node ctx) {
199-
// Create the context to parse the document against
200-
StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?><dummy");
201-
202-
// Run through each node up to the document node and find any xmlns: nodes
203-
Map<String, String> storedNamespaces = new HashMap<>();
204-
Node wk = ctx;
205-
while (wk != null) {
206-
NamedNodeMap atts = wk.getAttributes();
207-
if (atts != null) {
208-
for (int i = 0; i < atts.getLength(); ++i) {
209-
Node att = atts.item(i);
210-
String nodeName = att.getNodeName();
211-
if (("xmlns".equals(nodeName) || nodeName.startsWith("xmlns:"))
212-
&& !storedNamespaces.containsKey(att.getNodeName())) {
213-
sb.append(' ');
214-
sb.append(nodeName);
215-
sb.append("=\"");
216-
sb.append(att.getNodeValue());
217-
sb.append('\"');
218-
storedNamespaces.put(nodeName, att.getNodeValue());
219-
}
220-
}
221-
}
222-
wk = wk.getParentNode();
223-
}
224-
sb.append('>');
225-
sb.append(source);
226-
sb.append("</dummy>");
227-
return sb.toString();
228-
}
229-
230125
}

src/main/java/org/apache/xml/security/encryption/Serializer.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public interface Serializer {
4040
* <code>Element</code>.
4141
*
4242
* @param element the <code>Element</code> to serialize.
43-
* @return the <code>byte[]</code> representation of the serilaized
43+
* @return the <code>byte[]</code> representation of the serialized
4444
* <code>Element</code>.
4545
* @throws Exception
4646
*/
@@ -57,14 +57,6 @@ public interface Serializer {
5757
*/
5858
byte[] serializeToByteArray(NodeList content) throws Exception;
5959

60-
/**
61-
* Use the Canonicalizer to serialize the node
62-
* @param node
63-
* @return the (byte[]) canonicalization of the node
64-
* @throws Exception
65-
*/
66-
byte[] canonSerializeToByteArray(Node node) throws Exception;
67-
6860
/**
6961
* @param source
7062
* @param ctx

0 commit comments

Comments
 (0)