balld 00/07/05 20:40:24
Modified: . build.sh
samples/sql taglib.xml
src/org/apache/cocoon/framework Configurations.java
src/org/apache/cocoon/processor/xsp XSPProcessor.java
src/org/apache/cocoon/processor/xsp/library/java sql.xsl
src/org/apache/cocoon/processor/xsp/library/sql
XSPSQLLibrary.java
Added: lib turbine-2.0.jar
Log:
added turbine to lib and build.sh
added connection pool to sql logicsheet
Revision Changes Path
1.17 +2 -1 xml-cocoon/build.sh
Index: build.sh
===================================================================
RCS file: /home/cvs/xml-cocoon/build.sh,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- build.sh 2000/05/07 15:59:01 1.16
+++ build.sh 2000/07/06 03:39:54 1.17
@@ -19,7 +19,8 @@
XALAN=./lib/xalan_1_0_1.jar
FOP=./lib/fop_0_12_1.jar
SERVLETS=./lib/servlet_2_2.jar
-LOCALCLASSPATH=$ANT:$JAVAC:$XERCES:$XALAN:$FOP:$SERVLETS:$CLASSPATH
+TURBINE=./lib/turbine-2.0.jar
+LOCALCLASSPATH=$ANT:$JAVAC:$XERCES:$XALAN:$FOP:$SERVLETS:$TURBINE:$CLASSPATH
echo
echo Building with classpath $LOCALCLASSPATH
1.1 xml-cocoon/lib/turbine-2.0.jar
<<Binary file>>
1.4 +2 -1 xml-cocoon/samples/sql/taglib.xml
Index: taglib.xml
===================================================================
RCS file: /home/cvs/xml-cocoon/samples/sql/taglib.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- taglib.xml 2000/06/07 19:40:45 1.3
+++ taglib.xml 2000/07/06 03:40:10 1.4
@@ -6,6 +6,7 @@
language="java"
xmlns:sql="http://www.apache.org/1999/SQL"
xmlns:xsp="http://www.apache.org/1999/XSP/Core"
+ xmlns:request="http://www.apache.org/1999/XSP/Request"
>
<page title="SQL Search Results">
@@ -13,7 +14,6 @@
<sql:execute-query>
<sql:driver>org.gjt.mm.mysql.Driver</sql:driver>
<sql:dburl>jdbc:mysql://localhost/test</sql:dburl>
- <sql:query>select * from column_type_table</sql:query>
<sql:doc-element>things</sql:doc-element>
<sql:row-element>thing</sql:row-element>
<sql:column-format>
@@ -26,6 +26,7 @@
<sql:class>java.text.SimpleDateFormat</sql:class>
<sql:parameter>hh:mm (ss)</sql:parameter>
</sql:column-format>
+ <sql:query>select * from column_type_table where id =
<request:get-parameter name="id"/></sql:query>
</sql:execute-query>
</page>
1.8 +9 -2
xml-cocoon/src/org/apache/cocoon/framework/Configurations.java
Index: Configurations.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/framework/Configurations.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- Configurations.java 2000/05/01 23:51:18 1.7
+++ Configurations.java 2000/07/06 03:40:11 1.8
@@ -1,4 +1,4 @@
-/*-- $Id: Configurations.java,v 1.7 2000/05/01 23:51:18 stefano Exp $ --
+/*-- $Id: Configurations.java,v 1.8 2000/07/06 03:40:11 balld Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -58,7 +58,7 @@
* class to work.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version $Revision: 1.7 $ $Date: 2000/05/01 23:51:18 $
+ * @version $Revision: 1.8 $ $Date: 2000/07/06 03:40:11 $
*/
public class Configurations {
@@ -195,6 +195,13 @@
return c;
}
+ /**
+ * Get the Properties from the Configuration
+ */
+ public Properties getProperties() {
+ return this.properties;
+ }
+
public void setBasename(String baseName) {
this.baseName = baseName;
}
1.22 +40 -6
xml-cocoon/src/org/apache/cocoon/processor/xsp/XSPProcessor.java
Index: XSPProcessor.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/XSPProcessor.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- XSPProcessor.java 2000/05/07 00:43:51 1.21
+++ XSPProcessor.java 2000/07/06 03:40:16 1.22
@@ -1,4 +1,4 @@
-/*-- $Id: XSPProcessor.java,v 1.21 2000/05/07 00:43:51 ricardo Exp $ --
+/*-- $Id: XSPProcessor.java,v 1.22 2000/07/06 03:40:16 balld Exp $ --
============================================================================
The Apache Software License, Version 1.1
@@ -71,11 +71,13 @@
import org.apache.cocoon.processor.xsp.language.*;
+import org.apache.turbine.services.resources.TurbineResourceService;
+
/**
* This class implements the XSP engine.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
- * @version $Revision: 1.21 $ $Date: 2000/05/07 00:43:51 $
+ * @version $Revision: 1.22 $ $Date: 2000/07/06 03:40:16 $
*/
public class XSPProcessor extends AbstractActor
implements Processor, Configurable, Status
@@ -153,12 +155,15 @@
XSPLogicsheet logicsheet = new XSPLogicsheet(transformer,
parser, null);
String processorName = (String) c.get("processor");
- XSPLanguageProcessor languageProcessor = (XSPLanguageProcessor)
this.factory.create(processorName);
+ XSPLanguageProcessor languageProcessor =
+ (XSPLanguageProcessor)
this.factory.create(processorName);
this.languages.put(languageName, languageProcessor);
String logicsheetName = (String) c.get("logicsheet");
InputStream logicsheetInputStream =
this.getClass().getResourceAsStream(logicsheetName);
- if (logicsheetInputStream == null) throw new Exception("Resource
'" + logicsheetName + "' could not be found.");
+ if (logicsheetInputStream == null) throw new
Exception("Resource '" +
+
logicsheetName +
+
"' could not be
found.");
logicsheet.setStylesheet(this.parser.parse(new
InputSource(logicsheetInputStream)));
String preprocessorName = (String) c.get("preprocessor");
@@ -171,7 +176,8 @@
} catch (SAXException e) {
throw new
RuntimeException(Utils.getStackTraceAsString(e.getException()));
} catch (Exception e) {
- throw new RuntimeException("Error while initializing XSP engine:
" + Utils.getStackTraceAsString(e));
+ throw new RuntimeException("Error while
initializing XSP engine: " +
+
Utils.getStackTraceAsString(e));
}
}
@@ -249,11 +255,39 @@
byLanguage.put(language, this.store.get(resource.toString()));
} catch (Exception ex) {
// should we consider this fatal and throw an exception? (SM)
- logger.log(this, "Logicsheet for namespace '" + namespace + "' not
found at '" + location + "' due to " + ex, Logger.WARNING);
+ logger.log(this, "Logicsheet for namespace '" +
+ namespace + "' not found at
'" +
+ location +
+ "' due to " +
+ ex,
+ Logger.WARNING);
}
this.byNamespace.put(namespace, byLanguage);
}
+ // BPM me thinks that this is where I need to put the pool
information
+ // Load connection pool information
+ // Load namespace-mapped logicsheets
+ Configurations poolConf = conf.getConfigurations("pool");
+ Properties poolProperties = poolConf.getProperties();
+// Enumeration en = poolConf.keys();
+
+// while (en.hasMoreElements()) {
+// String key = (String) en.nextElement();
+// String value = (String) poolConf.get(key);
+// logger.log("@@@"+key+"="+value+"@@@", Logger.DEBUG);
+// }
+ try {
+ TurbineResourceService.setProperties(poolProperties);
+ logger.log("TurbineResources all set!!", Logger.DEBUG);
+ } catch (IOException ioexp) {
+ // should we consider this fatal and throw an
exception? (SM)
+ logger.log(this,
+ "Setting of TurbineResource
properties failed due to " +
+ ioexp,
+ Logger.WARNING);
+ }
+
}
public Document process(Document document, Dictionary parameters)
1.14 +33 -3
xml-cocoon/src/org/apache/cocoon/processor/xsp/library/java/sql.xsl
Index: sql.xsl
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/library/java/sql.xsl,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- sql.xsl 2000/05/16 20:01:04 1.13
+++ sql.xsl 2000/07/06 03:40:20 1.14
@@ -27,12 +27,12 @@
+ <xsl:apply-templates
select="."/>
</xsl:when>
<xsl:otherwise>
- + "<xsl:value-of
select="translate(.,'	 ',' ')"/>"
+ + "<xsl:value-of
select="normalize-space(translate(.,'	 ',' '))"/>"
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:when>
- <xsl:otherwise>"<xsl:value-of
select="$content"/>"</xsl:otherwise>
+ <xsl:otherwise>"<xsl:value-of
select="normalize-space($content)"/>"</xsl:otherwise>
</xsl:choose>
</xsl:template>
@@ -47,6 +47,11 @@
</xsl:template>
<xsl:template match="sql:execute-query">
+ <xsl:variable name="use-connection">
+ <xsl:call-template name="get-nested-string">
+ <xsl:with-param name="content"
select="sql:use-connection"/>
+ </xsl:call-template>
+ </xsl:variable>
<xsl:variable name="driver">
<xsl:call-template name="get-nested-string">
<xsl:with-param name="content" select="sql:driver"/>
@@ -179,7 +184,10 @@
column_formats.put(name,format);
}
</xsl:for-each>
- Element result_elements[] = XSPSQLLibrary.processQuery(
+ Element result_elements[] = null;
+ if (String.valueOf(<xsl:copy-of
select="$use-connection"/>) == "") {
+ result_elements =
+ XSPSQLLibrary.executeQuery(
document,
String.valueOf(<xsl:copy-of select="$driver"/>),
String.valueOf(<xsl:copy-of select="$dburl"/>),
@@ -201,6 +209,28 @@
String.valueOf(<xsl:copy-of select="$namespace"/>),
String.valueOf(<xsl:copy-of select="$query"/>),
column_formats);
+ } else {
+ result_elements =
+ XSPSQLLibrary.executeQuery(
+
document,
+
String.valueOf(<xsl:copy-of select="$use-connection"/>),
+
String.valueOf(<xsl:copy-of select="$doc-element"/>),
+
String.valueOf(<xsl:copy-of select="$row-element"/>),
+
String.valueOf(<xsl:copy-of select="$tag-case"/>),
+
String.valueOf(<xsl:copy-of select="$null-indicator"/>),
+
String.valueOf(<xsl:copy-of select="$id-attribute"/>),
+
String.valueOf(<xsl:copy-of select="$id-attribute-column"/>),
+
max_rows,
+
skip_rows,
+
String.valueOf(<xsl:copy-of select="$count-attribute"/>),
+
String.valueOf(<xsl:copy-of select="$query-attribute"/>),
+
String.valueOf(<xsl:copy-of select="$skip-rows-attribute"/>),
+
String.valueOf(<xsl:copy-of select="$max-rows-attribute"/>),
+
String.valueOf(<xsl:copy-of select="$update-rows-attribute"/>),
+
String.valueOf(<xsl:copy-of select="$namespace"/>),
+
String.valueOf(<xsl:copy-of select="$query"/>),
+
column_formats);
+ }
for (int i=0; i<result_elements.length; i++) {
<xsp:content><xsp:expr>result_elements[i]</xsp:expr></xsp:content>
}
1.9 +148 -17
xml-cocoon/src/org/apache/cocoon/processor/xsp/library/sql/XSPSQLLibrary.java
Index: XSPSQLLibrary.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/processor/xsp/library/sql/XSPSQLLibrary.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- XSPSQLLibrary.java 2000/06/22 19:49:18 1.8
+++ XSPSQLLibrary.java 2000/07/06 03:40:22 1.9
@@ -55,17 +55,79 @@
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import org.w3c.dom.*;
+import org.apache.turbine.util.db.pool.*;
+import org.apache.turbine.util.Log;
/**
* A processor that performs SQL database queries.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Donald Ball</a>
- * @version $Revision: 1.8 $ $Date: 2000/06/22 19:49:18 $
+ * @version $Revision: 1.9 $ $Date: 2000/07/06 03:40:22 $
*/
public class XSPSQLLibrary {
- public static Element[] processQuery(
+ static DBBroker pool = DBBroker.getInstance();
+
+ public static Element[] executeQuery(
+
Document document,
+
String connectionName,
+
String doc_element_name,
+
String row_element_name,
+
String tag_case,
+
String null_indicator,
+
String id_attribute,
+
String id_attribute_column,
+
Integer max_rows,
+
Integer skip_rows,
+
String count_attribute,
+
String query_attribute,
+
String skip_rows_attribute,
+
String max_rows_attribute,
+
String update_rows_attribute,
+
String namespace,
+
String query,
+
/** a table of Formats indexed by column name **/
+
Hashtable column_formats
+
)
+ throws SQLException,Exception
+ {
+ Connection connection = null;
+ DBConnection db = null;
+ //Log.note("executeQuery: connectionName = "+connectionName);
+ try {
+ db = pool.getConnection(connectionName);
+ connection = db.getConnection();
+ return processQuery( document,
+ connection,
+
doc_element_name,
+
row_element_name,
+ tag_case,
+ null_indicator,
+ id_attribute,
+
id_attribute_column,
+ max_rows,
+ skip_rows,
+
count_attribute,
+
query_attribute,
+
skip_rows_attribute,
+
max_rows_attribute,
+
update_rows_attribute,
+ namespace,
+ query,
+ /** a table of
Formats indexed by column name **/
+ column_formats
+ );
+ } catch (SQLException e) {
+ throw(new SQLException(query + e));
+ } finally {
+ if (connection != null) {
+ pool.releaseConnection(db);
+ }
+ }
+ }
+
+ public static Element[] executeQuery(
Document document,
String driver,
String dburl,
@@ -88,7 +150,9 @@
String query,
/** a table of Formats indexed by column name **/
Hashtable column_formats
- ) throws Exception {
+
)
+ throws Exception
+ {
Class.forName(driver).newInstance();
Connection conn;
@@ -97,6 +161,55 @@
} else {
conn = DriverManager.getConnection(dburl,username,password);
}
+ //Log.note("executeQuery: URL = "+dburl);
+ Element elm[] = processQuery( document,
+ conn,
+
doc_element_name,
+
row_element_name,
+
tag_case,
+
null_indicator,
+
id_attribute,
+
id_attribute_column,
+
max_rows,
+
skip_rows,
+
count_attribute,
+
query_attribute,
+
skip_rows_attribute,
+
max_rows_attribute,
+
update_rows_attribute,
+
namespace,
+ query,
+ /** a table of
Formats indexed by column name **/
+
column_formats
+ );
+ conn.close();
+ return elm;
+ }
+
+ public static Element[] processQuery(
+
Document document,
+
Connection conn,
+
String doc_element_name,
+
String row_element_name,
+
String tag_case,
+
String null_indicator,
+
String id_attribute,
+
String id_attribute_column,
+
Integer max_rows,
+
Integer skip_rows,
+
String count_attribute,
+
String query_attribute,
+
String skip_rows_attribute,
+
String max_rows_attribute,
+
String update_rows_attribute,
+
String namespace,
+
String query,
+
/** a table of Formats indexed by column name **/
+
Hashtable column_formats
+
)
+ throws Exception {
+
+ //Log.note("Query:"+query);
boolean create_row_elements = true;
if (row_element_name.equals("")) {
create_row_elements = false;
@@ -121,7 +234,8 @@
results_element =
createElement(document,namespace,doc_element_name);
results_node = results_element;
}
- if (results_element != null && !count_attribute.equals("")) {
+ if (results_element != null &&
+ !count_attribute.equals("")) {
String count_query = getCountQuery(query);
if (count_query != null) {
rs = st.executeQuery(count_query);
@@ -131,13 +245,16 @@
rs.close();
}
}
- if (results_element != null && !query_attribute.equals("")) {
+ if (results_element != null &&
+ !query_attribute.equals("")) {
results_element.setAttribute(query_attribute,URLEncoder.encode(query));
}
- if (results_element != null && !skip_rows_attribute.equals("")) {
+ if (results_element != null &&
+ !skip_rows_attribute.equals("")) {
results_element.setAttribute(skip_rows_attribute,""+skip_rows);
}
- if (results_element != null && !max_rows_attribute.equals("")) {
+ if (results_element != null &&
+ !max_rows_attribute.equals("")) {
results_element.setAttribute(max_rows_attribute,""+max_rows);
}
if (!st.execute(query)) {
@@ -176,7 +293,8 @@
if (create_row_elements) {
row_element =
createElement(document,namespace,row_element_name);
row_node = row_element;
- if (create_id_attribute && id_attribute_column_index ==
-1) {
+ if (create_id_attribute &&
+
id_attribute_column_index == -1) {
row_element.setAttribute(id_attribute,"" + count);
}
}
@@ -197,15 +315,19 @@
} else {
formatted_value =
format.format(value);
}
- if (create_row_elements && create_id_attribute &&
id_attribute_column_index == i) {
+ if (create_row_elements &&
+ create_id_attribute &&
+
id_attribute_column_index == i) {
row_element.setAttribute(id_attribute,formatted_value);
continue;
}
- if (value == null && !indicate_nulls) {
+ if (value == null &&
+ !indicate_nulls) {
continue;
}
column_element =
createElement(document,namespace,columns[i].name);
- if (value == null && indicate_nulls) {
+ if (value == null &&
+ indicate_nulls) {
column_element.setAttribute("NULL","YES");
column_element.appendChild(document.createTextNode(""));
} else {
@@ -214,12 +336,14 @@
row_node.appendChild(column_element);
}
if (create_row_elements) results_node.appendChild(row_node);
- if (max_rows.intValue() != -1 && count-skip_rows.intValue()
== max_rows.intValue()-1) break;
+ if (max_rows.intValue() != -1 &&
+ count-skip_rows.intValue() ==
max_rows.intValue()-1) break;
count++;
}
rs.close();
}
- st.close(); conn.close();
+ st.close();
+ //conn.close();
if (results_element != null) {
Element ary[] = new Element[1];
ary[0] = results_element;
@@ -235,19 +359,26 @@
}
}
- protected static Column[] getColumns(ResultSetMetaData md, String
tag_case) throws SQLException {
+ protected static Column[] getColumns(ResultSetMetaData md, String
tag_case)
+ throws SQLException {
Column columns[] = new Column[md.getColumnCount()];
if (tag_case.equals("preserve")) {
for (int i=0; i<columns.length; i++) {
- columns[i] = new
Column(md.getColumnName(i+1),md.getColumnType(i+1),md.getColumnTypeName(i+1));
+ columns[i] = new
Column(md.getColumnName(i+1),
+
md.getColumnType(i+1),
+
md.getColumnTypeName(i+1));
}
} else if (tag_case.equals("lower")) {
for (int i=0; i<columns.length; i++) {
- columns[i] = new
Column(md.getColumnName(i+1).toLowerCase(),md.getColumnType(i+1),md.getColumnTypeName(i+1));
+ columns[i] = new
Column(md.getColumnName(i+1).toLowerCase(),
+
md.getColumnType(i+1),
+
md.getColumnTypeName(i+1));
}
} else if (tag_case.equals("upper")) {
for (int i=0; i<columns.length; i++) {
- columns[i] = new
Column(md.getColumnName(i+1).toUpperCase(),md.getColumnType(i+1),md.getColumnTypeName(i+1));
+ columns[i] = new
Column(md.getColumnName(i+1).toUpperCase(),
+
md.getColumnType(i+1),
+
md.getColumnTypeName(i+1));
}
}
return columns;