Skip to content

Commit fa36d6e

Browse files
committed
SWS-309
1 parent f61e401 commit fa36d6e

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.io.OutputStreamWriter;
2222
import java.io.Reader;
2323
import java.io.Writer;
24+
import java.util.Iterator;
25+
import java.util.Properties;
2426
import javax.xml.stream.XMLEventReader;
2527
import javax.xml.stream.XMLEventWriter;
2628
import javax.xml.stream.XMLStreamReader;
@@ -95,6 +97,8 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing
9597

9698
private boolean ignoreExtraElements = false;
9799

100+
private Properties namespaceMappings;
101+
98102
/** Returns whether the Castor {@link Unmarshaller} should ignore attributes that do not match a specific field. */
99103
public boolean getIgnoreExtraAttributes() {
100104
return ignoreExtraAttributes;
@@ -103,6 +107,8 @@ public boolean getIgnoreExtraAttributes() {
103107
/**
104108
* Sets whether the Castor {@link Unmarshaller} should ignore attributes that do not match a specific field.
105109
* Default is <code>true</code>: extra attributes are ignored.
110+
*
111+
* @see org.exolab.castor.xml.Unmarshaller#setIgnoreExtraAttributes(boolean)
106112
*/
107113
public void setIgnoreExtraAttributes(boolean ignoreExtraAttributes) {
108114
this.ignoreExtraAttributes = ignoreExtraAttributes;
@@ -116,6 +122,8 @@ public boolean getIgnoreExtraElements() {
116122
/**
117123
* Sets whether the Castor {@link Unmarshaller} should ignore elements that do not match a specific field. Default
118124
* is <code>false</code>, extra attributes are flagged as an error.
125+
*
126+
* @see org.exolab.castor.xml.Unmarshaller#setIgnoreExtraElements(boolean)
119127
*/
120128
public void setIgnoreExtraElements(boolean ignoreExtraElements) {
121129
this.ignoreExtraElements = ignoreExtraElements;
@@ -129,6 +137,8 @@ public boolean getWhitespacePreserve() {
129137
/**
130138
* Sets whether the Castor {@link Unmarshaller} should preserve "ignorable" whitespace. Default is
131139
* <code>false</code>.
140+
*
141+
* @see org.exolab.castor.xml.Unmarshaller#setWhitespacePreserve(boolean)
132142
*/
133143
public void setWhitespacePreserve(boolean whitespacePreserve) {
134144
this.whitespacePreserve = whitespacePreserve;
@@ -139,11 +149,29 @@ public boolean isValidating() {
139149
return validating;
140150
}
141151

142-
/** Sets whether this marshaller should validate in- and outgoing documents. Default is <code>false</code>. */
152+
/**
153+
* Sets whether this marshaller should validate in- and outgoing documents. Default is <code>false</code>.
154+
*
155+
* @see Marshaller#setValidation(boolean)
156+
*/
143157
public void setValidating(boolean validating) {
144158
this.validating = validating;
145159
}
146160

161+
/** Returns the namespace mappings. Property names are interpreted as namespace prefixes; values are namespace URIs. */
162+
public Properties getNamespaceMappings() {
163+
return namespaceMappings;
164+
}
165+
166+
/**
167+
* Sets the namespace mappings. Property names are interpreted as namespace prefixes; values are namespace URIs.
168+
*
169+
* @see org.exolab.castor.xml.Marshaller#setNamespaceMapping(String, String)
170+
*/
171+
public void setNamespaceMappings(Properties namespaceMappings) {
172+
this.namespaceMappings = namespaceMappings;
173+
}
174+
147175
/**
148176
* Sets the encoding to be used for stream access. If this property is not set, the default encoding is used.
149177
*
@@ -280,10 +308,19 @@ private void marshal(Object graph, Marshaller marshaller) {
280308
* Template method that allows for customizing of the given Castor {@link Marshaller}.
281309
* <p/>
282310
* Default implementation invokes {@link Marshaller#setValidation(boolean)} with the property set on this
283-
* marshaller.
311+
* marshaller, and calls {@link Marshaller#setNamespaceMapping(String, String)} with the {@linkplain
312+
* #setNamespaceMappings(java.util.Properties) namespace mappings}.
284313
*/
285314
protected void customizeMarshaller(Marshaller marshaller) {
286315
marshaller.setValidation(isValidating());
316+
Properties namespaceMappings = getNamespaceMappings();
317+
if (namespaceMappings != null) {
318+
for (Iterator iterator = namespaceMappings.keySet().iterator(); iterator.hasNext();) {
319+
String prefix = (String) iterator.next();
320+
String uri = namespaceMappings.getProperty(prefix);
321+
marshaller.setNamespaceMapping(prefix, uri);
322+
}
323+
}
287324
}
288325

289326
//

0 commit comments

Comments
 (0)