1 package org.jahia.engines.applications; 2 3 import java.io.IOException ; 4 import java.io.PrintWriter ; 5 import java.util.Properties ; 6 import java.util.StringTokenizer ; 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 23 24 public class FullScreenDispatcherEngine implements JahiaEngine { 25 26 27 public static final String ENGINE_NAME = "appdispatcher"; 28 29 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 return true; 46 } 47 48 public String renderLink (ParamBean jParams, Object theObj) throws JahiaException { 49 String resultURL; 50 51 Properties paramPairs = new Properties (); 52 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 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 strToken = new StringTokenizer (appUniqueIDStr, "_"); 76 String fieldIDStr = strToken.nextToken (); 77 String appIDStr = strToken.nextToken (); 78 int fieldID = Integer.parseInt (fieldIDStr); 79 String appOutput = 80 ServicesRegistry.getInstance ().getJahiaApplicationsDispatchingService () 81 .getAppOutput (fieldID, appIDStr, jParams); 82 try { 83 PrintWriter out = jParams.getResponse ().getWriter (); 84 out.print (appOutput); 85 out.flush (); 86 } catch (IOException 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 102 public final String getName () { 103 return ENGINE_NAME; 104 } 105 } | Popular Tags |