bloritsch 01/01/10 05:42:21
Modified: src/org/apache/cocoon/serialization Tag: xml-cocoon2
AbstractTextSerializer.java
Log:
Modified to detect optional elements before trying anything that could cause
an
exception. As a result, the log file is a bit cleaner as the log message
only shows
up when elements are expected but the value throws an exception.
Revision Changes Path
No revision
No revision
1.1.2.5 +63 -54
xml-cocoon/src/org/apache/cocoon/serialization/Attic/AbstractTextSerializer.java
Index: AbstractTextSerializer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/serialization/Attic/AbstractTextSerializer.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- AbstractTextSerializer.java 2000/12/08 20:40:08 1.1.2.4
+++ AbstractTextSerializer.java 2001/01/10 13:42:21 1.1.2.5
@@ -20,7 +20,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Pierpaolo Fumagalli</a>
* (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.1.2.4 $ $Date: 2000/12/08 20:40:08 $
+ * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/01/10 13:42:21 $
*/
public abstract class AbstractTextSerializer extends AbstractSerializer
implements Configurable {
@@ -35,66 +35,75 @@
public void configure(Configuration conf)
throws ConfigurationException {
+ Configuration encoding = conf.getChild("encoding");
+ Configuration dtPublic = conf.getChild("doctype-public");
+ Configuration dtSystem = conf.getChild("doctype-system");
+ Configuration indent = conf.getChild("indent");
+ Configuration preserveSpace = conf.getChild("preserve-space");
+ Configuration declaration = conf.getChild("xml-declaration");
+ Configuration lineWidth = conf.getChild("line-width");
+
+ String doctypePublic = null;
+
format = new OutputFormat();
format.setPreserveSpace(true);
- try {
- Configuration encoding = conf.getChild("encoding");
- format.setEncoding(encoding.getValue());
- } catch (ConfigurationException ce) {
- log.debug("No Encoding");
- // TODO: how to handle non-existant encoding?
+ if (! encoding.getLocation().equals("-")) {
+ try {
+ format.setEncoding(encoding.getValue());
+ } catch (ConfigurationException ce) {
+ log.debug("No value for encoding--but expected", ce);
+ }
+ }
+
+ if (! dtPublic.getLocation().equals("-")) {
+ try {
+ doctypePublic = dtPublic.getValue();
+ } catch (ConfigurationException ce) {
+ log.debug("No Public Doctype--but expected", ce);
+ }
+ }
+
+ if (! dtSystem.getLocation().equals("-")) {
+ try {
+ format.setDoctype(doctypePublic, dtSystem.getValue());
+ } catch (ConfigurationException ce) {
+ log.debug("No System Doctype--but expected", ce);
+ }
}
-
- String doctypePublic = null;
- try {
- Configuration dtPublic = conf.getChild("doctype-public");
- doctypePublic = dtPublic.getValue();
- } catch (ConfigurationException ce) {
- log.debug("No Public Doctype");
- doctypePublic = null;
- }
-
- try {
- Configuration doctypeSystem = conf.getChild("doctype-system");
- format.setDoctype(doctypePublic, doctypeSystem.getValue());
- } catch (ConfigurationException ce) {
- log.debug("No System Doctype");
- // TODO: how to handle non-existant doctype-system?
+ if (! indent.getLocation().equals("-")) {
+ format.setIndenting(true);
+ try {
+ format.setIndent(indent.getValueAsInt());
+ } catch (ConfigurationException ce) {
+ log.debug("No indent value or invalid value--but expected",
ce);
+ }
+ }
+
+ if (! preserveSpace.getLocation().equals("-")) {
+ try {
+ format.setPreserveSpace(preserveSpace.getValueAsBoolean());
+ } catch (ConfigurationException ce) {
+ log.debug("No preserve-space value--but expected", ce);
+ }
+ }
+
+ if (! declaration.getLocation().equals("-")) {
+ try {
+
format.setOmitXMLDeclaration(!declaration.getValueAsBoolean());
+ } catch (ConfigurationException ce) {
+ log.debug("No declaration value or invalid value--but
expected", ce);
+ }
}
- try {
- Configuration indent = conf.getChild("indent");
- format.setIndenting(true);
- format.setIndent(indent.getValueAsInt());
- } catch (ConfigurationException ce) {
- log.debug("No indent");
- // TODO: how to handle non-existant indent?
- }
-
- try {
- Configuration preserveSpace = conf.getChild("preserve-space");
- format.setPreserveSpace(preserveSpace.getValueAsBoolean());
- } catch (ConfigurationException ce) {
- log.debug("No preserve-space");
- // TODO: how to handle non-existant preserve-space?
- }
-
- try {
- Configuration declaration = conf.getChild("xml-declaration");
- format.setOmitXMLDeclaration(!declaration.getValueAsBoolean());
- } catch (ConfigurationException ce) {
- log.debug("No XML Declaration");
- // TODO: how to handle non-existant xml-declaration?
- }
-
- try {
- Configuration lineWidth = conf.getChild("line-width");
- format.setLineWidth(lineWidth.getValueAsInt());
- } catch (ConfigurationException ce) {
- log.debug("No line-width");
- // TODO: how to handle non-existant line-width?
+
+ if (! lineWidth.getLocation().equals("-")) {
+ try {
+ format.setLineWidth(lineWidth.getValueAsInt());
+ } catch (ConfigurationException ce) {
+ log.debug("No line-width value or invalid value--but
expected", ce);
+ }
}
}
}