cziegeler 02/04/05 02:59:13 Modified: . changes.xml src/java/org/apache/cocoon/transformation AbstractSAXTransformer.java SQLTransformer.java Log: Rewrote SQLTransformer and added capability to store/fetch XML Revision Changes Path 1.136 +4 -1 xml-cocoon2/changes.xml Index: changes.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/changes.xml,v retrieving revision 1.135 retrieving revision 1.136 diff -u -r1.135 -r1.136 --- changes.xml 4 Apr 2002 03:15:55 -0000 1.135 +++ changes.xml 5 Apr 2002 10:59:12 -0000 1.136 @@ -4,7 +4,7 @@ <!-- History of Cocoon changes - $Id: changes.xml,v 1.135 2002/04/04 03:15:55 vgritsenko Exp $ + $Id: changes.xml,v 1.136 2002/04/05 10:59:12 cziegeler Exp $ --> <changes title="History of Changes"> @@ -35,6 +35,9 @@ </devs> <release version="@version@" date="@date@"> + <action dev="CZ" type="update"> + Rewrote SQLTransformer and added capability to store/fetch XML. + </action> <action dev="CZ" type="add"> Added AbstractSAXTransformer for much easier implementation of custom transformers. 1.2 +2 -2 xml-cocoon2/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java Index: AbstractSAXTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- AbstractSAXTransformer.java 2 Apr 2002 14:13:34 -0000 1.1 +++ AbstractSAXTransformer.java 5 Apr 2002 10:59:12 -0000 1.2 @@ -124,7 +124,7 @@ * * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: AbstractSAXTransformer.java,v 1.1 2002/04/02 14:13:34 cziegeler Exp $ + * @version CVS $Id: AbstractSAXTransformer.java,v 1.2 2002/04/05 10:59:12 cziegeler Exp $ */ public abstract class AbstractSAXTransformer extends AbstractTransformer @@ -547,7 +547,7 @@ * is specified, the default format is used. */ public void startSerializedXMLRecording(Properties format) - throws SAXException, IOException { + throws SAXException { if (this.getLogger().isDebugEnabled() == true) { this.getLogger().debug("BEGIN startSerializedXMLRecording format="+format); } 1.9 +241 -154 xml-cocoon2/src/java/org/apache/cocoon/transformation/SQLTransformer.java Index: SQLTransformer.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/transformation/SQLTransformer.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- SQLTransformer.java 22 Feb 2002 07:03:56 -0000 1.8 +++ SQLTransformer.java 5 Apr 2002 10:59:12 -0000 1.9 @@ -51,6 +51,7 @@ package org.apache.cocoon.transformation; import org.apache.avalon.excalibur.datasource.DataSourceComponent; +import org.apache.avalon.excalibur.xml.Parser; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.component.*; import org.apache.avalon.framework.configuration.Configurable; @@ -58,18 +59,24 @@ import org.apache.avalon.framework.configuration.ConfigurationException; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.components.sax.XMLDeserializer; +import org.apache.cocoon.components.sax.XMLSerializer; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.util.Tokenizer; +import org.apache.cocoon.xml.IncludeXMLConsumer; import org.apache.log.Logger; import org.xml.sax.Attributes; +import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; import java.io.IOException; +import java.io.StringReader; import java.lang.reflect.Field; import java.sql.*; import java.util.*; +import javax.xml.transform.OutputKeys; /** * @@ -78,11 +85,11 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> * (PWR Organisation & Entwicklung) * @author <a href="mailto:[EMAIL PROTECTED]">Sven Beauprez</a> - * @version CVS $Id: SQLTransformer.java,v 1.8 2002/02/22 07:03:56 cziegeler Exp $ + * @version CVS $Id: SQLTransformer.java,v 1.9 2002/04/05 10:59:12 cziegeler Exp $ */ public class SQLTransformer - extends AbstractTransformer + extends AbstractSAXTransformer implements Composable, Disposable, Configurable { /** The SQL namespace **/ @@ -138,15 +145,9 @@ /** The offset of the current query in the queries list **/ protected int current_query_index; - /** The name of the value element we're currently receiving **/ - protected String current_name; - /** The current state of the event receiving FSM **/ protected int current_state; - /** The value of the value element we're currently receiving **/ - protected StringBuffer current_value; - /** Check if nr of rows need to be written out. **/ protected boolean showNrOfRows; @@ -164,24 +165,37 @@ /** The database selector */ protected ComponentSelector dbSelector; - /** The component manager */ - protected ComponentManager manager; - /** The parameters of the current request */ - protected Parameters parameters; - /** The current object model */ - protected Map objectModel; + /** The format for serializing xml */ + protected Properties format; + + protected XMLSerializer compiler; + protected XMLDeserializer interpreter; + protected Parser parser; + + /** + * Constructor + */ + public SQLTransformer() { + // FIXME (CZ) We have to get the correct encoding from + // somewhere else (XML Serializer?) + this.format = new Properties(); + this.format.put(OutputKeys.METHOD, "text"); + this.format.put(OutputKeys.ENCODING, "ISO-8859-1"); + this.format.put(OutputKeys.OMIT_XML_DECLARATION, "yes"); + this.namespaceURI = NAMESPACE; + } /** * Composable */ public void compose( ComponentManager manager ) { + super.compose(manager); this.queries = new Vector(); try { - this.manager = manager; this.dbSelector = (ComponentSelector) manager.lookup( DataSourceComponent.ROLE + "Selector" ); } catch ( ComponentException cme ) { - getLogger().warn( "Could not get the DataSource Selector", cme ); + this.getLogger().warn( "Could not get the DataSource Selector", cme ); } } @@ -191,13 +205,15 @@ public void recycle() { super.recycle(); this.queries.clear(); - this.current_value = null; - this.current_name = null; - this.parameters = null; - this.objectModel = null; this.outUri = null; this.inPrefix = null; this.outPrefix = null; + this.manager.release(this.parser); + this.parser = null; + this.manager.release(this.compiler); + this.compiler = null; + this.manager.release(this.interpreter); + this.interpreter = null; } /** @@ -211,10 +227,13 @@ * configure */ public void configure( Configuration conf ) throws ConfigurationException { + super.configure( conf ); if ( conf != null ) { Configuration child = conf.getChild( "old-driver" ); this.oldDriver = child.getValueAsBoolean( false ); - getLogger().debug( "old-driver is " + this.oldDriver + " for " + this ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "old-driver is " + this.oldDriver + " for " + this ); + } } } @@ -224,14 +243,11 @@ public void setup( SourceResolver resolver, Map objectModel, String source, Parameters parameters ) throws ProcessingException, SAXException, IOException { + super.setup(resolver, objectModel, source, parameters); // setup instance variables - this.current_value = new StringBuffer(); this.current_query_index = -1; this.current_state = SQLTransformer.STATE_OUTSIDE; - this.parameters = parameters; - this.objectModel = objectModel; - this.showNrOfRows = parameters.getParameterAsBoolean( SQLTransformer.MAGIC_NR_OF_ROWS, false ); if ( this.getLogger().isDebugEnabled() ) { if ( this.parameters.getParameter( SQLTransformer.MAGIC_CONNECTION , null ) != null ) { @@ -250,19 +266,19 @@ /** * This will be the meat of SQLTransformer, where the query is run. */ - protected void executeQuery( int index ) throws SAXException { - + protected void executeQuery( int index ) + throws SAXException { + if ( this.getLogger().isDebugEnabled() ) { + this.getLogger().debug( "SQLTransformer executing query nr " + index ); + } this.outUri = getCurrentQuery().properties.getParameter( SQLTransformer.MAGIC_NS_URI_ELEMENT, NAMESPACE ); this.outPrefix = getCurrentQuery().properties.getParameter( SQLTransformer.MAGIC_NS_PREFIX_ELEMENT, "" ); if ( !"".equals( this.outPrefix ) && !"".equals( this.outUri ) ) { - this.contentHandler.startPrefixMapping( this.outPrefix, this.outUri ); + super.startPrefixMapping( this.outPrefix, this.outUri ); } - if ( this.getLogger().isDebugEnabled() ) { - this.getLogger().debug( "SQLTransformer executing query nr " + index ); - } AttributesImpl attr = new AttributesImpl(); Query query = (Query) queries.elementAt( index ); boolean query_failure = false; @@ -270,7 +286,9 @@ try { query.execute(); } catch ( SQLException e ) { - getLogger().debug( "SQLTransformer:.executeQuery() query.execute failed ", e ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "SQLTransformer:.executeQuery() query.execute failed ", e ); + } AttributesImpl my_attr = new AttributesImpl(); this.start( query.rowset_name, my_attr ); this.start( MAGIC_ERROR, my_attr); @@ -292,22 +310,26 @@ } this.start( query.rowset_name, attr ); attr = new AttributesImpl(); + if ( !query.isStoredProcedure() ) { while ( query.next() ) { this.start( query.row_name, attr ); - query.serializeRow(); + query.serializeRow(this.manager); if ( index + 1 < queries.size() ) { executeQuery( index + 1 ); } this.end( query.row_name ); } } else { - query.serializeStoredProcedure(); + query.serializeStoredProcedure(this.manager); } + this.end( query.rowset_name ); } } catch ( SQLException e ) { - getLogger().debug( "SQLTransformer.executeQuery()", e ); + if (this.getLogger().isDebugEnabled()) { + getLogger().debug( "SQLTransformer.executeQuery()", e ); + } throw new SAXException( e ); } finally { try { @@ -317,7 +339,7 @@ } } if ( !"".equals( this.outPrefix ) && !"".equals( this.outUri ) ) { - this.contentHandler.endPrefixMapping( this.outPrefix ); + super.endPrefixMapping( this.outPrefix ); } } @@ -339,11 +361,12 @@ } } - protected void startValueElement( String name ) { + protected void startValueElement( String name ) + throws SAXException { switch ( current_state ) { case SQLTransformer.STATE_INSIDE_EXECUTE_QUERY_ELEMENT: - current_name = name; - current_value.setLength( 0 ); + this.stack.push(name); + this.startTextRecording(); current_state = SQLTransformer.STATE_INSIDE_VALUE_ELEMENT; break; default: @@ -352,10 +375,11 @@ } } - protected void startQueryElement( Attributes attributes ) { + protected void startQueryElement( Attributes attributes ) + throws SAXException { switch ( current_state ) { case SQLTransformer.STATE_INSIDE_EXECUTE_QUERY_ELEMENT: - current_value.setLength( 0 ); + this.startSerializedXMLRecording(format); Query q = getCurrentQuery(); current_state = SQLTransformer.STATE_INSIDE_QUERY_ELEMENT; String isupdate = @@ -377,15 +401,16 @@ } } - protected void endQueryElement() { + protected void endQueryElement() + throws ProcessingException, SAXException { switch ( current_state ) { case SQLTransformer.STATE_INSIDE_QUERY_ELEMENT: - if ( current_value.length() > 0 ) { - getCurrentQuery().addQueryPart( - current_value.toString() ); - getLogger().debug( "QUERY IS \"" + - current_value.toString() + "\"" ); - current_value.setLength( 0 ); + final String value = this.endSerializedXMLRecording(); + if ( value.length() > 0 ) { + this.getCurrentQuery().addQueryPart( value ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "QUERY IS \"" + value + "\"" ); + } } current_state = SQLTransformer.STATE_INSIDE_EXECUTE_QUERY_ELEMENT; break; @@ -394,16 +419,18 @@ } } - protected void endValueElement() { + protected void endValueElement() + throws SAXException { switch ( current_state ) { case SQLTransformer.STATE_INSIDE_VALUE_ELEMENT: - getCurrentQuery().setParameter( current_name, - current_value.toString() ); - getLogger().debug( "SETTING VALUE ELEMENT name {" + - current_name + "} value {" + - current_value.toString() + "}" ); - - current_state = SQLTransformer.STATE_INSIDE_EXECUTE_QUERY_ELEMENT; + final String name = (String)this.stack.pop(); + final String value = this.endTextRecording(); + this.getCurrentQuery().setParameter(name, value); + this.current_state = SQLTransformer.STATE_INSIDE_EXECUTE_QUERY_ELEMENT; + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "SETTING VALUE ELEMENT name {" + + name + "} value {" + value + "}" ); + } break; default: throwIllegalStateException( "Not expecting an end value element" ); @@ -427,7 +454,8 @@ } } - protected void startAncestorValueElement( Attributes attributes ) { + protected void startAncestorValueElement( Attributes attributes ) + throws ProcessingException, SAXException { switch ( current_state ) { case SQLTransformer.STATE_INSIDE_QUERY_ELEMENT: int level = 0; @@ -435,7 +463,9 @@ level = Integer.parseInt( attributes.getValue( NAMESPACE, SQLTransformer.MAGIC_ANCESTOR_VALUE_LEVEL_ATTRIBUTE ) ); } catch ( Exception e ) { - getLogger().debug( "SQLTransformer", e ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "SQLTransformer", e ); + } throwIllegalStateException( "Ancestor value elements must have a " + SQLTransformer.MAGIC_ANCESTOR_VALUE_LEVEL_ATTRIBUTE + " attribute" ); } @@ -446,17 +476,20 @@ SQLTransformer.MAGIC_ANCESTOR_VALUE_NAME_ATTRIBUTE + " attribute" ); } AncestorValue av = new AncestorValue( level, name ); - getLogger().debug( "ANCESTOR VALUE " + level + " " + name ); - - if ( current_value.length() > 0 ) { - getCurrentQuery().addQueryPart( - current_value.toString() ); - getLogger().debug( "QUERY IS \"" + - current_value.toString() + "\"" ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "ANCESTOR VALUE " + level + " " + name ); + } - current_value.setLength( 0 ); + final String value = this.endSerializedXMLRecording(); + if ( value.length() > 0 ) { + this.getCurrentQuery().addQueryPart( value ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "QUERY IS \"" + value + "\"" ); + } } getCurrentQuery().addQueryPart( av ); + this.startSerializedXMLRecording(format); + current_state = SQLTransformer.STATE_INSIDE_ANCESTOR_VALUE_ELEMENT; break; default: @@ -468,7 +501,8 @@ current_state = SQLTransformer.STATE_INSIDE_QUERY_ELEMENT; } - protected void startSubstituteValueElement( Attributes attributes ) { + protected void startSubstituteValueElement( Attributes attributes ) + throws ProcessingException, SAXException { switch ( current_state ) { case SQLTransformer.STATE_INSIDE_QUERY_ELEMENT: String name = attributes.getValue( NAMESPACE, @@ -480,15 +514,19 @@ String substitute = parameters.getParameter( name, null ); //escape single quote substitute = replaceCharWithString( substitute, '\'', "''" ); - getLogger().debug( "SUBSTITUTE VALUE " + substitute ); - if ( current_value.length() > 0 ) { - getCurrentQuery().addQueryPart( current_value.toString() ); - getLogger().debug( "QUERY IS \"" + - current_value.toString() + "\"" ); - - current_value.setLength( 0 ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "SUBSTITUTE VALUE " + substitute ); } - getCurrentQuery().addQueryPart( substitute ); + final String value = this.endSerializedXMLRecording(); + if ( value.length() > 0 ) { + this.getCurrentQuery().addQueryPart( value ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "QUERY IS \"" + value + "\"" ); + } + } + this.getCurrentQuery().addQueryPart( substitute ); + this.startSerializedXMLRecording(format); + current_state = SQLTransformer.STATE_INSIDE_SUBSTITUTE_VALUE_ELEMENT; break; default: @@ -500,15 +538,18 @@ current_state = SQLTransformer.STATE_INSIDE_QUERY_ELEMENT; } - protected void startEscapeStringElement( Attributes attributes ) { + protected void startEscapeStringElement( Attributes attributes ) + throws ProcessingException, SAXException { switch ( current_state ) { case SQLTransformer.STATE_INSIDE_QUERY_ELEMENT: - if ( current_value.length() > 0 ) { - getCurrentQuery().addQueryPart( current_value.toString() ); - getLogger().debug( "QUERY IS \"" + - current_value.toString() + "\"" ); - current_value.setLength( 0 ); + final String value = this.endSerializedXMLRecording(); + if ( value.length() > 0 ) { + this.getCurrentQuery().addQueryPart( value ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "QUERY IS \"" + value + "\"" ); + } } + this.startTextRecording(); current_state = SQLTransformer.STATE_INSIDE_ESCAPE_STRING; break; @@ -517,18 +558,20 @@ } } - protected void endEscapeStringElement() { + protected void endEscapeStringElement() + throws SAXException { switch ( current_state) { case SQLTransformer.STATE_INSIDE_ESCAPE_STRING: - if ( current_value.length() > 0 ) { - String escape = current_value.toString(); - escape = replaceCharWithString( escape, '\'', "''" ); - escape = replaceCharWithString( escape, '\\', "\\\\" ); - getCurrentQuery().addQueryPart( escape ); - getLogger().debug( "QUERY IS \"" + - current_value.toString() + "\"" ); - current_value.setLength( 0 ); + String value = this.endTextRecording(); + if ( value.length() > 0 ) { + value = replaceCharWithString( value, '\'', "''" ); + value = replaceCharWithString( value, '\\', "\\\\" ); + this.getCurrentQuery().addQueryPart( value ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "QUERY IS \"" + value + "\"" ); + } } + this.startSerializedXMLRecording(format); current_state = SQLTransformer.STATE_INSIDE_QUERY_ELEMENT; break; default: @@ -543,7 +586,9 @@ SQLTransformer.MAGIC_IN_PARAMETER_NR_ATTRIBUTE ); String value = attributes.getValue( NAMESPACE, SQLTransformer.MAGIC_IN_PARAMETER_VALUE_ATTRIBUTE ); - getLogger().debug( "IN PARAMETER NR " + nr + "; VALUE " + value ); + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "IN PARAMETER NR " + nr + "; VALUE " + value ); + } int position = Integer.parseInt( nr ); getCurrentQuery().setInParameter( position, value ); current_state = SQLTransformer.STATE_INSIDE_IN_PARAMETER_ELEMENT; @@ -566,7 +611,9 @@ SQLTransformer.MAGIC_OUT_PARAMETER_NR_ATTRIBUTE ); String type = attributes.getValue( NAMESPACE, SQLTransformer.MAGIC_OUT_PARAMETER_TYPE_ATTRIBUTE ); - getLogger().debug( "OUT PARAMETER NAME" + name + ";NR " + nr + "; TYPE " + type ); + if (this.getLogger().isDebugEnabled()) { + getLogger().debug( "OUT PARAMETER NAME" + name + ";NR " + nr + "; TYPE " + type ); + } int position = Integer.parseInt( nr ); getCurrentQuery().setOutParameter( position, type, name ); current_state = SQLTransformer.STATE_INSIDE_OUT_PARAMETER_ELEMENT; @@ -627,20 +674,25 @@ /** * ContentHandler method */ - public void startPrefixMapping( String prefix, String uri ) throws SAXException { + public void startPrefixMapping( String prefix, String uri ) + throws SAXException { if ( uri.equals( NAMESPACE ) ) { + if (inPrefix != null) { + super.startPrefixMapping( inPrefix, NAMESPACE); + } inPrefix = prefix; } else { - super.contentHandler.startPrefixMapping( prefix, uri ); + super.startPrefixMapping( prefix, uri ); } } /** * ContentHandler method */ - public void endPrefixMapping( String prefix ) throws SAXException { + public void endPrefixMapping( String prefix ) + throws SAXException { if ( !prefix.equals( inPrefix ) ) { - super.contentHandler.endPrefixMapping( prefix ); + super.endPrefixMapping( prefix ); } } @@ -653,88 +705,71 @@ getLogger().debug( "PUBLIC ID: " + locator.getPublicId() ); getLogger().debug( "SYSTEM ID: " + locator.getSystemId() ); } - if ( super.contentHandler != null ) - super.contentHandler.setDocumentLocator( locator ); + super.setDocumentLocator( locator ); } /** * ContentHandler method */ - public void startElement( String uri, String name, String raw, - Attributes attributes ) throws SAXException { - if ( !uri.equals( NAMESPACE ) ) { - super.startElement( uri, name, raw, attributes ); - return; + public void startTransformingElement( String uri, String name, String raw, + Attributes attributes ) + throws ProcessingException, SAXException { + if (this.getLogger().isDebugEnabled()) { + getLogger().debug( "RECEIVED START ELEMENT " + name ); } - getLogger().debug( "RECEIVED START ELEMENT " + name ); if ( name.equals( SQLTransformer.MAGIC_EXECUTE_QUERY ) ) { - startExecuteQueryElement(); + this.startExecuteQueryElement(); } else if ( name.equals( SQLTransformer.MAGIC_QUERY ) ) { - startQueryElement( attributes ); + this.startQueryElement( attributes ); } else if ( name.equals( SQLTransformer.MAGIC_ANCESTOR_VALUE ) ) { - startAncestorValueElement( attributes ); + this.startAncestorValueElement( attributes ); } else if ( name.equals( SQLTransformer.MAGIC_SUBSTITUTE_VALUE ) ) { - startSubstituteValueElement( attributes ); + this.startSubstituteValueElement( attributes ); } else if ( name.equals( SQLTransformer.MAGIC_IN_PARAMETER ) ) { - startInParameterElement( attributes ); + this.startInParameterElement( attributes ); } else if ( name.equals( SQLTransformer.MAGIC_OUT_PARAMETER ) ) { - startOutParameterElement( attributes ); + this.startOutParameterElement( attributes ); } else if ( name.equals( SQLTransformer.MAGIC_ESCAPE_STRING ) ) { - startEscapeStringElement( attributes ); + this.startEscapeStringElement( attributes ); } else { - startValueElement( name ); + this.startValueElement( name ); } } /** * ContentHandler method */ - public void endElement( String uri, String name, - String raw ) throws SAXException { - if ( !uri.equals( NAMESPACE ) ) { - super.endElement( uri, name, raw ); - return; + public void endTransformingElement( String uri, String name, + String raw ) + throws ProcessingException, IOException, SAXException { + if (this.getLogger().isDebugEnabled()) { + this.getLogger().debug( "RECEIVED END ELEMENT " + name + "(" + uri + ")" ); } - getLogger().debug( "RECEIVED END ELEMENT " + name + "(" + uri + ")" ); if ( name.equals( SQLTransformer.MAGIC_EXECUTE_QUERY ) ) { - endExecuteQueryElement(); + this.endExecuteQueryElement(); } else if ( name.equals( SQLTransformer.MAGIC_QUERY ) ) { - endQueryElement(); + this.endQueryElement(); } else if ( name.equals( SQLTransformer.MAGIC_ANCESTOR_VALUE ) ) { - endAncestorValueElement(); + this.endAncestorValueElement(); } else if ( name.equals( SQLTransformer.MAGIC_SUBSTITUTE_VALUE ) ) { - endSubstituteValueElement(); + this.endSubstituteValueElement(); } else if ( name.equals( SQLTransformer.MAGIC_IN_PARAMETER ) ) { - endInParameterElement(); + this.endInParameterElement(); } else if ( name.equals( SQLTransformer.MAGIC_OUT_PARAMETER ) ) { - endOutParameterElement(); - } else if ( name.equals( SQLTransformer.MAGIC_VALUE ) || current_state == SQLTransformer.STATE_INSIDE_VALUE_ELEMENT ) { - endValueElement(); + this.endOutParameterElement(); + } else if ( name.equals( SQLTransformer.MAGIC_VALUE ) + || current_state == SQLTransformer.STATE_INSIDE_VALUE_ELEMENT ) { + this.endValueElement(); } else if ( name.equals( SQLTransformer.MAGIC_ESCAPE_STRING ) ) { - endEscapeStringElement(); + this.endEscapeStringElement(); } else { - super.endElement( uri, name, raw ); + super.endTransformingElement( uri, name, raw ); } } /** - * ContentHandler method - */ - public void characters( char ary[], int start, - int length ) throws SAXException { - if ( current_state != SQLTransformer.STATE_INSIDE_VALUE_ELEMENT && - current_state != SQLTransformer.STATE_INSIDE_QUERY_ELEMENT && - current_state != SQLTransformer.STATE_INSIDE_ESCAPE_STRING ) { - super.characters( ary, start, length ); - } - getLogger().debug( "RECEIVED CHARACTERS: " + - new String( ary, start, length ) ); - current_value.append( ary, start, length ); - } - - /** * Helper method for generating SAX events */ private void attribute( AttributesImpl attr, String name, String value ) { @@ -744,8 +779,15 @@ /** * Helper method for generating SAX events */ - private void start( String name, AttributesImpl attr ) throws SAXException { - super.contentHandler.startElement( outUri, name, nsQualify( name, outPrefix ), attr ); + private void start( String name, AttributesImpl attr ) + throws SAXException { + try { + super.startTransformingElement( outUri, name, nsQualify( name, outPrefix ), attr ); + } catch (IOException ioe) { + throw new SAXException(ioe); + } catch (ProcessingException pe) { + throw new SAXException(pe); + } attr.clear(); } @@ -753,7 +795,13 @@ * Helper method for generating SAX events */ private void end( String name ) throws SAXException { - super.contentHandler.endElement( outUri, name, nsQualify( name, outPrefix ) ); + try { + super.endTransformingElement( outUri, name, nsQualify( name, outPrefix ) ); + } catch (IOException ioe) { + throw new SAXException(ioe); + } catch (ProcessingException pe) { + throw new SAXException(pe); + } } /** @@ -761,7 +809,7 @@ */ private void data( String data ) throws SAXException { if ( data != null ) { - super.contentHandler.characters( data.toCharArray(), 0, data.length() ); + super.characters( data.toCharArray(), 0, data.length() ); } } @@ -1002,7 +1050,9 @@ } } String query = sb.toString(); - transformer.getTheLogger().debug( "EXECUTING " + query ); + if (transformer.getTheLogger().isDebugEnabled()) { + transformer.getTheLogger().debug( "EXECUTING " + query ); + } conn = getConnection(); @@ -1120,23 +1170,60 @@ query_parts.addElement( object ); } - protected void serializeRow() throws SQLException, SAXException { + protected void serializeData(ComponentManager manager, + String value) + throws SQLException, SAXException { + if (value != null) { + value = value.trim(); + // Could this be XML ? + if (value.length() > 0 && value.charAt(0) == '<') { + try { + if (transformer.parser != null) { + transformer.parser = (Parser)manager.lookup(Parser.ROLE); + } + if (transformer.compiler != null) { + compiler = (XMLSerializer)manager.lookup(XMLSerializer.ROLE); + } + if (transformer.interpreter != null) { + interpreter = (XMLDeserializer)manager.lookup(XMLDeserializer.ROLE); + } + parser.parse(new InputSource(new StringReader("<root>"+value+"</root>")), compiler); + + IncludeXMLConsumer filter = new IncludeXMLConsumer(transformer, transformer); + filter.setIgnoreRootElement(true); + + interpreter.setConsumer(filter); + + interpreter.deserialize(compiler.getSAXFragment()); + } catch (Exception local) { + // if an exception occured the data was not xml + transformer.data(value); + } + } else { + transformer.data(value); + } + } + } + + protected void serializeRow(ComponentManager manager) + throws SQLException, SAXException { AttributesImpl attr = new AttributesImpl(); if ( !isupdate && !isstoredprocedure ) { for ( int i = 1; i <= md.getColumnCount(); i++ ) { transformer.start( md.getColumnName( i ).toLowerCase(), attr ); - transformer.data( getColumnValue( i ) ); + this.serializeData(manager, getColumnValue( i ) ); transformer.end( md.getColumnName( i ).toLowerCase() ); } } else if ( isupdate && !isstoredprocedure ) { transformer.start( "returncode", attr ); - transformer.data( String.valueOf( rv ) ); + this.serializeData(manager, String.valueOf( rv ) ); transformer.end( "returncode" ); rv = -1; // we only want the return code shown once. } } - protected void serializeStoredProcedure() throws SQLException, SAXException { + protected void serializeStoredProcedure(ComponentManager manager) + throws SQLException, SAXException { if ( outParametersNames == null || cst == null ) return; //make sure output follows order as parameter order in stored procedure @@ -1152,7 +1239,7 @@ Object obj = cst.getObject( counter.intValue() ); if ( !( obj instanceof ResultSet ) ) { transformer.start( (String) outParametersNames.get( counter ), attr ); - transformer.data( transformer.getStringValue( obj ) ); + this.serializeData(manager, transformer.getStringValue( obj ) ); transformer.end( (String) outParametersNames.get( counter ) ); } else { ResultSet rs = (ResultSet) obj; @@ -1163,7 +1250,7 @@ transformer.start( this.row_name, attr ); for ( int i = 1; i <= md.getColumnCount(); i++ ) { transformer.start( md.getColumnName( i ).toLowerCase(), attr ); - transformer.data( transformer.getStringValue( rs.getObject( i ) ) ); + this.serializeData(manager, transformer.getStringValue( rs.getObject( i ) )); transformer.end( md.getColumnName( i ).toLowerCase() ); } transformer.end( this.row_name );
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]