From 0474bcec6d3bb8972eec0964a34872712122f340 Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Tue, 12 Mar 2002 18:03:32 +0000 Subject: [PATCH] Initial version. --- helm/DEVEL/gdome_xslt/C/gdome_xslt/.cvsignore | 1 + helm/DEVEL/gdome_xslt/C/gdome_xslt/Makefile | 7 + .../gdome_xslt/C/gdome_xslt/gdome_xslt.c | 98 ++++++++++++++ .../gdome_xslt/C/gdome_xslt/gdome_xslt.h | 30 +++++ helm/DEVEL/gdome_xslt/C/test/.cvsignore | 1 + helm/DEVEL/gdome_xslt/C/test/Makefile | 10 ++ helm/DEVEL/gdome_xslt/C/test/test.c | 94 +++++++++++++ .../gdome_xslt/ocaml/gdome_xslt/.cvsignore | 21 +++ .../DEVEL/gdome_xslt/ocaml/gdome_xslt/.depend | 5 + .../DEVEL/gdome_xslt/ocaml/gdome_xslt/META.in | 5 + .../gdome_xslt/ocaml/gdome_xslt/Makefile.in | 88 ++++++++++++ .../gdome_xslt/ocaml/gdome_xslt/configure.in | 41 ++++++ .../gdome_xslt/ocaml/gdome_xslt/gdome_xslt.ml | 36 +++++ .../ocaml/gdome_xslt/gdome_xslt.mli | 38 ++++++ .../ocaml/gdome_xslt/gdome_xslt_init.ml | 39 ++++++ .../ocaml/gdome_xslt/gdome_xslt_init.mli | 35 +++++ .../ocaml/gdome_xslt/i_gdome_xslt.ml | 31 +++++ .../ocaml/gdome_xslt/ml_gdome_xslt.c | 126 ++++++++++++++++++ .../ocaml/gdome_xslt/ml_gdome_xslt.h | 30 +++++ helm/DEVEL/gdome_xslt/ocaml/test/.cvsignore | 6 + helm/DEVEL/gdome_xslt/ocaml/test/Makefile | 17 +++ helm/DEVEL/gdome_xslt/ocaml/test/test.ml | 60 +++++++++ helm/DEVEL/gdome_xslt/test_files/.cvsignore | 1 + helm/DEVEL/gdome_xslt/test_files/input.xml | 4 + .../gdome_xslt/test_files/output.xml.correct | 4 + .../gdome_xslt/test_files/stylesheet.xsl | 22 +++ 26 files changed, 850 insertions(+) create mode 100644 helm/DEVEL/gdome_xslt/C/gdome_xslt/.cvsignore create mode 100644 helm/DEVEL/gdome_xslt/C/gdome_xslt/Makefile create mode 100644 helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.c create mode 100644 helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.h create mode 100644 helm/DEVEL/gdome_xslt/C/test/.cvsignore create mode 100644 helm/DEVEL/gdome_xslt/C/test/Makefile create mode 100644 helm/DEVEL/gdome_xslt/C/test/test.c create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/.cvsignore create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/.depend create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/META.in create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/Makefile.in create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/configure.in create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt.ml create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt.mli create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt_init.ml create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt_init.mli create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/i_gdome_xslt.ml create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/ml_gdome_xslt.c create mode 100644 helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/ml_gdome_xslt.h create mode 100644 helm/DEVEL/gdome_xslt/ocaml/test/.cvsignore create mode 100644 helm/DEVEL/gdome_xslt/ocaml/test/Makefile create mode 100644 helm/DEVEL/gdome_xslt/ocaml/test/test.ml create mode 100644 helm/DEVEL/gdome_xslt/test_files/.cvsignore create mode 100644 helm/DEVEL/gdome_xslt/test_files/input.xml create mode 100644 helm/DEVEL/gdome_xslt/test_files/output.xml.correct create mode 100644 helm/DEVEL/gdome_xslt/test_files/stylesheet.xsl diff --git a/helm/DEVEL/gdome_xslt/C/gdome_xslt/.cvsignore b/helm/DEVEL/gdome_xslt/C/gdome_xslt/.cvsignore new file mode 100644 index 000000000..9bcdefdcb --- /dev/null +++ b/helm/DEVEL/gdome_xslt/C/gdome_xslt/.cvsignore @@ -0,0 +1 @@ +gdome_xslt.o diff --git a/helm/DEVEL/gdome_xslt/C/gdome_xslt/Makefile b/helm/DEVEL/gdome_xslt/C/gdome_xslt/Makefile new file mode 100644 index 000000000..3f1809d65 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/C/gdome_xslt/Makefile @@ -0,0 +1,7 @@ +INCLUDES = `gdome-config --cflags` `xslt-config --cflags` + +gdome_xslt.o: gdome_xslt.c + gcc -c $(INCLUDES) $< + +clean: + rm -f gdome_xslt.o diff --git a/helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.c b/helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.c new file mode 100644 index 000000000..d3163a4fa --- /dev/null +++ b/helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.c @@ -0,0 +1,98 @@ +/* This file implements a XSLT engine working on Gdome documents. In fact, + * it just maps Gdome documents to libxml documents back and forth, and + * applyes the transformation on libxml documents using libxlt. + * + * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT + * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT) + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + */ + +#include +#include +#include +#include +#include +#include +#include + +// Begin of Gdome internals exposed +typedef struct _Gdome_xml_Document Gdome_xml_Document; +struct _Gdome_xml_Document { + GdomeDocument super; + const GdomeDocumentVtab* vtab; + int refcnt; + xmlDocPtr n; + GdomeAccessType accessType; +}; + +GdomeNode* gdome_xml_n_mkref(xmlNode* n); +// End of Gdome internals exposed + +// Begin of the abstraction of Gdome internals. Uses the Gdome internals exposed +xmlDocPtr libxml_of_gdome(GdomeDocument* doc) +{ + return ((Gdome_xml_Document*)doc)->n; +} + +GdomeDocument* gdome_of_libxml(xmlDocPtr n) +{ + return (GdomeDocument*)gdome_xml_n_mkref((xmlNode*)n); +} +// End of the abstraction of Gdome internals. Uses the Gdome internals exposed. + + + +// From now on no Gdome internal should be used directly. + +xsltStylesheetPtr processStylesheet(GdomeDocument* style) +{ + xmlDocPtr style_copy; + xmlDocPtr style_libxml; + + if (style == NULL) { + return NULL; + } + style_libxml = libxml_of_gdome(style); + style_copy = xmlCopyDoc(style_libxml, 1); + style_copy->URL = xmlStrdup(style_libxml->URL); + + xsltSetGenericDebugFunc(NULL, NULL); + + return xsltParseStylesheetDoc(style_copy); +} + +GdomeDocument* applyStylesheet(GdomeDocument* source, xsltStylesheetPtr style_libxslt, const char** params) +{ + xmlDocPtr source_libxml; + xmlDocPtr output_libxml; + + if (source == NULL) return NULL; + source_libxml = libxml_of_gdome(source); + + xsltSetGenericDebugFunc(NULL, NULL); + + output_libxml = xsltApplyStylesheet(style_libxslt, + source_libxml, + params); + + if (output_libxml == NULL) return NULL; + + return gdome_of_libxml(output_libxml); +} diff --git a/helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.h b/helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.h new file mode 100644 index 000000000..7ae286d82 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/C/gdome_xslt/gdome_xslt.h @@ -0,0 +1,30 @@ +/* This file implements a XSLT engine working on Gdome documents. In fact, + * it just maps Gdome documents to libxml documents back and forth, and + * applyes the transformation on libxml documents using libxlt. + * + * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT + * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT) + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + */ + + +xsltStylesheetPtr processStylesheet(GdomeDocument* style); + +GdomeDocument* applyStylesheet(GdomeDocument* source, xsltStylesheetPtr style_libxslt, const char** params); diff --git a/helm/DEVEL/gdome_xslt/C/test/.cvsignore b/helm/DEVEL/gdome_xslt/C/test/.cvsignore new file mode 100644 index 000000000..9daeafb98 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/C/test/.cvsignore @@ -0,0 +1 @@ +test diff --git a/helm/DEVEL/gdome_xslt/C/test/Makefile b/helm/DEVEL/gdome_xslt/C/test/Makefile new file mode 100644 index 000000000..6f9482eec --- /dev/null +++ b/helm/DEVEL/gdome_xslt/C/test/Makefile @@ -0,0 +1,10 @@ +INCLUDES = `gdome-config --cflags` `xslt-config --cflags` -I $(GDOMEXSLTPATH) +LIBS = `gdome-config --libs` `xslt-config --libs` + +GDOMEXSLTPATH = ../gdome_xslt + +test: test.c + gcc -o $@ $(INCLUDES) $(LIBS) $(GDOMEXSLTPATH)/gdome_xslt.o $< + +clean: + rm -f test diff --git a/helm/DEVEL/gdome_xslt/C/test/test.c b/helm/DEVEL/gdome_xslt/C/test/test.c new file mode 100644 index 000000000..d6881dbe7 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/C/test/test.c @@ -0,0 +1,94 @@ +/* This file is a test for the XSLT engine working on Gdome documents. + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + */ + +#include +#include +#include +#include +#include + +#include "gdome_xslt.h" + +GdomeDocument* loadDocument(GdomeDOMImplementation *domimpl, char *uri) +{ + GdomeDocument *doc; + GdomeException exc; + + doc = gdome_di_createDocFromURI(domimpl, uri, GDOME_LOAD_PARSING, &exc); + if (doc == NULL) { + fprintf (stderr, + "DOMImplementation.createDocFromURI: failed\n\tException #%d\n", + exc); + } + + return doc; +} + +int saveDocument(GdomeDOMImplementation *domimpl, GdomeDocument* doc, char *uri) +{ + GdomeException exc; + + if (!gdome_di_saveDocToFile (domimpl, doc, uri, GDOME_SAVE_STANDARD, &exc)) { + fprintf (stderr, + "DOMImplementation.saveDocToFile: failed\n\tException #%d\n", + exc); + return 0; + } + + return 1; +} + + +int main(void) +{ + GdomeDOMImplementation *domimpl; + GdomeDocument *input; + GdomeDocument *style; + xsltStylesheetPtr style_libxslt; + GdomeDocument *output; + GdomeException exc; + const char* params[] = {"parameter1", "'value1'", + "parameter2", "'value2'", + "parameter3", "'value3'", + NULL}; + + domimpl = gdome_di_mkref(); + + if (!(input = loadDocument(domimpl, "../../test_files/input.xml"))) return 1; + if (!(style = loadDocument(domimpl, "../../test_files/stylesheet.xsl"))) return 1; + + style_libxslt = processStylesheet(style); + + output = applyStylesheet(input, style_libxslt, params); + + if (!(saveDocument(domimpl, output, "../../test_files/output.xml"))) return 1; + + xsltFreeStylesheet(style_libxslt); + gdome_di_freeDoc (domimpl, input, &exc); + gdome_di_freeDoc (domimpl, style, &exc); + gdome_di_freeDoc (domimpl, output, &exc); + gdome_di_unref (domimpl, &exc); + + printf("The test was successful iff ../../test_files/output.xml.correct is\n"); + printf("equal to ../../test_files/output.xml\n"); + + return 0; +} diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/.cvsignore b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/.cvsignore new file mode 100644 index 000000000..5b31626e4 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/.cvsignore @@ -0,0 +1,21 @@ +META +Makefile +config.cache +config.log +config.status +configure +gdome_xslt.cma +gdome_xslt.cmi +gdome_xslt.cmo +gdome_xslt.cmx +gdome_xslt.cmxa +gdome_xslt.o +gdome_xslt_init.cmi +gdome_xslt_init.cmo +gdome_xslt_init.cmx +gdome_xslt_init.o +i_gdome_xslt.cmi +i_gdome_xslt.cmo +i_gdome_xslt.cmx +i_gdome_xslt.o +ml_gdome_xslt.o diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/.depend b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/.depend new file mode 100644 index 000000000..9e7b5fb8b --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/.depend @@ -0,0 +1,5 @@ +gdome_xslt_init.cmo: i_gdome_xslt.cmo gdome_xslt_init.cmi +gdome_xslt_init.cmx: i_gdome_xslt.cmx gdome_xslt_init.cmi +gdome_xslt.cmo: i_gdome_xslt.cmo gdome_xslt.cmi +gdome_xslt.cmx: i_gdome_xslt.cmx gdome_xslt.cmi +gdome_xslt.cmi: i_gdome_xslt.cmo diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/META.in b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/META.in new file mode 100644 index 000000000..3a9568cf7 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/META.in @@ -0,0 +1,5 @@ +requires="gdome2" +version="@VERSION@" +archive(byte)="gdome_xslt_init.cmo gdome_xslt.cma" +archive(native)="gdome_xslt_init.cmx gdome_xslt.cmxa" +linkopts="" diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/Makefile.in b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/Makefile.in new file mode 100644 index 000000000..fa719897e --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/Makefile.in @@ -0,0 +1,88 @@ +PACKAGE = @PACKAGE@ +VERSION = @VERSION@ +INCLUDEDIR = @OCAML_INCLUDE_DIR@ +CGDOMEXSLTPATH = ../../C/gdome_xslt +PREFIX = +OBJECTS_C = ml_gdome_xslt.o +OBJECTS = i_gdome_xslt.cmo gdome_xslt.cmo +OBJECTS_NOT_IN_ARCHIVE = gdome_xslt_init.cmo +OBJECTS_OPT = i_gdome_xslt.cmx gdome_xslt.cmx +OBJECTS_OPT_NOT_IN_ARCHIVE = gdome_xslt_init.cmx +INST = META gdome_xslt_init.cmi i_gdome_xslt.cmi gdome_xslt.cmi gdome_xslt_init.cmo gdome_xslt.mli gdome_xslt_init.mli +INSTOPT = gdome_xslt_init.cmx gdome_xslt_init.o +DIST_FILES = \ + AUTHORS COPYING ChangeLog LICENSE Makefile.in NEWS README \ + configure.in ml_gdome_xslt.c gdome_xslt_init.ml i_gdome_xslt.ml \ + gdome_xslt.ml META.in +DOC_FILES = AUTHORS COPYING ChangeLog NEWS README +REQUIRES = gdome2 +PREDICATES = +MLFLAGS = -labels + +OCAMLC = ocamlfind ocamlc $(MLFLAGS) +OCAMLOPT = ocamlfind ocamlopt $(MLFLAGS) +OCAMLDEP = ocamldep + +ARCHIVE = $(PACKAGE).cma +ARCHIVE_A = $(PACKAGE).a +ARCHIVE_SO = dll$(PACKAGE).so +ARCHIVE_OPT = $(PACKAGE).cmxa + +all: $(ARCHIVE) $(ARCHIVE_SO) $(OBJECTS_NOT_IN_ARCHIVE) + +opt: $(OBJECTS_C) $(ARCHIVE_OPT) $(ARCHIVE_A) $(ARCHIVE_SO) $(OBJECTS_OPT_NOT_IN_ARCHIVE) + +dist: + rm -rf $(PACKAGE)-$(VERSION) + mkdir $(PACKAGE)-$(VERSION) + cp $(DIST_FILES) $(DOC_FILES) $(PACKAGE)-$(VERSION) + tar cvfz $(PACKAGE)-$(VERSION).tar.gz $(PACKAGE)-$(VERSION) + rm -rf $(PACKAGE)-$(VERSION) + +ml_gdome_xslt.o: ml_gdome_xslt.c + gcc -c -I$(INCLUDEDIR) `gdome-config --cflags` `ocamlfind query -i-format gdome2` -I$(CGDOMEXSLTPATH) $< + +.SUFFIXES: .cmo .cmi .cmx .ml .mli + +.ml.cmo: + $(OCAMLC) -package "$(REQUIRES)" -predicates "$(PREDICATES)" \ + -c $< +.mli.cmi: + $(OCAMLC) -package "$(REQUIRES)" -predicates "$(PREDICATES)" \ + -c $< +.ml.cmx: + $(OCAMLOPT) -package "$(REQUIRES)" -predicates "$(PREDICATES)" \ + -c $< + +depend: *.ml *.mli + $(OCAMLDEP) *.ml *.mli >.depend +include .depend + +$(ARCHIVE): $(OBJECTS) $(ARCHIVE_SO) + $(OCAMLC) -a -package "$(REQUIRES)" \ + -predicates "$(PREDICATES)" -o $@ $^ \ + -cclib "`gdome-config --libs`" -dllib -l$(PACKAGE) +$(ARCHIVE_OPT) $(ARCHIVE_A): $(OBJECTS_OPT) + INSTPATH=`ocamlfind query gdome2` ; \ + $(OCAMLOPT) -a -package "$(REQUIRES)" \ + -predicates "$(PREDICATES)" -o $@ $^ \ + -cclib "`gdome-config --libs`" \ + -cclib "`echo $$INSTPATH | sed "s/\\(.*\\)\\/gdome2/\\1/"`/$(PACKAGE)/$(ARCHIVE_SO)" + +$(ARCHIVE_SO): $(OBJECTS_C) + gcc -shared -o $@ $< $(CGDOMEXSLTPATH)/gdome_xslt.o -lmlgdome -lxslt -L `ocamlfind query gdome2` -Xlinker -rpath -Xlinker `ocamlfind query gdome2` + + + +install: + test ! -f $(ARCHIVE_OPT) || extra="$(ARCHIVE_A) $(ARCHIVE_OPT) $(INSTOPT)" ; \ + ocamlfind install $(PACKAGE) $(ARCHIVE) $(ARCHIVE_SO) $(INST) $$extra + +uninstall: + ocamlfind remove $(PACKAGE) + +clean: + rm -f *.o *.cm? $(ARCHIVE) $(ARCHIVE_A) $(ARCHIVE_SO) $(ARCHIVE_OPT) + +distclean: clean + rm -f config.log config.cache config.status Makefile META diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/configure.in b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/configure.in new file mode 100644 index 000000000..40b2cab2d --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/configure.in @@ -0,0 +1,41 @@ +AC_INIT(gdome_xslt.ml) + +PACKAGE=gdome_xslt + +GDOMEXSLT_MAJOR_VERSION=0 +GDOMEXSLT_MINOR_VERSION=0 +GDOMEXSLT_MICRO_VERSION=1 +GDOMEXSLT_VERSION=$GDOMEXSLT_MAJOR_VERSION.$GDOMEXSLT_MINOR_VERSION.$GDOMEXSLT_MICRO_VERSION +VERSION=$GDOMEXSLT_VERSION + +AC_CHECK_PROG(HAVE_OCAMLC, ocamlc, yes, no) +if test $HAVE_OCAMLC = "no"; then + AC_MSG_ERROR(could not find ocamlc in PATH, please make sure ocaml is installed) +fi + +AC_CHECK_PROG(HAVE_OCAMLFIND, ocamlfind, yes, no) +if test $HAVE_OCAMLFIND = "no"; then + AC_MSG_ERROR(could not find ocamlfind in PATH, please make sure findlib is installed) +fi + +AC_MSG_CHECKING("for gdome2") +ocamlfind query gdome2 || + AC_MSG_ERROR(gdome2 not installed (according to findlib)) + +AC_MSG_CHECKING("for the ocaml library dir") +OCAML_LIB_DIR=`ocamlc -where` +AC_MSG_RESULT($OCAML_LIB_DIR) + +AC_CHECK_FILE(/usr/include/caml/mlvalues.h, + OCAML_INCLUDE_DIR=/usr/include/caml, + OCAML_INCLUDE_DIR=$OCAML_LIB_DIR/caml +) + +AC_SUBST(PACKAGE) +AC_SUBST(VERSION) +AC_SUBST(OCAML_INCLUDE_DIR) + +AC_OUTPUT([ + Makefile + META +]) diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt.ml b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt.ml new file mode 100644 index 000000000..6ca611cb3 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt.ml @@ -0,0 +1,36 @@ +(* This file is part of an ocaml binding of an XSLT engine working on Gdome + * documents. + * + * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT + * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT) + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + *) + +let processStylesheet style = + I_gdome_xslt.processStylesheet style#as_Document +;; + +let applyStylesheet ~source ~stylesheet ~params = + let res = + I_gdome_xslt.applyStylesheet ~source:(source#as_Document) ~stylesheet + ~params + in + new Gdome.document res +;; diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt.mli b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt.mli new file mode 100644 index 000000000..a67fdd61e --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt.mli @@ -0,0 +1,38 @@ +(* This file is part of an ocaml binding of an XSLT engine working on Gdome + * documents. + * + * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT + * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT) + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + *) + +(* processStylesheet stylesheet *) +(* Process a stylesheet so that it can be subsequently used *) +(* with applyStylesheet. *) +val processStylesheet : + Gdome.document -> I_gdome_xslt.processed_stylesheet + +(* applyStylesheet source stylesheet params *) +(* Applies a processed stylesheet to a source document, using *) +(* the given list of parameters (couples name,value) *) +val applyStylesheet : + source: Gdome.document -> + stylesheet:I_gdome_xslt.processed_stylesheet -> + params:(string * string) list -> Gdome.document diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt_init.ml b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt_init.ml new file mode 100644 index 000000000..447f6c510 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt_init.ml @@ -0,0 +1,39 @@ +(* This file is part of an ocaml binding of an XSLT engine working on Gdome + * documents. + * + * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT + * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT) + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + *) + +exception ProcessStylesheetException +exception ApplyStylesheetException + +let _ = + Callback.register_exception + "ProcessStylesheetException" ProcessStylesheetException +;; + +let _ = + Callback.register_exception + "ApplyStylesheetException" ApplyStylesheetException +;; + +I_gdome_xslt.setXsltMaxDepth 2000;; diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt_init.mli b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt_init.mli new file mode 100644 index 000000000..2d5278791 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/gdome_xslt_init.mli @@ -0,0 +1,35 @@ +(* This file is part of an ocaml binding of an XSLT engine working on Gdome + * documents. + * + * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT + * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT) + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + *) + +(**************************** WARNING!!! ***********************************) +(*** ***) +(*** This file must always be linked with any code using gdome_xslt and ***) +(*** must be linked as the first file. It is responsible of initializing ***) +(*** the whole binding, registering some ocaml values to the C level. ***) +(*** ***) +(***************************************************************************) + +exception ProcessStylesheetException +exception ApplyStylesheetException diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/i_gdome_xslt.ml b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/i_gdome_xslt.ml new file mode 100644 index 000000000..c4f25e6c8 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/i_gdome_xslt.ml @@ -0,0 +1,31 @@ +(* This file is part of an ocaml binding of an XSLT engine working on Gdome + * documents. + * + * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT + * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT) + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + *) + +type processed_stylesheet + +external setXsltMaxDepth : int -> unit = "setXsltMaxDepth" + +external processStylesheet: [> `Document] GdomeT.t -> processed_stylesheet = "ml_processStylesheet" +external applyStylesheet : source:[> `Document] GdomeT.t -> stylesheet:processed_stylesheet -> params:(string * string) list -> TDocument.t = "ml_applyStylesheet" diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/ml_gdome_xslt.c b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/ml_gdome_xslt.c new file mode 100644 index 000000000..e9af428a3 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/ml_gdome_xslt.c @@ -0,0 +1,126 @@ +/* This file is part of an ocaml binding of an XSLT engine working on Gdome + * documents. + * + * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT + * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT) + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + */ + +#include + +#include +#include +#include + +#include +#include + +#include "mlgdomevalue.h" +#include "gdome_xslt.h" + +xsltStylesheetPtr XsltStylesheetPtr_val(value); + +static void ml_xsltFreeStylesheet(value v) +{ + xsltFreeStylesheet(XsltStylesheetPtr_val(v)); +} + +xsltStylesheetPtr XsltStylesheetPtr_val(value v) +{ + CAMLparam1(v); + xsltStylesheetPtr res = *((xsltStylesheetPtr*) Data_custom_val(v)); + CAMLreturn(res); +} + +value Val_XsltStylesheetPtr(xsltStylesheetPtr obj) +{ + CAMLparam0(); + CAMLlocal1(v); + static struct custom_operations ops = { + "http://www.cs.unibo.it/helm/gdome_xslt/XsltStylesheetPtr", + ml_xsltFreeStylesheet, + custom_compare_default, + custom_hash_default, + custom_serialize_default, + custom_deserialize_default + }; + + v = alloc_custom(&ops, sizeof(xsltStylesheetPtr), 0, 1); + *((xsltStylesheetPtr*) Data_custom_val(v)) = obj; + + CAMLreturn(v); +} + +value ml_processStylesheet(value style) +{ + CAMLparam1(style); + xsltStylesheetPtr res; + res = processStylesheet(Document_val(style)); + if (res == NULL) { + value* excp; + excp = caml_named_value("ProcessStylesheetException"); + assert(excp != NULL); + raise_constant(*excp); + } + CAMLreturn(Val_XsltStylesheetPtr(res)); +} + +value setXsltMaxDepth(value depth) +{ + CAMLparam1(depth); + xsltMaxDepth = Int_val(depth); + CAMLreturn0; +} + +value ml_applyStylesheet(value source, value style, value params) +{ + CAMLparam3(source,style,params); + CAMLlocal1(list); + GdomeDocument* res; + int i; + const char** c_params; + + i = 0 ; list = params; + while(list != Val_int(0)) { + list = Field(list,1); + i++; + } + c_params = (const char **)malloc(sizeof(char *) * (i * 2 + 1)); + + i = 0; list = params; + while(list != Val_int(0)) { + c_params[i] = String_val(Field(Field(list,0),0)); + c_params[i+1] = String_val(Field(Field(list,0),1)); + list = Field(list,1); + i+=2; + } + c_params[i] = NULL; + res = applyStylesheet(Document_val(source), + XsltStylesheetPtr_val(style), + c_params); + free(c_params); + if (res == NULL) { + value* excp; + excp = caml_named_value("ApplyStylesheetException"); + assert(excp != NULL); + raise_constant(*excp); + } + CAMLreturn(Val_Document(res)); +} diff --git a/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/ml_gdome_xslt.h b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/ml_gdome_xslt.h new file mode 100644 index 000000000..6f12e4b11 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/gdome_xslt/ml_gdome_xslt.h @@ -0,0 +1,30 @@ +/* This file is part of an ocaml binding of an XSLT engine working on Gdome + * documents. + * + * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT + * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT) + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + */ + +xsltStylesheetPtr XsltStylesheetPtr_val(value); +value Val_XsltStylesheetPtr(xsltStylesheetPtr); + +value ml_processStylesheet(value style); +value ml_applyStylesheet(value source, value style, value params); diff --git a/helm/DEVEL/gdome_xslt/ocaml/test/.cvsignore b/helm/DEVEL/gdome_xslt/ocaml/test/.cvsignore new file mode 100644 index 000000000..6deb7349f --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/test/.cvsignore @@ -0,0 +1,6 @@ +test.cmi +test.cmo +test.cmx +test.o +test +test.opt diff --git a/helm/DEVEL/gdome_xslt/ocaml/test/Makefile b/helm/DEVEL/gdome_xslt/ocaml/test/Makefile new file mode 100644 index 000000000..b36523d5d --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/test/Makefile @@ -0,0 +1,17 @@ +REQUIRES = gdome_xslt +PREDICATES = +OCAMLOPTIONS = -package "$(REQUIRES)" -predicates "$(PREDICATES)" +OCAMLC = ocamlfind ocamlc $(OCAMLOPTIONS) +OCAMLOPT = ocamlfind ocamlopt $(OCAMLOPTIONS) + +all: test +opt: test.opt + +test: test.ml + $(OCAMLC) -linkpkg -o $@ $< + +test.opt: test.ml + $(OCAMLOPT) -linkpkg -o $@ $< + +clean: + rm -f test test.opt test.cmi test.cmo text.cmx diff --git a/helm/DEVEL/gdome_xslt/ocaml/test/test.ml b/helm/DEVEL/gdome_xslt/ocaml/test/test.ml new file mode 100644 index 000000000..3e313ed6c --- /dev/null +++ b/helm/DEVEL/gdome_xslt/ocaml/test/test.ml @@ -0,0 +1,60 @@ +(* This file is part of an ocaml binding of an XSLT engine working on Gdome + * documents. + * + * The code is largely based on the code of T.J. Mather's XML::GDOME::XSLT + * Perl module (http://kobesearch.cpan.org/search?dist=XML-GDOME-XSLT) + * + * Copyright (C) 2002 Claudio Sacerdoti Coen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * For more information, please send an email to + *) + +let domImpl = Gdome.domImplementation () in + let input = + domImpl#createDocumentFromURI ~uri:"../../test_files/input.xml" () + and style = + domImpl#createDocumentFromURI ~uri:"../../test_files/stylesheet.xsl" () + in + (* First of all, let's try the exception handling machinery *) + let _ = + try + ignore (Gdome_xslt.processStylesheet input) ; + assert false (* previous line should rise an exception *) + with + Gdome_xslt_init.ProcessStylesheetException -> () + in + let pstyle = Gdome_xslt.processStylesheet style in + let output = + Gdome_xslt.applyStylesheet input pstyle + ["parameter1","'value1'" ; + "parameter2","'value2'" ; + "parameter3","'value3'" + ] + in + let res = + domImpl#saveDocumentToFile ~doc:output ~name:"../../test_files/output.xml" + () + in + if not res then + prerr_endline "Error saving to document ../../test_files/output.xml" + else + begin + print_endline + "The test was successful iff ../../test_files/output.xml.correct is" ; + print_endline "equal to ../../test_files/output.xml" + end +;; diff --git a/helm/DEVEL/gdome_xslt/test_files/.cvsignore b/helm/DEVEL/gdome_xslt/test_files/.cvsignore new file mode 100644 index 000000000..0184bf05d --- /dev/null +++ b/helm/DEVEL/gdome_xslt/test_files/.cvsignore @@ -0,0 +1 @@ +output.xml diff --git a/helm/DEVEL/gdome_xslt/test_files/input.xml b/helm/DEVEL/gdome_xslt/test_files/input.xml new file mode 100644 index 000000000..b6ffa38fd --- /dev/null +++ b/helm/DEVEL/gdome_xslt/test_files/input.xml @@ -0,0 +1,4 @@ + + + It works! + diff --git a/helm/DEVEL/gdome_xslt/test_files/output.xml.correct b/helm/DEVEL/gdome_xslt/test_files/output.xml.correct new file mode 100644 index 000000000..c4adda3d7 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/test_files/output.xml.correct @@ -0,0 +1,4 @@ + +value2value3value1 + It works! + diff --git a/helm/DEVEL/gdome_xslt/test_files/stylesheet.xsl b/helm/DEVEL/gdome_xslt/test_files/stylesheet.xsl new file mode 100644 index 000000000..ca4534e12 --- /dev/null +++ b/helm/DEVEL/gdome_xslt/test_files/stylesheet.xsl @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + -- 2.39.2