Added xslt support.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18935 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-03-28 04:42:11 +00:00
parent dd0beb1657
commit ca3d4a1a01
6 changed files with 503 additions and 3 deletions

View file

@ -1,3 +1,10 @@
2004-03-27 Mark Allison <mark@brainstorm.co.uk>
* Headers/Additions/GNUstepBase/GSXML.h:
* Source/Additions/GSXML.m: Add support for stylesheet processing using
libxslt if it is available.
* configure.ac: Check for presence of libxslt
2004-03-26 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSIndexSet.m: Check before each usage of _other if it is

View file

@ -355,6 +355,26 @@
- (GSXMLNode *) nodeAtIndex: (unsigned)index;
@end
@interface GSXMLDocument (XSLT)
+ (GSXMLDocument*) xsltTransformFile: (NSString*)xmlFile
stylesheet: (NSString*)xsltStylesheet
params: (NSDictionary*)params;
+ (GSXMLDocument*) xsltTransformFile: (NSString*)xmlFile
stylesheet: (NSString*)xsltStylesheet;
+ (GSXMLDocument*) xsltTransformXml: (NSData*)xmlData
stylesheet: (NSData*)xsltStylesheet
params: (NSDictionary*)params;
+ (GSXMLDocument*) xsltTransformXml: (NSData*)xmlData
stylesheet: (NSData*)xsltSylesheet;
- (GSXMLDocument*) xsltTransform: (GSXMLDocument*)xsltStylesheet
params: (NSDictionary*)parameters;
- (GSXMLDocument*) xsltTransform: (GSXMLDocument*)xsltStylesheet;
@end
#endif /* STRICT_MACOS_X */
#endif /* STRICT_OPENSTEP */

View file

@ -106,6 +106,9 @@
/* Define if libxml available */
#undef HAVE_LIBXML
/* Define if libxslt available */
#undef HAVE_LIBXSLT
/* Define to 1 if you have the <limits.h> header file. */
#undef HAVE_LIMITS_H

View file

@ -70,6 +70,13 @@
#include <libxml/xmlmemory.h>
#include <libxml/xpath.h>
#ifdef HAVE_LIBXSLT
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
#endif /* HAVE_LIBXSLT */
extern int xmlGetWarningsDefaultValue;
/*
@ -3818,6 +3825,241 @@ static BOOL warned = NO; if (warned == NO) { warned = YES; NSLog(@"WARNING, use
- (GSXMLDocument*) doc { static BOOL warned = NO; if (warned == NO) { warned = YES; NSLog(@"WARNING, use of deprecated method ... [%@ -%@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd)); } return [self document]; }
@end
@implementation GSXMLDocument (XSLT)
#ifdef HAVE_LIBXSLT
/**
* Performs an XSLT transformation on the specified file using the
* sytelsheet provided.<br />
*
* Returns an autoreleased GSXMLDocument containing the transformed
* XML, or nil on failure.
*/
+ (GSXMLDocument*) xsltTransformFile: (NSString*)xmlFile
stylesheet: (NSString*)xsltStylesheet
{
return [GSXMLDocument xsltTransformFile: xmlFile
stylesheet: xsltStylesheet
params: nil];
}
/**
* Performs an XSLT transformation on the specified file using the
* sytelsheet and parameters provided. See the libxslt documentation
* for details of the supported parameters.<br />
*
* Returns an autoreleased GSXMLDocument containing the transformed
* XML, or nil on failure.
*/
+ (GSXMLDocument*) xsltTransformFile: (NSString*)xmlFile
stylesheet: (NSString*)xsltStylesheet
params: (NSDictionary*)params
{
GSXMLDocument *newdoc;
NS_DURING
{
NSData *xml;
NSData *ss;
xml = [NSData dataWithContentsOfFile: xmlFile];
ss = [NSData dataWithContentsOfFile: xsltStylesheet];
if (xml == nil || ss == nil)
{
newdoc = nil;
}
else
{
newdoc = [GSXMLDocument xsltTransformXml: xml
stylesheet: ss
params: params];
}
}
NS_HANDLER
{
newdoc = nil;
}
NS_ENDHANDLER
return newdoc;
}
/**
* Performs an XSLT transformation on the specified file using the
* sytelsheet provided.<br />
*
* Returns an autoreleased GSXMLDocument containing the transformed
* XML, or nil on failure.
*/
+ (GSXMLDocument*) xsltTransformXml: (NSData*)xmlData
stylesheet: (NSData*)xsltStylesheet
{
return [GSXMLDocument xsltTransformXml: xmlData
stylesheet: xsltStylesheet
params: nil];
}
/**
* Performs an XSLT transformation on the specified file using the
* sytelsheet and parameters provided.See the libxslt documentation
* for details of the supported parameters.<br />
*
* Returns an autoreleased GSXMLDocument containing the transformed
* XML, or nil on failure.
*/
+ (GSXMLDocument*) xsltTransformXml: (NSData*)xmlData
stylesheet: (NSData*)xsltStylesheet
params: (NSDictionary*)params
{
GSXMLDocument *newdoc;
NS_DURING
{
GSXMLParser *xmlParser;
GSXMLDocument *xml;
GSXMLParser *ssParser;
GSXMLDocument *ss;
xmlParser = [GSXMLParser parserWithData: xmlData];
[xmlParser parse];
xml = [xmlParser document];
ssParser = [GSXMLParser parserWithData: xsltStylesheet];
[ssParser parse];
ss = [ssParser document];
newdoc = [xml xsltTransform: ss params: params];
}
NS_HANDLER
{
newdoc = nil;
}
NS_ENDHANDLER
return newdoc;
}
/**
* Performs an XSLT transformation on the current document using the
* supplied stylesheet.<br />
*
* Returns an autoreleased GSXMLDocument containing the transformed
* XML, or nil on failure.
*/
- (GSXMLDocument*) xsltTransform: (GSXMLDocument*)xsltStylesheet
{
return [self xsltTransform: xsltStylesheet params: nil];
}
/**
* Performs an XSLT transformation on the current document using the
* supplied stylesheet and paramaters (parameters may be nil).
* See the libxslt documentation for details of the supported parameters.<br />
*
* Returns an autoreleased GSXMLDocument containing the transformed
* XML, or nil on failure.
*/
- (GSXMLDocument*) xsltTransform: (GSXMLDocument*)xsltStylesheet
params: (NSDictionary*)params
{
GSXMLDocument *newdoc = nil;
NS_DURING
{
xsltStylesheetPtr ss = NULL;
xmlDocPtr ssXml = (xmlDocPtr)[xsltStylesheet lib];
int pSize = params == nil ? 1 : ([params count] * 2) + 1;
int pNum = 0;
const char *parameters[pSize];
if (params != nil)
{
NSEnumerator *keys = [params keyEnumerator];
if (keys != nil)
{
NSString *key = [keys nextObject];
while (key != nil)
{
NSString *value = [params objectForKey: key];
parameters[pNum++] = [key cString];
parameters[pNum++] = [value cString];
key = [keys nextObject];
}
}
}
parameters[pNum] = NULL;
ss = xsltParseStylesheetDoc(ssXml);
if (xsltStylesheet != NULL)
{
xmlDocPtr res = NULL;
res = xsltApplyStylesheet(ss, lib, parameters);
if (res != NULL)
{
newdoc = [GSXMLDocument alloc];
newdoc = [newdoc _initFrom: res
parent: self
ownsLib: YES];
AUTORELEASE(newdoc);
}
}
/*
* N.B. We don't want to call xsltFreeStylesheet() to free the
* stylesheet xmlDocPtr because that will destroy the lib which
* is owned by the xsltStylesheet object.
*/
xsltCleanupGlobals();
}
NS_HANDLER
{
newdoc= nil;
}
NS_ENDHANDLER
return newdoc;
}
#else /* HAVE_LIBXSLT */
+ (GSXMLDocument*) xsltTransformFile: (NSString*)xmlFile
stylesheet: (NSString*)xsltStylesheet
params: (NSDictionary*)params
{
NSLog(@"libxslt is not available");
return nil;
}
+ (GSXMLDocument*) xsltTransformFile: (NSString*)xmlFile
stylesheet: (NSString*)xsltStylesheet
{
NSLog(@"libxslt is not available");
return nil;
}
+ (GSXMLDocument*) xsltTransformXml: (NSData*)xmlData
stylesheet: (NSData*)xsltStylesheet
params: (NSDictionary*)params
{
NSLog(@"libxslt is not available");
return nil;
}
+ (GSXMLDocument*) xsltTransformXml: (NSData*)xmlData
stylesheet: (NSData*)xsltStylesheet
{
NSLog(@"libxslt is not available");
return nil;
}
- (GSXMLDocument*) xsltTransform: (GSXMLDocument*)xsltStylesheet
params: (NSDictionary*)parameters
{
NSLog(@"libxslt is not available");
return nil;
}
- (GSXMLDocument*) xsltTransform: (GSXMLDocument*)xsltStylesheet
{
NSLog(@"libxslt is not available");
return nil;
}
#endif /* HAVE_LIBXSLT */
@end
#else
#ifndef NeXT_Foundation_LIBRARY
@ -3887,6 +4129,7 @@ static BOOL warned = NO; if (warned == NO) { warned = YES; NSLog(@"WARNING, use
@end
@implementation GSXMLAttribute
@end
#endif

215
configure vendored
View file

@ -309,7 +309,7 @@ ac_includes_default="\
#endif"
ac_subdirs_all="$ac_subdirs_all Source/mframe SSL"
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP WHOAMI EGREP GS_WORDS_BIGENDIAN GS_SINT8 GS_UINT8 ac_cv_sizeof_short ac_cv_sizeof_int ac_cv_sizeof_long ac_cv_sizeof_long_long ac_cv_sizeof_float ac_cv_sizeof_double ac_cv_sizeof_voidp GS_ADDR GS_SINT16 GS_UINT16 GS_SINT32 GS_UINT32 GS_SINT64 GS_UINT64 GS_HAVE_I64 GS_SINT128 GS_UINT128 GS_HAVE_I128 GS_FLT32 GS_FLT64 _GSC_S_SHT _GSC_S_INT _GSC_S_LNG _GSC_S_LNG_LNG DYNAMIC_LINKER NX_CONST_STRING_OBJCFLAGS NX_CONST_STRING_CLASS HAVE_PTHREAD_H HAVE_PTS_STREAM_MODULES USE_ZLIB GS_PASS_ARGUMENTS GS_FAKE_MAIN WITH_FFI XML2_CONFIG XML_CONFIG XML_CFLAGS XML_LIBS HAVE_LIBXML USE_GMP INCLUDE_FLAGS subdirs VERSION MAJOR_VERSION MINOR_VERSION SUBMINOR_VERSION GCC_VERSION LIBOBJS LTLIBOBJS'
ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os CC CFLAGS LDFLAGS CPPFLAGS ac_ct_CC EXEEXT OBJEXT CPP WHOAMI EGREP GS_WORDS_BIGENDIAN GS_SINT8 GS_UINT8 ac_cv_sizeof_short ac_cv_sizeof_int ac_cv_sizeof_long ac_cv_sizeof_long_long ac_cv_sizeof_float ac_cv_sizeof_double ac_cv_sizeof_voidp GS_ADDR GS_SINT16 GS_UINT16 GS_SINT32 GS_UINT32 GS_SINT64 GS_UINT64 GS_HAVE_I64 GS_SINT128 GS_UINT128 GS_HAVE_I128 GS_FLT32 GS_FLT64 _GSC_S_SHT _GSC_S_INT _GSC_S_LNG _GSC_S_LNG_LNG DYNAMIC_LINKER NX_CONST_STRING_OBJCFLAGS NX_CONST_STRING_CLASS HAVE_PTHREAD_H HAVE_PTS_STREAM_MODULES USE_ZLIB GS_PASS_ARGUMENTS GS_FAKE_MAIN WITH_FFI XML2_CONFIG XML_CONFIG XML_CFLAGS XML_LIBS HAVE_LIBXML HAVE_LIBXSLT USE_GMP INCLUDE_FLAGS subdirs VERSION MAJOR_VERSION MINOR_VERSION SUBMINOR_VERSION GCC_VERSION LIBOBJS LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
@ -12985,6 +12985,218 @@ echo "$as_me: WARNING: Missing support for XML funtionality." >&2;}
fi
#--------------------------------------------------------------------
# Check for (optional) libxslt
#--------------------------------------------------------------------
echo "$as_me:$LINENO: checking for xsltApplyStylesheet in -lxslt" >&5
echo $ECHO_N "checking for xsltApplyStylesheet in -lxslt... $ECHO_C" >&6
if test "${ac_cv_lib_xslt_xsltApplyStylesheet+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lxslt $LIBS"
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
/* Override any gcc2 internal prototype to avoid an error. */
#ifdef __cplusplus
extern "C"
#endif
/* We use char because int might match the return type of a gcc2
builtin and then its argument prototype would still apply. */
char xsltApplyStylesheet ();
int
main ()
{
xsltApplyStylesheet ();
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext conftest$ac_exeext
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
(eval $ac_link) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -s conftest$ac_exeext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_cv_lib_xslt_xsltApplyStylesheet=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_cv_lib_xslt_xsltApplyStylesheet=no
fi
rm -f conftest.$ac_objext conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
echo "$as_me:$LINENO: result: $ac_cv_lib_xslt_xsltApplyStylesheet" >&5
echo "${ECHO_T}$ac_cv_lib_xslt_xsltApplyStylesheet" >&6
if test $ac_cv_lib_xslt_xsltApplyStylesheet = yes; then
xslt_ok=yes
else
xslt_ok=no
fi
if test "$xslt_ok" = "yes"; then
if test "${ac_cv_header_libxslt_xslt_h+set}" = set; then
echo "$as_me:$LINENO: checking for libxslt/xslt.h" >&5
echo $ECHO_N "checking for libxslt/xslt.h... $ECHO_C" >&6
if test "${ac_cv_header_libxslt_xslt_h+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
fi
echo "$as_me:$LINENO: result: $ac_cv_header_libxslt_xslt_h" >&5
echo "${ECHO_T}$ac_cv_header_libxslt_xslt_h" >&6
else
# Is the header compilable?
echo "$as_me:$LINENO: checking libxslt/xslt.h usability" >&5
echo $ECHO_N "checking libxslt/xslt.h usability... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
$ac_includes_default
#include <libxslt/xslt.h>
_ACEOF
rm -f conftest.$ac_objext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -s conftest.$ac_objext'
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
(eval $ac_try) 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
ac_header_compiler=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_header_compiler=no
fi
rm -f conftest.$ac_objext conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
echo "${ECHO_T}$ac_header_compiler" >&6
# Is the header present?
echo "$as_me:$LINENO: checking libxslt/xslt.h presence" >&5
echo $ECHO_N "checking libxslt/xslt.h presence... $ECHO_C" >&6
cat >conftest.$ac_ext <<_ACEOF
#line $LINENO "configure"
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
#include <libxslt/xslt.h>
_ACEOF
if { (eval echo "$as_me:$LINENO: \"$ac_cpp conftest.$ac_ext\"") >&5
(eval $ac_cpp conftest.$ac_ext) 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } >/dev/null; then
if test -s conftest.err; then
ac_cpp_err=$ac_c_preproc_warn_flag
else
ac_cpp_err=
fi
else
ac_cpp_err=yes
fi
if test -z "$ac_cpp_err"; then
ac_header_preproc=yes
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_header_preproc=no
fi
rm -f conftest.err conftest.$ac_ext
echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
echo "${ECHO_T}$ac_header_preproc" >&6
# So? What about this header?
case $ac_header_compiler:$ac_header_preproc in
yes:no )
{ echo "$as_me:$LINENO: WARNING: libxslt/xslt.h: accepted by the compiler, rejected by the preprocessor!" >&5
echo "$as_me: WARNING: libxslt/xslt.h: accepted by the compiler, rejected by the preprocessor!" >&2;}
{ echo "$as_me:$LINENO: WARNING: libxslt/xslt.h: proceeding with the preprocessor's result" >&5
echo "$as_me: WARNING: libxslt/xslt.h: proceeding with the preprocessor's result" >&2;}
(
cat <<\_ASBOX
## ------------------------------------ ##
## Report this to bug-autoconf@gnu.org. ##
## ------------------------------------ ##
_ASBOX
) |
sed "s/^/$as_me: WARNING: /" >&2
;;
no:yes )
{ echo "$as_me:$LINENO: WARNING: libxslt/xslt.h: present but cannot be compiled" >&5
echo "$as_me: WARNING: libxslt/xslt.h: present but cannot be compiled" >&2;}
{ echo "$as_me:$LINENO: WARNING: libxslt/xslt.h: check for missing prerequisite headers?" >&5
echo "$as_me: WARNING: libxslt/xslt.h: check for missing prerequisite headers?" >&2;}
{ echo "$as_me:$LINENO: WARNING: libxslt/xslt.h: proceeding with the preprocessor's result" >&5
echo "$as_me: WARNING: libxslt/xslt.h: proceeding with the preprocessor's result" >&2;}
(
cat <<\_ASBOX
## ------------------------------------ ##
## Report this to bug-autoconf@gnu.org. ##
## ------------------------------------ ##
_ASBOX
) |
sed "s/^/$as_me: WARNING: /" >&2
;;
esac
echo "$as_me:$LINENO: checking for libxslt/xslt.h" >&5
echo $ECHO_N "checking for libxslt/xslt.h... $ECHO_C" >&6
if test "${ac_cv_header_libxslt_xslt_h+set}" = set; then
echo $ECHO_N "(cached) $ECHO_C" >&6
else
ac_cv_header_libxslt_xslt_h=$ac_header_preproc
fi
echo "$as_me:$LINENO: result: $ac_cv_header_libxslt_xslt_h" >&5
echo "${ECHO_T}$ac_cv_header_libxslt_xslt_h" >&6
fi
if test $ac_cv_header_libxslt_xslt_h = yes; then
xslthdr_ok=yes
else
xslthdr_ok=no
fi
if test "$xslthdr_ok" = "yes"; then
HAVE_LIBXSLT=1
cat >>confdefs.h <<\_ACEOF
#define HAVE_LIBXSLT 1
_ACEOF
LIBS="$LIBS -lxslt"
fi
fi
#--------------------------------------------------------------------
# Check GMP for NSDecimal
#--------------------------------------------------------------------
@ -14301,6 +14513,7 @@ s,@XML_CONFIG@,$XML_CONFIG,;t t
s,@XML_CFLAGS@,$XML_CFLAGS,;t t
s,@XML_LIBS@,$XML_LIBS,;t t
s,@HAVE_LIBXML@,$HAVE_LIBXML,;t t
s,@HAVE_LIBXSLT@,$HAVE_LIBXSLT,;t t
s,@USE_GMP@,$USE_GMP,;t t
s,@INCLUDE_FLAGS@,$INCLUDE_FLAGS,;t t
s,@subdirs@,$subdirs,;t t

View file

@ -1009,6 +1009,20 @@ else
fi
AC_SUBST(HAVE_LIBXML)
#--------------------------------------------------------------------
# Check for (optional) libxslt
#--------------------------------------------------------------------
AC_CHECK_LIB(xslt, xsltApplyStylesheet, xslt_ok=yes, xslt_ok=no)
if test "$xslt_ok" = "yes"; then
AC_CHECK_HEADER(libxslt/xslt.h, xslthdr_ok=yes, xslthdr_ok=no)
if test "$xslthdr_ok" = "yes"; then
HAVE_LIBXSLT=1
AC_DEFINE(HAVE_LIBXSLT,1,[Define if libxslt available])
LIBS="$LIBS -lxslt"
fi
fi
AC_SUBST(HAVE_LIBXSLT)
#--------------------------------------------------------------------
# Check GMP for NSDecimal
#--------------------------------------------------------------------