From 8996a2d6792e78b105902a0fc9deb374cf559630 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 2 Apr 2007 10:33:16 +0000 Subject: [PATCH] fixed #SWS-96: set WhitespacePreserve flag in CastorMarshaller --- changelog.txt | 1 + .../oxm/castor/CastorMarshaller.java | 39 +++++++++++-------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/changelog.txt b/changelog.txt index cb1d7b72..d60840ce 100644 --- a/changelog.txt +++ b/changelog.txt @@ -6,6 +6,7 @@ Changes in version 1.0-RC1 ------------------------- Package org.springframework.oxm.castor * fixed #SWS-88: Allow CastorMarshaller to accept more than one mapping file +* fixed #SWS-96: set WhitespacePreserve flag in CastorMarshaller Package org.springframework.oxm.jibx * fixed #SWS-97: OXM Marshal encoding definition diff --git a/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java b/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java index e8c2b4af..743fed61 100644 --- a/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java +++ b/oxm/src/main/java/org/springframework/oxm/castor/CastorMarshaller.java @@ -76,26 +76,35 @@ import org.xml.sax.ext.LexicalHandler; */ public class CastorMarshaller extends AbstractMarshaller implements InitializingBean { - /** - * The default encoding used for stream access. - */ + /** The default encoding used for stream access. */ public static final String DEFAULT_ENCODING = "UTF-8"; private Resource[] mappingLocations; - private String encoding; + private String encoding = DEFAULT_ENCODING; private Class targetClass; private XMLClassDescriptorResolver classDescriptorResolver; + private boolean validating = false; + + private boolean whitespacePreserve = false; + /** - * Returns the encoding to be used for stream access. If this property is not set, the default encoding is used. - * - * @see #DEFAULT_ENCODING + * Set if the Castor Unmarshaller should validate the incoming document. Default is + * false. */ - private String getEncoding() { - return encoding != null ? encoding : DEFAULT_ENCODING; + public void setValidating(boolean validating) { + this.validating = validating; + } + + /** + * Indicates whether the Castor Unmarshaller should preserve "ignorable" whitespace. Default is + * false. + */ + public void setWhitespacePreserve(boolean whitespacePreserve) { + this.whitespacePreserve = whitespacePreserve; } /** @@ -117,16 +126,12 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing this.targetClass = targetClass; } - /** - * Sets the locations of the Castor XML Mapping files. - */ + /** Sets the locations of the Castor XML Mapping files. */ public void setMappingLocation(Resource mappingLocation) { mappingLocations = new Resource[]{mappingLocation}; } - /** - * Sets the locations of the Castor XML Mapping files. - */ + /** Sets the locations of the Castor XML Mapping files. */ public void setMappingLocations(Resource[] mappingLocations) { this.mappingLocations = mappingLocations; } @@ -213,6 +218,8 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing unmarshaller = new Unmarshaller(); } unmarshaller.setResolver(classDescriptorResolver); + unmarshaller.setValidation(validating); + unmarshaller.setWhitespacePreserve(whitespacePreserve); return unmarshaller; } @@ -243,7 +250,7 @@ public class CastorMarshaller extends AbstractMarshaller implements Initializing protected void marshalOutputStream(Object graph, OutputStream outputStream) throws XmlMappingException, IOException { - OutputStreamWriter writer = new OutputStreamWriter(outputStream, getEncoding()); + OutputStreamWriter writer = new OutputStreamWriter(outputStream, encoding); marshalWriter(graph, writer); }