You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ja...@apache.org on 2006/10/13 23:10:54 UTC
svn commit: r463831 - in /xerces/c/trunk/swig/perl/Handler:
PerlContentCallbackHandler.cpp PerlContentCallbackHandler.hpp
PerlDocumentCallbackHandler.cpp PerlDocumentCallbackHandler.hpp
PerlSAXCallbackHandler.cpp PerlSAXCallbackHandler.hpp
Author: jasons
Date: Fri Oct 13 14:10:53 2006
New Revision: 463831
URL: http://svn.apache.org/viewvc?view=rev&rev=463831
Log:
new attempt to centralize all callback handlers by module instead of by class
Added:
xerces/c/trunk/swig/perl/Handler/PerlSAXCallbackHandler.cpp
xerces/c/trunk/swig/perl/Handler/PerlSAXCallbackHandler.hpp
Removed:
xerces/c/trunk/swig/perl/Handler/PerlContentCallbackHandler.cpp
xerces/c/trunk/swig/perl/Handler/PerlContentCallbackHandler.hpp
xerces/c/trunk/swig/perl/Handler/PerlDocumentCallbackHandler.cpp
xerces/c/trunk/swig/perl/Handler/PerlDocumentCallbackHandler.hpp
Added: xerces/c/trunk/swig/perl/Handler/PerlSAXCallbackHandler.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/swig/perl/Handler/PerlSAXCallbackHandler.cpp?view=auto&rev=463831
==============================================================================
--- xerces/c/trunk/swig/perl/Handler/PerlSAXCallbackHandler.cpp (added)
+++ xerces/c/trunk/swig/perl/Handler/PerlSAXCallbackHandler.cpp Fri Oct 13 14:10:53 2006
@@ -0,0 +1,438 @@
+/*
+ * Copyright 2002,2004 The Apache Software Foundation.
+ *
+ * Licensed 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+#include <stdlib.h>
+#include "PerlSAXCallbackHandler.hpp"
+
+XERCES_CPP_NAMESPACE_USE
+
+PerlSAXCallbackHandler::PerlSAXCallbackHandler()
+{
+ callbackObj = NULL;
+}
+
+PerlSAXCallbackHandler::~PerlSAXCallbackHandler()
+{}
+
+PerlSAXCallbackHandler::PerlSAXCallbackHandler(SV *obj)
+{
+ set_callback_obj(obj);
+}
+
+void
+PerlSAXCallbackHandler::startElement(const XMLCh* const uri,
+ const XMLCh* const localname,
+ const XMLCh* const qname,
+ const Attributes& attrs)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // the next argument is the uri
+ SV *string1 = UTF8_TRANSCODER->XMLString2Local(uri);
+ XPUSHs(string1);
+
+ // the next argument is the localname
+ SV *string2 = UTF8_TRANSCODER->XMLString2Local(localname);
+ XPUSHs(string2);
+
+ // the next argument is the qname
+ SV *string3 = UTF8_TRANSCODER->XMLString2Local(qname);
+ XPUSHs(string3);
+
+ // next is the attributes
+ char *class_name = "XML::Xerces::Attributes";
+ XPUSHs(sv_setref_pv(sv_newmortal(),
+ class_name,
+ (void *)&attrs));
+ PUTBACK;
+
+ perl_call_method("startElement", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::endElement(const XMLCh* const uri,
+ const XMLCh* const localname,
+ const XMLCh* const qname)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // the next argument is the uri
+ SV *string1 = UTF8_TRANSCODER->XMLString2Local(uri);
+ XPUSHs(string1);
+
+ // the next argument is the localname
+ SV *string2 = UTF8_TRANSCODER->XMLString2Local(localname);
+ XPUSHs(string2);
+
+ // the next argument is the qname
+ SV *string3 = UTF8_TRANSCODER->XMLString2Local(qname);
+ XPUSHs(string3);
+
+ PUTBACK;
+
+ perl_call_method("endElement", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::startElement(const XMLCh* const localname,
+ AttributeList& attrs)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // the next argument is the localname
+ SV *string2 = UTF8_TRANSCODER->XMLString2Local(localname);
+ XPUSHs(string2);
+
+ // next is the attributes
+ char *class_name = "XML::Xerces::AttributeList";
+ XPUSHs(sv_setref_pv(sv_newmortal(),
+ class_name,
+ (void *)&attrs));
+ PUTBACK;
+
+ perl_call_method("startElement", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::endElement(const XMLCh* const localname)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // the next argument is the localname
+ SV *string2 = UTF8_TRANSCODER->XMLString2Local(localname);
+ XPUSHs(string2);
+
+ PUTBACK;
+
+ perl_call_method("endElement", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::characters(const XMLCh* const chars,
+ const unsigned int length)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // the next argument is the char data
+ SV *string = UTF8_TRANSCODER->XMLString2Local(chars);
+ XPUSHs(string);
+
+ // next is the length
+ XPUSHs(sv_2mortal(newSViv(length)));
+
+ PUTBACK;
+
+ perl_call_method("characters", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+void
+PerlSAXCallbackHandler::ignorableWhitespace(const XMLCh* const chars,
+ const unsigned int length)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // the next argument is the char data
+ SV *string = UTF8_TRANSCODER->XMLString2Local(chars);
+ XPUSHs(string);
+
+ // next is the length
+ XPUSHs(sv_2mortal(newSViv(length)));
+
+ PUTBACK;
+
+ perl_call_method("ignorableWhitespace", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::resetDocument(void)
+{
+ return;
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ PUTBACK;
+
+ perl_call_method("resetDocument", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::startDocument(void)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ PUTBACK;
+
+ perl_call_method("startDocument", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::endDocument(void)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ PUTBACK;
+
+ perl_call_method("endDocument", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+
+void
+PerlSAXCallbackHandler::processingInstruction(const XMLCh* const target,
+ const XMLCh* const data)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // the next argument is the target
+ SV *string1 = UTF8_TRANSCODER->XMLString2Local(target);
+ XPUSHs(string1);
+
+ // the next argument is the data
+ SV *string2 = UTF8_TRANSCODER->XMLString2Local(data);
+ XPUSHs(string2);
+
+ PUTBACK;
+
+ perl_call_method("processingInstruction", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::setDocumentLocator(const Locator* const locator)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // next is the attribute list
+ char *class_name = "XML::Xerces::Locator";
+ XPUSHs(sv_setref_pv(sv_newmortal(),
+ class_name,
+ (void *)locator));
+
+ PUTBACK;
+
+ perl_call_method("setDocumentLocator", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::startPrefixMapping (const XMLCh* const prefix,
+ const XMLCh* const uri)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // the next argument is the prefix
+ SV *string1 = UTF8_TRANSCODER->XMLString2Local(prefix);
+ XPUSHs(string1);
+
+ // the next argument is the uri
+ SV *string2 = UTF8_TRANSCODER->XMLString2Local(uri);
+ XPUSHs(string2);
+
+ PUTBACK;
+
+ perl_call_method("startPrefixMapping", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::endPrefixMapping (const XMLCh* const prefix)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // the next argument is the prefix
+ SV *string1 = UTF8_TRANSCODER->XMLString2Local(prefix);
+ XPUSHs(string1);
+
+ PUTBACK;
+
+ perl_call_method("endPrefixMapping", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
+
+void
+PerlSAXCallbackHandler::skippedEntity (const XMLCh* const name)
+{
+ if (!callbackObj) return;
+
+ dSP;
+
+ ENTER;
+ SAVETMPS;
+
+ PUSHMARK(SP);
+ // first put the callback object on the stack
+ XPUSHs(callbackObj);
+
+ // the next argument is the name
+ SV *string1 = UTF8_TRANSCODER->XMLString2Local(name);
+ XPUSHs(string1);
+
+ PUTBACK;
+
+ perl_call_method("skippedEntity", G_VOID);
+
+ FREETMPS;
+ LEAVE;
+}
Added: xerces/c/trunk/swig/perl/Handler/PerlSAXCallbackHandler.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/swig/perl/Handler/PerlSAXCallbackHandler.hpp?view=auto&rev=463831
==============================================================================
--- xerces/c/trunk/swig/perl/Handler/PerlSAXCallbackHandler.hpp (added)
+++ xerces/c/trunk/swig/perl/Handler/PerlSAXCallbackHandler.hpp Fri Oct 13 14:10:53 2006
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2002,2004 The Apache Software Foundation.
+ *
+ * Licensed 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+#ifndef __PERLSAXCALLBACKHANDLER
+#define __PERLSAXCALLBACKHANDLER
+
+#include "PerlCallbackHandler.hpp"
+#include "xercesc/sax/DocumentHandler.hpp"
+#include "xercesc/sax2/ContentHandler.hpp"
+#include "xercesc/util/XMLString.hpp"
+
+XERCES_CPP_NAMESPACE_BEGIN
+
+class PerlSAXCallbackHandler : public ContentHandler
+ , public DocumentHandler
+ , public PerlCallbackHandler
+{
+
+protected:
+
+public:
+
+ PerlSAXCallbackHandler();
+ PerlSAXCallbackHandler(SV *obj);
+ ~PerlSAXCallbackHandler();
+
+ int type() {return PERLCALLBACKHANDLER_SAX_TYPE;}
+
+ // The DocumentHandler interface
+ void characters(const XMLCh* const chars,
+ const unsigned int length);
+ void ignorableWhitespace(const XMLCh* const chars,
+ const unsigned int length);
+ void startElement(const XMLCh* const, AttributeList&);
+ void endElement(const XMLCh* const);
+
+ void resetDocument();
+ void startDocument();
+ void endDocument();
+ void processingInstruction (const XMLCh* const target,
+ const XMLCh* const data);
+ void setDocumentLocator(const Locator* const locator);
+
+ // The ContentHandler interface
+ void startElement(const XMLCh* const uri,
+ const XMLCh* const localname,
+ const XMLCh* const qname,
+ const Attributes& attrs);
+ void endElement(const XMLCh* const uri,
+ const XMLCh* const localname,
+ const XMLCh* const qname);
+ void startPrefixMapping (const XMLCh* const prefix,
+ const XMLCh* const uri);
+ void endPrefixMapping (const XMLCh* const prefix);
+ void skippedEntity (const XMLCh* const name);
+};
+
+XERCES_CPP_NAMESPACE_END
+
+#endif /* __PERLSAXCALLBACKHANDLER */
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org