You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ne...@apache.org on 2003/11/27 22:29:05 UTC
cvs commit: xml-xerces/c/src/xercesc/framework/psvi XSAnnotation.cpp XSAnnotation.hpp
neilg 2003/11/27 13:29:05
Modified: c/src/xercesc/framework/psvi XSAnnotation.cpp
XSAnnotation.hpp
Log:
implement writeAnnotation; thanks to Dave Cargill
Revision Changes Path
1.6 +71 -20 xml-xerces/c/src/xercesc/framework/psvi/XSAnnotation.cpp
Index: XSAnnotation.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/psvi/XSAnnotation.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XSAnnotation.cpp 14 Nov 2003 22:47:53 -0000 1.5
+++ XSAnnotation.cpp 27 Nov 2003 21:29:05 -0000 1.6
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.6 2003/11/27 21:29:05 neilg
+ * implement writeAnnotation; thanks to Dave Cargill
+ *
* Revision 1.5 2003/11/14 22:47:53 neilg
* fix bogus log message from previous commit...
*
@@ -79,6 +82,13 @@
#include <xercesc/framework/psvi/XSAnnotation.hpp>
#include <xercesc/util/XMLString.hpp>
+#include <xercesc/framework/MemBufInputSource.hpp>
+
+#include <xercesc/sax2/SAX2XMLReader.hpp>
+#include <xercesc/sax2/XMLReaderFactory.hpp>
+#include <xercesc/parsers/XercesDOMParser.hpp>
+#include <xercesc/dom/DOMElement.hpp>
+
XERCES_CPP_NAMESPACE_BEGIN
XSAnnotation::XSAnnotation(const XMLCh* const content,
@@ -105,28 +115,69 @@
}
// XSAnnotation methods
-
-/**
- * Write contents of the annotation to the specified object. If the
- * specified <code>target</code> object is a DOM in-scope namespace
- * declarations for <code>annotation</code> element are added as
- * attribute nodes of the serialized <code>annotation</code>, otherwise
- * the corresponding events for all in-scope namespace declaration are
- * sent via the specified document handler.
- * @param target A target pointer to the annotation target object, i.e.
- * <code>DOMDocument</code>,
- * <code>DOMElement</code>,
- * <code>ContentHandler</code>.
- * @param targetType A target type.
- * @return If the <code>target</code> is a recognized type that is supported by
- * this implementation, and the operation succeeds, return true; otherwise return false.
- */
-bool XSAnnotation::writeAnnotation(void *target,
- ANNOTATION_TARGET targetType)
+void XSAnnotation::writeAnnotation(DOMNode* node, ANNOTATION_TARGET targetType)
{
- // REVISIT
- return false;
+ XercesDOMParser *parser = new (fMemoryManager) XercesDOMParser(0, fMemoryManager);
+ parser->setDoNamespaces(true);
+ parser->setValidationScheme(XercesDOMParser::Val_Never);
+
+ DOMDocument* futureOwner = (targetType == W3C_DOM_ELEMENT) ?
+ ((DOMElement*)node)->getOwnerDocument() :
+ (DOMDocument*)node;
+
+ MemBufInputSource* memBufIS = new (fMemoryManager) MemBufInputSource
+ (
+ (const XMLByte*)fContents
+ , XMLString::stringLen(fContents)*sizeof(XMLCh)
+ , ""
+ , false
+ , fMemoryManager
+ );
+
+ try
+ {
+ parser->parse(*memBufIS);
+ }
+ catch (const XMLException&)
+ {
+ }
+
+ DOMNode* newElem = futureOwner->importNode((parser->getDocument())->getDocumentElement(), true);
+ node->insertBefore(newElem, node->getFirstChild());
+
+ delete parser;
+ delete memBufIS;
+}
+
+
+void XSAnnotation::writeAnnotation(ContentHandler* handler)
+{
+ SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(fMemoryManager);
+ parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
+ parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
+ parser->setContentHandler(handler);
+
+ MemBufInputSource* memBufIS = new (fMemoryManager) MemBufInputSource
+ (
+ (const XMLByte*)fContents
+ , XMLString::stringLen(fContents)*sizeof(XMLCh)
+ , ""
+ , false
+ , fMemoryManager
+ );
+
+ try
+ {
+ parser->parse(*memBufIS);
+ }
+ catch (const XMLException&)
+ {
+ }
+
+ delete parser;
+ delete memBufIS;
}
+
void XSAnnotation::setNext(XSAnnotation* const nextAnnotation)
{
1.6 +22 -16 xml-xerces/c/src/xercesc/framework/psvi/XSAnnotation.hpp
Index: XSAnnotation.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/psvi/XSAnnotation.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XSAnnotation.hpp 14 Nov 2003 22:47:53 -0000 1.5
+++ XSAnnotation.hpp 27 Nov 2003 21:29:05 -0000 1.6
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.6 2003/11/27 21:29:05 neilg
+ * implement writeAnnotation; thanks to Dave Cargill
+ *
* Revision 1.5 2003/11/14 22:47:53 neilg
* fix bogus log message from previous commit...
*
@@ -91,6 +94,9 @@
* it is obtained.
*/
+// forward declarations
+class DOMNode;
+class ContentHandler;
class XMLPARSER_EXPORT XSAnnotation : public XSerializable, public XSObject
{
@@ -106,10 +112,6 @@
* The object type is <code>org.w3c.dom.Document</code>.
*/
W3C_DOM_DOCUMENT = 2,
- /**
- * The object type is <code>org.xml.sax.ContentHandler</code>.
- */
- SAX_CONTENTHANDLER = 3
};
// Constructors and Destructor
@@ -141,21 +143,25 @@
//@{
/**
- * Write contents of the annotation to the specified object. If the
- * specified <code>target</code> object is a DOM in-scope namespace
- * declarations for <code>annotation</code> element are added as
- * attribute nodes of the serialized <code>annotation</code>, otherwise
- * the corresponding events for all in-scope namespace declaration are
+ * Write contents of the annotation to the specified DOM object. In-scope
+ * namespace declarations for <code>annotation</code> element are added as
+ * attribute nodes of the serialized <code>annotation</code>.
+ * @param target A target pointer to the annotation target object, i.e.
+ * either <code>DOMDocument</code> or <code>DOMElement</code> cast as
+ * <code>DOMNode</code).
+ * @param targetType A target type.
+ */
+
+ void writeAnnotation(DOMNode* node, ANNOTATION_TARGET targetType);
+
+ /**
+ * Write contents of the annotation to the specified object.
+ * The corresponding events for all in-scope namespace declarations are
* sent via the specified document handler.
* @param target A target pointer to the annotation target object, i.e.
- * <code>DOMDocument</code>,
- * <code>DOMElement</code>,
* <code>ContentHandler</code>.
- * @param targetType A target type.
- * @return If the <code>target</code> is a recognized type that is supported by
- * this implementation, and the operation succeeds, return true; otherwise return false.
- */
- bool writeAnnotation(void *target, ANNOTATION_TARGET targetType);
+ */
+ void writeAnnotation(ContentHandler* handler);
/**
* A text representation of annotation.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org