dbertoni 01/01/30 17:39:59
Modified: c/src/XMLSupport FormatterToHTML.cpp FormatterToHTML.hpp
Log:
Support for namespace-aware processing.
Revision Changes Path
1.47 +172 -96 xml-xalan/c/src/XMLSupport/FormatterToHTML.cpp
Index: FormatterToHTML.cpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToHTML.cpp,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- FormatterToHTML.cpp 2001/01/25 17:13:30 1.46
+++ FormatterToHTML.cpp 2001/01/31 01:39:58 1.47
@@ -84,12 +84,14 @@
#include <DOMSupport/DOMServices.hpp>
+#include <DOMSupport/PrefixResolver.hpp>
-#include <map>
+const XalanDOMString FormatterToHTML::s_emptyString;
+
FormatterToHTML::FormatterToHTML(
Writer& writer,
const XalanDOMString& encoding,
@@ -119,7 +121,9 @@
m_isScriptOrStyleElem(false),
m_escapeURLs(true),
m_isFirstElement(false),
- m_elementLevel(0)
+ m_elementLevel(0),
+ m_prefixResolver(0),
+ m_hasNamespaceStack()
{
initCharsMap();
}
@@ -270,73 +274,81 @@
const XMLCh* const name,
AttributeList& attrs)
{
- writeParentTagEnd();
+ if (pushHasNamespace(name) == true)
+ {
+ FormatterToXML::startElement(name, attrs);
+ }
+ else
+ {
- const ElemDesc& elemDesc =
- getElemDesc(name);
+ writeParentTagEnd();
- const bool isBlockElement = elemDesc.is(ElemDesc::BLOCK);
- const bool isHeadElement = elemDesc.is(ElemDesc::HEADELEM);
+ const ElemDesc& elemDesc =
+ getElemDesc(name);
- m_isScriptOrStyleElem =
- equalsIgnoreCaseASCII(name, c_wstr(s_scriptString)) ||
- equalsIgnoreCaseASCII(name, c_wstr(s_styleString));
+ const bool isBlockElement = elemDesc.is(ElemDesc::BLOCK);
+ const bool isHeadElement = elemDesc.is(ElemDesc::HEADELEM);
- // Increment the level...
- ++m_elementLevel;
+ m_isScriptOrStyleElem =
+ equalsIgnoreCaseASCII(name,
c_wstr(s_scriptString)) ||
+ equalsIgnoreCaseASCII(name,
c_wstr(s_styleString));
- if(m_ispreserve == true)
- {
- m_ispreserve = false;
- }
- else if(m_doIndent &&
- m_elementLevel > 0 && m_isFirstElement == false &&
- (m_inBlockElem == false || isBlockElement == true))
- {
- m_startNewLine = true;
+ // Increment the level...
+ ++m_elementLevel;
- indent(m_currentIndent);
- }
+ if(m_ispreserve == true)
+ {
+ m_ispreserve = false;
+ }
+ else if(m_doIndent &&
+ m_elementLevel > 0 && m_isFirstElement == false
&&
+ (m_inBlockElem == false || isBlockElement ==
true))
+ {
+ m_startNewLine = true;
+
+ indent(m_currentIndent);
+ }
- m_inBlockElem = !isBlockElement;
+ m_inBlockElem = !isBlockElement;
- m_isRawStack.push_back(elemDesc.is(ElemDesc::RAW));
+ m_isRawStack.push_back(elemDesc.is(ElemDesc::RAW));
- accumContent(XalanUnicode::charLessThanSign);
+ accumContent(XalanUnicode::charLessThanSign);
- accumName(name);
+ accumName(name);
- const unsigned int nAttrs = attrs.getLength();
+ const unsigned int nAttrs = attrs.getLength();
- for (unsigned int i = 0; i < nAttrs ; i++)
- {
- processAttribute(attrs.getName(i), attrs.getValue(i), elemDesc);
- }
+ for (unsigned int i = 0; i < nAttrs ; i++)
+ {
+ processAttribute(attrs.getName(i), attrs.getValue(i),
elemDesc);
+ }
- // Flag the current element as not yet having any children.
- openElementForChildren();
+ // Flag the current element as not yet having any children.
+ openElementForChildren();
- m_currentIndent += m_indent;
+ m_currentIndent += m_indent;
- m_isprevtext = false;
+ m_isprevtext = false;
- if (isHeadElement)
- {
- writeParentTagEnd();
+ if (isHeadElement)
+ {
+ writeParentTagEnd();
- if (m_doIndent)
- indent(m_currentIndent);
+ if (m_doIndent)
+ indent(m_currentIndent);
- accumContent(s_metaString);
- accumContent(getEncoding());
- accumContent(XalanUnicode::charQuoteMark);
- accumContent(XalanUnicode::charGreaterThanSign);
- }
+ accumContent(s_metaString);
+ accumContent(getEncoding());
+ accumContent(XalanUnicode::charQuoteMark);
+ accumContent(XalanUnicode::charGreaterThanSign);
+ }
- // We've written the first element, so turn off the flag...
- m_isFirstElement = false;
+ // We've written the first element, so turn off the flag...
+ m_isFirstElement = false;
- assert(m_elementLevel > 0);
+ assert(m_elementLevel > 0);
+ }
}
@@ -344,49 +356,44 @@
void
FormatterToHTML::endElement(const XMLCh* const name)
{
- m_currentIndent -= m_indent;
-
- const bool hasChildNodes = childNodesWereAdded();
-
- m_isRawStack.pop_back();
-
- const ElemDesc& elemDesc =
- getElemDesc(name);
-
- const bool isBlockElement = elemDesc.is(ElemDesc::BLOCK);
-
- bool shouldIndent = false;
-
- if(m_ispreserve == true)
+ if (popHasNamespace() == true)
{
- m_ispreserve = false;
+ FormatterToXML::endElement(name);
}
- else if(m_doIndent == true && (m_inBlockElem == false || isBlockElement
== true))
+ else
{
- m_startNewLine = true;
+ m_currentIndent -= m_indent;
- shouldIndent = true;
- }
+ const bool hasChildNodes = childNodesWereAdded();
+
+ m_isRawStack.pop_back();
+
+ const ElemDesc& elemDesc =
+ getElemDesc(name);
- m_inBlockElem = !isBlockElement;
+ const bool isBlockElement = elemDesc.is(ElemDesc::BLOCK);
- if (hasChildNodes)
- {
- if (shouldIndent == true)
+ bool shouldIndent = false;
+
+ if(m_ispreserve == true)
{
- indent(m_currentIndent);
+ m_ispreserve = false;
}
+ else if(m_doIndent == true && (m_inBlockElem == false ||
isBlockElement == true))
+ {
+ m_startNewLine = true;
- accumContent(XalanUnicode::charLessThanSign);
- accumContent(XalanUnicode::charSolidus);
- accumName(name);
- accumContent(XalanUnicode::charGreaterThanSign);
- }
- else
- {
- if(elemDesc.is(ElemDesc::EMPTY) == false)
+ shouldIndent = true;
+ }
+
+ m_inBlockElem = !isBlockElement;
+
+ if (hasChildNodes)
{
- accumContent(XalanUnicode::charGreaterThanSign);
+ if (shouldIndent == true)
+ {
+ indent(m_currentIndent);
+ }
accumContent(XalanUnicode::charLessThanSign);
accumContent(XalanUnicode::charSolidus);
@@ -395,27 +402,39 @@
}
else
{
- accumContent(XalanUnicode::charGreaterThanSign);
+ if(elemDesc.is(ElemDesc::EMPTY) == false)
+ {
+ accumContent(XalanUnicode::charGreaterThanSign);
+
+ accumContent(XalanUnicode::charLessThanSign);
+ accumContent(XalanUnicode::charSolidus);
+ accumName(name);
+ accumContent(XalanUnicode::charGreaterThanSign);
+ }
+ else
+ {
+ accumContent(XalanUnicode::charGreaterThanSign);
+ }
}
- }
- if (elemDesc.is(ElemDesc::WHITESPACESENSITIVE) == true)
- {
- m_ispreserve = true;
- }
+ if (elemDesc.is(ElemDesc::WHITESPACESENSITIVE) == true)
+ {
+ m_ispreserve = true;
+ }
- if (hasChildNodes == true)
- {
- if (m_preserves.empty() == false)
+ if (hasChildNodes == true)
{
- m_preserves.pop_back();
+ if (m_preserves.empty() == false)
+ {
+ m_preserves.pop_back();
+ }
}
- }
- m_isprevtext = false;
+ m_isprevtext = false;
- // Decrement the level...
- --m_elementLevel;
+ // Decrement the level...
+ --m_elementLevel;
+ }
}
@@ -1001,6 +1020,63 @@
accumContent(m_stringBuffer);
clear(m_stringBuffer);
+}
+
+
+
+bool
+FormatterToHTML::popHasNamespace()
+{
+ if (m_hasNamespaceStack.empty() == true)
+ {
+ return false;
+ }
+ else
+ {
+ const bool theValue = m_hasNamespaceStack.back();
+
+ m_hasNamespaceStack.pop_back();
+
+ return theValue;
+ }
+}
+
+
+
+bool
+FormatterToHTML::pushHasNamespace(const XalanDOMChar* theElementName)
+{
+ bool fHasNamespace = false;
+
+ if (m_prefixResolver != 0)
+ {
+ const unsigned int theLength = length(theElementName);
+ const unsigned int theColonIndex = indexOf(theElementName,
XalanUnicode::charSemicolon);
+
+ const XalanDOMString* thePrefix = &s_emptyString;
+
+ if (theColonIndex < theLength)
+ {
+ m_stringBuffer = substring(theElementName, 0,
theColonIndex);
+
+ thePrefix = &m_stringBuffer;
+ }
+
+ assert(thePrefix != 0);
+
+ // Check for the namespace...
+ const XalanDOMString& theNamespace =
+
m_prefixResolver->getNamespaceForPrefix(*thePrefix);
+
+ if (length(theNamespace) != 0)
+ {
+ m_hasNamespaceStack.push_back(true);
+
+ fHasNamespace = true;
+ }
+ }
+
+ return fHasNamespace;
}
1.23 +44 -8 xml-xalan/c/src/XMLSupport/FormatterToHTML.hpp
Index: FormatterToHTML.hpp
===================================================================
RCS file: /home/cvs/xml-xalan/c/src/XMLSupport/FormatterToHTML.hpp,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- FormatterToHTML.hpp 2001/01/25 17:13:31 1.22
+++ FormatterToHTML.hpp 2001/01/31 01:39:59 1.23
@@ -58,7 +58,7 @@
#define FORMATTERTOHTML_HEADER_GUARD_1357924680
/**
- * $Id: FormatterToHTML.hpp,v 1.22 2001/01/25 17:13:31 dbertoni Exp $
+ * $Id: FormatterToHTML.hpp,v 1.23 2001/01/31 01:39:59 dbertoni Exp $
*
* $State: Exp $
*
@@ -91,6 +91,10 @@
+class PrefixResolver;
+
+
+
/**
* FormatterToHTML formats SAX-style events into HTML.
*/
@@ -194,6 +198,18 @@
const XMLCh* const data);
+ const PrefixResolver*
+ getPrefixResolver() const
+ {
+ return m_prefixResolver;
+ }
+
+ void
+ setPrefixResolver(const PrefixResolver* thePrefixResolver)
+ {
+ m_prefixResolver = thePrefixResolver;
+ }
+
class ElemDesc
{
public:
@@ -433,27 +449,47 @@
*/
void
accumHexNumber(const XalanDOMChar theChar);
+
+ bool
+ popHasNamespace();
- XalanDOMString m_currentElementName;
+ bool
+ pushHasNamespace(const XalanDOMChar* theElementName);
- bool m_inBlockElem;
+ // Data members...
+ XalanDOMString m_currentElementName;
- BoolStackType m_isRawStack;
+ bool m_inBlockElem;
- bool m_isScriptOrStyleElem;
+ BoolStackType m_isRawStack;
- bool m_escapeURLs;
+ bool m_isScriptOrStyleElem;
+ bool m_escapeURLs;
+
/**
* A flag so we know whether or not we've put out the first
* element.
*/
- bool m_isFirstElement;
+ bool m_isFirstElement;
/**
* A counter so we can tell if we're inside the document element.
+ */
+ int m_elementLevel;
+
+ /**
+ * A prefix resolver for elements that have prefixes.
*/
- int m_elementLevel;
+ const PrefixResolver* m_prefixResolver;
+
+ /**
+ * A stack to determine if the current element has
+ * a namespace.
+ */
+ BoolStackType m_hasNamespaceStack;
+
+ static const XalanDOMString s_emptyString;
};