On 03.Jun.2002 -- 11:53 PM, John Austin wrote: > On Monday 03 June 2002 01:50 pm, you wrote: > > On 03.Jun.2002 -- 10:11 AM, daniel robinson wrote: > > > Hi, > > > > > > I've been poking around but I'm clueless (yes, generally as well as > > > specifically). > > I have some code that simply uses embedded Java in an XSP and a Java > temp file. This code processes a File that is submitted by the user's > Applet simulating a FORM with method=PUT. The user's FILE parameter is > an XML document produced by the applet. I have to insert the DTD stuff > because the Serializer I am generating this file from doesn't generate > the DTD statements. > > After the file is pulled into a string and written to a File, I add it > to my PostgreSQL database as a BLOB. > > > <?xml version="1.0" encoding="ISO-8859-1"?> > > <xsp:page > language="java" > create-session="yes" > xmlns:xsp="http://apache.org/xsp" > xmlns:session="http://apache.org/xsp/session/2.0" > xmlns:xsp-request="http://apache.org/xsp/request/2.0" > xmlns:xsp-response="http://apache.org/xsp/response/2.0" xmlns:esql="http://apache.org/cocoon/SQL/v2" > xmlns:log="http://apache.org/xsp/log/2.0"> > > <xsp:structure> > <xsp:include>java.io.*</xsp:include> > <xsp:include>java.sql.*</xsp:include> > </xsp:structure> > <page> > <content> > <xsp:logic> > File output = null; > try { > > String username = (String) > <session:get-attribute name="username" default="nobody" />; > //System.err.println( "username=" + username ); > > String filename = > <xsp-request:get-parameter name="FILENAME" />; > //System.err.println( "filename=" + filename ); > > String config_data = > <xsp-request:get-parameter name="FILE" />; > //System.err.println( "config_data=" + config_data ); > > int position = config_data.indexOf( <![CDATA["<product>"]]> ); > > StringBuffer saveString = new StringBuffer( config_data.substring( 0, > position ) ); > <![CDATA[ > saveString.append( "<!DOCTYPE product [\n" + > "<!ELEMENT product (page+)>\n" + > "<!ELEMENT children (page+)>\n" + > "<!ELEMENT Company EMPTY>\n" + > "<!ELEMENT page (#PCDATA | Company | children)*>\n" + > "<!ATTLIST page level (1 | 2 | 3 | 4 | 5 | 8 ) #REQUIRED\n" + > " target CDATA #REQUIRED\n" + > " checkbox (true | false) #REQUIRED\n" + > ">\n" + > "]>\n" ); > ]]> > saveString.append( config_data.substring( position) ); > > output = File.createTempFile( "phoenix_", ".xml" ); > > FileWriter fw = new FileWriter( output ); > > fw.write( saveString.toString() ); > > fw.close(); > <esql:connection> <esql:driver>org.postgresql.Driver</esql:driver> <esql:dburl>jdbc:postgresql://192.168.1.100:5432/test</esql:dburl> <esql:username>postgres</esql:username> <esql:password></esql:password> <esql:execute-query> <esql:query>UPDATE user_products SET product_file=lo_import('"<xsp:expr>output.getAbsolutePath()</xsp:expr>"') where name = <esql:parameter><xsp:expr>username</xsp:expr> AND productname = <esql:parameter><xsp:expr>filename</xsp:expr></esql:parameter>;</esql:query> <esql:update-results> <xsp:logic> int rows = <esql:get-update-count/> </xsp:logic> </esql:update-results> <esql:error-results> <xsp:logic> System.err.println( "Caught: " + <esql:get-message/> ); <xsp:logic> <esql:get-stacktrace/> </esql:error-results> </esql:execute-query> </esql:connection>
> </xsp:logic> > <session:set-attribute name="TEMPFILENAME"> > <xsp:logic><xsp:expr>output.getAbsolutePath()</xsp:expr></xsp:logic> > </session:set-attribute> > <para> > TEMPFILENAME=<session:get-attribute name="TEMPFILENAME" /> > </para> > </content> > </page> > </xsp:page> The above *might* work. If it doesn't, try to remove the esql:parameter tags (and leave only the xsp:expr tags). Chris. -- C h r i s t i a n H a u l [EMAIL PROTECTED] fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 --------------------------------------------------------------------- Please check that your question has not already been answered in the FAQ before posting. <http://xml.apache.org/cocoon/faqs.html> To unsubscribe, e-mail: <[EMAIL PROTECTED]> For additional commands, e-mail: <[EMAIL PROTECTED]>