AbstractAnnotationAction for Cocoon 2.x
Hi. I've written a simple class which may help others writing Actions with lesser code. Feel free to use it (and expand it) if you like it. An example: public class TestAction extends AbstractAnnotationAction { @ActionMethod protected void doMyAction (@SitemapParam(my-param) @DefaultValue(true) boolean myParam, @QueryParam(login) String login, @QueryParam(counter) @DefaultValue(0) int counter; Session session) { System.out.println (Login: +login); } } You can use @QueryParam, @SitemapParam, @ConfParam, @HeaderParam, @CookieParam, @FileParam. In the signature of the method you can just add variables if you need them: Request, Session, Redirector, Response, ResultHashMap, Conext, SourceResolver. All of them will be set automatically. All parameters are casted when needed. The method to be invoked must have a @ActionMethod annotation or you can define the method using _method request or sitemap parameter. Cheers, Jörn import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.HashMap; import java.util.Map; import org.apache.avalon.framework.parameters.Parameters; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.acting.AbstractConfigurableAction; import org.apache.cocoon.environment.Context; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.Response; import org.apache.cocoon.environment.Session; import org.apache.cocoon.environment.SourceResolver; public abstract class AbstractAnnotationAction extends AbstractConfigurableAction implements ThreadSafe { public final static String STATE = state; public final static String SUCCESS = success; public final static String FAILURE = failure; public final static String MESSAGE = message; public final static String METHOD_CALL_NAME = _method; protected class ResultHashMap extends HashMapString, String { private static final long serialVersionUID = -4191539718741319953L; } @Target(ElementType.PARAMETER) @Retention (RetentionPolicy.RUNTIME) public @interface QueryParam { String value(); } @Target(ElementType.PARAMETER) @Retention (RetentionPolicy.RUNTIME) public @interface SitemapParam { String value(); } @Target(ElementType.PARAMETER) @Retention (RetentionPolicy.RUNTIME) public @interface ConfParam { String value(); } @Target(ElementType.PARAMETER) @Retention (RetentionPolicy.RUNTIME) public @interface DefaultValue { String value(); } @Target(ElementType.PARAMETER) @Retention (RetentionPolicy.RUNTIME) public @interface Format { String value (); } // TODO @Target(ElementType.PARAMETER) @Retention (RetentionPolicy.RUNTIME) public @interface HeaderParam { String value (); } // TODO @Target(ElementType.PARAMETER) @Retention (RetentionPolicy.RUNTIME) public @interface CookieParam { String value (); } //TODO @Target(ElementType.PARAMETER) @Retention (RetentionPolicy.RUNTIME) public @interface FileParam { String value (); } @Target(ElementType.METHOD) @Retention (RetentionPolicy.RUNTIME) public @interface ActionMethod {} @SuppressWarnings(unchecked) public Map act (Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters params) throws Exception { ResultHashMap hashMap = new ResultHashMap (); Request request = ObjectModelHelper.getRequest (objectModel); try { Method[] methods = this.getClass ().getDeclaredMethods (); for (Method m : methods) { if (m.isAnnotationPresent (ActionMethod.class) || m.getName ().equals (request.getParameter (METHOD_CALL_NAME)) || m.getName ().equals (params.getParameter (METHOD_CALL_NAME, ))) { callMethod (m, hashMap, redirector, resolver, objectModel, source, params); } } } catch (Throwable t) { t.printStackTrace (); if (t instanceof Exception) throw (Exception) t; else throw new Exception (t); } return hashMap; } protected void callMethod (Method m, ResultHashMap hashMap, Redirector redirector, SourceResolver resolver, MapString,String objectModel, String source, Parameters params) throws Exception { Request request = ObjectModelHelper.getRequest (objectModel);
Re: XSLT transformation
Just remember that XML Spy does not use the same XSLT transformer as Cocoon. I think there is an error in your stylesheet. Try to comment out some parts of it to find the lines which causes the error. JOERN Antony Grinyer schrieb: Hi, A have a simple sitemap entry as below: map:match pattern=listcontainers map:generate type=file src=content/showsyscontainer.xml/ map:transform type=bdbxml/ map:transform type=xslt src=style/xsl/containerslist.xsl/ map:serialize type=html/ /map:match The generator is a simple XML file which is passed to a java class transformer ( referenced as type=bdbxml) which returns XML results. This all works fine if I use map:serialize type=xml/ to simply output the XML, however if I try to transform the XML output with the XSLT transformer above I get an error: Error executing pipeline. org.apache.cocoon.ProcessingException: Error executing pipeline.: java.lang.RuntimeException I know the XSLT containerslist.xsl is correct as I've tried it against some sample output XML in XMLSpy, but it appears that when I add this XSLT transformer I get a Processing Exception? In the sitemap.log it is reported as: Unable to get parser: java.lang.RuntimeException: java.lang.NullPointerException Any ideas please? (for a Cocoon newbie) Thx in advance, Ant - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
outputBufferSize problem
Hello. I've used map:pipeline map:parameter name=outputBufferSize value=1/ and map:pipes default=noncaching map:pipe name=noncaching src=org.apache.cocoon.components.pipeline.impl.NonCachingProcessingPipeline parameter name=outputBufferSize value=1/ to realize, that the output of a XSP file will be send to the client directly, without any caching. I used the following XSP to test it: xsp:page language=java xmlns:xsp=http://apache.org/xsp; html head /head body div id=dataText/div xsp:logic try { Thread.sleep (3000); } catch (Exception ex) {} /xsp:logic script language=JavaScript document.getElementById ('data').innerHTML = 'Test-Row 1'; /script xsp:logic try { Thread.sleep (3000); } catch (Exception ex) {} /xsp:logic script language=JavaScript document.getElementById ('data').innerHTML = 'Test-Row 2'; /script xsp:logic try { Thread.sleep (3000); } catch (Exception ex) {} /xsp:logic script language=JavaScript document.getElementById ('data').innerHTML = 'Test-Row 3'; /script /body /html /xsp:page Well, the page will be displayed 15s after asking the server... Does anybody know the reason? I'm using Cocoon 2.1.6 and Resin 3.0.10 on Win XP. Regards, JOERN_HEID - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
AW: Running Cocoon from CD
What about using Jetty? You can write your own startup app which launches Jetty+Cocoon, even as an autostart-exe which uses a jre on the cd (which might be a little bit slow). -Ursprüngliche Nachricht- Von: Michael Faschinger [mailto:[EMAIL PROTECTED] Gesendet: Donnerstag, 22. April 2004 17:03 An: [EMAIL PROTECTED] Betreff: Running Cocoon from CD Hello everyone! I just try to set up Tomcat(4.0.6) + Cocoon (2.0) to run from CD. Tomcat works perfectly fine but cocoon won't work as it tries to write some files (WEB-INF\db\commondb.*) to the CD. Is there a way to avoid this? Are there any further problems that might appear? I am not using database services, only XML+XSLT - HTML. Regards, Michael -- NEU : GMX Internet.FreeDSL Ab sofort DSL-Tarif ohne Grundgebühr: http://www.gmx.net/dsl - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Solution for Protecting Cocoon Apps
Background: If you want to gíve customers your application (e.g. for a demo, proof-of-concept, discussion) you habe to include source code, everybody can see as plain text. If one of your customer has evil intensions he can look at all interna of your application, e.g. XSL-stylesheets, SVG data, the sitemap or XML files with private data. Idea: Protect some files from read directly from the file system. When running Cocoon, it should decrypt those files without having to change any code of the Java apps (Cocoon, Tomcat, Jetty, whatever). Solution: To do so, you can replace the java.io.FileInputStream class with one you can easily extend. E.g. via looking for the file extension and if it's .xmap decrypt the file. You can easily crypt those files before building the demo. The problem is that java.io.FileInputStream uses native methods so that you cannot change the file directly. But you can write your own WrappedFileInputStream which uses it's own native methods. The shared library acts like a wrapper, so calling WrappedFileInputStream.open() will forward the call to FileInputStream.open(). If you've done that, your own FileInputStream can extend WrappedFileInputStream and decrypt files as needed. You can then use -Xbootclasspath to replace the JDK's FileInputStream with your version. I've done so with Jetty, Cocoon, J2SE 1.4.2 on Win32 and it worked. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
AW: How to protect a Cocoon project
It's about a demo (with an installer). I can't say: Before you install, please create a new user and forget the password of him :) -Ursprüngliche Nachricht- Von: news [mailto:[EMAIL PROTECTED] Im Auftrag von Olivier Billard Gesendet: Mittwoch, 22. Oktober 2003 09:54 An: [EMAIL PROTECTED] Betreff: Re: How to protect a Cocoon project Hi Joern, Isn't it the goal of filesystems, to protect file from beeing read by non authorized persons ? It's possible with WinNT, 2000, XP, and of course Unix-like OSes. Just give the right rights to the right persons ;) -- Olivier BILLARD On 22/10/2003 09:47, Jörn Heid wrote: Hello. I want to give my customer a demo of my Cocoon based application which runs with Jetty on their local machine. But the problem is everybody can see the internals of the app. All the pipelines in sitemap.xmap, all XSL and XML. It can be used to find backdoors in the sitemap for example. So the question is, how to protect files from being read directly. A solution would probably be to encrypt (for example via XOR) all the files. After that, Cocoon (Jetty) has to be started with modified Java-IO classes (via bootclasspath). Does anybody know which classes have to be changed or if there's somebody who has done something like that... JOERN_HEID - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Calling a pipeline without triggering through a URL
Hi. I want to save the output of a pipeline using a schedule class. E.g. saving an excel file every hour automatically. An approch would be to call the specific URL (e.g. http://localhost/get-excel-sheet.xls) but as I use a login-prompt I have to call serveral pages before. So, there must be a better way. I need something like calling cocon://get-excel-sheet.xls but as it is not triggered by a browser I do not have a context map. So, is there a way to use the Cocoon servlet class or something static (or whatever) where I can call the specific pipeline? Hope I have explained it understandable... JOERN - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]