cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johannes Becker" <jonnybec...@hotmail.com>
Subject Re: Weird logicsheet problem
Date Tue, 28 Oct 2003 16:30:41 GMT
Hi.

this piece posted works almost fine:
<xsl:template match="xsp:page">
                         <xsp:page>
                                     <xsl:apply-templates select="@*"/>
                                     <xsp:structure>
<xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include>
<xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
                                     </xsp:structure>
                                     <xsp:logic>
                                          public void contextualize(Context
context) throws ContextException (
                                                uploadDir = (File)
context.get(Contstants.CONTEXT_UPLOAD_DIR);
                                          }
                                         String[] filelist = 
uploadDir.list();
                                     </xsp:logic>
                                     <xsl:apply-templates select="node()"/>
                         </xsp:page>
             </xsl:template>


The only problem: It always gives a nullpointer-exception, because the 
"uploadDir.list()" is empty (for some stupid reason).
In my xsp's this code works fine. It gets all the names of the 
files(+directories) of the upload-directory I specified in the web.xml file 
(and in my case this directory isn't empty).

Thanks
Jonny


>From: Christopher Painter-Wakefield <paint007@mc.duke.edu>
>Reply-To: users@cocoon.apache.org
>To: users@cocoon.apache.org
>Subject: Re: Weird logicsheet problem
>Date: Mon, 27 Oct 2003 14:03:20 -0500
>
>
>
>
>
>what does your XSP program (the one that uses this logicsheet) look like?
>It looks to me as if you are either putting a function inside the main
>generate() function, or else you are putting XML output code outside any
>function (at the class level).  Based on your syntax error, I suspect the
>former.  You have:
>       <xsl:template match="jonny:test">
>             <xsp:logic>
>                   File uploadDir = null;
>                   /** Contextualize this class */
>                   public void contextualize(Context context) throws
>ContextException {
>                         uploadDir = (File)
>context.get(Constants.CONTEXT_UPLOAD_DIR);
>                   }
>                   String[] filelist = uploadDir.list();
>             </xsp:logic>
>             <xsp:expr>filelist[0]</xsp:expr>
>       </xsl:template>
>
>The first few lines define variables and functions, which are legal outside
>any function in the class, e.g., inside an <xsp:logic> statement nested
>directly under the <xsp:page> element.  The last line does
><xsp:expr>filelist[0]</xsp:expr>, which turns into a line of bare java
>code, that isn't legal outside any function at the class level.  So this is
>confused.
>
>You may need to move part or all of your xsp:logic block (at least the part
>defining the contextualize() function) up into your template matching
><xsp:page>, e.g.:
>
>              <xsl:template match="xsp:page">
>                          <xsp:page>
>                                      <xsl:apply-templates select="@*"/>
>                                      <xsp:structure>
>
><xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include>
>
>
><xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
>
>                                      </xsp:structure>
>                                      <xsp:logic>
>                                           public void 
>contextualize(Context
>context) throws ContextException (
>                                                 uploadDir = (File)
>context.get(Contstants.CONTEXT_UPLOAD_DIR);
>                                           }
>                                      </xsp:logic>
>                                      <xsl:apply-templates 
>select="node()"/>
>                          </xsp:page>
>              </xsl:template>
>
>alternatively, perhaps you want
>
>       <xsl:template match="jonny:test">
>             <xsp:logic>
>                   File uploadDir = null;
>                   /** Contextualize this class */
>                   try{
>                         uploadDir = (File)
>context.get(Constants.CONTEXT_UPLOAD_DIR);
>                   } catch ContextException e {
>                         ...
>                   }
>                   String[] filelist = uploadDir.list();
>             </xsp:logic>
>             <xsp:expr>filelist[0]</xsp:expr>
>       </xsl:template>
>
>The important thing is to remember that you are applying a stylesheet to
>transform an XSP program into another XSP program.  Think about what the
>resulting, transformed program looks like (or test it by applying the
>stylesheet yourself to see what the result is).
>-Christopher
>
>
>
>|---------+---------------------------->
>|         |           "Johannes Becker"|
>|         |           <jonnybecker@hotm|
>|         |           ail.com>         |
>|         |                            |
>|         |           10/27/2003 01:41 |
>|         |           PM               |
>|         |           Please respond to|
>|         |           users            |
>|         |                            |
>|---------+---------------------------->
>   
> >--------------------------------------------------------------------------------------------------------------|
>   |                                                                        
>                                       |
>   |       To:       users@cocoon.apache.org                                
>                                       |
>   |       cc:                                                              
>                                       |
>   |       Subject:  Re: Weird logicsheet problem                           
>                                       |
>   
> >--------------------------------------------------------------------------------------------------------------|
>
>
>
>
>Hi,
>
>now I changed the logicsheet:
>__________________________________________________________________________________
>
><?xml version="1.0"?>
><xsl:stylesheet version="1.0"
>xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>xmlns:xsp="http://apache.org/xsp" xmlns:jonny="http://jonny.de/jonny">
>              <xsl:template match="xsp:page">
>                          <xsp:page>
>                                      <xsl:apply-templates select="@*"/>
>                                      <xsp:structure>
>
><xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include>
>
>
><xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
>
>                                      </xsp:structure>
>                                      <xsl:apply-templates 
>select="node()"/>
>                          </xsp:page>
>              </xsl:template>
>              <xsl:template match="jonny:test">
>                          <xsp:logic>
>                            File uploadDir = null;
>                            /** Contextualize this class */
>                            public void contextualize(Context context)
>throws ContextException {
>                              uploadDir = (File)
>context.get(Constants.CONTEXT_UPLOAD_DIR);
>                            }
>                    String[] filelist = uploadDir.list();
>                          </xsp:logic>
>                          <xsp:expr>filelist[0]</xsp:expr>
>              </xsl:template>
>              <xsl:template match="@*|node()" priority="-2">
>                          <xsl:copy>
>                                      <xsl:apply-templates
>select="@*|node()"/>
>                          </xsl:copy>
>              </xsl:template>
></xsl:stylesheet>
>
>But it still throws an error:
>______________________________________________________________________________
>
>An Error Occurred
>Language Exception
>
>org.apache.cocoon.ProcessingException: Language Exception:
>org.apache.cocoon.components.language.LanguageException: Error compiling
>jonny_xsp: ERROR 1 (org\apache\cocoon\www\logicsheet\jonny_xsp.java): ...
>this.characters("\n\t\t"); File uploadDir = null; /** Contextualize this
>class */ // start error (lines 112-112) "Syntax error on token "(", ";"
>expected" public void contextualize(Context context) throws
>ContextException
>{ // end error uploadDir = (File)
>context.get(Constants.CONTEXT_UPLOAD_DIR);
>} String[] filelist = uploadDir.list(); ... Line 112, column 0: Syntax
>error
>on token "(", ";" expected
>
>cause: org.apache.cocoon.components.language.LanguageException: Error
>compiling jonny_xsp: ERROR 1
>(org\apache\cocoon\www\logicsheet\jonny_xsp.java): ...
>this.characters("\n\t\t"); File uploadDir = null; /** Contextualize this
>class */ // start error (lines 112-112) "Syntax error on token "(", ";"
>expected" public void contextualize(Context context) throws
>ContextException
>{ // end error uploadDir = (File)
>context.get(Constants.CONTEXT_UPLOAD_DIR);
>} String[] filelist = uploadDir.list(); ... Line 112, column 0: Syntax
>error
>on token "(", ";" expected
>
>full exception chain stacktrace[hide]
>
>Original Exception:
>org.apache.cocoon.components.language.LanguageException:
>Error compiling jonny_xsp:
>ERROR 1 (org\apache\cocoon\www\logicsheet\jonny_xsp.java):
>...
>         this.characters("\n\t\t");
>
>                            File uploadDir = null;
>
>                            /** Contextualize this class */
>
>
>// start error (lines 112-112) "Syntax error on token "(", ";" expected"
>                            public void contextualize(Context context)
>throws ContextException {
>
>
>// end error
>                              uploadDir = (File)
>context.get(Constants.CONTEXT_UPLOAD_DIR);
>
>                            }
>
>                    String[] filelist = uploadDir.list();
>
>...
>Line 112, column 0: Syntax error on token "(", ";" expected
>
>              at
>org.apache.cocoon.components.language.programming.java.JavaLanguage.compile(JavaLanguage.java:236)
>
>
>              at
>org.apache.cocoon.components.language.programming.CompiledProgrammingLanguage.load(CompiledProgrammingLanguage.java:208)
>
>
>              at
>org.apache.cocoon.components.language.generator.ProgramGeneratorImpl.loadProgram(ProgramGeneratorImpl.java:427)
>
>_______________________________________________________________-
>
>The strange thing here is (in my opinion) that I got these errors before in
>
>my xsp's with the same code. But now they're gone in the xsp's and I have
>em
>in the logicsheet.
>
>Thanks
>jonny
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>

_________________________________________________________________
Sch├╝tzen Sie Ihren Posteingang vor unerw├╝nschten E-Mails. 
http://www.msn.de/antispam Jetzt Hotmail-Junk-Filter aktivieren!


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message