diff --git a/swig/perl/Handler/PerlDocumentCallbackHandler.cpp b/swig/perl/Handler/PerlDocumentCallbackHandler.cpp deleted file mode 100644 index 33d5b33e7c3ffeb001fa704b137c495366f34e6d..0000000000000000000000000000000000000000 --- a/swig/perl/Handler/PerlDocumentCallbackHandler.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/* - * 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 "PerlDocumentCallbackHandler.hpp" - -PerlDocumentCallbackHandler::PerlDocumentCallbackHandler() -{ - callbackObj = NULL; -} - -PerlDocumentCallbackHandler::~PerlDocumentCallbackHandler() -{} - -PerlDocumentCallbackHandler::PerlDocumentCallbackHandler(SV *obj) -{ - set_callback_obj(obj); -} - -// SV* -// PerlDocumentCallbackHandler::set_callback_obj(SV* object) { -// SV *oldRef = &PL_sv_undef; // default to 'undef' -// if (callbackObj != NULL) { -// oldRef = callbackObj; -// #if defined(PERL_VERSION) && PERL_VERSION >= 8 -// // SvREFCNT_dec(oldRef); -// #endif -// } -// SvREFCNT_inc(object); -// callbackObj = object; -// return oldRef; -// } - -void -PerlDocumentCallbackHandler::startElement(const XMLCh* const name, - AttributeList& attributes) { - if (!callbackObj) return; - - dSP; - - ENTER; - SAVETMPS; - - PUSHMARK(SP); - // first put the callback object on the stack - XPUSHs(callbackObj); - - // the next argument is the element name - SV *string = UTF8_TRANSCODER->XMLString2Perl(name); - XPUSHs(string); - - // next is the attribute list - char *class_name = "XML::Xerces::AttributeList"; - XPUSHs(sv_setref_pv(sv_newmortal(), - class_name, - (void *)&attributes)); - - PUTBACK; - - perl_call_method("start_element", G_DISCARD); - - FREETMPS; - LEAVE; -} - -void -PerlDocumentCallbackHandler::endElement(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 element name - SV *string = UTF8_TRANSCODER->XMLString2Perl(name); - XPUSHs(string); - - PUTBACK; - - perl_call_method("end_element", G_DISCARD); - - FREETMPS; - LEAVE; -} - -void -PerlDocumentCallbackHandler::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->XMLString2Perl(chars); - XPUSHs(string); - - // next is the length - XPUSHs(sv_2mortal(newSViv(length))); - - PUTBACK; - - perl_call_method("characters", G_DISCARD); - - FREETMPS; - LEAVE; -} -void -PerlDocumentCallbackHandler::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 element name - SV *string = UTF8_TRANSCODER->XMLString2Perl(chars); - XPUSHs(string); - - // next is the length - XPUSHs(sv_2mortal(newSViv(length))); - - PUTBACK; - - perl_call_method("ignorable_whitespace", G_DISCARD); - - FREETMPS; - LEAVE; -} - -void -PerlDocumentCallbackHandler::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("reset_document", G_DISCARD); - - FREETMPS; - LEAVE; -} - -void -PerlDocumentCallbackHandler::startDocument(void) -{ - if (!callbackObj) return; - - dSP; - - ENTER; - SAVETMPS; - - PUSHMARK(SP); - // first put the callback object on the stack - XPUSHs(callbackObj); - - PUTBACK; - - perl_call_method("start_document", G_DISCARD); - - FREETMPS; - LEAVE; -} - -void -PerlDocumentCallbackHandler::endDocument(void) -{ - if (!callbackObj) return; - - dSP; - - ENTER; - SAVETMPS; - - PUSHMARK(SP); - // first put the callback object on the stack - XPUSHs(callbackObj); - - PUTBACK; - - perl_call_method("end_document", G_DISCARD); - - FREETMPS; - LEAVE; -} - - -void -PerlDocumentCallbackHandler::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->XMLString2Perl(target); - XPUSHs(string1); - - // the next argument is the data - SV *string2 = UTF8_TRANSCODER->XMLString2Perl(data); - XPUSHs(string2); - - PUTBACK; - - perl_call_method("processing_instruction", G_DISCARD); - - FREETMPS; - LEAVE; -} - -void -PerlDocumentCallbackHandler::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("set_document_locator", G_DISCARD); - - FREETMPS; - LEAVE; -} - diff --git a/swig/perl/Handler/PerlDocumentCallbackHandler.hpp b/swig/perl/Handler/PerlDocumentCallbackHandler.hpp deleted file mode 100644 index 29fad2279cedb30980f8c0539cc4df9aad2fd5a8..0000000000000000000000000000000000000000 --- a/swig/perl/Handler/PerlDocumentCallbackHandler.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 __PERLDOCUMENTCALLBACKHANDLER -#define __PERLDOCUMENTCALLBACKHANDLER - -#include "PerlCallbackHandler.hpp" -#include "xercesc/sax/DocumentHandler.hpp" -#include "xercesc/util/XMLString.hpp" - -XERCES_CPP_NAMESPACE_USE - - -class PerlDocumentCallbackHandler : public DocumentHandler - , public PerlCallbackHandler -{ - -protected: - -public: - - PerlDocumentCallbackHandler(); - PerlDocumentCallbackHandler(SV *obj); - ~PerlDocumentCallbackHandler(); - - int type() {return PERLCALLBACKHANDLER_DOCUMENT_TYPE;} - - // The DocumentHandler interface - void startElement(const XMLCh* const name, - AttributeList& attributes); - void characters(const XMLCh* const chars, - const unsigned int length); - void ignorableWhitespace(const XMLCh* const chars, - const unsigned int length); - void endElement(const XMLCh* const name); - void resetDocument(); - void startDocument(); - void endDocument(); - void processingInstruction (const XMLCh* const target, - const XMLCh* const data); - void setDocumentLocator(const Locator* const locator); - -}; - -#endif /* __PERLDOCUMENTCALLBACKHANDLER */ diff --git a/swig/perl/Handler/PerlContentCallbackHandler.cpp b/swig/perl/Handler/PerlSAXCallbackHandler.cpp similarity index 59% rename from swig/perl/Handler/PerlContentCallbackHandler.cpp rename to swig/perl/Handler/PerlSAXCallbackHandler.cpp index 7ca123f1366457a5902b585d7b2ef8ba5265d924..6e777afbfe163d99ff0855b707bb4037f70349e6 100644 --- a/swig/perl/Handler/PerlContentCallbackHandler.cpp +++ b/swig/perl/Handler/PerlSAXCallbackHandler.cpp @@ -15,23 +15,25 @@ */ #include <stdlib.h> -#include "PerlContentCallbackHandler.hpp" +#include "PerlSAXCallbackHandler.hpp" -PerlContentCallbackHandler::PerlContentCallbackHandler() +XERCES_CPP_NAMESPACE_USE + +PerlSAXCallbackHandler::PerlSAXCallbackHandler() { callbackObj = NULL; } -PerlContentCallbackHandler::~PerlContentCallbackHandler() +PerlSAXCallbackHandler::~PerlSAXCallbackHandler() {} -PerlContentCallbackHandler::PerlContentCallbackHandler(SV *obj) +PerlSAXCallbackHandler::PerlSAXCallbackHandler(SV *obj) { set_callback_obj(obj); } void -PerlContentCallbackHandler::startElement(const XMLCh* const uri, +PerlSAXCallbackHandler::startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs) @@ -48,15 +50,15 @@ PerlContentCallbackHandler::startElement(const XMLCh* const uri, XPUSHs(callbackObj); // the next argument is the uri - SV *string1 = UTF8_TRANSCODER->XMLString2Perl(uri); + SV *string1 = UTF8_TRANSCODER->XMLString2Local(uri); XPUSHs(string1); // the next argument is the localname - SV *string2 = UTF8_TRANSCODER->XMLString2Perl(localname); + SV *string2 = UTF8_TRANSCODER->XMLString2Local(localname); XPUSHs(string2); // the next argument is the qname - SV *string3 = UTF8_TRANSCODER->XMLString2Perl(qname); + SV *string3 = UTF8_TRANSCODER->XMLString2Local(qname); XPUSHs(string3); // next is the attributes @@ -66,14 +68,14 @@ PerlContentCallbackHandler::startElement(const XMLCh* const uri, (void *)&attrs)); PUTBACK; - perl_call_method("start_element", G_VOID); + perl_call_method("startElement", G_VOID); FREETMPS; LEAVE; } void -PerlContentCallbackHandler::endElement(const XMLCh* const uri, +PerlSAXCallbackHandler::endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname) { @@ -89,27 +91,85 @@ PerlContentCallbackHandler::endElement(const XMLCh* const uri, XPUSHs(callbackObj); // the next argument is the uri - SV *string1 = UTF8_TRANSCODER->XMLString2Perl(uri); + SV *string1 = UTF8_TRANSCODER->XMLString2Local(uri); XPUSHs(string1); // the next argument is the localname - SV *string2 = UTF8_TRANSCODER->XMLString2Perl(localname); + SV *string2 = UTF8_TRANSCODER->XMLString2Local(localname); XPUSHs(string2); // the next argument is the qname - SV *string3 = UTF8_TRANSCODER->XMLString2Perl(qname); + SV *string3 = UTF8_TRANSCODER->XMLString2Local(qname); XPUSHs(string3); PUTBACK; - perl_call_method("end_element", G_VOID); + 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 -PerlContentCallbackHandler::characters(const XMLCh* const chars, +PerlSAXCallbackHandler::characters(const XMLCh* const chars, const unsigned int length) { if (!callbackObj) return; @@ -124,7 +184,7 @@ PerlContentCallbackHandler::characters(const XMLCh* const chars, XPUSHs(callbackObj); // the next argument is the char data - SV *string = UTF8_TRANSCODER->XMLString2Perl(chars); + SV *string = UTF8_TRANSCODER->XMLString2Local(chars); XPUSHs(string); // next is the length @@ -138,7 +198,7 @@ PerlContentCallbackHandler::characters(const XMLCh* const chars, LEAVE; } void -PerlContentCallbackHandler::ignorableWhitespace(const XMLCh* const chars, +PerlSAXCallbackHandler::ignorableWhitespace(const XMLCh* const chars, const unsigned int length) { if (!callbackObj) return; @@ -153,7 +213,7 @@ PerlContentCallbackHandler::ignorableWhitespace(const XMLCh* const chars, XPUSHs(callbackObj); // the next argument is the char data - SV *string = UTF8_TRANSCODER->XMLString2Perl(chars); + SV *string = UTF8_TRANSCODER->XMLString2Local(chars); XPUSHs(string); // next is the length @@ -161,14 +221,14 @@ PerlContentCallbackHandler::ignorableWhitespace(const XMLCh* const chars, PUTBACK; - perl_call_method("ignorable_whitespace", G_VOID); + perl_call_method("ignorableWhitespace", G_VOID); FREETMPS; LEAVE; } void -PerlContentCallbackHandler::resetDocument(void) +PerlSAXCallbackHandler::resetDocument(void) { return; if (!callbackObj) return; @@ -184,14 +244,14 @@ PerlContentCallbackHandler::resetDocument(void) PUTBACK; - perl_call_method("reset_document", G_VOID); + perl_call_method("resetDocument", G_VOID); FREETMPS; LEAVE; } void -PerlContentCallbackHandler::startDocument(void) +PerlSAXCallbackHandler::startDocument(void) { if (!callbackObj) return; @@ -206,14 +266,14 @@ PerlContentCallbackHandler::startDocument(void) PUTBACK; - perl_call_method("start_document", G_VOID); + perl_call_method("startDocument", G_VOID); FREETMPS; LEAVE; } void -PerlContentCallbackHandler::endDocument(void) +PerlSAXCallbackHandler::endDocument(void) { if (!callbackObj) return; @@ -228,7 +288,7 @@ PerlContentCallbackHandler::endDocument(void) PUTBACK; - perl_call_method("end_document", G_VOID); + perl_call_method("endDocument", G_VOID); FREETMPS; LEAVE; @@ -236,7 +296,7 @@ PerlContentCallbackHandler::endDocument(void) void -PerlContentCallbackHandler::processingInstruction(const XMLCh* const target, +PerlSAXCallbackHandler::processingInstruction(const XMLCh* const target, const XMLCh* const data) { if (!callbackObj) return; @@ -251,23 +311,23 @@ PerlContentCallbackHandler::processingInstruction(const XMLCh* const target, XPUSHs(callbackObj); // the next argument is the target - SV *string1 = UTF8_TRANSCODER->XMLString2Perl(target); + SV *string1 = UTF8_TRANSCODER->XMLString2Local(target); XPUSHs(string1); // the next argument is the data - SV *string2 = UTF8_TRANSCODER->XMLString2Perl(data); + SV *string2 = UTF8_TRANSCODER->XMLString2Local(data); XPUSHs(string2); PUTBACK; - perl_call_method("processing_instruction", G_VOID); + perl_call_method("processingInstruction", G_VOID); FREETMPS; LEAVE; } void -PerlContentCallbackHandler::setDocumentLocator(const Locator* const locator) +PerlSAXCallbackHandler::setDocumentLocator(const Locator* const locator) { if (!callbackObj) return; @@ -288,14 +348,14 @@ PerlContentCallbackHandler::setDocumentLocator(const Locator* const locator) PUTBACK; - perl_call_method("set_document_locator", G_VOID); + perl_call_method("setDocumentLocator", G_VOID); FREETMPS; LEAVE; } void -PerlContentCallbackHandler::startPrefixMapping (const XMLCh* const prefix, +PerlSAXCallbackHandler::startPrefixMapping (const XMLCh* const prefix, const XMLCh* const uri) { if (!callbackObj) return; @@ -310,23 +370,23 @@ PerlContentCallbackHandler::startPrefixMapping (const XMLCh* const prefix, XPUSHs(callbackObj); // the next argument is the prefix - SV *string1 = UTF8_TRANSCODER->XMLString2Perl(prefix); + SV *string1 = UTF8_TRANSCODER->XMLString2Local(prefix); XPUSHs(string1); // the next argument is the uri - SV *string2 = UTF8_TRANSCODER->XMLString2Perl(uri); + SV *string2 = UTF8_TRANSCODER->XMLString2Local(uri); XPUSHs(string2); PUTBACK; - perl_call_method("start_prefix_mapping", G_VOID); + perl_call_method("startPrefixMapping", G_VOID); FREETMPS; LEAVE; } void -PerlContentCallbackHandler::endPrefixMapping (const XMLCh* const prefix) +PerlSAXCallbackHandler::endPrefixMapping (const XMLCh* const prefix) { if (!callbackObj) return; @@ -340,19 +400,19 @@ PerlContentCallbackHandler::endPrefixMapping (const XMLCh* const prefix) XPUSHs(callbackObj); // the next argument is the prefix - SV *string1 = UTF8_TRANSCODER->XMLString2Perl(prefix); + SV *string1 = UTF8_TRANSCODER->XMLString2Local(prefix); XPUSHs(string1); PUTBACK; - perl_call_method("end_prefix_mapping", G_VOID); + perl_call_method("endPrefixMapping", G_VOID); FREETMPS; LEAVE; } void -PerlContentCallbackHandler::skippedEntity (const XMLCh* const name) +PerlSAXCallbackHandler::skippedEntity (const XMLCh* const name) { if (!callbackObj) return; @@ -366,12 +426,12 @@ PerlContentCallbackHandler::skippedEntity (const XMLCh* const name) XPUSHs(callbackObj); // the next argument is the name - SV *string1 = UTF8_TRANSCODER->XMLString2Perl(name); + SV *string1 = UTF8_TRANSCODER->XMLString2Local(name); XPUSHs(string1); PUTBACK; - perl_call_method("skipped_entity", G_VOID); + perl_call_method("skippedEntity", G_VOID); FREETMPS; LEAVE; diff --git a/swig/perl/Handler/PerlContentCallbackHandler.hpp b/swig/perl/Handler/PerlSAXCallbackHandler.hpp similarity index 72% rename from swig/perl/Handler/PerlContentCallbackHandler.hpp rename to swig/perl/Handler/PerlSAXCallbackHandler.hpp index 5b89cac7cc759560ec522dc9bd6ba843e9fc43c0..cc12b41031479bed3dc4d1ed87b7768e03504c19 100644 --- a/swig/perl/Handler/PerlContentCallbackHandler.hpp +++ b/swig/perl/Handler/PerlSAXCallbackHandler.hpp @@ -14,52 +14,60 @@ * limitations under the License. */ -#ifndef __PERLCONTENTCALLBACKHANDLER -#define __PERLCONTENTCALLBACKHANDLER +#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_USE +XERCES_CPP_NAMESPACE_BEGIN -class PerlContentCallbackHandler : public ContentHandler - , public PerlCallbackHandler +class PerlSAXCallbackHandler : public ContentHandler + , public DocumentHandler + , public PerlCallbackHandler { protected: -// SV *callbackObj; public: - PerlContentCallbackHandler(); - PerlContentCallbackHandler(SV *obj); - ~PerlContentCallbackHandler(); + PerlSAXCallbackHandler(); + PerlSAXCallbackHandler(SV *obj); + ~PerlSAXCallbackHandler(); - int type() {return PERLCALLBACKHANDLER_CONTENT_TYPE;} + int type() {return PERLCALLBACKHANDLER_SAX_TYPE;} - // The ContentHandler interface - void startElement(const XMLCh* const uri, - const XMLCh* const localname, - const XMLCh* const qname, - const Attributes& attrs); + // The DocumentHandler interface void characters(const XMLCh* const chars, const unsigned int length); void ignorableWhitespace(const XMLCh* const chars, const unsigned int length); - void endElement(const XMLCh* const uri, - const XMLCh* const localname, - const XMLCh* const qname); - void resetDocument(void); + 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); }; -#endif /* __PERLCONTENTCALLBACKHANDLER */ +XERCES_CPP_NAMESPACE_END + +#endif /* __PERLSAXCALLBACKHANDLER */