Newer
Older
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
Boris Kolpackov
committed
*
* http://www.apache.org/licenses/LICENSE-2.0
Boris Kolpackov
committed
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id$
*/
#if !defined(XERCESC_INCLUDE_GUARD_DOMLSSERIALIZERMPL_HPP)
#define XERCESC_INCLUDE_GUARD_DOMLSSERIALIZERMPL_HPP
#include <xercesc/dom/DOM.hpp>
#include <xercesc/dom/DOMLSSerializer.hpp>
#include <xercesc/util/XMLDOMMsg.hpp>
#include <xercesc/util/RefHashTableOf.hpp>
#include <xercesc/util/RefVectorOf.hpp>
Alberto Massari
committed
#include <xercesc/framework/XMLFormatter.hpp>
XERCES_CPP_NAMESPACE_BEGIN
class CDOM_EXPORT DOMLSSerializerImpl : public XMemory,
public DOMLSSerializer,
Boris Kolpackov
committed
public DOMConfiguration
{
public:
/** @name Constructor and Destructor */
//@{
/**
* Constructor.
*/
DOMLSSerializerImpl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
/**
* Destructor.
*/
~DOMLSSerializerImpl();
//@}
/** @name Implementation of DOMLSSerializer interface */
//@{
virtual DOMConfiguration* getDomConfig();
virtual void setNewLine(const XMLCh* const newLine);
virtual const XMLCh* getNewLine() const;
virtual void setFilter(DOMLSSerializerFilter *filter);
virtual DOMLSSerializerFilter* getFilter() const;
Alberto Massari
committed
virtual bool write(const DOMNode* nodeToWrite,
DOMLSOutput* const destination);
Boris Kolpackov
committed
virtual bool writeToURI(const DOMNode* nodeToWrite,
Alberto Massari
committed
const XMLCh* uri);
/**
* The caller is responsible for the release of the returned string
*/
Alberto Massari
committed
virtual XMLCh* writeToString(const DOMNode* nodeToWrite, MemoryManager* manager = NULL);
virtual void release();
//@}
/** @name Implementation of DOMConfiguration interface */
//@{
virtual void setParameter(const XMLCh* name, const void* value);
virtual void setParameter(const XMLCh* name, bool value);
virtual const void* getParameter(const XMLCh* name) const;
virtual bool canSetParameter(const XMLCh* name, const void* value) const;
virtual bool canSetParameter(const XMLCh* name, bool value) const;
virtual const DOMStringList* getParameterNames() const;
//@}
private:
/** unimplemented copy ctor and assignment operator */
DOMLSSerializerImpl(const DOMLSSerializerImpl&);
DOMLSSerializerImpl & operator = (const DOMLSSerializerImpl&);
Boris Kolpackov
committed
protected:
/** helper **/
void processNode(const DOMNode* const);
void procCdataSection(const XMLCh* const nodeValue
Boris Kolpackov
committed
, const DOMNode* const nodeToWrite);
void procUnrepCharInCdataSection(const XMLCh* const nodeValue
Boris Kolpackov
committed
, const DOMNode* const nodeToWrite);
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
protected:
/**
* Overidden by derived classes to extend the abilities of the standard writer
* always returns false in the default implementation
* @return true if the method deals with nodeToWrite
*/
virtual bool customNodeSerialize(const DOMNode* const nodeToWrite, int level);
DOMNodeFilter::FilterAction checkFilter(const DOMNode* const) const;
bool checkFeature(const XMLCh* const featName
, bool state
, int& featureId) const;
bool reportError(const DOMNode* const errorNode
, DOMError::ErrorSeverity errorType
, const XMLCh* const errorMsg);
bool reportError(const DOMNode* const errorNode
, DOMError::ErrorSeverity errorType
, XMLDOMMsg::Codes toEmit);
bool canSetFeature(const int featureId
, bool val) const;
void setFeature(const int featureId
, bool val);
bool getFeature(const int featureId) const;
void printNewLine();
void setURCharRef();
bool isDefaultNamespacePrefixDeclared() const;
bool isNamespaceBindingActive(const XMLCh* prefix, const XMLCh* uri) const;
void printIndent(unsigned int level);
//does the actual work for processNode while keeping track of the level
void processNode(const DOMNode* const nodeToWrite, int level);
void processBOM();
// -----------------------------------------------------------------------
// Private data members
//
// fFeatures
//
// fNewLine
// own it
//
// fErrorHandler
// don't own it
//
// fFilter
// don't own it
//
// fDocumentVersion
// The XML Version of the document to be serialized.
Boris Kolpackov
committed
//
// fSupportedParameters
// A list of the parameters that can be set, including the ones
// specific of Xerces
//
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// fEncodingUsed (session var)
// the actual encoding used in write(),
// it does not own any data(memory).
//
// fNewLineUsed (session var)
// the actual "end of line" sequence used in write(),
// it does not own any data(memory).
//
// fFormatter (session var)
// the formatter used in write()
//
// fErrorCount
// the count of error encountered in the serialization,
// which neither the error handler, nor the serializer itself,
// treat as fatal. And the serializer will return true/false
// based on this value.
//
// fCurrentLine
// the current line. Used to track the line number the current
// node begins on
//
// -----------------------------------------------------------------------
int fFeatures;
XMLCh *fNewLine;
DOMErrorHandler *fErrorHandler;
DOMLSSerializerFilter *fFilter;
const XMLCh *fDocumentVersion;
//session vars
const XMLCh *fEncodingUsed;
const XMLCh *fNewLineUsed;
XMLFormatter *fFormatter;
int fErrorCount;
int fCurrentLine;
unsigned int fLastWhiteSpaceInTextNode;
RefVectorOf< RefHashTableOf<XMLCh> >* fNamespaceStack;
MemoryManager* fMemoryManager;
};
inline DOMConfiguration* DOMLSSerializerImpl::getDomConfig()
{
return this;
}
inline void DOMLSSerializerImpl::setFeature(const int featureId
, bool val)
{
(val)? fFeatures |= (1<<featureId) : fFeatures &= ~(1<<featureId);
inline bool DOMLSSerializerImpl::getFeature(const int featureId) const
{
return ((fFeatures & ( 1<<featureId )) != 0) ? true : false;