shuber 2005/04/26 13:56:13 CEST
Modified files: (Branch: JAHIA-4-1-BRANCH)
src/java/org/jahia/engines/core Core_Engine.java
Log:
Implemented dynamic template switching, by using the /template URL parameter.
Revision Changes Path
1.16.2.1.2.2 +37 -13
jahia/src/java/org/jahia/engines/core/Core_Engine.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/engines/core/Core_Engine.java.diff?r1=1.16.2.1.2.1&r2=1.16.2.1.2.2&f=h
Index: Core_Engine.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/engines/core/Attic/Core_Engine.java,v
retrieving revision 1.16.2.1.2.1
retrieving revision 1.16.2.1.2.2
diff -u -r1.16.2.1.2.1 -r1.16.2.1.2.2
--- Core_Engine.java 25 Apr 2005 16:51:23 -0000 1.16.2.1.2.1
+++ Core_Engine.java 26 Apr 2005 11:56:13 -0000 1.16.2.1.2.2
@@ -34,6 +34,8 @@
import org.jahia.exceptions.JahiaForbiddenAccessException;
import org.jahia.data.events.JahiaEvent;
import org.jahia.registries.ServicesRegistry;
+import java.io.File;
+import java.util.Date;
public class Core_Engine implements JahiaEngine {
@@ -164,10 +166,23 @@
fireLoadPage(theEvent);
// compose the fileName...
- String fileName = null;
+ String fileName = resolveJSPFullFileName(jData);
+
+ // compose a new hashmap with engine properties...
+ HashMap engineHashMap = new HashMap ();
+ engineHashMap.put (ENGINE_NAME_PARAM, ENGINE_NAME);
+ engineHashMap.put (ENGINE_OUTPUT_FILE_PARAM, fileName);
+ engineHashMap.put (RENDER_TYPE_PARAM, new Integer
(JahiaEngine.RENDERTYPE_FORWARD));
+
+ EngineRenderer.getInstance ().render (jData, engineHashMap);
+ }
+
+ private String resolveJSPFullFileName (JahiaData jData) {
+ String jspFullFileName = null;
+
JahiaPageDefinition template = jData.params ().getPage
().getPageTemplate ();
if (template != null) {
- fileName = template.getSourcePath ();
+ jspFullFileName = template.getSourcePath ();
}
// now let's check for template override parameter
@@ -177,22 +192,31 @@
String pathToAlternateTemplate = jData.params ().getParameter
(ParamBean.TEMPLATE_PARAMETER);
if (pathToAlternateTemplate.indexOf("..") == -1) {
- fileName = "/jsp/test/" +
- jData.params ().getParameter
(ParamBean.TEMPLATE_PARAMETER);
- logger.debug ("Overriding page template with URL template :
" + fileName);
- }
+ logger.debug ("template source path :" + jspFullFileName);
+ int lastSlashPos = jspFullFileName.lastIndexOf ("/");
+ if (lastSlashPos != -1) {
+ jspFullFileName = jspFullFileName.substring(0,
lastSlashPos + 1) + jData.params ().getParameter (ParamBean.TEMPLATE_PARAMETER);
+ }
+ logger.debug ("resolvedJSPFullFileName :" + jspFullFileName);
+
+ File jspFile = new File (jData.params().getContext
().getRealPath (jspFullFileName));
+ if (!jspFile.exists ()) {
+ jspFullFileName = "/jsp/test/" + jData.params
().getParameter (ParamBean.TEMPLATE_PARAMETER);
+ }
+ logger.debug ("Overriding page template with URL template :
" + jspFullFileName);
+
+ // since we overrided the template, we deactivate the cache
for
+ // the page.
+ // expires the cache immediately, not even storing it.
+ jData.params().setCacheExpirationDate(new Date());
+ }
}
- // compose a new hashmap with engine properties...
- HashMap engineHashMap = new HashMap ();
- engineHashMap.put (ENGINE_NAME_PARAM, ENGINE_NAME);
- engineHashMap.put (ENGINE_OUTPUT_FILE_PARAM, fileName);
- engineHashMap.put (RENDER_TYPE_PARAM, new Integer
(JahiaEngine.RENDERTYPE_FORWARD));
-
- EngineRenderer.getInstance ().render (jData, engineHashMap);
+ return jspFullFileName;
}
+
/**
* General post-process method. Add here any code that should be
executed after dispatching
* to the template