KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > engines > applications > FullScreenDispatcherEngine


1 package org.jahia.engines.applications;
2
3 import java.io.IOException JavaDoc;
4 import java.io.PrintWriter JavaDoc;
5 import java.util.Properties JavaDoc;
6 import java.util.StringTokenizer JavaDoc;
7
8 import org.jahia.data.JahiaData;
9 import org.jahia.engines.JahiaEngine;
10 import org.jahia.exceptions.JahiaException;
11 import org.jahia.params.ParamBean;
12 import org.jahia.registries.ServicesRegistry;
13
14 /**
15  * <p>Title: Full screen application dispatcher engine</p> <p>Description: The goal of this
16  * engine is to allow applications to "take" over the HTML screen, without Jahia giving up it's
17  * hand. This can be useful for all types of applications.</p> <p>Copyright: Copyright (c)
18  * 2002</p> <p>Company: Jahia Ltd</p>
19  *
20  * @author Serge Huber
21  * @version 1.0
22  */

23
24 public class FullScreenDispatcherEngine implements JahiaEngine {
25
26     /** The engine's name */
27     public static final String JavaDoc ENGINE_NAME = "appdispatcher";
28
29     /** logging */
30     private static final org.apache.log4j.Logger logger =
31             org.apache.log4j.Logger.getLogger (FullScreenDispatcherEngine.class);
32
33
34     public FullScreenDispatcherEngine () {
35         logger.debug (
36                 "***** Starting " + FullScreenDispatcherEngine.class.getName () +
37                 " engine *****");
38     }
39
40
41     public boolean authoriseRender (ParamBean jParams) {
42         // render is always authorized as even guest users might need this.
43
// Actually the rendering is controlled more by the application than
44
// by the user.
45
return true;
46     }
47
48     public String JavaDoc renderLink (ParamBean jParams, Object JavaDoc theObj) throws JahiaException {
49         String JavaDoc resultURL;
50
51         Properties JavaDoc paramPairs = new Properties JavaDoc ();
52         // paramPairs.setProperty("fieldid", )
53
paramPairs.setProperty (ParamBean.PAGE_ID_PARAMETER,
54                 Integer.toString (jParams.getPageID ()));
55
56         resultURL = jParams.composeEngineUrl (ENGINE_NAME, paramPairs, EMPTY_STRING);
57         return resultURL;
58     }
59
60     public boolean needsJahiaData (ParamBean jParams) {
61         return false;
62     }
63
64     public void handleActions (ParamBean jParams, JahiaData jData)
65             throws JahiaException {
66         String JavaDoc appUniqueIDStr = jParams.getParameter ("appid");
67         if (appUniqueIDStr == null) {
68             throw new JahiaException (
69                     "Error while displaying application",
70                     "Missing appID parameter for engine " +
71                     FullScreenDispatcherEngine.ENGINE_NAME,
72                     JahiaException.APPLICATION_ERROR,
73                     JahiaException.ERROR_SEVERITY);
74         }
75         StringTokenizer JavaDoc strToken = new StringTokenizer JavaDoc (appUniqueIDStr, "_");
76         String JavaDoc fieldIDStr = strToken.nextToken ();
77         String JavaDoc appIDStr = strToken.nextToken ();
78         int fieldID = Integer.parseInt (fieldIDStr);
79         String JavaDoc appOutput =
80                 ServicesRegistry.getInstance ().getJahiaApplicationsDispatchingService ()
81                 .getAppOutput (fieldID, appIDStr, jParams);
82         try {
83             PrintWriter JavaDoc out = jParams.getResponse ().getWriter ();
84             out.print (appOutput);
85             out.flush ();
86         } catch (IOException JavaDoc ioe) {
87             throw new JahiaException (
88                     "Error while displaying application output",
89                     "Couldn't get HttpResponse PrintWriter instance",
90                     JahiaException.APPLICATION_ERROR,
91                     JahiaException.ERROR_SEVERITY,
92                     ioe
93             );
94         }
95     }
96
97     /**
98      * Retrieve the engine name.
99      *
100      * @return the engine name.
101      */

102     public final String JavaDoc getName () {
103         return ENGINE_NAME;
104     }
105 }
Popular Tags