You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by mi...@apache.org on 2006/03/10 07:16:09 UTC
svn commit: r384712 - in /xalan/java/trunk/src/org/apache/xml/serializer:
ToHTMLStream.java ToStream.java
Author: minchau
Date: Thu Mar 9 22:16:06 2006
New Revision: 384712
URL: http://svn.apache.org/viewcvs?rev=384712&view=rev
Log:
Committing patch for XALANJ-2276 to get the name of the element
after the DOCTYPE correct more often for HTML output.
Modified:
xalan/java/trunk/src/org/apache/xml/serializer/ToHTMLStream.java
xalan/java/trunk/src/org/apache/xml/serializer/ToStream.java
Modified: xalan/java/trunk/src/org/apache/xml/serializer/ToHTMLStream.java
URL: http://svn.apache.org/viewcvs/xalan/java/trunk/src/org/apache/xml/serializer/ToHTMLStream.java?rev=384712&r1=384711&r2=384712&view=diff
==============================================================================
--- xalan/java/trunk/src/org/apache/xml/serializer/ToHTMLStream.java (original)
+++ xalan/java/trunk/src/org/apache/xml/serializer/ToHTMLStream.java Thu Mar 9 22:16:06 2006
@@ -687,7 +687,15 @@
m_needToOutputDocTypeDecl = true;
m_startNewLine = false;
setOmitXMLDeclaration(true);
+ }
+ /**
+ * This method should only get called once.
+ * If a DOCTYPE declaration needs to get written out, it will
+ * be written out. If it doesn't need to be written out, then
+ * the call to this method has no effect.
+ */
+ private void outputDocTypeDecl(String name) throws SAXException {
if (true == m_needToOutputDocTypeDecl)
{
String doctypeSystem = getDoctypeSystem();
@@ -697,7 +705,8 @@
final java.io.Writer writer = m_writer;
try
{
- writer.write("<!DOCTYPE html");
+ writer.write("<!DOCTYPE ");
+ writer.write(name);
if (null != doctypePublic)
{
@@ -798,6 +807,16 @@
startDocumentInternal();
m_needToCallStartDocument = false;
}
+
+ if (m_needToOutputDocTypeDecl) {
+ String n = name;
+ if (n == null || n.length() == 0) {
+ // If the lexical QName is not given
+ // use the localName in the DOCTYPE
+ n = localName;
+ }
+ outputDocTypeDecl(n);
+ }
// if this element has a namespace then treat it like XML
@@ -1511,6 +1530,14 @@
if (m_elemContext.m_isRaw)
{
+
+ // Clean up some pending issues.
+ if (m_elemContext.m_startTagOpen)
+ {
+ closeStartTag();
+ m_elemContext.m_startTagOpen = false;
+ }
+
try
{
if (m_elemContext.m_startTagOpen)
@@ -1652,14 +1679,32 @@
{
try
{
- if (m_elemContext.m_startTagOpen)
- {
- closeStartTag();
- m_elemContext.m_startTagOpen = false;
- }
- else if (m_needToCallStartDocument)
- startDocumentInternal();
+ // clean up any pending things first
+ if (m_elemContext.m_startTagOpen)
+ {
+ closeStartTag();
+ m_elemContext.m_startTagOpen = false;
+ }
+ else if (m_cdataTagOpen)
+ {
+ closeCDATA();
+ }
+ else if (m_needToCallStartDocument)
+ {
+ startDocumentInternal();
+ }
+
+
+ /*
+ * Perhaps processing instructions can be written out in HTML before
+ * the DOCTYPE, in which case this could be emitted with the
+ * startElement call, that knows the name of the document element
+ * doing it right.
+ */
+ if (true == m_needToOutputDocTypeDecl)
+ outputDocTypeDecl("html"); // best guess for the upcoming element
+
if (shouldIndent())
indent();
@@ -1951,6 +1996,33 @@
// The internal DTD subset is not serialized by the ToHTMLStream serializer
if (m_inDTD)
return;
+
+ // Clean up some pending issues, just in case
+ // this call is coming right after a startElement()
+ // or we are in the middle of writing out CDATA
+ // or if a startDocument() call was not received
+ if (m_elemContext.m_startTagOpen)
+ {
+ closeStartTag();
+ m_elemContext.m_startTagOpen = false;
+ }
+ else if (m_cdataTagOpen)
+ {
+ closeCDATA();
+ }
+ else if (m_needToCallStartDocument)
+ {
+ startDocumentInternal();
+ }
+
+ /*
+ * Perhaps comments can be written out in HTML before the DOCTYPE.
+ * In this case we might delete this call to writeOutDOCTYPE, and
+ * it would be handled within the startElement() call.
+ */
+ if (m_needToOutputDocTypeDecl)
+ outputDocTypeDecl("html"); // best guess for the upcoming element
+
super.comment(ch, start, length);
}
Modified: xalan/java/trunk/src/org/apache/xml/serializer/ToStream.java
URL: http://svn.apache.org/viewcvs/xalan/java/trunk/src/org/apache/xml/serializer/ToStream.java?rev=384712&r1=384711&r2=384712&view=diff
==============================================================================
--- xalan/java/trunk/src/org/apache/xml/serializer/ToStream.java (original)
+++ xalan/java/trunk/src/org/apache/xml/serializer/ToStream.java Thu Mar 9 22:16:06 2006
@@ -1905,13 +1905,12 @@
closeCDATA();
try
{
- if ((true == m_needToOutputDocTypeDecl)
- && (null != getDoctypeSystem()))
- {
- outputDocTypeDecl(name, true);
+ if (m_needToOutputDocTypeDecl) {
+ if(null != getDoctypeSystem()) {
+ outputDocTypeDecl(name, true);
+ }
+ m_needToOutputDocTypeDecl = false;
}
-
- m_needToOutputDocTypeDecl = false;
/* before we over-write the current elementLocalName etc.
* lets close out the old one (if we still need to)
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org