libgda r3118 - in trunk: . libgda-xslt samples/XSLT tests/data-models tests/meta-store tests/value-holders



Author: vivien
Date: Sun Apr  6 13:37:13 2008
New Revision: 3118
URL: http://svn.gnome.org/viewvc/libgda?rev=3118&view=rev

Log:
2008-04-06  Vivien Malerba <malerba gnome-db org>

	* samples/XSLT/test.xsl:
	* samples/XSLT/transform.c:
	* libgda-xslt/libgda-xslt.h:
	* libgda-xslt/sqlexslt.c:
	* libgda-xslt/sql_backend.c:
	* libgda-xslt/sql_exslt_internal.c:
	* libgda-xslt/sql_backend.h: applied patch from Pawel Cesar Sanjuan Szklarz to
	add a new function to the xslt extension libgda-xslt


Modified:
   trunk/ChangeLog
   trunk/libgda-xslt/libgda-xslt.h
   trunk/libgda-xslt/sql_backend.c
   trunk/libgda-xslt/sql_backend.h
   trunk/libgda-xslt/sql_exslt_internal.c
   trunk/libgda-xslt/sqlexslt.c
   trunk/samples/XSLT/   (props changed)
   trunk/samples/XSLT/test.xsl
   trunk/samples/XSLT/transform.c
   trunk/tests/data-models/   (props changed)
   trunk/tests/meta-store/   (props changed)
   trunk/tests/value-holders/   (props changed)

Modified: trunk/libgda-xslt/libgda-xslt.h
==============================================================================
--- trunk/libgda-xslt/libgda-xslt.h	(original)
+++ trunk/libgda-xslt/libgda-xslt.h	Sun Apr  6 13:37:13 2008
@@ -2,7 +2,7 @@
  * Copyright (C) 2007 - 2008 The GNOME Foundation.
  *
  * AUTHORS:
- *      Pawe Cesar Sanjuan Szklarz <paweld2 gmail com>
+ *      PaweÅ Cesar Sanjuan Szklarz <paweld2 gmail com>
  *
  * This Library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public License as
@@ -28,7 +28,7 @@
 #include <libxslt/transform.h>
 
 G_BEGIN_DECLS
-#define GDA_XSLT_EXTENSION_URI "http://www.gnome-db.org/ns/gda-sql-ext";
+#define GDA_XSLT_EXTENSION_URI "http://www.gnome-db.org/ns/gda-sql-ext-v4";
 struct _GdaXsltExCont
 {
 	int            init;

Modified: trunk/libgda-xslt/sql_backend.c
==============================================================================
--- trunk/libgda-xslt/sql_backend.c	(original)
+++ trunk/libgda-xslt/sql_backend.c	Sun Apr  6 13:37:13 2008
@@ -2,7 +2,7 @@
  * Copyright (C) 2007 - 2008 The GNOME Foundation.
  *
  * AUTHORS:
- *      Pawe³ Cesar Sanjuan Szklarz <paweld2 gmail com>
+ *      PaweÅ Cesar Sanjuan Szklarz <paweld2 gmail com>
  *      Vivien Malerba <malerba gnome-db org>
  *
  * This Library is free software; you can redistribute it and/or
@@ -200,11 +200,16 @@
 
 xmlXPathObjectPtr
 gda_xslt_bk_fun_getvalue (xmlChar * set, xmlChar * name, GdaXsltExCont * exec,
-			  GdaXsltIntCont * pdata)
+			  GdaXsltIntCont * pdata,int getXml)
 {
 	xmlXPathObjectPtr value;
 	int res;
-	printf ("running function:gda_xslt_bk_fun_getvalue\n");
+	xmlDocPtr sqlxmldoc;
+	xmlNodePtr rootnode;
+	xmlNodePtr copyrootnode;
+#ifdef GDA_DEBUG_NO
+	g_print ("running function:gda_xslt_bk_fun_getvalue (getxml [%d])", getXml);
+#endif
 	char *strvalue;
 	res = get_resultset_col_value (pdata, (const char *) set,
 				       (const char *) name, &strvalue,
@@ -214,8 +219,28 @@
 				  "gda_xslt_bk_fun_getvalue: internal error on get_resultset_col_value\n");
 		return NULL;
 	}
-	value = (xmlXPathObjectPtr) xmlXPathNewCString ((const char *)
-							strvalue);
+
+	if( getXml) {
+		sqlxmldoc = xmlParseDoc((const xmlChar *)strvalue);
+		if (sqlxmldoc == NULL) {
+			xsltGenericError (xsltGenericErrorContext,
+					"gda_xslt_bk_fun_getvalue: xmlParseDoc fauld\n");
+			return NULL;
+		}
+		rootnode = xmlDocGetRootElement(sqlxmldoc);
+		copyrootnode = xmlCopyNode(rootnode,1);
+		if (copyrootnode == NULL) {
+			xsltGenericError (xsltGenericErrorContext,
+					"gda_xslt_bk_fun_getvalue: get or copy of root node fauld\n");
+			return NULL;
+		}
+		value = (xmlXPathObjectPtr) xmlXPathNewNodeSet (copyrootnode);
+		xmlFreeDoc(sqlxmldoc );
+	} else {
+		value = (xmlXPathObjectPtr) xmlXPathNewCString ((const char *)
+								strvalue);
+	}
+
 	if (value == NULL) {
 		xsltGenericError (xsltGenericErrorContext,
 				  "gda_xslt_bk_fun_getvalue: internal error\n");

Modified: trunk/libgda-xslt/sql_backend.h
==============================================================================
--- trunk/libgda-xslt/sql_backend.h	(original)
+++ trunk/libgda-xslt/sql_backend.h	Sun Apr  6 13:37:13 2008
@@ -2,7 +2,7 @@
  * Copyright (C) 2007 The GNOME Foundation.
  *
  * AUTHORS:
- *      Pawe Cesar Sanjuan Szklarz <paweld2 gmail com>
+ *      PaweÅ Cesar Sanjuan Szklarz <paweld2 gmail com>
  *
  * This Library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public License as
@@ -32,6 +32,7 @@
 G_BEGIN_DECLS
 
 #define GDA_XSLT_FUNC_GETVALUE       "getvalue"
+#define GDA_XSLT_FUNC_GETXMLVALUE    "getxmlvalue"
 #define GDA_XSLT_FUNC_GETNODESET     "getnodeset"
 #define GDA_XSLT_FUNC_CHECKIF        "checkif"
 #define GDA_XSLT_ELEM_SECTION        "section"
@@ -59,7 +60,8 @@
 /* functions backend */
 xmlXPathObjectPtr gda_xslt_bk_fun_getvalue (xmlChar * set, xmlChar * name,
 					    GdaXsltExCont * exec,
-					    GdaXsltIntCont * pdata);
+					    GdaXsltIntCont * pdata,
+					    int getXml);
 xmlXPathObjectPtr gda_xslt_bk_fun_getnodeset (xmlChar * set,
 					      GdaXsltExCont * exec,
 					      GdaXsltIntCont * pdata);

Modified: trunk/libgda-xslt/sql_exslt_internal.c
==============================================================================
--- trunk/libgda-xslt/sql_exslt_internal.c	(original)
+++ trunk/libgda-xslt/sql_exslt_internal.c	Sun Apr  6 13:37:13 2008
@@ -2,7 +2,7 @@
  * Copyright (C) 2007 The GNOME Foundation.
  *
  * AUTHORS:
- *      Pawe³ Cesar Sanjuan Szklarz <paweld2 gmail com>
+ *      PaweÅ Cesar Sanjuan Szklarz <paweld2 gmail com>
  *
  * This Library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public License as
@@ -39,6 +39,8 @@
 				       int nargs);
 static void gda_xslt_getvalue_function (xmlXPathParserContextPtr ctxt,
 					int nargs);
+static void gda_xslt_getxmlvalue_function (xmlXPathParserContextPtr ctxt,
+					int nargs);
 static void gda_xslt_section_element (xsltTransformContextPtr tctxt,
 				      xmlNodePtr node, xmlNodePtr inst,
 				      xsltStylePreCompPtr comp);
@@ -77,6 +79,10 @@
 				       (const xmlChar *)
 				       GDA_XSLT_FUNC_GETVALUE, URI,
 				       gda_xslt_getvalue_function);
+	res = xsltRegisterExtFunction (ctxt,
+				       (const xmlChar *)
+				       GDA_XSLT_FUNC_GETXMLVALUE, URI,
+				       gda_xslt_getxmlvalue_function);
 	res |= xsltRegisterExtFunction (ctxt,
 					(const xmlChar *)
 					GDA_XSLT_FUNC_CHECKIF, URI,
@@ -119,7 +125,7 @@
 	GdaXsltExCont *execc;
 	if (nargs != 1) {
 		xsltGenericError (xsltGenericErrorContext,
-				  "gda_xslt_getvalue_function: invalid number of arguments\n");
+				  "gda_xslt_getnodeset_function: invalid number of arguments\n");
 		return;
 	}
 	tctxt = xsltXPathGetTransformContext (ctxt);
@@ -133,13 +139,13 @@
 						  GDA_XSLT_EXTENSION_URI);
 	if (data == NULL) {
 		xsltGenericError (xsltGenericErrorContext,
-				  "PEIMP_xslt_normal_latex_escape: failed to get module data\n");
+				  "sqlxslt: failed to get module data\n");
 		return;
 	}
 	setname = valuePop (ctxt);
 	if (setname == NULL) {
 		xsltGenericError (xsltGenericErrorContext,
-				  "PEIMP_xslt_normal_latex_escape: internal error\n");
+				  "sqlxslt: internal error\n");
 		return;
 	}
 
@@ -149,7 +155,7 @@
 		setname = valuePop (ctxt);
 		if (setname == NULL) {
 			xsltGenericError (xsltGenericErrorContext,
-					  "PEIMP_xslt_normal_latex_escape: internal error\n");
+					  "sqlxslt: internal error\n");
 			return;
 		}
 	}
@@ -285,7 +291,7 @@
 	}
 
 	value = gda_xslt_bk_fun_getvalue (set->stringval, name->stringval,
-					  execc, data);
+					  execc, data,0);
 	if (value == NULL) {
 		xsltGenericError (xsltGenericErrorContext,
 				  "gda_xslt_getvalue_function: internal error. Empty value\n");
@@ -295,6 +301,73 @@
 }
 
 static void
+gda_xslt_getxmlvalue_function (xmlXPathParserContextPtr ctxt, int nargs)
+{
+	GdaXsltIntCont *data;
+	xsltTransformContextPtr tctxt;
+	xmlXPathObjectPtr set, name, value;
+	GdaXsltExCont *execc;
+
+	if (nargs != 2) {
+		xsltGenericError (xsltGenericErrorContext,
+				  "gda_xslt_getxmlvalue_function: invalid number of arguments\n");
+		return;
+	}
+	tctxt = xsltXPathGetTransformContext (ctxt);
+	if (tctxt == NULL) {
+		xsltGenericError (xsltGenericErrorContext,
+				  "gda_xslt_getxmlvalue_function: failed to get the transformation context\n");
+		return;
+	}
+
+	execc = (GdaXsltExCont *) tctxt->_private;
+	data = (GdaXsltIntCont *) xsltGetExtData (tctxt,
+						  GDA_XSLT_EXTENSION_URI);
+	if (data == NULL || execc == NULL) {
+		xsltGenericError (xsltGenericErrorContext,
+				  "gda_xslt_getxmlvalue_function: failed to get module internal data\n");
+		return;
+	}
+	name = valuePop (ctxt);
+	set = valuePop (ctxt);
+	if (name == NULL || set == NULL) {
+		xsltGenericError (xsltGenericErrorContext,
+				  "gda_xslt_getxmlvalue_function: internal error\n");
+		return;
+	}
+
+	if (name->type != XPATH_STRING) {
+		valuePush (ctxt, name);
+		xmlXPathStringFunction (ctxt, 1);
+		name = valuePop (ctxt);
+		if (name == NULL) {
+			xsltGenericError (xsltGenericErrorContext,
+					  "gda_xslt_getxmlvalue_function: internal error. Name parameter is not a string\n");
+			return;
+		}
+	}
+	if (set->type != XPATH_STRING) {
+		valuePush (ctxt, set);
+		xmlXPathStringFunction (ctxt, 1);
+		set = valuePop (ctxt);
+		if (set == NULL) {
+			xsltGenericError (xsltGenericErrorContext,
+					  "gda_xslt_getxmlvalue_function: internal error. Set parameter is not a string\n");
+			return;
+		}
+	}
+
+	value = gda_xslt_bk_fun_getvalue (set->stringval, name->stringval,
+					  execc, data,1);
+	if (value == NULL) {
+		xsltGenericError (xsltGenericErrorContext,
+				  "gda_xslt_getxmlvalue_function: internal error. Empty value\n");
+		return;
+	}
+	valuePush (ctxt, value);
+}
+
+static void
 gda_xslt_section_element (xsltTransformContextPtr tctxt,
 			  xmlNodePtr node,
 			  xmlNodePtr inst, xsltStylePreCompPtr comp)

Modified: trunk/libgda-xslt/sqlexslt.c
==============================================================================
--- trunk/libgda-xslt/sqlexslt.c	(original)
+++ trunk/libgda-xslt/sqlexslt.c	Sun Apr  6 13:37:13 2008
@@ -2,7 +2,7 @@
  * Copyright (C) 2007 - 2008 The GNOME Foundation.
  *
  * AUTHORS:
- *      Pawe³ Cesar Sanjuan Szklarz <paweld2 gmail com>
+ *      PaweÅ Cesar Sanjuan Szklarz <paweld2 gmail com>
  *      Vivien Malerba <malerba gnome-db org>
  *
  * This Library is free software; you can redistribute it and/or
@@ -36,7 +36,7 @@
 /**
  * gda_xslt_register
  *
- * FIXME: ADD COMMENT
+ * Register the xslt extension to libxslt
  */
 void
 gda_xslt_register (void)
@@ -59,7 +59,7 @@
 /**
  * gda_xslt_set_execution_context
  *
- * FIXME: ADD COMMENT
+ * Set the internal gda-xslt context to the xsltTransformationContext.
  */
 void
 gda_xslt_set_execution_context (xsltTransformContextPtr tcxt,
@@ -71,7 +71,7 @@
 /**
  * gda_xslt_create_context_simple
  *
- * FIXME: ADD COMMENT
+ *  create a gda-xslt context with the Gdaconnection and not predefined queries
  *
  * Returns:
  */
@@ -91,7 +91,7 @@
 /**
  * gda_xslt_finalize_context
  * 
- * FIXME: ADD COMMENT
+ * clear the gda-xslt context
  *
  * Returns:
  */

Modified: trunk/samples/XSLT/test.xsl
==============================================================================
--- trunk/samples/XSLT/test.xsl	(original)
+++ trunk/samples/XSLT/test.xsl	Sun Apr  6 13:37:13 2008
@@ -1,6 +1,6 @@
 <xsl:stylesheet version = '1.0'
      xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
-     xmlns:sql="http://www.gnome-db.org/ns/gda-sql-ext";
+     xmlns:sql="http://www.gnome-db.org/ns/gda-sql-ext-v4";
      extension-element-prefixes="sql">
 
 <xsl:output method="html" indent="yes" encoding="utf-8"/>

Modified: trunk/samples/XSLT/transform.c
==============================================================================
--- trunk/samples/XSLT/transform.c	(original)
+++ trunk/samples/XSLT/transform.c	Sun Apr  6 13:37:13 2008
@@ -5,11 +5,13 @@
 gchar *inputfile = NULL;
 gchar *outputfile = NULL;
 gchar *xslfile = NULL;
+gchar *dsn = NULL;
 
 static GOptionEntry entries[] = {
         { "in", 'i', 0, G_OPTION_ARG_STRING, &inputfile, "Input file", NULL},
         { "out", 'o', 0, G_OPTION_ARG_STRING, &outputfile, "Output file", NULL},
         { "xsl", 'x', 0, G_OPTION_ARG_STRING, &xslfile, "XSL file", NULL},
+	{ "dsn", 'd', 0, G_OPTION_ARG_STRING, &dsn, "Data source name", NULL},
         { NULL }
 };
 
@@ -46,13 +48,17 @@
 		g_print ("Missing XSL file (use --help option)\n");
 		exit (EXIT_FAILURE);
 	}
+	if (!dsn) {
+		g_print ("Missing Data source name, using the default \"SalesTest\"\n");
+		dsn = "SalesTest";
+	}
 
         gda_init ("LibgdaXsltProc", "1.0", argc, argv);
 
 	/* open connection */
-        cnc = gda_connection_open_from_dsn ("SalesTest", NULL, 0, &error);
+	cnc = gda_connection_open_from_dsn (dsn, NULL, GDA_CONNECTION_OPTIONS_NONE, &error);
         if (!cnc) {
-                g_print ("Could not open connection to DSN 'SalesTest': %s\n",
+                g_print ("Could not open connection to DSN '%s': %s\n", dsn,
                          error && error->message ? error->message : "No detail");
                 exit (EXIT_FAILURE);
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]