ytalwar 2005/03/02 15:08:08
Modified: java/src/org/apache/xml/serializer SerializerConstants.java
ToXMLStream.java ToStream.java
java/src/org/apache/xml/serializer/utils MsgKey.java
SerializerMessages.java
Log:
This patch fix XALANJ-2070.
This patch add XML 1.1 support in term of following:
- Output Document can be of Version XML 1.1
- Control Characters in Range C0 and C1 are output as NCR.
- Namespaces in XML 1.1 can be IRIs.
- NCNames and QNames can conform to XML 1.1 specifications.
- NEL and LSEP characters are treated as new end of line character as per XML
1.1 specifications.
Thanks to Brian Minchau for reviewing the patch. Brian Minchau and Henry
Zongaro has also helped how XML 1.1 support should be done.
Revision Changes Path
1.6 +7 -1
xml-xalan/java/src/org/apache/xml/serializer/SerializerConstants.java
Index: SerializerConstants.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/serializer/SerializerConstants.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SerializerConstants.java 15 Dec 2004 17:35:52 -0000 1.5
+++ SerializerConstants.java 2 Mar 2005 23:08:08 -0000 1.6
@@ -48,4 +48,10 @@
static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
public static final String
DEFAULT_SAX_SERIALIZER="org.apache.xml.serializer.ToXMLSAXHandler";
+
+ /**
+ * Define the XML version.
+ */
+ static final String XMLVERSION11 = "1.1";
+ static final String XMLVERSION10 = "1.0";
}
1.19 +46 -5
xml-xalan/java/src/org/apache/xml/serializer/ToXMLStream.java
Index: ToXMLStream.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToXMLStream.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ToXMLStream.java 11 Feb 2005 06:18:13 -0000 1.18
+++ ToXMLStream.java 2 Mar 2005 23:08:08 -0000 1.19
@@ -124,13 +124,14 @@
m_needToOutputDocTypeDecl = true;
m_startNewLine = false;
-
+ /* The call to getXMLVersion() might emit an error message
+ * and we should emit this message regardless of if we are
+ * writing out an XML header or not.
+ */
+ final String version = getXMLVersion();
if (getOmitXMLDeclaration() == false)
{
String encoding = Encodings.getMimeEncoding(getEncoding());
- String version = getVersion();
- if (version == null)
- version = "1.0";
String standalone;
if (m_standaloneWasSpecified)
@@ -579,4 +580,44 @@
}
+ /**
+ * This method checks for the XML version of output document.
+ * If XML version of output document is not specified, then output
+ * document is of version XML 1.0.
+ * If XML version of output doucment is specified, but it is not either
+ * XML 1.0 or XML 1.1, a warning message is generated, the XML Version of
+ * output document is set to XML 1.0 and processing continues.
+ * @return string (XML version)
+ */
+ private String getXMLVersion()
+ {
+ String xmlVersion = getVersion();
+ if(xmlVersion == null || xmlVersion.equals(XMLVERSION10))
+ {
+ xmlVersion = XMLVERSION10;
+ }
+ else if(xmlVersion.equals(XMLVERSION11))
+ {
+ xmlVersion = XMLVERSION11;
+ }
+ else
+ {
+ String msg = Utils.messages.createMessage(
+ MsgKey.ER_XML_VERSION_NOT_SUPPORTED,new
Object[]{ xmlVersion });
+ try
+ {
+ // Prepare to issue the warning message
+ Transformer tran = super.getTransformer();
+ ErrorListener errHandler = tran.getErrorListener();
+ // Issue the warning message
+ if (null != errHandler && m_sourceLocator != null)
+ errHandler.warning(new TransformerException(msg,
m_sourceLocator));
+ else
+ System.out.println(msg);
+ }
+ catch (Exception e){}
+ xmlVersion = XMLVERSION10;
+ }
+ return xmlVersion;
+ }
}
1.40 +60 -4
xml-xalan/java/src/org/apache/xml/serializer/ToStream.java
Index: ToStream.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/serializer/ToStream.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- ToStream.java 21 Feb 2005 18:34:56 -0000 1.39
+++ ToStream.java 2 Mar 2005 23:08:08 -0000 1.40
@@ -480,6 +480,16 @@
m_spaceBeforeClose = true;
}
+ /*
+ * This code is added for XML 1.1 Version output.
+ */
+ String version = getVersion();
+ if (null == version)
+ {
+ version = format.getProperty(OutputKeys.VERSION);
+ setVersion(version);
+ }
+
// initCharsMap();
String encoding = getEncoding();
if (null == encoding)
@@ -1445,6 +1455,7 @@
// int lengthClean; // number of clean characters in a row
// final boolean[] isAsciiClean = m_charInfo.getASCIIClean();
+ final boolean isXML10 = XMLVERSION10.equals(getVersion());
// we've skipped the leading whitespace, now deal with the rest
for (; i < end; i++)
{
@@ -1462,8 +1473,12 @@
}
final char ch = chars[i];
- if (
-
+ /* The check for isCharacterInC0orC1Ranger and
+ * isNELorLSEPCharacter has been added
+ * to support Control Characters in XML 1.1
+ */
+ if (!isCharacterInC0orC1Range(ch) &&
+ (isXML10 || !isNELorLSEPCharacter(ch)) &&
(escapingNotNeeded(ch) &&
(!m_charInfo.isSpecialTextChar(ch)))
|| ('"' == ch))
{
@@ -1496,6 +1511,35 @@
// time to fire off characters generation event
if (m_tracer != null)
super.fireCharEvent(chars, start, length);
+ }
+ /**
+ * This method checks if a given character is between C0 or C1 range
+ * of Control characters.
+ * This method is added to support Control Characters for XML 1.1
+ * If a given character is TAB (0x09), LF (0x0A) or CR (0x0D), this
method
+ * return false. Since they are whitespace characters, no special
processing is needed.
+ *
+ * @param ch
+ * @return boolean
+ */
+ private static boolean isCharacterInC0orC1Range(char ch)
+ {
+ if(ch == 0x09 || ch == 0x0A || ch == 0x0D)
+ return false;
+ else
+ return (ch >= 0x7F && ch <= 0x9F)|| (ch >= 0x01 && ch <= 0x1F);
+ }
+ /**
+ * This method checks if a given character either NEL (0x85) or LSEP
(0x2028)
+ * These are new end of line charcters added in XML 1.1. These
characters must be
+ * written as Numeric Character References (NCR) in XML 1.1 output
document.
+ *
+ * @param ch
+ * @return boolean
+ */
+ private static boolean isNELorLSEPCharacter(char ch)
+ {
+ return (ch == 0x85 || ch == 0x2028);
}
/**
* Process a dirty character and any preeceding clean characters
@@ -1644,7 +1688,19 @@
}
else
{
- if ((!escapingNotNeeded(ch) ||
+ /* This if check is added to support control characters in
XML 1.1.
+ * If a character is a Control Character within C0 and C1
range, it is desirable
+ * to write it out as Numeric Character Reference(NCR)
regardless of XML Version
+ * being used for output document.
+ */
+ if (isCharacterInC0orC1Range(ch) ||
+ (XMLVERSION11.equals(getVersion()) &&
isNELorLSEPCharacter(ch)))
+ {
+ writer.write("&#");
+ writer.write(Integer.toString(ch));
+ writer.write(';');
+ }
+ else if ((!escapingNotNeeded(ch) ||
( (fromTextNode && m_charInfo.isSpecialTextChar(ch))
|| (!fromTextNode &&
m_charInfo.isSpecialAttrChar(ch))))
&& m_elemContext.m_currentElemDepth > 0)
1.2 +2 -1
xml-xalan/java/src/org/apache/xml/serializer/utils/MsgKey.java
Index: MsgKey.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/serializer/utils/MsgKey.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MsgKey.java 16 Dec 2004 19:15:41 -0000 1.1
+++ MsgKey.java 2 Mar 2005 23:08:08 -0000 1.2
@@ -91,4 +91,5 @@
public static final String ER_NO_USERINFO_IF_NO_HOST =
"ER_NO_USERINFO_IF_NO_HOST";
public static final String ER_SCHEME_REQUIRED = "ER_SCHEME_REQUIRED";
+ public static final String ER_XML_VERSION_NOT_SUPPORTED =
"ER_XML_VERSION_NOT_SUPPORTED";
}
1.6 +4 -1
xml-xalan/java/src/org/apache/xml/serializer/utils/SerializerMessages.java
Index: SerializerMessages.java
===================================================================
RCS file:
/home/cvs/xml-xalan/java/src/org/apache/xml/serializer/utils/SerializerMessages.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- SerializerMessages.java 23 Jan 2005 00:52:41 -0000 1.5
+++ SerializerMessages.java 2 Mar 2005 23:08:08 -0000 1.6
@@ -179,6 +179,9 @@
{ MsgKey.ER_NO_USERINFO_IF_NO_HOST,
"Userinfo may not be specified if host is not specified" },
+ { MsgKey.ER_XML_VERSION_NOT_SUPPORTED,
+ "Warning: The version of the output document is requested
to be ''{0}''. This version of XML is not supported. The version of the
output document will be ''1.0''." },
+
{ MsgKey.ER_SCHEME_REQUIRED,
"Scheme is required!" }
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]