*/
-public class Mir extends AbstractServlet
-{
+public class Mir extends AbstractServlet {
+
+ private static ModuleUsers usersModule=null;
+ private static ModuleMessage messageModule=null;
+ private final static HashMap servletModuleInstanceHash = new HashMap();
- private static ModuleUsers usersModule=null;
- private static ModuleMessage messageModule=null;
- //private static boolean confed=false;
public HttpSession session;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException, UnavailableException {
long startTime = (new java.util.Date()).getTime();
- Class theServletModule;
- ServletModule smod;
long sessionConnectTime=0;
String http="";
_sendStartPage(res,req, res.getWriter(),userEntity);
return;
}
+ // end of auth
- //From now on regular dispatching...
-
- /** @todo i do already have the code for a ServletModuleInstanceMap
- * i will insert it soon. the code is 100times faster than doing
- * a classForName-lookup with every execution. will be moved to
- * getServletModuleForName //rk
- */
-
+ // From now on regular dispatching...
try {
- try {
- theServletModule = Class.forName("mircoders.servlet.ServletModule" + moduleName);
- } catch (ClassNotFoundException e) {
- // searching servletmodule in mir.servlet-classes
- theServletModule = Class.forName("mir.servlet.ServletModule" + moduleName);
- }
- //Instantiate the ServletModule
- Method m = theServletModule.getMethod("getInstance",null);
- smod = (ServletModule)m.invoke(null,null);
+ // get servletmodule by parameter and continue with dispacher
+ ServletModule smod = getServletModuleForName(moduleName);
ServletModuleDispatch.dispatch(smod,req,res);
}
- catch (NoSuchMethodException e) { handleError( res,res.getWriter(), "ServletModule" + moduleName + " getInstance() not found."); }
- catch (InvocationTargetException e) { handleError( res,res.getWriter(), "ServletModule" + moduleName + " target not found."); }
- catch (ClassNotFoundException e) { handleError(res, res.getWriter(), "ServletModule" + moduleName + " not found."); }
- catch (IllegalArgumentException e) { handleError( res,res.getWriter(), "ServletModule" + moduleName + " not found."); }
+ catch (ServletModuleException e) {
+ handleError(res, res.getWriter(), "ServletException in Module " + moduleName + " -- " + e.toString());
+ }
catch (ServletModuleUserException e) {
- handleUserError(res,res.getWriter(), e.getMsg());
+ handleUserError(res,res.getWriter(), "User error" + e.toString());
}
- catch (ServletModuleException e){ handleError(res,res.getWriter(), "ServletException in Module ServletModule" + moduleName + " -- " + e.toString()); }
- catch (IllegalAccessException e){
- handleError(res,res.getWriter(), "No access to class ServletModule" + moduleName + " -- " + e.toString()); }
// timing...
sessionConnectTime = new java.util.Date().getTime() - startTime;
theLog.printInfo("EXECTIME (" + moduleName + "): " + sessionConnectTime + " ms");
}
+
+ /**
+ * Private method getServletModuleForName returns ServletModule
+ * from Cache
+ *
+ * @return ServletModule
+ *
+ */
+ private static ServletModule getServletModuleForName(String moduleName)
+ throws ServletModuleException {
+
+ // Instance in Map ?
+ if (!servletModuleInstanceHash.containsKey(moduleName)) {
+ // was not found in hash...
+ try {
+ Class theServletModuleClass=null;
+ try {
+ // first we try to get ServletModule from stern.che3.servlet
+ theServletModuleClass = Class.forName("mircoders.servlet.ServletModule" + moduleName);
+ } catch (ClassNotFoundException e) {
+ // on failure, we try to get it from lib-layer
+ theServletModuleClass = Class.forName("mir.servlet.ServletModule"+ moduleName);
+ }
+ Method m = theServletModuleClass.getMethod("getInstance", null);
+ ServletModule smod = (ServletModule)m.invoke(null, null);
+ // we put it into map for further reference
+ servletModuleInstanceHash.put(moduleName,smod);
+ return smod;
+ } catch (Exception e) {
+ throw new ServletModuleException("*** error resolving classname for " +
+ moduleName +" -- "+ e.toString());
+ }
+ }
+ else return (ServletModule)servletModuleInstanceHash.get(moduleName);
+ }
+
+
private void handleError(HttpServletResponse res, PrintWriter out, String errorString) {
+
try {
theLog.printError(errorString);
SimpleHash modelRoot = new SimpleHash();
session=res.encodeURL("");
}
+ /** @todo why do we double those? should be cleaned up and
+ * statically initialized, we do not need to assemble a config
+ * hash everytime we give out a page, only exception is
+ * date "now" // rk */
// put standard configuration into tempalteRootmodel
SimpleHash configHash = new SimpleHash();
configHash.put("docroot", new SimpleScalar(producerDocRoot));
tmr.put("videoHost", new SimpleScalar(videoHost));
tmr.put("audioHost", new SimpleScalar(audioHost));
tmr.put("imageHost", new SimpleScalar(imageHost));
+ // this conform to updated freemarker syntax
+ tmr.put("compressWhitespace", new freemarker.template.utility.CompressWhitespace() );
tmr.put("config", configHash);
tmpl.process(tmr, out);
*
* @deprecated This method is deprecated and will be deleted in the next
* release. Entity interfaces freemarker.template.TemplateHashModel now
- * and can be used in the same way as SimpleHash. It is not necessary any
+ * and can be used in the same way as SimpleHash. It is not necessary any
* more to make a SimpleHash from an Entity
*/
public static SimpleHash makeSimpleHash(Entity entity) {
{
Template returnTemplate = null;
if (templateFilename!=null)
- returnTemplate = templateCache.getTemplate(templateFilename);
+ returnTemplate = (Template)templateCache.getItem(templateFilename,"template");
if (returnTemplate==null) {
static {
// init
- try {
- contentModule = new ModuleContent(DatabaseContent.getInstance());
- topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
- linksImcsModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
- schwerpunktModule = new ModuleSchwerpunkt(DatabaseFeature.getInstance());
- featureModule = new ModuleFeature(DatabaseFeature.getInstance());
- imageModule = new ModuleImages(DatabaseImages.getInstance());
- uploadedMediaModule = new ModuleUploadedMedia(DatabaseImages.getInstance());
- } catch(StorageObjectException e) {;}
+ try {
+ contentModule = new ModuleContent(DatabaseContent.getInstance());
+ topicsModule = new ModuleTopics(DatabaseTopics.getInstance());
+ linksImcsModule = new ModuleLinksImcs(DatabaseLinksImcs.getInstance());
+ schwerpunktModule = new ModuleSchwerpunkt(DatabaseFeature.getInstance());
+ featureModule = new ModuleFeature(DatabaseFeature.getInstance());
+ imageModule = new ModuleImages(DatabaseImages.getInstance());
+ uploadedMediaModule = new ModuleUploadedMedia(DatabaseImages.getInstance());
+ }
+ catch(StorageObjectException e)
+ {
+ System.err.println("*** failed to initialize Producer " + e.toString());
+ }
}
public void handle(PrintWriter htmlout, EntityUsers user)