cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject svn commit: r123619 - /cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java /cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/DocType.java
Date Wed, 29 Dec 2004 10:21:45 GMT
Author: antonio
Date: Wed Dec 29 02:21:44 2004
New Revision: 123619

URL: http://svn.apache.org/viewcvs?view=rev&rev=123619
Log:
Add and use DocType.toString()
Modified:
   cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java
   cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/DocType.java

Modified: cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java?view=diff&rev=123619&p1=cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java&r1=123618&p2=cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java&r2=123619
==============================================================================
--- cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java
(original)
+++ cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java
Wed Dec 29 02:21:44 2004
@@ -25,9 +25,8 @@
 
 /**
  *
- *
  * @author <a href="mailto:pier@apache.org">Pier Fumagalli</a>, February 2003
- * @version CVS $Id: XMLSerializer.java,v 1.7 2004/07/11 23:02:54 antonio Exp $
+ * @version CVS $Id$
  */
 public class XMLSerializer extends EncodingSerializer {
 
@@ -39,12 +38,6 @@
     private static final char S_DOCUMENT_2[] = "\" encoding=\"".toCharArray();
     private static final char S_DOCUMENT_3[] = "\"?>".toCharArray();
 
-    private static final char S_DOCTYPE_1[] = "<!DOCTYPE ".toCharArray();
-    private static final char S_DOCTYPE_2[] = " PUBLIC \"".toCharArray();
-    private static final char S_DOCTYPE_3[] = "\" \"".toCharArray();
-    private static final char S_DOCTYPE_4[] = " SYSTEM \"".toCharArray();
-    private static final char S_DOCTYPE_5[] = "\">".toCharArray();
-
     private static final char S_ELEMENT_1[] = "=\"".toCharArray();
     private static final char S_ELEMENT_2[] = "</".toCharArray();
     private static final char S_ELEMENT_3[] = " />".toCharArray();
@@ -187,43 +180,20 @@
     public void body(String uri, String local, String qual)
     throws SAXException {
         this.processing_prolog = false;
-
         this.writeln();
 
         /* We have a document type. */
         if (this.doctype != null) {
 
             String root_name = this.doctype.getName();
-            String public_id = this.doctype.getPublicId();
-            String system_id = this.doctype.getSystemId();
-
             /* Check the DTD and the root element */
             if (!root_name.equals(qual)) {
                 throw new SAXException("Root element name \"" + root_name
                         + "\" declared by document type declaration differs "
                         + "from actual root element name \"" + qual + "\"");
             }
-
-            /* Output a <!DOCTYPE ...> declaration. */
-            this.write(S_DOCTYPE_1); // [<!DOCTYPE ]
-            this.write(root_name);
-            if (public_id != null) {
-                this.write(S_DOCTYPE_2); // [ PUBLIC "]
-                this.write(public_id);
-                /* This is wring in XML, but not in SGML/HTML */
-                if (system_id != null) {
-                    this.write(S_DOCTYPE_3); // [" "]
-                    this.write(system_id);
-                }
-                this.write(S_DOCTYPE_5); // [">]
-            } else if (system_id != null) {
-                this.write(S_DOCTYPE_4); // [ SYSTEM "]
-                this.write(system_id);
-                this.write(S_DOCTYPE_5); // [">]
-            } else {
-                this.write(C_GT); // [>]
-            }
-            this.writeln();
+            /* Output the <!DOCTYPE ...> declaration. */
+            this.write(this.doctype.toString());
         }
 
         /* Output all PIs and comments we cached in the prolog */

Modified: cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/DocType.java
Url: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/DocType.java?view=diff&rev=123619&p1=cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/DocType.java&r1=123618&p2=cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/DocType.java&r2=123619
==============================================================================
--- cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/DocType.java
(original)
+++ cocoon/trunk/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/DocType.java
Wed Dec 29 02:21:44 2004
@@ -20,9 +20,17 @@
  * the document type public and system IDs and root element name.
  * 
  * @author <a href="mailto:pier@apache.org">Pier Fumagalli</a>, February 2003
- * @version CVS $Id: DocType.java,v 1.2 2004/04/30 19:34:46 pier Exp $
+ * @version CVS $Id$
  */
 public class DocType {
+
+    private static final char S_DOCTYPE_1[] = "<!DOCTYPE ".toCharArray();
+    private static final char S_DOCTYPE_2[] = " PUBLIC \"".toCharArray();
+    private static final char S_DOCTYPE_3[] = "\" \"".toCharArray();
+    private static final char S_DOCTYPE_4[] = " SYSTEM \"".toCharArray();
+    private static final char S_DOCTYPE_5[] = "\">".toCharArray();
+    private static final char S_DOCTYPE_6[] = ">".toCharArray();
+    
     /** The name of the root element. */
     protected String root_name = null;
     /** The configured system identifier. */
@@ -90,6 +98,33 @@
      */
     public String getSystemId() {
         return(this.system_id);
+    }
+
+    /**
+     * Return the document type declaration as a string
+     */
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+
+        buf.append(S_DOCTYPE_1); // [<!DOCTYPE ]
+        buf.append(this.root_name);
+        if (this.public_id != null) {
+            buf.append(S_DOCTYPE_2); // [ PUBLIC "]
+            buf.append(this.public_id);
+            /* This is wrong in XML, but not in SGML/HTML */
+            if (this.system_id != null) {
+                buf.append(S_DOCTYPE_3); // [" "]
+                buf.append(this.system_id);
+            }
+            buf.append(S_DOCTYPE_5); // [">]
+        } else if (this.system_id != null) {
+            buf.append(S_DOCTYPE_4); // [ SYSTEM "]
+            buf.append(this.system_id);
+            buf.append(S_DOCTYPE_5); // [">]
+        } else {
+            buf.append(S_DOCTYPE_6); // [>]
+        }
+        return(buf.toString());
     }
 
     /**

Mime
View raw message