cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r907784 - /cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java
Date Mon, 08 Feb 2010 20:37:53 GMT
Author: simonetripodi
Date: Mon Feb  8 20:37:52 2010
New Revision: 907784

URL: http://svn.apache.org/viewvc?rev=907784&view=rev
Log:
COCOON3-52
XMLSerializer setup method resets output method to xml by Charles Yates

optimized strings allocations using constants

Modified:
    cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java

Modified: cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java?rev=907784&r1=907783&r2=907784&view=diff
==============================================================================
--- cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java
(original)
+++ cocoon/cocoon3/trunk/cocoon-sax/src/main/java/org/apache/cocoon/sax/component/XMLSerializer.java
Mon Feb  8 20:37:52 2010
@@ -41,6 +41,30 @@
     private static final SAXTransformerFactory SAX_TRANSFORMER_FACTORY = (SAXTransformerFactory)
TransformerFactory
             .newInstance();
 
+    private static final String EMPTY = "";
+
+    private static final String YES = "yes";
+
+    private static final String NO = "no";
+
+    private static final String METHOD = "method";
+
+    private static final String UTF_8 = "UTF-8";
+
+    private static final String XML = "xml";
+
+    private static final String HTML = "html";
+
+    private static final String TEXT_XML = "text/xml";
+
+    private static final String TEXT_HTML_UTF_8 = "text/html;charset=utf-8";
+
+    private static final String XHTML_STRICT_DOCTYPE_PUBLIC = "-//W3C//DTD XHTML 1.0 Strict//EN";
+
+    private static final String HTML_TRANSICTIONAL_DOCTYPE_PUBLIC = "-//W3C//DTD HTML 4.01
Transitional//EN";
+
+    private static final String XHTML_STRICT_DOCTYPE_SYSTEM = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
+
     private Properties format;
 
     private TransformerHandler transformerHandler;
@@ -68,7 +92,7 @@
     }
 
     public XMLSerializer setCDataSectionElements(String cdataSectionElements) {
-        if (cdataSectionElements == null || "".equals(cdataSectionElements)) {
+        if (cdataSectionElements == null || EMPTY.equals(cdataSectionElements)) {
             throw new SetupException("A ... has to be passed as argument.");
         }
 
@@ -77,7 +101,7 @@
     }
 
     public XMLSerializer setDoctypePublic(String doctypePublic) {
-        if (doctypePublic == null || "".equals(doctypePublic)) {
+        if (doctypePublic == null || EMPTY.equals(doctypePublic)) {
             throw new SetupException("A doctype-public has to be passed as argument.");
         }
 
@@ -86,7 +110,7 @@
     }
 
     public XMLSerializer setDoctypeSystem(String doctypeSystem) {
-        if (doctypeSystem == null || "".equals(doctypeSystem)) {
+        if (doctypeSystem == null || EMPTY.equals(doctypeSystem)) {
             throw new SetupException("A doctype-system has to be passed as argument.");
         }
 
@@ -95,7 +119,7 @@
     }
 
     public XMLSerializer setEncoding(String encoding) {
-        if (encoding == null || "".equals(encoding)) {
+        if (encoding == null || EMPTY.equals(encoding)) {
             throw new SetupException("A encoding has to be passed as argument.");
         }
 
@@ -108,12 +132,12 @@
     }
 
     public XMLSerializer setIndent(boolean indent) {
-        this.format.put(OutputKeys.INDENT, indent ? "yes" : "no");
+        this.format.put(OutputKeys.INDENT, indent ? YES : NO);
         return this;
     }
 
     public XMLSerializer setMediaType(String mediaType) {
-        if (mediaType == null || "".equals(mediaType)) {
+        if (mediaType == null || EMPTY.equals(mediaType)) {
             throw new SetupException("A media-type has to be passed as argument.");
         }
 
@@ -122,7 +146,7 @@
     }
 
     public XMLSerializer setMethod(String method) {
-        if (method == null || "".equals(method)) {
+        if (method == null || EMPTY.equals(method)) {
             throw new SetupException("A method has to be passed as argument.");
         }
 
@@ -131,7 +155,7 @@
     }
 
     public XMLSerializer setOmitXmlDeclaration(boolean omitXmlDeclration) {
-        this.format.put(OutputKeys.OMIT_XML_DECLARATION, omitXmlDeclration ? "yes" : "no");
+        this.format.put(OutputKeys.OMIT_XML_DECLARATION, omitXmlDeclration ? YES : NO);
         return this;
     }
 
@@ -141,7 +165,7 @@
     }
 
     public XMLSerializer setStandAlone(boolean standalone) {
-        this.format.put(OutputKeys.STANDALONE, standalone ? "yes" : "no");
+        this.format.put(OutputKeys.STANDALONE, standalone ? YES : NO);
         return this;
     }
 
@@ -155,8 +179,8 @@
 
         // set a default method because some transformer implementations run
         // into NPEs if it is missing
-        if (!this.format.containsKey("format")) {
-            this.format.put("method", "xml");
+        if (!this.format.containsKey(METHOD)) {
+            this.format.put(METHOD, XML);
         }
 
         this.transformerHandler.getTransformer().setOutputProperties(this.format);
@@ -165,7 +189,7 @@
     }
 
     public XMLSerializer setVersion(String version) {
-        if (version == null || "".equals(version)) {
+        if (version == null || EMPTY.equals(version)) {
             throw new SetupException("A version has to be passed as argument.");
         }
 
@@ -180,11 +204,11 @@
     public static XMLSerializer createXHTMLSerializer() {
         XMLSerializer serializer = new XMLSerializer();
 
-        serializer.setContentType("text/html;charset=utf-8");
-        serializer.setDoctypePublic("-//W3C//DTD XHTML 1.0 Strict//EN");
-        serializer.setDoctypeSystem("http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd");
-        serializer.setEncoding("UTF-8");
-        serializer.setMethod("xml");
+        serializer.setContentType(TEXT_HTML_UTF_8);
+        serializer.setDoctypePublic(XHTML_STRICT_DOCTYPE_PUBLIC);
+        serializer.setDoctypeSystem(XHTML_STRICT_DOCTYPE_SYSTEM);
+        serializer.setEncoding(UTF_8);
+        serializer.setMethod(XML);
 
         return serializer;
     }
@@ -192,10 +216,10 @@
     public static XMLSerializer createHTML4Serializer() {
         XMLSerializer serializer = new XMLSerializer();
 
-        serializer.setContentType("text/html;charset=utf-8");
-        serializer.setDoctypePublic("-//W3C//DTD HTML 4.01 Transitional//EN");
-        serializer.setEncoding("UTF-8");
-        serializer.setMethod("html");
+        serializer.setContentType(TEXT_HTML_UTF_8);
+        serializer.setDoctypePublic(HTML_TRANSICTIONAL_DOCTYPE_PUBLIC);
+        serializer.setEncoding(UTF_8);
+        serializer.setMethod(HTML);
 
         return serializer;
     }
@@ -203,9 +227,9 @@
     public static XMLSerializer createXMLSerializer() {
         XMLSerializer serializer = new XMLSerializer();
 
-        serializer.setContentType("text/xml");
-        serializer.setEncoding("UTF-8");
-        serializer.setMethod("xml");
+        serializer.setContentType(TEXT_XML);
+        serializer.setEncoding(UTF_8);
+        serializer.setMethod(XML);
 
         return serializer;
     }



Mime
View raw message