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 2001/08/02 04:30:44 UTC
cvs commit: xml-xerces/perl/Handler PerlEntityResolverHandler.hpp PerlEntityResolverHandler.i PerlEntityResolverHandler.swig.hpp
jasons 01/08/01 19:30:44
Added: perl/Handler PerlEntityResolverHandler.hpp
PerlEntityResolverHandler.i
PerlEntityResolverHandler.swig.hpp
Log:
* Handler/PerlEntityResolverHandler.hpp (Repository):
Finally implemented the EntityResolver interface
Revision Changes Path
1.1 xml-xerces/perl/Handler/PerlEntityResolverHandler.hpp
Index: PerlEntityResolverHandler.hpp
===================================================================
#ifdef __cplusplus
/* Needed on some windows machines---since MS plays funny
games with the header files under C++ */
#include <math.h>
#include <stdlib.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Get rid of free and malloc defined by perl */
#undef free
#undef malloc
#include <string.h>
#ifdef __cplusplus
}
#endif
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
#ifndef PL_sv_yes
#define PL_sv_yes sv_yes
#endif
#ifndef PL_sv_undef
#define PL_sv_undef sv_undef
#endif
#ifndef PL_na
#define PL_na na
#endif
#endif
#include "sax/EntityResolver.hpp"
#include "util/XMLString.hpp"
class InputSource;
class PerlEntityResolverHandler: public EntityResolver {
private:
SV *callbackObj;
public:
PerlEntityResolverHandler();
~PerlEntityResolverHandler();
SV* set_callback_obj(SV*);
// The EntityResolver interface
InputSource* resolveEntity (const XMLCh* const publicId,
const XMLCh* const systemId);
};
1.1 xml-xerces/perl/Handler/PerlEntityResolverHandler.i
Index: PerlEntityResolverHandler.i
===================================================================
#include <iostream.h>
#include "sax/InputSource.hpp"
#include "PerlEntityResolverHandler.hpp"
PerlEntityResolverHandler::PerlEntityResolverHandler() {
callbackObj = NULL;
}
PerlEntityResolverHandler::~PerlEntityResolverHandler() {
if (callbackObj) {
SvREFCNT_dec(callbackObj);
callbackObj = NULL;
}
}
SV*
PerlEntityResolverHandler::set_callback_obj(SV* object) {
SV *oldRef = &PL_sv_undef; // default to 'undef'
if (callbackObj != NULL) {
oldRef = callbackObj;
SvREFCNT_dec(oldRef);
}
SvREFCNT_inc(object);
callbackObj = object;
return oldRef;
}
InputSource *
PerlEntityResolverHandler::resolveEntity (const XMLCh* const publicId,
const XMLCh* const systemId)
{
if (!callbackObj) {
cerr << "\nresolveEntity: "
<< "no EntityResolver set.\n" << endl;
return NULL;
}
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first put the callback object on the stack
XPUSHs(callbackObj);
// the next argument is the publicId
char *cptr1 = XMLString::transcode(publicId);
SV *string1 = sv_newmortal();
sv_setpv(string1, (char *)cptr1);
XPUSHs(string1);
// the next argument is the systemId
char *cptr2 = XMLString::transcode(systemId);
SV *string2 = sv_newmortal();
sv_setpv(string2, (char *)cptr2);
XPUSHs(string2);
PUTBACK;
int count = perl_call_method("resolve_entity", G_SCALAR);
SPAGAIN ;
if (count != 1)
croak("EntityResolver did not retury any object\n") ;
SV* source_sv = POPs;
InputSource *source;
if (!sv_derived_from(source_sv,"XML::Xerces::InputSource")) {
croak("EntityResolver did not retury an InputSource\n") ;
}
if (SWIG_ConvertPtr(source_sv,(void **) &source, SWIGTYPE_p_InputSource) < 0) {
croak("EntityResolver did not retury an InputSource. Expected %s", SWIGTYPE_p_DOMParser->name);
}
PUTBACK ;
FREETMPS;
LEAVE;
return source;
}
1.1 xml-xerces/perl/Handler/PerlEntityResolverHandler.swig.hpp
Index: PerlEntityResolverHandler.swig.hpp
===================================================================
class PerlEntityResolverHandler : public EntityResolver {
public:
PerlEntityResolverHandler();
~PerlEntityResolverHandler();
SV* set_callback_obj(SV*);
// InputSource* resolveEntity (const XMLCh* /*const*/ publicId,
// const XMLCh* /*const*/ systemId);
//
};
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org