You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by tn...@apache.org on 2001/06/19 18:45:11 UTC
cvs commit: xml-xerces/c/src/parsers SAX2XMLReaderImpl.cpp SAX2XMLReaderImpl.hpp
tng 01/06/19 09:45:11
Modified: c/src/parsers SAX2XMLReaderImpl.cpp SAX2XMLReaderImpl.hpp
Log:
Add installAdvDocHandler to SAX2XMLReader as the code is there already.
Revision Changes Path
1.14 +104 -5 xml-xerces/c/src/parsers/SAX2XMLReaderImpl.cpp
Index: SAX2XMLReaderImpl.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/parsers/SAX2XMLReaderImpl.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- SAX2XMLReaderImpl.cpp 2001/06/03 19:26:19 1.13
+++ SAX2XMLReaderImpl.cpp 2001/06/19 16:45:08 1.14
@@ -56,6 +56,9 @@
/*
* $Log: SAX2XMLReaderImpl.cpp,v $
+ * Revision 1.14 2001/06/19 16:45:08 tng
+ * Add installAdvDocHandler to SAX2XMLReader as the code is there already.
+ *
* Revision 1.13 2001/06/03 19:26:19 jberry
* Add support for querying error count following parse; enables simple parse without requiring error handler.
*
@@ -330,7 +333,94 @@
delete prefixCounts ;
}
+// ---------------------------------------------------------------------------
+// SAX2XMLReaderImpl: Advanced document handler list maintenance methods
+// ---------------------------------------------------------------------------
+void SAX2XMLReaderImpl::installAdvDocHandler(XMLDocumentHandler* const toInstall)
+{
+ // See if we need to expand and do so now if needed
+ if (fAdvDHCount == fAdvDHListSize)
+ {
+ // Calc a new size and allocate the new temp buffer
+ const unsigned int newSize = (unsigned int)(fAdvDHListSize * 1.5);
+ XMLDocumentHandler** newList = new XMLDocumentHandler*[newSize];
+
+ // Copy over the old data to the new list and zero out the rest
+ memcpy(newList, fAdvDHList, sizeof(void*) * fAdvDHListSize);
+ memset
+ (
+ &newList[fAdvDHListSize]
+ , 0
+ , sizeof(void*) * (newSize - fAdvDHListSize)
+ );
+
+ // And now clean up the old array and store the new stuff
+ delete [] fAdvDHList;
+ fAdvDHList = newList;
+ fAdvDHListSize = newSize;
+ }
+
+ // Add this new guy into the empty slot
+ fAdvDHList[fAdvDHCount++] = toInstall;
+
+ //
+ // Install ourself as the document handler with the scanner. We might
+ // already be, but its not worth checking, just do it.
+ //
+ fScanner->setDocHandler(this);
+}
+
+
+bool SAX2XMLReaderImpl::removeAdvDocHandler(XMLDocumentHandler* const toRemove)
+{
+ // If our count is zero, can't be any installed
+ if (!fAdvDHCount)
+ return false;
+ //
+ // Search the array until we find this handler. If we find a null entry
+ // first, we can stop there before the list is kept contiguous.
+ //
+ unsigned int index;
+ for (index = 0; index < fAdvDHCount; index++)
+ {
+ //
+ // We found it. We have to keep the list contiguous, so we have to
+ // copy down any used elements after this one.
+ //
+ if (fAdvDHList[index] == toRemove)
+ {
+ //
+ // Optimize if only one entry (pretty common). Otherwise, we
+ // have to copy them down to compact them.
+ //
+ if (fAdvDHCount > 1)
+ {
+ index++;
+ while (index < fAdvDHCount)
+ fAdvDHList[index - 1] = fAdvDHList[index];
+ }
+
+ // Bump down the count and zero out the last one
+ fAdvDHCount--;
+ fAdvDHList[fAdvDHCount] = 0;
+
+ //
+ // If this leaves us with no advanced handlers and there is
+ // no SAX doc handler installed on us, then remove us from the
+ // scanner as the document handler.
+ //
+ if (!fAdvDHCount && !fDocHandler)
+ fScanner->setDocHandler(0);
+
+ return true;
+ }
+ }
+
+ // Never found it
+ return false;
+}
+
// ---------------------------------------------------------------------------
// SAX2XMLReaderImpl Validator functions
// ---------------------------------------------------------------------------
@@ -483,6 +573,7 @@
}
}
+
// ---------------------------------------------------------------------------
// SAX2XMLReaderImpl: Overrides of the XMLDocumentHandler interface
// ---------------------------------------------------------------------------
@@ -538,12 +629,20 @@
}
-void SAX2XMLReaderImpl::XMLDecl(const XMLCh* const
- , const XMLCh* const
- , const XMLCh* const
- , const XMLCh* const)
+void SAX2XMLReaderImpl::XMLDecl( const XMLCh* const versionStr
+ , const XMLCh* const encodingStr
+ , const XMLCh* const standaloneStr
+ , const XMLCh* const actualEncodingStr
+ )
{
- // SAX has no way to report this event
+ // SAX has no way to report this event. But, if there are any installed
+ // advanced handlers, then lets call them with this info.
+ //
+ for (unsigned int index = 0; index < fAdvDHCount; index++)
+ fAdvDHList[index]->XMLDecl( versionStr,
+ encodingStr,
+ standaloneStr,
+ actualEncodingStr );
}
1.11 +99 -24 xml-xerces/c/src/parsers/SAX2XMLReaderImpl.hpp
Index: SAX2XMLReaderImpl.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/parsers/SAX2XMLReaderImpl.hpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- SAX2XMLReaderImpl.hpp 2001/06/04 21:01:49 1.10
+++ SAX2XMLReaderImpl.hpp 2001/06/19 16:45:08 1.11
@@ -56,6 +56,9 @@
/*
* $Log: SAX2XMLReaderImpl.hpp,v $
+ * Revision 1.11 2001/06/19 16:45:08 tng
+ * Add installAdvDocHandler to SAX2XMLReader as the code is there already.
+ *
* Revision 1.10 2001/06/04 21:01:49 jberry
* getErrorCount is virtual in this class reflecting derivation from SAX2XMLReader.
*
@@ -1018,6 +1021,39 @@
virtual XMLValidator* getValidator() const;
//@}
+ // -----------------------------------------------------------------------
+ // Advanced document handler list maintenance methods
+ // -----------------------------------------------------------------------
+
+ /** @name Advanced document handler list maintenance methods */
+ //@{
+ /**
+ * This method installs the specified 'advanced' document callback
+ * handler, thereby allowing the user to customize the processing,
+ * if they choose to do so. Any number of advanced callback handlers
+ * maybe installed.
+ *
+ * <p>The methods in the advanced callback interface represent
+ * Xerces-C extensions. There is no specification for this interface.</p>
+ *
+ * @param toInstall A pointer to the users advanced callback handler.
+ *
+ * @see #removeAdvDocHandler
+ */
+ virtual void installAdvDocHandler(XMLDocumentHandler* const toInstall);
+
+ /**
+ * This method removes the 'advanced' document handler callback from
+ * the underlying parser scanner. If no handler is installed, advanced
+ * callbacks are not invoked by the scanner.
+ * @param toRemove A pointer to the advanced callback handler which
+ * should be removed.
+ *
+ * @see #installAdvDocHandler
+ */
+ virtual bool removeAdvDocHandler(XMLDocumentHandler* const toRemove);
+ //@}
+
private :
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
@@ -1035,30 +1071,69 @@
//
// fDocHandler
// The installed SAX content handler, if any. Null if none.
+ //
+ // fnamespacePrefix
+ // Indicates whether the namespace-prefix feature is on or off.
+ //
+ // fautoValidation
+ // Indicates whether automatic validation is on or off
+ //
+ // fValidation
+ // Indicates whether the 'validation' core features is on or off
+ //
+ // fReuseGrammar
+ // Tells the parser whether it should reuse the grammar or not.
+ // If true, there cannot be any internal subset.
+ //
+ // fStringBuffers
+ // Any temporary strings we need are pulled out of this pool
+ //
+ // fPrefixes
+ // A Stack of the current namespace prefixes that need calls to
+ // endPrefixMapping
+ //
+ // fPrefixCounts
+ // A Stack of the number of prefixes that need endPrefixMapping
+ // calls for that element
+ //
+ // fDTDHandler
+ // The installed SAX DTD handler, if any. Null if none.
+ //
+ // fElemDepth
+ // This is used to track the element nesting depth, so that we can
+ // know when we are inside content. This is so we can ignore char
+ // data outside of content.
+ //
+ // fEntityResolver
+ // The installed SAX entity handler, if any. Null if none.
+ //
+ // fErrorHandler
+ // The installed SAX error handler, if any. Null if none.
+ //
+ // fLexicalHandler
+ // The installed SAX lexical handler, if any. Null if none.
+ //
+ // fAdvDHCount
+ // fAdvDHList
+ // fAdvDHListSize
+ // This is an array of pointers to XMLDocumentHandlers, which is
+ // how we see installed advanced document handlers. There will
+ // usually not be very many at all, so a simple array is used
+ // instead of a collection, for performance. It will grow if needed,
+ // but that is unlikely.
+ //
+ // The count is how many handlers are currently installed. The size
+ // is how big the array itself is (for expansion purposes.) When
+ // count == size, is time to expand.
+ //
+ // fParseInProgress
+ // This flag is set once a parse starts. It is used to prevent
+ // multiple entrance or reentrance of the parser.
+ //
+ // fScanner
+ // The scanner being used by this parser. It is created internally
+ // during construction.
//
- // fnamespacePrefix
- // Indicates whether the namespace-prefix feature is on or off.
- //
- // fautoValidation
- // Indicates whether automatic validation is on or off
- //
- // fValidation
- // Indicates whether the 'validation' core features is on or off
- //
- // fReuseGrammar
- // Tells the parser whether it should reuse the grammar or not.
- // If true, there cannot be any internal subset.
- //
- // fStringBuffers
- // Any temporary strings we need are pulled out of this pool
- //
- // fPrefixes
- // A Stack of the current namespace prefixes that need calls to
- // endPrefixMapping
- //
- // fPrefixCounts
- // A Stack of the number of prefixes that need endPrefixMapping
- // calls for that element
// -----------------------------------------------------------------------
VecAttributesImpl fAttrList ;
ContentHandler* fDocHandler ;
@@ -1077,7 +1152,7 @@
unsigned int fElemDepth;
EntityResolver* fEntityResolver;
ErrorHandler* fErrorHandler;
- LexicalHandler* fLexicalHandler;
+ LexicalHandler* fLexicalHandler;
unsigned int fAdvDHCount;
XMLDocumentHandler** fAdvDHList;
unsigned int fAdvDHListSize;
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org