Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 10:27:02

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  *
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  *
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_DOMLSSERIALIZERMPL_HPP)
0023 #define XERCESC_INCLUDE_GUARD_DOMLSSERIALIZERMPL_HPP
0024 
0025 #include <xercesc/dom/DOM.hpp>
0026 #include <xercesc/dom/DOMLSSerializer.hpp>
0027 #include <xercesc/util/XMLDOMMsg.hpp>
0028 #include <xercesc/util/RefHashTableOf.hpp>
0029 #include <xercesc/util/RefVectorOf.hpp>
0030 #include <xercesc/framework/XMLFormatter.hpp>
0031 
0032 XERCES_CPP_NAMESPACE_BEGIN
0033 
0034 class DOMStringListImpl;
0035 
0036 class CDOM_EXPORT DOMLSSerializerImpl : public XMemory,
0037                                         public DOMLSSerializer,
0038                                         public DOMConfiguration
0039 {
0040 
0041 public:
0042 
0043     /** @name Constructor and Destructor */
0044     //@{
0045 
0046     /**
0047      * Constructor.
0048      */
0049     DOMLSSerializerImpl(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0050 
0051     /**
0052      * Destructor.
0053      */
0054     ~DOMLSSerializerImpl();
0055     //@}
0056 
0057     /** @name Implementation of DOMLSSerializer interface */
0058     //@{
0059 
0060     virtual DOMConfiguration*       getDomConfig();
0061 
0062     virtual void                    setNewLine(const XMLCh* const newLine);
0063     virtual const XMLCh*            getNewLine() const;
0064 
0065     virtual void                    setFilter(DOMLSSerializerFilter *filter);
0066     virtual DOMLSSerializerFilter*  getFilter() const;
0067 
0068     virtual bool                    write(const DOMNode*        nodeToWrite,
0069                                           DOMLSOutput* const    destination);
0070     virtual bool                    writeToURI(const DOMNode*   nodeToWrite,
0071                                                const XMLCh*     uri);
0072     /**
0073       *  The caller is responsible for the release of the returned string
0074       */
0075     virtual XMLCh*                  writeToString(const DOMNode* nodeToWrite, MemoryManager* manager = NULL);
0076     virtual void                    release();
0077 
0078     //@}
0079 
0080     /** @name Implementation of DOMConfiguration interface */
0081     //@{
0082     virtual void setParameter(const XMLCh* name, const void* value);
0083     virtual void setParameter(const XMLCh* name, bool value);
0084     virtual const void* getParameter(const XMLCh* name) const;
0085     virtual bool canSetParameter(const XMLCh* name, const void* value) const;
0086     virtual bool canSetParameter(const XMLCh* name, bool value) const;
0087     virtual const DOMStringList* getParameterNames() const;
0088     //@}
0089 
0090 private:
0091 
0092     /** unimplemented copy ctor and assignment operator */
0093     DOMLSSerializerImpl(const DOMLSSerializerImpl&);
0094     DOMLSSerializerImpl & operator = (const DOMLSSerializerImpl&);
0095 
0096 protected:
0097     /** helper **/
0098     void                          processNode(const DOMNode* const);
0099 
0100     void                          procCdataSection(const XMLCh*   const nodeValue
0101                                                  , const DOMNode* const nodeToWrite);
0102 
0103     void                          procUnrepCharInCdataSection(const XMLCh*   const nodeValue
0104                                                             , const DOMNode* const nodeToWrite);
0105 
0106 protected:
0107     /**
0108      * Overidden by derived classes to extend the abilities of the standard writer
0109      * always returns false in the default implementation
0110      * @return true if the method deals with nodeToWrite
0111      */
0112     virtual bool                          customNodeSerialize(const DOMNode* const nodeToWrite, int level);
0113 
0114     DOMNodeFilter::FilterAction   checkFilter(const DOMNode* const) const;
0115 
0116     bool                          checkFeature(const XMLCh* const featName
0117                                              , bool               state
0118                                              , int&               featureId) const;
0119 
0120     bool                          reportError(const DOMNode* const    errorNode
0121                                             , DOMError::ErrorSeverity errorType
0122                                             , const XMLCh*   const    errorMsg);
0123     bool                          reportError(const DOMNode* const    errorNode
0124                                             , DOMError::ErrorSeverity errorType
0125                                             , XMLDOMMsg::Codes        toEmit);
0126 
0127     bool                          canSetFeature(const int featureId
0128                                               , bool      val)     const;
0129     void                          setFeature(const int featureId
0130                                            , bool      val);
0131     bool                          getFeature(const int featureId) const;
0132 
0133     void                          printNewLine();
0134     void                          setURCharRef();
0135     bool                          isDefaultNamespacePrefixDeclared() const;
0136     bool                          isNamespaceBindingActive(const XMLCh* prefix, const XMLCh* uri) const;
0137     void                          ensureValidString(const DOMNode* nodeToWrite, const XMLCh* string);
0138 
0139 
0140     void printIndent(unsigned int level);
0141     //does the actual work for processNode while keeping track of the level
0142     void processNode(const DOMNode* const nodeToWrite, int level);
0143 
0144     void processBOM();
0145 
0146     // -----------------------------------------------------------------------
0147     //  Private data members
0148     //
0149     //  fFeatures
0150     //
0151     //  fNewLine
0152     //      own it
0153     //
0154     //  fErrorHandler
0155     //      don't own it
0156     //
0157     //  fFilter
0158     //      don't own it
0159     //
0160     //  fDocumentVersion
0161     //      The XML Version of the document to be serialized.
0162     //
0163     //  fSupportedParameters
0164     //      A list of the parameters that can be set, including the ones
0165     //      specific of Xerces
0166     //
0167     //  fEncodingUsed (session var)
0168     //      the actual encoding used in write(),
0169     //      it does not own any data(memory).
0170     //
0171     //  fNewLineUsed (session var)
0172     //      the actual "end of line" sequence used in write(),
0173     //      it does not own any data(memory).
0174     //
0175     //  fFormatter (session var)
0176     //      the formatter used in write()
0177     //
0178     //  fErrorCount
0179     //      the count of error encountered in the serialization,
0180     //      which neither the error handler, nor the serializer itself,
0181     //      treat as fatal. And the serializer will return true/false
0182     //      based on this value.
0183     //
0184     //  fCurrentLine
0185     //      the current line. Used to track the line number the current
0186     //      node begins on
0187     //
0188     // -----------------------------------------------------------------------
0189 
0190     int                           fFeatures;
0191     XMLCh                        *fNewLine;
0192     DOMErrorHandler              *fErrorHandler;
0193     DOMLSSerializerFilter        *fFilter;
0194     const XMLCh                  *fDocumentVersion;
0195     DOMStringListImpl            *fSupportedParameters;
0196 
0197     //session vars
0198     const XMLCh                  *fEncodingUsed;
0199     const XMLCh                  *fNewLineUsed;
0200     XMLFormatter                 *fFormatter;
0201     int                           fErrorCount;
0202     int                           fCurrentLine;
0203     bool                          fLineFeedInTextNodePrinted;
0204     unsigned int                  fLastWhiteSpaceInTextNode;
0205     bool                          fIsXml11;
0206 
0207     RefVectorOf< RefHashTableOf<XMLCh> >* fNamespaceStack;
0208     MemoryManager*               fMemoryManager;
0209 };
0210 
0211 inline DOMConfiguration* DOMLSSerializerImpl::getDomConfig()
0212 {
0213     return this;
0214 }
0215 
0216 inline void DOMLSSerializerImpl::setFeature(const int featureId
0217                                     , bool      val)
0218 {
0219     (val)? fFeatures |= (1<<featureId) : fFeatures &= ~(1<<featureId);
0220 }
0221 
0222 inline bool DOMLSSerializerImpl::getFeature(const int featureId) const
0223 {
0224     return ((fFeatures & ( 1<<featureId )) != 0) ? true : false;
0225 }
0226 
0227 inline void DOMLSSerializerImpl::setURCharRef()
0228 {
0229     fFormatter->setUnRepFlags(XMLFormatter::UnRep_CharRef);
0230 }
0231 
0232 XERCES_CPP_NAMESPACE_END
0233 
0234 #endif