You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by am...@apache.org on 2006/06/12 14:53:14 UTC
svn commit: r413647 - in /xerces/c/trunk/src/xercesc:
dom/DOMLSSerializer.hpp dom/impl/DOMLSSerializerImpl.cpp
dom/impl/DOMLSSerializerImpl.hpp util/XMLUni.cpp util/XMLUni.hpp
Author: amassari
Date: Mon Jun 12 05:53:13 2006
New Revision: 413647
URL: http://svn.apache.org/viewvc?rev=413647&view=rev
Log:
Added parameter http://apache.org/xml/features/pretty-print/space-first-level-elements to DOMLSSerializer to let the user control whether the children of the document root should have an extra line feed between them (jira# 1561)
Modified:
xerces/c/trunk/src/xercesc/dom/DOMLSSerializer.hpp
xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp
xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.hpp
xerces/c/trunk/src/xercesc/util/XMLUni.cpp
xerces/c/trunk/src/xercesc/util/XMLUni.hpp
Modified: xerces/c/trunk/src/xercesc/dom/DOMLSSerializer.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/DOMLSSerializer.hpp?rev=413647&r1=413646&r2=413647&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/DOMLSSerializer.hpp (original)
+++ xerces/c/trunk/src/xercesc/dom/DOMLSSerializer.hpp Mon Jun 12 05:53:13 2006
@@ -233,9 +233,30 @@
* <dd>[required]
* (default) Don't pretty-print the result. </dd>
* </dl></dd>
+ * <dt><code>"http://apache.org/xml/features/dom/byte-order-mark"</code></dt>
+ * <dd>
+ * <dl>
+ * <dt><code>false</code></dt>
+ * <dd>[optional]
+ * (default) Setting this feature to true will output the correct BOM for the specified
+ * encoding. </dd>
+ * <dt><code>true</code></dt>
+ * <dd>[required]
+ * Don't generate a BOM. </dd>
+ * </dl></dd>
+ * <dt><code>"http://apache.org/xml/features/pretty-print/space-first-level-elements"</code></dt>
+ * <dd>
+ * <dl>
+ * <dt><code>true</code></dt>
+ * <dd>[optional]
+ * (default) Setting this feature to true will add an extra line feed between the elements
+ * that are children of the document root. </dd>
+ * <dt><code>false</code></dt>
+ * <dd>[required]
+ * Don't add the extra line feed. </dd>
+ * </dl></dd>
* </dl>
- * <p>See also the <a href='http://www.w3.org/TR/2002/WD-DOM-Level-3-ASLS-20020409'>Document Object Model (DOM) Level 3 Abstract Schemas and Load
- * and Save Specification</a>.
+ * <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407'>Document Object Model (DOM) Level 3 Load and Save Specification</a>.
*
* @since DOM Level 3
*/
Modified: xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp?rev=413647&r1=413646&r2=413647&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp (original)
+++ xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.cpp Mon Jun 12 05:53:13 2006
@@ -55,7 +55,8 @@
static const int VALIDATION_ID = 0x6;
static const int WHITESPACE_IN_ELEMENT_CONTENT_ID = 0x7;
static const int BYTE_ORDER_MARK_ID = 0x8;
-static const int XML_DECLARATION = 0x9;
+static const int XML_DECLARATION = 0x9;
+static const int FORMAT_PRETTY_PRINT_1ST_LEVEL_ID = 0xA;
// feature true false
// ================================================================================
@@ -83,8 +84,9 @@
true, true, // split-cdata-sections
false, true, // validation
true, false, // whitespace-in-element-content
- true, true, // byte-order-mark
- true, true // xml-declaration
+ true, true, // http://apache.org/xml/features/dom/byte-order-mark
+ true, true, // xml-declaration
+ true, true // http://apache.org/xml/features/pretty-print/space-first-level-elements
};
// default end-of-line sequence
@@ -225,9 +227,6 @@
static const XMLByte BOM_ucs4be[] = {(XMLByte)0x00, (XMLByte)0x00, (XMLByte)0xFE, (XMLByte)0xFF, (XMLByte) 0};
static const XMLByte BOM_ucs4le[] = {(XMLByte)0xFF, (XMLByte)0xFE, (XMLByte)0x00, (XMLByte)0x00, (XMLByte) 0};
-static bool lineFeedInTextNodePrinted = false;
-static int lastWhiteSpaceInTextNode = 0;
-
//
// Notification of the error though error handler
//
@@ -275,6 +274,8 @@
,fFormatter(0)
,fErrorCount(0)
,fCurrentLine(0)
+,fLineFeedInTextNodePrinted(false)
+,fLastWhiteSpaceInTextNode(0)
,fNamespaceStack(0)
,fMemoryManager(manager)
{
@@ -293,8 +294,9 @@
setFeature(WHITESPACE_IN_ELEMENT_CONTENT_ID, true );
setFeature(BYTE_ORDER_MARK_ID, false);
setFeature(XML_DECLARATION, true );
+ setFeature(FORMAT_PRETTY_PRINT_1ST_LEVEL_ID, true );
- fSupportedParameters=new (fMemoryManager) DOMStringListImpl(11, fMemoryManager);
+ fSupportedParameters=new (fMemoryManager) DOMStringListImpl(12, fMemoryManager);
fSupportedParameters->add(XMLUni::fgDOMErrorHandler);
fSupportedParameters->add(XMLUni::fgDOMWRTCanonicalForm);
fSupportedParameters->add(XMLUni::fgDOMWRTDiscardDefaultContent);
@@ -306,6 +308,7 @@
fSupportedParameters->add(XMLUni::fgDOMWRTWhitespaceInElementContent);
fSupportedParameters->add(XMLUni::fgDOMWRTBOM);
fSupportedParameters->add(XMLUni::fgDOMXMLDeclaration);
+ fSupportedParameters->add(XMLUni::fgDOMWRTXercesPrettyPrint);
}
bool DOMLSSerializerImpl::canSetParameter(const XMLCh* const featName
@@ -350,6 +353,7 @@
if ((featureId == CANONICAL_FORM_ID) && state)
{
setFeature(FORMAT_PRETTY_PRINT_ID, false);
+ setFeature(FORMAT_PRETTY_PRINT_1ST_LEVEL_ID, false);
setFeature(DISCARD_DEFAULT_CONTENT_ID, false);
setFeature(XML_DECLARATION, false);
}
@@ -484,6 +488,9 @@
fErrorCount = 0;
+ fLineFeedInTextNodePrinted = false;
+ fLastWhiteSpaceInTextNode = 0;
+
try
{
fFormatter = new (fMemoryManager) XMLFormatter( fEncodingUsed
@@ -638,8 +645,8 @@
if (getFeature(FORMAT_PRETTY_PRINT_ID))
{
- lineFeedInTextNodePrinted = false;
- lastWhiteSpaceInTextNode = 0;
+ fLineFeedInTextNodePrinted = false;
+ fLastWhiteSpaceInTextNode = 0;
if(XMLString::isAllWhiteSpace(nodeValue))
{
@@ -659,8 +666,8 @@
int pos = XMLString::lastIndexOf(nodeValue, chLF);
if (-1 != pos)
{
- lineFeedInTextNodePrinted = true;
- lastWhiteSpaceInTextNode = lent - pos;
+ fLineFeedInTextNodePrinted = true;
+ fLastWhiteSpaceInTextNode = lent - pos;
}
else
{
@@ -669,8 +676,8 @@
pos = XMLString::lastIndexOf(nodeValue, chCR);
if (-1 != pos)
{
- lineFeedInTextNodePrinted = true;
- lastWhiteSpaceInTextNode = lent - pos;
+ fLineFeedInTextNodePrinted = true;
+ fLastWhiteSpaceInTextNode = lent - pos;
}
}
}
@@ -687,7 +694,7 @@
if (checkFilter(nodeToWrite) != DOMNodeFilter::FILTER_ACCEPT)
break;
- if(level == 1)
+ if(level == 1 && getFeature(FORMAT_PRETTY_PRINT_1ST_LEVEL_ID))
printNewLine();
printNewLine();
@@ -763,16 +770,16 @@
if ( filterAction == DOMNodeFilter::FILTER_REJECT)
break;
- if (!lineFeedInTextNodePrinted)
+ if (!fLineFeedInTextNodePrinted)
{
- if(level == 1)
+ if(level == 1 && getFeature(FORMAT_PRETTY_PRINT_1ST_LEVEL_ID))
printNewLine();
printNewLine();
}
else
{
- lineFeedInTextNodePrinted = false;
+ fLineFeedInTextNodePrinted = false;
}
printIndent(level);
@@ -988,16 +995,16 @@
//this node then print a new line and indent
if(nodeLine != fCurrentLine)
{
- if (!lineFeedInTextNodePrinted)
+ if (!fLineFeedInTextNodePrinted)
{
printNewLine();
}
else
{
- lineFeedInTextNodePrinted = false;
+ fLineFeedInTextNodePrinted = false;
}
- if(nodeLine != fCurrentLine && level == 0)
+ if(nodeLine != fCurrentLine && level == 0 && getFeature(FORMAT_PRETTY_PRINT_1ST_LEVEL_ID))
printNewLine();
printIndent(level);
@@ -1131,7 +1138,7 @@
if (checkFilter(nodeToWrite) != DOMNodeFilter::FILTER_ACCEPT)
break;
- if(level == 1)
+ if(level == 1 && getFeature(FORMAT_PRETTY_PRINT_1ST_LEVEL_ID))
printNewLine();
printNewLine();
@@ -1166,7 +1173,7 @@
if (checkFilter(nodeToWrite) != DOMNodeFilter::FILTER_ACCEPT)
break;
- if(level == 1)
+ if(level == 1 && getFeature(FORMAT_PRETTY_PRINT_1ST_LEVEL_ID))
printNewLine();
printNewLine();
@@ -1340,6 +1347,8 @@
featureId = BYTE_ORDER_MARK_ID;
else if (XMLString::equals(featName, XMLUni::fgDOMXMLDeclaration))
featureId = XML_DECLARATION;
+ else if (XMLString::equals(featName, XMLUni::fgDOMWRTXercesPrettyPrint))
+ featureId = FORMAT_PRETTY_PRINT_1ST_LEVEL_ID;
//feature name not resolvable
@@ -1596,15 +1605,15 @@
}
}
-void DOMLSSerializerImpl::printIndent(int level) const
+void DOMLSSerializerImpl::printIndent(int level)
{
if (getFeature(FORMAT_PRETTY_PRINT_ID))
{
- if (lastWhiteSpaceInTextNode)
+ if (fLastWhiteSpaceInTextNode)
{
- level -= lastWhiteSpaceInTextNode/2; // two chSpaces equals one indent level
- lastWhiteSpaceInTextNode = 0;
- // if lastWhiteSpaceInTextNode/2 is greater than level, then
+ level -= fLastWhiteSpaceInTextNode/2; // two chSpaces equals one indent level
+ fLastWhiteSpaceInTextNode = 0;
+ // if fLastWhiteSpaceInTextNode/2 is greater than level, then
// it means too many spaces have been written to the
// output stream and we can no longer indent properly
}
Modified: xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.hpp?rev=413647&r1=413646&r2=413647&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.hpp (original)
+++ xerces/c/trunk/src/xercesc/dom/impl/DOMLSSerializerImpl.hpp Mon Jun 12 05:53:13 2006
@@ -135,7 +135,7 @@
void setURCharRef();
- void printIndent(int level) const;
+ void printIndent(int level);
//does the actual work for processNode while keeping track of the level
void processNode(const DOMNode* const nodeToWrite, int level);
@@ -198,6 +198,8 @@
XMLFormatter *fFormatter;
int fErrorCount;
int fCurrentLine;
+ bool fLineFeedInTextNodePrinted;
+ int fLastWhiteSpaceInTextNode;
RefVectorOf< RefHashTableOf<XMLCh> >* fNamespaceStack;
MemoryManager* fMemoryManager;
Modified: xerces/c/trunk/src/xercesc/util/XMLUni.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLUni.cpp?rev=413647&r1=413646&r2=413647&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLUni.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLUni.cpp Mon Jun 12 05:53:13 2006
@@ -1620,6 +1620,23 @@
chLatin_n, chNull
};
+//Xerces: http://apache.org/xml/features/pretty-print/space-first-level-elements
+const XMLCh XMLUni::fgDOMWRTXercesPrettyPrint[] =
+{
+ chLatin_h, chLatin_t, chLatin_t, chLatin_p, chColon, chForwardSlash,
+ chForwardSlash, chLatin_a, chLatin_p, chLatin_a, chLatin_c, chLatin_h,
+ chLatin_e, chPeriod, chLatin_o, chLatin_r, chLatin_g, chForwardSlash,
+ chLatin_x, chLatin_m, chLatin_l, chForwardSlash, chLatin_f, chLatin_e,
+ chLatin_a, chLatin_t, chLatin_u, chLatin_r, chLatin_e, chLatin_s,
+ chForwardSlash, chLatin_p, chLatin_r, chLatin_e, chLatin_t, chLatin_t,
+ chLatin_y, chDash, chLatin_p, chLatin_r, chLatin_i, chLatin_n, chLatin_t,
+ chForwardSlash, chLatin_s, chLatin_p, chLatin_a, chLatin_c, chLatin_e,
+ chDash, chLatin_f, chLatin_i, chLatin_r, chLatin_s, chLatin_t, chDash,
+ chLatin_l, chLatin_e, chLatin_v, chLatin_e, chLatin_l, chDash,
+ chLatin_e, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n,
+ chLatin_t, chLatin_s, chNull
+};
+
const XMLCh XMLUni::fgXercescInterfacePSVITypeInfo[] =
{
chLatin_D, chLatin_O, chLatin_M, chLatin_P, chLatin_S, chLatin_V, chLatin_I,
Modified: xerces/c/trunk/src/xercesc/util/XMLUni.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLUni.hpp?rev=413647&r1=413646&r2=413647&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLUni.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLUni.hpp Mon Jun 12 05:53:13 2006
@@ -277,6 +277,7 @@
static const XMLCh fgDOMWRTWhitespaceInElementContent[];
static const XMLCh fgDOMWRTBOM[];
static const XMLCh fgDOMXMLDeclaration[];
+ static const XMLCh fgDOMWRTXercesPrettyPrint[];
// Private interface names
static const XMLCh fgXercescInterfacePSVITypeInfo[];
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org