roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject svn commit: r1201435 [1/3] - in /roller/trunk: weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/ weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/mobile/ weblogger-web/src/main/java/org/apache/roller/weblogger/ui...
Date Sun, 13 Nov 2011 15:01:38 GMT
Author: snoopdave
Date: Sun Nov 13 15:01:36 2011
New Revision: 1201435

URL: http://svn.apache.org/viewvc?rev=1201435&view=rev
Log:
This was originally a fix for "Saving Template causes Null Pointer Exception"
https://issues.apache.org/jira/browse/ROL-1930

But once I fixed the problem I found a series of other problems and ended up making some fundamental changes in the way that Roller's new mobile template support is implemented. I will summarize.

1) The Template Edit page now uses the YUI tab control to switch between a Page's standard and mobile template code on the client side. Both values are saved on the client-side and switching tabs no longer causes a page refresh.

2) Instead of determining the device-type and then injecting the right template code into the Roller Page object, which could cause other requests to get the wrong data inside the Page object, we now determine the device type and pass it down deep into Roller's rendering engine. At the RollerResourceLoader level we use the deviceType to fetch the correct template code for the deviceType.

3) Type is no now an enum called DeviceType and the variable is called deviceType instead of "type" everywhere



Added:
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/assets/
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/assets/border_tabs.css
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/assets/loading.gif   (with props)
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/assets/skin-sam.css
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/assets/skins/
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/assets/skins/sam/
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/assets/skins/sam/tabview-skin.css
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/assets/skins/sam/tabview.css
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/assets/tabview-core.css
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/assets/tabview.css
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/tabview-debug.js
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/tabview-min.js
    roller/trunk/weblogger-webapp/src/main/webapp/roller-ui/yui/tabview/tabview.js
Modified:
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/RendererFactory.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/RendererManager.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/mobile/MobileDeviceRepository.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/model/PageModel.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/FeedServlet.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PageServlet.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PlanetFeedServlet.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PreviewServlet.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/RSDServlet.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/SearchServlet.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/util/ParsedRequest.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/WeblogCacheWarmupJob.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RollerResourceLoader.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RollerVelocity.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/ThemeResourceLoader.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/VelocityRenderer.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/VelocityRendererFactory.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/WebappResourceLoader.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java
    roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEditBean.java
    roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileEdit.jsp
    roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/TemplateEdit.jsp
    roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/taglibs-struts2.jsp

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/RendererFactory.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/RendererFactory.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/RendererFactory.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/RendererFactory.java Sun Nov 13 15:01:36 2011
@@ -19,6 +19,7 @@
 package org.apache.roller.weblogger.ui.rendering;
 
 import org.apache.roller.weblogger.pojos.Template;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository;
 
 
 /**
@@ -29,7 +30,6 @@ import org.apache.roller.weblogger.pojos
  */
 public interface RendererFactory {
     
-    
     /**
      * Get a Renderer that will handle the given Template.
      * If a RendererFactory does not have a Renderer which can handle the
@@ -40,6 +40,7 @@ public interface RendererFactory {
      * while trying to find a renderer.  It is up to the factory itself to
      * report any relevant exceptions itself.
      */
-    public Renderer getRenderer(Template template);
+    public Renderer getRenderer(Template template, 
+		MobileDeviceRepository.DeviceType deviceType);
     
 }

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/RendererManager.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/RendererManager.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/RendererManager.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/RendererManager.java Sun Nov 13 15:01:36 2011
@@ -15,139 +15,112 @@
  * copyright in this work, please see the NOTICE file in the top level
  * directory of this distribution.
  */
-
 package org.apache.roller.weblogger.ui.rendering;
 
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.pojos.Template;
-import org.apache.roller.weblogger.pojos.ThemeTemplate;
-import org.apache.roller.weblogger.pojos.WeblogTemplateCode;
 
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository;
 
 /**
- * Returns Renderer for Template via configured RendererFactories. 
- * 
- * The purpose of the RendererManager is to provide a level of abstraction 
+ * Returns Renderer for Template via configured RendererFactories.
+ * <p/>
+ * The purpose of the RendererManager is to provide a level of abstraction
  * between classes that are rendering content and the implementations of the
  * rendering technology.  This allows us to provide easily pluggable rendering
  * implementations.
  */
 public class RendererManager {
-    
+
     private static Log log = LogFactory.getLog(RendererManager.class);
-    
     // a set of all renderer factories we are consulting
     private static Set rendererFactories = new HashSet();
-    
-    
+
     static {
         // lookup set of renderer factories we are going to use
         String rollerFactories = WebloggerConfig.getProperty("rendering.rollerRendererFactories");
         String userFactories = WebloggerConfig.getProperty("rendering.userRendererFactories");
-        
+
         // instantiate user defined renderer factory classes
-        if(userFactories != null && userFactories.trim().length() > 0) {
-            
+        if (userFactories != null && userFactories.trim().length() > 0) {
+
             RendererFactory rendererFactory = null;
             String[] uFactories = userFactories.split(",");
-            for(int i=0; i < uFactories.length; i++) {
+            for (int i = 0; i < uFactories.length; i++) {
                 try {
                     Class factoryClass = Class.forName(uFactories[i]);
                     rendererFactory = (RendererFactory) factoryClass.newInstance();
                     rendererFactories.add(rendererFactory);
-                } catch(ClassCastException cce) {
-                    log.error("It appears that your factory does not implement "+
-                            "the RendererFactory interface", cce);
-                } catch(Exception e) {
-                    log.error("Unable to instantiate renderer factory ["+uFactories[i]+"]", e);
+                } catch (ClassCastException cce) {
+                    log.error("It appears that your factory does not implement "
+                            + "the RendererFactory interface", cce);
+                } catch (Exception e) {
+                    log.error("Unable to instantiate renderer factory [" + uFactories[i] + "]", e);
                 }
             }
         }
-        
+
         // instantiate roller standard renderer factory classes
-        if(rollerFactories != null && rollerFactories.trim().length() > 0) {
-            
+        if (rollerFactories != null && rollerFactories.trim().length() > 0) {
+
             RendererFactory rendererFactory = null;
             String[] rFactories = rollerFactories.split(",");
-            for(int i=0; i < rFactories.length; i++) {
+            for (int i = 0; i < rFactories.length; i++) {
                 try {
                     Class factoryClass = Class.forName(rFactories[i]);
                     rendererFactory = (RendererFactory) factoryClass.newInstance();
                     rendererFactories.add(rendererFactory);
-                } catch(ClassCastException cce) {
-                    log.error("It appears that your factory does not implement "+
-                            "the RendererFactory interface", cce);
-                } catch(Exception e) {
-                    log.error("Unable to instantiate renderer factory ["+rFactories[i]+"]", e);
+                } catch (ClassCastException cce) {
+                    log.error("It appears that your factory does not implement "
+                            + "the RendererFactory interface", cce);
+                } catch (Exception e) {
+                    log.error("Unable to instantiate renderer factory [" + rFactories[i] + "]", e);
                 }
             }
         }
-        
-        if(rendererFactories.size() < 1) {
+
+        if (rendererFactories.size() < 1) {
             // hmm ... failed to load any renderer factories?
-            log.warn("Failed to load any renderer factories.  "+
-                    "Rendering probably won't function as you expect.");
+            log.warn("Failed to load any renderer factories.  "
+                    + "Rendering probably won't function as you expect.");
         }
-        
+
         log.info("Renderer Manager Initialized.");
     }
-    
-    
+
     // this class is non-instantiable
-    private RendererManager() {}
-    
-    
+    private RendererManager() {
+    }
+
     /**
      * Find the appropriate Renderer for the given content.
-     *
+     * <p/>
      * This method checks all renderer factories configured for the Roller
      * instance and tries to find a Renderer for the content.  If no Renderer
      * can be found then we throw an exception.
      */
-    public static Renderer getRenderer(Template template)
+    public static Renderer getRenderer(Template template, MobileDeviceRepository.DeviceType deviceType)
             throws RenderingException {
-        
+
         Renderer renderer = null;
-        
+
         // iterate over our renderer factories and see if one of them
         // wants to handle this content
         Iterator factories = rendererFactories.iterator();
-        while(factories.hasNext()) {
-            renderer = ((RendererFactory)factories.next()).getRenderer(template);
-            
-            if(renderer != null) {
-                return renderer;
-            }
-        }
-        
-        throw new RenderingException("No renderer found for template "+
-                template.getId()+"!");
-    }
+        while (factories.hasNext()) {
+            renderer = ((RendererFactory) factories.next()).getRenderer(template, deviceType);
 
-    public static ThemeTemplate prepareTemplate(ThemeTemplate page, String type)throws RenderingException{
-        try {
-            WeblogTemplateCode templateCode = page.getTemplateCode(type);
-
-            if(templateCode != null){
-            page.setContents(templateCode.getTemplate());
-            page.setTemplateLanguage(templateCode.getTemplateLanguage());
-            }
-            else{
-                // if there is no template code present we fall back to default template
-                return page;
+            if (renderer != null) {
+                return renderer;
             }
-        } catch (WebloggerException e) {
-            throw new RenderingException("Error while loading template code for template :"+page.getId(),e);
         }
-         return page;
 
+        throw new RenderingException("No renderer found for template "
+                + template.getId() + "!");
     }
-    
 }

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/mobile/MobileDeviceRepository.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/mobile/MobileDeviceRepository.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/mobile/MobileDeviceRepository.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/mobile/MobileDeviceRepository.java Sun Nov 13 15:01:36 2011
@@ -15,82 +15,77 @@
  * copyright in this work, please see the NOTICE file in the top level
  * directory of this distribution.
  */
-
 package org.apache.roller.weblogger.ui.rendering.mobile;
 
-import org.omg.CORBA.Request;
-import sun.tools.tree.ThisExpression;
-
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 
 public class MobileDeviceRepository {
 
+	public enum DeviceType { standard, mobile };
 
-    public static final String possibleDevices1 = ".*(android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)" +
-            "|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\\\/|" +
-            "plucker|pocket|psp|symbian|treo|up\\\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino).*" ;
-
-    public static final String possibleDevices2=
-            "\"1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\\\-)|" +
-            "ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\\\-m|r |s )|" +
-            "avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\\\-(n|u)|c55\\\\/|capi|ccwa|cdm\\\\-|" +
-            "cell|chtm|cldc|cmd\\\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\\\-d)|" +
-            "el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\\\-|_)|g1 u|g560|gene|gf\\\\-5|g\\\\-mo|" +
-            "go(\\\\.w|od)|gr(ad|un)|haie|hcit|hd\\\\-(m|p|t)|hei\\\\-|hi(pt|ta)|hp( i|ip)|hs\\\\-c|" +
-            "ht(c(\\\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\\\-(20|go|ma)|i230|iac( |\\\\-|\\\\/)|ibro|idea|ig01|ikom|im1k|" +
-            "inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\\\/)|klon|kpt |kwc\\\\-|kyo(c|k)|le(no|xi)|" +
-            "lg( g|\\\\/(k|l|u)|50|54|e\\\\-|e\\\\/|\\\\-[a-w])|libw|lynx|m1\\\\-w|m3ga|m50\\\\/|" +
-            "ma(te|ui|xo)|mc(01|21|ca)|m\\\\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\\\-| |o|v)|zz)|" +
-            "mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\\\-|on|tf|wf|wg|wt)|" +
-            "nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\\\-([1-8]|c))|phil|pire|pl(ay|uc)|" +
-            "pn\\\\-2|po(ck|rt|se)|prox|psio|pt\\\\-g|qa\\\\-a|qc(07|12|21|32|60|\\\\-[2-7]|i\\\\-)|qtek|r380|r600|raks|" +
-            "rim9|ro(ve|zo)|s55\\\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\\\-|oo|p\\\\-)|sdk\\\\/|" +
-            "se(c(\\\\-|0|1)|47|mc|nd|ri)|sgh\\\\-|shar|sie(\\\\-|m)|sk\\\\-0|sl(45|id)|" +
-            "sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\\\-|v\\\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|" +
-            "ta(gt|lk)|tcl\\\\-|tdg\\\\-|tel(i|m)|tim\\\\-|t\\\\-mo|to(pl|sh)|ts(70|m\\\\-|m3|m5)|tx\\\\-9|" +
-            "up(\\\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\\\-v)|vm40|voda|vulc|" +
-            "vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\\\\-|2|g)|" +
-            "yas\\\\-|your|zeto|zte\\\\-";
-
-    public static final String USER_REQUEST_TYPE ="roller_user_request_type";
-
-    /**
-     *
-     * ToCheck if a request is mobile.
-     * @param request
-     * @return   boolean
-     */
-    public static boolean isMobileDevice(HttpServletRequest request) {
-
-        String userAgent = request.getHeader("User-Agent").toLowerCase();
-        return (userAgent.matches(possibleDevices1)||userAgent.substring(0,4).matches(possibleDevices2));
-
-    }
-
-    public static String getRequestType(HttpServletRequest request) {
-        String type = "standard";
-        String cookie =getCookieValue(request.getCookies(), USER_REQUEST_TYPE,null);
-
-        if(cookie != null){
-            return cookie;
-        }
-
-        if (isMobileDevice(request)) {
-            type = "mobile";
-        }
-        return type;
-    }
-
-    private static String getCookieValue(Cookie[] cookies,
-                                         String cookieName,
-                                         String defaultValue) {
-        for (int i = 0; i < cookies.length; i++) {
-            Cookie cookie = cookies[i];
-            if (cookieName.equals(cookie.getName()))
-                return (cookie.getValue());
-        }
-        return (defaultValue);
-    }
-
+	public static final String possibleDevices1 = ".*(android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)"
+			+ "|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\\\/|"
+			+ "plucker|pocket|psp|symbian|treo|up\\\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino).*";
+	public static final String possibleDevices2 =
+			"\"1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\\\-)|"
+			+ "ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\\\-m|r |s )|"
+			+ "avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\\\-(n|u)|c55\\\\/|capi|ccwa|cdm\\\\-|"
+			+ "cell|chtm|cldc|cmd\\\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\\\-d)|"
+			+ "el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\\\-|_)|g1 u|g560|gene|gf\\\\-5|g\\\\-mo|"
+			+ "go(\\\\.w|od)|gr(ad|un)|haie|hcit|hd\\\\-(m|p|t)|hei\\\\-|hi(pt|ta)|hp( i|ip)|hs\\\\-c|"
+			+ "ht(c(\\\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\\\-(20|go|ma)|i230|iac( |\\\\-|\\\\/)|ibro|idea|ig01|ikom|im1k|"
+			+ "inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\\\/)|klon|kpt |kwc\\\\-|kyo(c|k)|le(no|xi)|"
+			+ "lg( g|\\\\/(k|l|u)|50|54|e\\\\-|e\\\\/|\\\\-[a-w])|libw|lynx|m1\\\\-w|m3ga|m50\\\\/|"
+			+ "ma(te|ui|xo)|mc(01|21|ca)|m\\\\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\\\-| |o|v)|zz)|"
+			+ "mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\\\-|on|tf|wf|wg|wt)|"
+			+ "nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\\\-([1-8]|c))|phil|pire|pl(ay|uc)|"
+			+ "pn\\\\-2|po(ck|rt|se)|prox|psio|pt\\\\-g|qa\\\\-a|qc(07|12|21|32|60|\\\\-[2-7]|i\\\\-)|qtek|r380|r600|raks|"
+			+ "rim9|ro(ve|zo)|s55\\\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\\\-|oo|p\\\\-)|sdk\\\\/|"
+			+ "se(c(\\\\-|0|1)|47|mc|nd|ri)|sgh\\\\-|shar|sie(\\\\-|m)|sk\\\\-0|sl(45|id)|"
+			+ "sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\\\-|v\\\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|"
+			+ "ta(gt|lk)|tcl\\\\-|tdg\\\\-|tel(i|m)|tim\\\\-|t\\\\-mo|to(pl|sh)|ts(70|m\\\\-|m3|m5)|tx\\\\-9|"
+			+ "up(\\\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\\\-v)|vm40|voda|vulc|"
+			+ "vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\\\\-|2|g)|"
+			+ "yas\\\\-|your|zeto|zte\\\\-";
+	public static final String USER_REQUEST_TYPE = "roller_user_request_type";
+
+	/**
+	 *
+	 * ToCheck if a request is mobile.
+	 * @param request
+	 * @return   boolean
+	 */
+	public static boolean isMobileDevice(HttpServletRequest request) {
+
+		String userAgent = request.getHeader("User-Agent").toLowerCase();
+		return (userAgent.matches(possibleDevices1) || userAgent.substring(0, 4).matches(possibleDevices2));
+
+	}
+
+	public static DeviceType getRequestType(HttpServletRequest request) {
+		DeviceType type = DeviceType.standard;
+		String cookie = getCookieValue(request.getCookies(), USER_REQUEST_TYPE, null);
+
+		if (cookie != null) {
+			return cookie.equals("standard") ? DeviceType.standard : DeviceType.mobile;
+		}
+
+		if (isMobileDevice(request)) {
+			type = DeviceType.mobile; 
+		}
+		return type;
+	}
+
+	private static String getCookieValue(Cookie[] cookies,
+			String cookieName,
+			String defaultValue) {
+		for (int i = 0; i < cookies.length; i++) {
+			Cookie cookie = cookies[i];
+			if (cookieName.equals(cookie.getName())) {
+				return (cookie.getValue());
+			}
+		}
+		return (defaultValue);
+	}
 }

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/model/PageModel.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/model/PageModel.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/model/PageModel.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/model/PageModel.java Sun Nov 13 15:01:36 2011
@@ -32,7 +32,7 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.pojos.wrapper.WeblogCategoryWrapper;
 import org.apache.roller.weblogger.pojos.wrapper.WeblogEntryWrapper;
 import org.apache.roller.weblogger.pojos.wrapper.WeblogWrapper;
-import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository.DeviceType;
 import org.apache.roller.weblogger.ui.rendering.pagers.WeblogEntriesDayPager;
 import org.apache.roller.weblogger.ui.rendering.pagers.WeblogEntriesLatestPager;
 import org.apache.roller.weblogger.ui.rendering.pagers.WeblogEntriesMonthPager;
@@ -55,7 +55,7 @@ public class PageModel implements Model 
     private WeblogEntryCommentForm commentForm = null;
     private Map requestParameters = null;
     private Weblog weblog = null;
-    private String type = null;
+    private DeviceType deviceType = null;
     
     
     /**
@@ -109,7 +109,7 @@ public class PageModel implements Model 
         // extract weblog object
         weblog = pageRequest.getWeblog();
 
-        this.type = weblogRequest.getType();
+        this.deviceType = weblogRequest.getDeviceType();
     }    
     
     
@@ -125,7 +125,7 @@ public class PageModel implements Model 
      * Get weblog being displayed.
      */
     public WeblogWrapper getWeblog() {
-        return WeblogWrapper.wrap(weblog, urlStrategy, getType());
+        return WeblogWrapper.wrap(weblog, urlStrategy, getDeviceType().toString());
     }
     
     
@@ -318,11 +318,11 @@ public class PageModel implements Model 
         return null;
     }
 
-    public String getType() {
-        return type;
+    public DeviceType getDeviceType() {
+        return deviceType;
     }
 
-    public void setType(String type) {
-        this.type = type;
+    public void setDeviceType(DeviceType type) {
+        this.deviceType = type;
     }
 }

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/FeedServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/FeedServlet.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/FeedServlet.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/FeedServlet.java Sun Nov 13 15:01:36 2011
@@ -40,6 +40,7 @@ import org.apache.roller.weblogger.ui.re
 import org.apache.roller.weblogger.util.cache.CachedContent;
 import org.apache.roller.weblogger.ui.rendering.Renderer;
 import org.apache.roller.weblogger.ui.rendering.RendererManager;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository;
 import org.apache.roller.weblogger.ui.rendering.model.ModelLoader;
 import org.apache.roller.weblogger.ui.rendering.model.SearchResultsFeedModel;
 import org.apache.roller.weblogger.ui.rendering.util.cache.SiteWideCache;
@@ -270,7 +271,7 @@ public class FeedServlet extends HttpSer
         try {
             log.debug("Looking up renderer");
             Template template = new StaticTemplate(pageId, "velocity");
-            renderer = RendererManager.getRenderer(template);
+            renderer = RendererManager.getRenderer(template, MobileDeviceRepository.DeviceType.standard);
         } catch(Exception e) {
             // nobody wants to render my content :(
 

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PageServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PageServlet.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PageServlet.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PageServlet.java Sun Nov 13 15:01:36 2011
@@ -37,7 +37,6 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.ui.core.RollerContext;
 import org.apache.roller.weblogger.ui.rendering.Renderer;
 import org.apache.roller.weblogger.ui.rendering.RendererManager;
-import org.apache.roller.weblogger.ui.rendering.RenderingException;
 import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository;
 import org.apache.roller.weblogger.ui.rendering.model.ModelLoader;
 import org.apache.roller.weblogger.ui.rendering.util.InvalidRequestException;
@@ -243,12 +242,14 @@ public class PageServlet extends HttpSer
 
         log.debug("Looking for template to use for rendering");
 
-        // Get the type from user agent
-        String type = MobileDeviceRepository.getRequestType(request);
+        // Get the deviceType from user agent
+        MobileDeviceRepository.DeviceType deviceType = MobileDeviceRepository.getRequestType(request);
 
-        // for previews we explicitly set the type attribute
-        if(request.getParameter("type") != null){
-            type = request.getParameter("type");
+        // for previews we explicitly set the deviceType attribute
+        if (request.getParameter("type") != null) {
+            deviceType = request.getParameter("type").equals("standard") 
+				? MobileDeviceRepository.DeviceType.standard
+				: MobileDeviceRepository.DeviceType.mobile;
         }
 
         // figure out what template to use
@@ -330,13 +331,6 @@ public class PageServlet extends HttpSer
 
         log.debug("page found, dealing with it");
 
-        // load the correct template using template codes.
-        try {
-            page = RendererManager.prepareTemplate(page, type);
-        } catch (RenderingException e) {
-            log.error("error while preparing template ", e);
-        }
-
         // validation.  make sure that request input makes sense.
         boolean invalid = false;
         if (pageRequest.getWeblogPageName() != null && page.isHidden()) {
@@ -404,14 +398,14 @@ public class PageServlet extends HttpSer
 
 
         // looks like we need to render content
-        // set the content type
+        // set the content deviceType
         String contentType = "text/html; charset=utf-8";
         if (StringUtils.isNotEmpty(page.getOutputContentType())) {
             contentType = page.getOutputContentType() + "; charset=utf-8";
         } else {
             String mimeType = RollerContext.getServletContext().getMimeType(page.getLink());
             if (mimeType != null) {
-                // we found a match ... set the content type
+                // we found a match ... set the content deviceType
                 contentType = mimeType + "; charset=utf-8";
             } else {
                 contentType = "text/html; charset=utf-8";
@@ -469,7 +463,7 @@ public class PageServlet extends HttpSer
         Renderer renderer = null;
         try {
             log.debug("Looking up renderer");
-            renderer = RendererManager.getRenderer(page);
+            renderer = RendererManager.getRenderer(page, deviceType);
         } catch (Exception e) {
             // nobody wants to render my content :(
             log.error("Couldn't find renderer for page " + page.getId(), e);

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PlanetFeedServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PlanetFeedServlet.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PlanetFeedServlet.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PlanetFeedServlet.java Sun Nov 13 15:01:36 2011
@@ -38,6 +38,7 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.pojos.Template;
 import org.apache.roller.weblogger.ui.rendering.Renderer;
 import org.apache.roller.weblogger.ui.rendering.RendererManager;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository.DeviceType;
 import org.apache.roller.weblogger.ui.rendering.model.UtilitiesModel;
 import org.apache.roller.weblogger.ui.rendering.util.cache.PlanetCache;
 import org.apache.roller.weblogger.ui.rendering.util.PlanetRequest;
@@ -175,7 +176,7 @@ public class PlanetFeedServlet extends H
         try {
             log.debug("Looking up renderer");
             Template template = new StaticTemplate("templates/planet/planetrss.vm", "velocity");
-            renderer = RendererManager.getRenderer(template);
+            renderer = RendererManager.getRenderer(template, DeviceType.mobile);
         } catch (Exception e) {
             // nobody wants to render my content :(
             log.error("Couldn't find renderer for planet rss", e);

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PreviewServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PreviewServlet.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PreviewServlet.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PreviewServlet.java Sun Nov 13 15:01:36 2011
@@ -28,7 +28,6 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.ui.core.RollerContext;
 import org.apache.roller.weblogger.ui.rendering.Renderer;
 import org.apache.roller.weblogger.ui.rendering.RendererManager;
-import org.apache.roller.weblogger.ui.rendering.RenderingException;
 import org.apache.roller.weblogger.ui.rendering.model.ModelLoader;
 import org.apache.roller.weblogger.ui.rendering.util.WeblogPreviewRequest;
 import org.apache.roller.weblogger.util.cache.CachedContent;
@@ -43,6 +42,7 @@ import javax.servlet.jsp.PageContext;
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository;
 
 
 /**
@@ -80,7 +80,7 @@ public class PreviewServlet extends Http
         
         WeblogPreviewRequest previewRequest = null;
 
-         String type = null;
+        String type = null;
 
         try {
             previewRequest = new WeblogPreviewRequest(request);
@@ -101,7 +101,17 @@ public class PreviewServlet extends Http
             return;
         }
         
-        Weblog tmpWebsite = weblog;
+        // Get the deviceType from user agent
+        MobileDeviceRepository.DeviceType deviceType = MobileDeviceRepository.getRequestType(request);
+
+        // for previews we explicitly set the deviceType attribute
+        if (request.getParameter("type") != null) {
+            deviceType = request.getParameter("type").equals("standard") 
+				? MobileDeviceRepository.DeviceType.standard
+				: MobileDeviceRepository.DeviceType.mobile;
+        }
+
+		Weblog tmpWebsite = weblog;
         
         if (previewRequest.getThemeName() != null) {
             // only create temporary weblog object if theme name was specified
@@ -178,13 +188,6 @@ public class PreviewServlet extends Http
         
         
         log.debug("preview page found, dealing with it");
-
-        // load the correct template using template codes.
-        try {
-            page = RendererManager.prepareTemplate((ThemeTemplate) page, type);
-        } catch (RenderingException e) {
-            log.error("error while preparing template ", e);
-        }
         
         // set the content type
         String pageLink = previewRequest.getWeblogPageName();
@@ -244,7 +247,7 @@ public class PreviewServlet extends Http
         Renderer renderer = null;
         try {
             log.debug("Looking up renderer");
-            renderer = RendererManager.getRenderer(page);
+            renderer = RendererManager.getRenderer(page, deviceType);
         } catch(Exception e) {
             // nobody wants to render my content :(
             log.error("Couldn't find renderer for page "+page.getId(), e);

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/RSDServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/RSDServlet.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/RSDServlet.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/RSDServlet.java Sun Nov 13 15:01:36 2011
@@ -36,6 +36,7 @@ import org.apache.roller.weblogger.ui.re
 import org.apache.roller.weblogger.ui.rendering.util.ModDateHeaderUtil;
 import org.apache.roller.weblogger.ui.rendering.Renderer;
 import org.apache.roller.weblogger.ui.rendering.RendererManager;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository.DeviceType;
 import org.apache.roller.weblogger.util.cache.CachedContent;
 
 
@@ -120,7 +121,7 @@ public class RSDServlet extends HttpServ
         try {
             log.debug("Looking up renderer");
             Template template = new StaticTemplate("templates/weblog/rsd.vm", "velocity");
-            renderer = RendererManager.getRenderer(template);
+            renderer = RendererManager.getRenderer(template, DeviceType.standard); 
         } catch(Exception e) {
             // nobody wants to render my content :(
             log.error("Couldn't find renderer for rsd template", e);

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/SearchServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/SearchServlet.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/SearchServlet.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/SearchServlet.java Sun Nov 13 15:01:36 2011
@@ -99,9 +99,15 @@ public class SearchServlet extends HttpS
             return;
         }
 
-        //is a mobile request
+		// Get the deviceType from user agent
+        MobileDeviceRepository.DeviceType deviceType = MobileDeviceRepository.getRequestType(request);
 
-       String  type = MobileDeviceRepository.getRequestType(request);
+        // for previews we explicitly set the deviceType attribute
+        if (request.getParameter("type") != null) {
+            deviceType = request.getParameter("type").equals("standard") 
+				? MobileDeviceRepository.DeviceType.standard
+				: MobileDeviceRepository.DeviceType.mobile;
+        }
         
         // do we need to force a specific locale for the request?
         if(searchRequest.getLocale() == null && !weblog.isShowAllLangs()) {
@@ -206,18 +212,11 @@ public class SearchServlet extends HttpS
 			}
 		}
 
-        //prepare template for detected type
-        try {
-            page = RendererManager.prepareTemplate(page ,type);
-        } catch (RenderingException e) {
-            log.debug("Error while preparing page template");
-        }
-
         // lookup Renderer we are going to use
         Renderer renderer = null;
         try {
             log.debug("Looking up renderer");
-            renderer = RendererManager.getRenderer(page);
+            renderer = RendererManager.getRenderer(page, deviceType);
         } catch(Exception e) {
             // nobody wants to render my content :(
             log.error("Couldn't find renderer for rsd template", e);

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/util/ParsedRequest.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/util/ParsedRequest.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/util/ParsedRequest.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/util/ParsedRequest.java Sun Nov 13 15:01:36 2011
@@ -48,7 +48,8 @@ public abstract class ParsedRequest {
     // lightweight attributes
     private String authenticUser = null;
 
-    private String type = "standard";
+    private MobileDeviceRepository.DeviceType deviceType = 
+			MobileDeviceRepository.DeviceType.standard;
     
     // heavyweight attributes
     private User user = null;
@@ -74,8 +75,7 @@ public abstract class ParsedRequest {
             this.authenticUser = prince.getName();
         }
         // set the detected type of the request
-        type = MobileDeviceRepository.getRequestType(request);
-        
+        deviceType = MobileDeviceRepository.getRequestType(request);
     }
     
     
@@ -113,11 +113,11 @@ public abstract class ParsedRequest {
         return (this.authenticUser != null);
     }
 
-    public String getType() {
-        return type;
+    public MobileDeviceRepository.DeviceType getDeviceType() {
+        return deviceType;
     }
 
-    public void setType(String type) {
-        this.type = type;
+    public void setDeviceType(MobileDeviceRepository.DeviceType type) {
+        this.deviceType = type;
     }
 }

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/WeblogCacheWarmupJob.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/WeblogCacheWarmupJob.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/WeblogCacheWarmupJob.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/util/cache/WeblogCacheWarmupJob.java Sun Nov 13 15:01:36 2011
@@ -24,18 +24,14 @@ import java.util.List;
 import java.util.Map;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.runnable.Job;
 import org.apache.roller.weblogger.config.WebloggerConfig;
-import org.apache.roller.weblogger.business.WebloggerFactory;
-import org.apache.roller.weblogger.business.UserManager;
 import org.apache.roller.weblogger.pojos.StaticTemplate;
 import org.apache.roller.weblogger.pojos.Template;
-import org.apache.roller.weblogger.pojos.Weblog;
 import org.apache.roller.weblogger.ui.rendering.Renderer;
 import org.apache.roller.weblogger.ui.rendering.RendererManager;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository.DeviceType;
 import org.apache.roller.weblogger.ui.rendering.model.ModelLoader;
-import org.apache.roller.weblogger.ui.rendering.util.cache.WeblogFeedCache;
 import org.apache.roller.weblogger.ui.rendering.util.WeblogFeedRequest;
 import org.apache.roller.weblogger.util.cache.CachedContent;
 
@@ -138,8 +134,9 @@ public class WeblogCacheWarmupJob implem
                 
                 // lookup Renderer we are going to use
                 Renderer renderer = null;
-                Template template = new StaticTemplate("templates/feeds/weblog-"+type+"-"+format+".vm", "velocity");
-                renderer = RendererManager.getRenderer(template);
+                Template template = new StaticTemplate(
+					"templates/feeds/weblog-"+type+"-"+format+".vm", "velocity");
+                renderer = RendererManager.getRenderer(template, DeviceType.standard);
                 
                 
                 // render content.  use default size of about 24K for a standard page

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RollerResourceLoader.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RollerResourceLoader.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RollerResourceLoader.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RollerResourceLoader.java Sun Nov 13 15:01:36 2011
@@ -29,6 +29,7 @@ import org.apache.velocity.runtime.resou
 import org.apache.roller.weblogger.WebloggerException;
 import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.pojos.WeblogTemplate;
+import org.apache.roller.weblogger.pojos.WeblogTemplateCode;
 
 
 /**
@@ -42,22 +43,20 @@ import org.apache.roller.weblogger.pojos
  */
 public class RollerResourceLoader extends ResourceLoader {
     
-    private static Log mLogger = LogFactory.getLog(RollerResourceLoader.class);
+    private static Log logger = LogFactory.getLog(RollerResourceLoader.class);
     
     
     public void init(ExtendedProperties configuration) {
-        if (mLogger.isDebugEnabled()) {
-            mLogger.debug(configuration);
+        if (logger.isDebugEnabled()) {
+            logger.debug(configuration);
         }
     }
     
-    
     public boolean isSourceModified(Resource resource) {
         return (resource.getLastModified() !=
                 readLastModified(resource, "checking timestamp"));
     }
     
-    
     public long getLastModified(Resource resource) {
         return readLastModified(resource, "getting timestamp");
     }
@@ -72,29 +71,49 @@ public class RollerResourceLoader extend
     public InputStream getResourceStream(String name)
             throws ResourceNotFoundException {
         
+		logger.debug("Looking for: " + name);
+
         if (name == null || name.length() == 0) {
             throw new ResourceNotFoundException("Need to specify a template name!");
         }
-        
+
+		String deviceType = "standard";
+		if (name.contains("|")) {
+			String[] pair = name.split("\\|");
+			name = pair[0];
+			deviceType = pair[1];
+		}
+
+		logger.debug("   Actually, it's " + name);
+
         try {
-            WeblogTemplate page = 
-                    WebloggerFactory.getWeblogger().getWeblogManager().getPage(name);
+            WeblogTemplate page = WebloggerFactory
+				.getWeblogger().getWeblogManager().getPage(name);
             
             if (page == null) {
                 throw new ResourceNotFoundException(
                         "RollerResourceLoader: page \"" +
                         name + "\" not found");
             }
-            return new ByteArrayInputStream( page.getContents().getBytes("UTF-8") );
+			String contents;
+			WeblogTemplateCode templateCode = page.getTemplateCode(deviceType);
+			if (templateCode != null) {
+				contents = templateCode.getTemplate(); 
+			} else {
+				contents = page.getContents();
+			}
+            return new ByteArrayInputStream(contents.getBytes("UTF-8") );
+
         } catch (UnsupportedEncodingException uex) {
             // This should never actually happen.  We expect UTF-8 in all JRE installation.
             // This rethrows as a Runtime exception after logging.
-            mLogger.error(uex);
+            logger.error(uex);
             throw new RuntimeException(uex);
-        } catch (WebloggerException re) {
+
+        } catch (Exception re) {
             String msg = "RollerResourceLoader Error: " +
                     "database problem trying to load resource " + name;
-            mLogger.error( msg, re );
+            logger.error( msg, re );
             throw new ResourceNotFoundException(msg);
         }
     }
@@ -110,21 +129,25 @@ public class RollerResourceLoader extend
      */
     private long readLastModified(Resource resource, String i_operation) {
         
-        /*
-         *  get the template name from the resource
-         */
+        // get the template name from the resource
         String name = resource.getName();
+
+		if (name.contains("|")) {
+			String[] pair = name.split("\\|");
+			name = pair[0];
+		}
+
         try {
             WeblogTemplate page = 
                     WebloggerFactory.getWeblogger().getWeblogManager().getPage(name);
             
-            if (mLogger.isDebugEnabled()) {
-                mLogger.debug(name + ": resource=" + resource.getLastModified() +
+            if (logger.isDebugEnabled()) {
+                logger.debug(name + ": resource=" + resource.getLastModified() +
                         " vs. page=" + page.getLastModified().getTime());
             }
             return page.getLastModified().getTime();
         } catch (WebloggerException re) {
-            mLogger.error( "Error " + i_operation, re );
+            logger.error( "Error " + i_operation, re );
         }
         return 0;
     }

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RollerVelocity.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RollerVelocity.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RollerVelocity.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/RollerVelocity.java Sun Nov 13 15:01:36 2011
@@ -24,6 +24,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.ui.core.RollerContext;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository;
 import org.apache.velocity.Template;
 import org.apache.velocity.app.VelocityEngine;
 import org.apache.velocity.exception.ParseErrorException;
@@ -90,22 +91,37 @@ public class RollerVelocity {
         return velocityEngine;
     }
     
-    
     /**
      * Convenience static method for looking up a template.
      */
     public static Template getTemplate(String name)
             throws ResourceNotFoundException, ParseErrorException, Exception {
-        return velocityEngine.getTemplate(name);
+        return velocityEngine.getTemplate(name + "|standard");
+    }
+
+    /**
+     * Convenience static method for looking up a template.
+     */
+    public static Template getTemplate(String name, 
+			MobileDeviceRepository.DeviceType deviceType)
+            throws ResourceNotFoundException, ParseErrorException, Exception {
+        return velocityEngine.getTemplate(name + "|" + deviceType);
     }
-    
     
     /**
      * Convenience static method for looking up a template.
      */
     public static Template getTemplate(String name, String encoding)
             throws ResourceNotFoundException, ParseErrorException, Exception {
-        return velocityEngine.getTemplate(name, encoding);
+        return velocityEngine.getTemplate(name + "|standard", encoding);
+    }
+	
+    /**
+     * Convenience static method for looking up a template.
+     */
+    public static Template getTemplate(String name, 
+			MobileDeviceRepository.DeviceType deviceType, String encoding)
+            throws ResourceNotFoundException, ParseErrorException, Exception {
+        return velocityEngine.getTemplate(name + "|" + deviceType, encoding);
     }
-    
 }

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/ThemeResourceLoader.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/ThemeResourceLoader.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/ThemeResourceLoader.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/ThemeResourceLoader.java Sun Nov 13 15:01:36 2011
@@ -48,24 +48,29 @@ import org.apache.roller.weblogger.pojos
  */
 public class ThemeResourceLoader extends ResourceLoader {
     
-    private static Log mLogger = 
+    private static Log logger = 
         LogFactory.getFactory().getInstance(ThemeResourceLoader.class);
         
     
     public void init(ExtendedProperties configuration) {
-        mLogger.debug(configuration);
+        logger.debug(configuration);
     }
     
     
     public InputStream getResourceStream( String name )
         throws ResourceNotFoundException {
         
-        mLogger.debug("Looking up resource named ... "+name);
-        
+		logger.debug("Looking for: " + name);
+       
         if (name == null || name.length() < 1) {
             throw new ResourceNotFoundException("Need to specify a template name!");
         }
         
+		if (name.contains("|")) {
+			String[] pair = name.split("\\|");
+			name = pair[0];
+		}
+
         try {
             // parse the name ... theme templates name are <theme>:<template>
             String[] split = name.split(":", 2);
@@ -81,7 +86,7 @@ public class ThemeResourceLoader extends
                 throw new ResourceNotFoundException("Template ["+split[1]+
                         "] doesn't seem to be part of theme ["+split[0]+"]");
             
-            mLogger.debug("Resource found!");
+            logger.debug("Resource found!");
             
             // return the input stream
             return new ByteArrayInputStream(template.getContents().getBytes("UTF-8"));
@@ -89,17 +94,17 @@ public class ThemeResourceLoader extends
         } catch (UnsupportedEncodingException uex) {
             // We expect UTF-8 in all JRE installation.
             // This rethrows as a Runtime exception after logging.
-            mLogger.error(uex);
+            logger.error(uex);
             throw new RuntimeException(uex);
            
         } catch (ThemeNotFoundException tnfe) {
             String msg = "ThemeResourceLoader Error: " + tnfe.getMessage();
-            mLogger.error(msg, tnfe);
+            logger.error(msg, tnfe);
             throw new ResourceNotFoundException(msg);
             
         } catch (WebloggerException re) {
             String msg = "RollerResourceLoader Error: " + re.getMessage();
-            mLogger.error( msg, re );
+            logger.error( msg, re );
             throw new ResourceNotFoundException(msg);
         }
     }
@@ -114,7 +119,7 @@ public class ThemeResourceLoader extends
         long last_mod = 0;
         String name = resource.getName();
         
-        mLogger.debug("Checking last modified time for resource named ... "+name);
+        logger.debug("Checking last modified time for resource named ... "+name);
         
         if (name == null || name.length() < 1)
             return last_mod;

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/VelocityRenderer.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/VelocityRenderer.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/VelocityRenderer.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/VelocityRenderer.java Sun Nov 13 15:01:36 2011
@@ -27,6 +27,7 @@ import org.apache.roller.weblogger.pojos
 import org.apache.roller.weblogger.pojos.ThemeTemplate;
 import org.apache.roller.weblogger.ui.rendering.Renderer;
 import org.apache.roller.weblogger.ui.rendering.RenderingException;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository;
 import org.apache.roller.weblogger.ui.rendering.model.UtilitiesModel;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.context.Context;
@@ -43,6 +44,7 @@ public class VelocityRenderer implements
     
     // the original template we are supposed to render
     private Template renderTemplate = null;
+	private MobileDeviceRepository.DeviceType deviceType = null;
     
     // the velocity templates
     private org.apache.velocity.Template velocityTemplate = null;
@@ -52,16 +54,18 @@ public class VelocityRenderer implements
     private Exception parseException = null;
     
     
-    public VelocityRenderer(Template template) throws Exception {
+    public VelocityRenderer(Template template, 
+			MobileDeviceRepository.DeviceType deviceType) throws Exception {
         
         // the Template we are supposed to render
         this.renderTemplate = template;
+		this.deviceType = deviceType;
         
         try {
             // make sure that we can locate the template
             // if we can't then this will throw an exception
-            velocityTemplate = RollerVelocity.getTemplate(template.getId(), "UTF-8");
-            
+            velocityTemplate = RollerVelocity.getTemplate(template.getId(), deviceType, "UTF-8");
+           
             // if this is a ThemeTemplate than look for a decorator too
             if(template instanceof ThemeTemplate) {
                 ThemeTemplate templ = (ThemeTemplate) template;
@@ -86,7 +90,7 @@ public class VelocityRenderer implements
             parseException = ex;
             
             // need to lookup error page template
-            velocityTemplate = RollerVelocity.getTemplate("templates/error-page.vm");
+            velocityTemplate = RollerVelocity.getTemplate("templates/error-page.vm", deviceType);
             
         } catch(Exception ex) {
             // some kind of generic/unknown exception, dump it to the logs
@@ -101,6 +105,7 @@ public class VelocityRenderer implements
     public void render(Map model, Writer out) throws RenderingException {
         
         try {
+
             if(parseException != null) {
                 
                 Context ctx = new VelocityContext(model);
@@ -120,7 +125,7 @@ public class VelocityRenderer implements
             // convert model to Velocity Context
             Context ctx = new VelocityContext(model);
             
-            if(velocityDecorator != null) {
+            if (velocityDecorator != null) {
                 
                 /**
                  * We only allow decorating once, so the process isn't

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/VelocityRendererFactory.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/VelocityRendererFactory.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/VelocityRendererFactory.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/VelocityRendererFactory.java Sun Nov 13 15:01:36 2011
@@ -23,38 +23,36 @@ import org.apache.commons.logging.LogFac
 import org.apache.roller.weblogger.pojos.Template;
 import org.apache.roller.weblogger.ui.rendering.Renderer;
 import org.apache.roller.weblogger.ui.rendering.RendererFactory;
+import org.apache.roller.weblogger.ui.rendering.mobile.MobileDeviceRepository;
 
 
 /**
  * RendererFactory for Velocity, creates VelocityRenderers.
  */
 public class VelocityRendererFactory implements RendererFactory {
-    
     private static Log log = LogFactory.getLog(VelocityRendererFactory.class);
     
-    
-    public Renderer getRenderer(Template template) {
-        
+    public Renderer getRenderer(Template template, 
+			MobileDeviceRepository.DeviceType deviceType) {
         Renderer renderer = null;
         
         // nothing we can do with null values
-        if(template.getTemplateLanguage() == null || template.getId() == null) {
+        if (template.getTemplateLanguage() == null || template.getId() == null) {
             return null;
         }
         
-        if("velocity".equals(template.getTemplateLanguage())) { 
+        if ("velocity".equals(template.getTemplateLanguage())) { 
             
             // standard velocity template
             try {
-               renderer = new VelocityRenderer(template);
+               renderer = new VelocityRenderer(template, deviceType);
             } catch(Exception ex) {
+				log.error("ERROR creating VelocityRenderer", ex);
                 // some kind of exception so we don't have a renderer
                 // we do catching/logging in VelocityRenderer constructor
                 return null;
             }            
-            
         }
-        
         return renderer;
     }
     

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/WebappResourceLoader.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/WebappResourceLoader.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/WebappResourceLoader.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/velocity/WebappResourceLoader.java Sun Nov 13 15:01:36 2011
@@ -38,7 +38,7 @@ import org.apache.velocity.runtime.resou
  */
 public class WebappResourceLoader extends ResourceLoader {
     
-    private static Log log = LogFactory.getLog(WebappResourceLoader.class);
+    private static Log logger = LogFactory.getLog(WebappResourceLoader.class);
     
     private ServletContext mContext = null;
     
@@ -48,16 +48,16 @@ public class WebappResourceLoader extend
      */
     public void init(ExtendedProperties config) {
         
-        log.debug("WebappResourceLoader : initialization starting.");
+        logger.debug("WebappResourceLoader : initialization starting.");
         
         if (mContext == null) {
             mContext = RollerContext.getServletContext();
-            log.debug("Servlet Context = "+mContext.getRealPath("/WEB-INF/velocity/"));
+            logger.debug("Servlet Context = "+mContext.getRealPath("/WEB-INF/velocity/"));
         }
         
-        log.debug(config);
+        logger.debug(config);
         
-        log.debug("WebappResourceLoader : initialization complete.");
+        logger.debug("WebappResourceLoader : initialization complete.");
     }
     
     
@@ -67,25 +67,30 @@ public class WebappResourceLoader extend
     public InputStream getResourceStream(String name) 
             throws ResourceNotFoundException {
         
-        log.debug("Looking up resource named ... "+name);
+       	logger.debug("Looking for resource: " + name);
         
         if (name == null || name.length() == 0) {
             throw new ResourceNotFoundException("No template name provided");
         }
         
-        InputStream result = null;
+		if (name.contains("|")) {
+			String[] pair = name.split("\\|");
+			name = pair[0];
+		}
+				
+		InputStream result = null;
         
         try {
-            if(!name.startsWith("/"))
+            if(!name.startsWith("/")) {
                 name = "/WEB-INF/velocity/" + name;
-            
+			}
             result = this.mContext.getResourceAsStream(name);
             
         } catch(Exception e) {
             throw new ResourceNotFoundException(e.getMessage());
         }
         
-        if(result == null) {
+        if (result == null) {
             throw new ResourceNotFoundException("Couldn't find "+name);
         }
         

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEdit.java Sun Nov 13 15:01:36 2011
@@ -26,7 +26,6 @@ import org.apache.roller.weblogger.busin
 import org.apache.roller.weblogger.config.WebloggerConfig;
 import org.apache.roller.weblogger.pojos.WeblogPermission;
 import org.apache.roller.weblogger.pojos.WeblogTemplate;
-import org.apache.roller.weblogger.pojos.WeblogTemplateCode;
 import org.apache.roller.weblogger.ui.struts2.util.UIAction;
 import org.apache.roller.weblogger.util.Utilities;
 import org.apache.roller.weblogger.util.cache.CacheManager;
@@ -42,36 +41,36 @@ import java.util.List;
  * Action which handles editing for a single WeblogTemplate.
  */
 public class TemplateEdit extends UIAction {
-    
+
     private static Log log = LogFactory.getLog(TemplateEdit.class);
-    
+
     // form bean for collection all template properties
     private TemplateEditBean bean = new TemplateEditBean();
-    
+
     // the template we are working on
     private WeblogTemplate template = null;
 
     private String type = null;
-    
-    
+
+
     public TemplateEdit() {
         this.actionName = "templateEdit";
         this.desiredMenu = "editor";
         this.pageTitle = "pagesForm.title";
     }
-    
-    
+
+
     @Override
     public List<String> requiredWeblogPermissionActions() {
         return Collections.singletonList(WeblogPermission.ADMIN);
     }
-    
+
 
     public void myPrepare() {
         try {
             setTemplate(WebloggerFactory.getWeblogger().getWeblogManager().getPage(getBean().getId()));
         } catch (WebloggerException ex) {
-            log.error("Error looking up template - "+getBean().getId(), ex);
+            log.error("Error looking up template - " + getBean().getId(), ex);
         }
     }
 
@@ -81,105 +80,53 @@ public class TemplateEdit extends UIActi
      */
     @SkipValidation
     public String execute() {
-        
-        if(getTemplate() == null) {
-            // TODO: i18n
-            addError("Unable to locate specified template");
-            return LIST;
-        }
-        
-        WeblogTemplate page = getTemplate();
-        getBean().copyFrom(template);
+        try {
+            if (getTemplate() == null) {
+                // TODO: i18n
+                addError("Unable to locate specified template");
+                return LIST;
+            }
+            WeblogTemplate page = getTemplate();
+            getBean().copyFrom(template);
 
-        WeblogTemplateCode templateCode = null;
+            // empty content-type indicates that page uses auto content-type detection
+            if (StringUtils.isEmpty(page.getOutputContentType())) {
+                getBean().setAutoContentType(Boolean.TRUE);
+            } else {
+                getBean().setAutoContentType(Boolean.FALSE);
+                getBean().setManualContentType(page.getOutputContentType());
+            }
 
-        // look for the template code
-        try {
-           templateCode = WebloggerFactory.getWeblogger().getWeblogManager().
-                   getTemplateCodeByType(template.getId(), getBean().getType());
-        } catch (WebloggerException e) {
-            log.error("Unable to look weblog code for template "+template.getName() +"of type "+getBean().getType());
-        }
-         //set the content for the type.
-        if(templateCode != null){
-            getBean().setContents(templateCode.getTemplate());
+        } catch (WebloggerException ex) {
+           log.error("Error updating page - " + getBean().getId(), ex);
+           // TODO: i18n
+           addError("Error saving template");
         }
 
-        // empty content-type indicates that page uses auto content-type detection
-        if (StringUtils.isEmpty(page.getOutputContentType())) {
-            getBean().setAutoContentType(Boolean.TRUE);
-        } else {
-            getBean().setAutoContentType(Boolean.FALSE);
-            getBean().setManualContentType(page.getOutputContentType());
-        }
-        
         return INPUT;
     }
 
     /**
-     * This is to sync mobile theme and standard theme if name or link changed
-     */
-      private void synchronizeThemes(){
-
-          boolean isModified = false;
-          WeblogTemplate mobileTemplate = null;
-          WeblogTemplate standardTemplate = null;
-          try {
-              mobileTemplate = WebloggerFactory.getWeblogger().getWeblogManager().
-                      getPage(getBean().getMobileTemplateId());
-              standardTemplate = WebloggerFactory.getWeblogger().getWeblogManager().
-                      getPage(getBean().getStandardTemplateId());
-          } catch (WebloggerException e) {
-              log.error("error in looking up theme ", e);
-          }
-
-          if (standardTemplate != null && mobileTemplate != null) {
-              // if standard template has a different tempalte version we are going to change mobile accordingly
-              if (!mobileTemplate.getName().equals(standardTemplate.getName() + ".Mobile")) {
-                  mobileTemplate.setName(standardTemplate.getName() + ".Mobile");
-                  isModified = true;
-              }
-              if (!mobileTemplate.getLink().equals(standardTemplate.getLink())) {
-                  mobileTemplate.setLink(standardTemplate.getLink());
-                  isModified = true;
-              }
-              if (isModified) {
-                  // save template and flush
-                  try {
-                      WebloggerFactory.getWeblogger().getWeblogManager().savePage(mobileTemplate);
-                      WebloggerFactory.getWeblogger().flush();
-                  } catch (WebloggerException e) {
-                      log.error("Error syncing with standard template", e);
-                  }
-                  // notify caches
-                  CacheManager.invalidate(mobileTemplate);
-              }
-
-          }
-
-      }
-    
-    
-    /**
      * Save an existing template.
      */
     public String save() {
-        
-        if(getTemplate() == null) {
+        log.debug("Entering save()");
+
+        if (getTemplate() == null) {
             // TODO: i18n
             addError("Unable to locate specified template");
             return LIST;
         }
-        
+
         // validation
         myValidate();
-        
-        if(!hasActionErrors()) try {
-            
+
+        if (!hasActionErrors()) try {
+
             WeblogTemplate template = getTemplate();
             getBean().copyTo(template);
             template.setLastModified(new Date());
-            
+
             if (getBean().getAutoContentType() == null ||
                     !getBean().getAutoContentType().booleanValue()) {
                 template.setOutputContentType(getBean().getManualContentType());
@@ -187,81 +134,39 @@ public class TemplateEdit extends UIActi
                 // empty content-type indicates that template uses auto content-type detection
                 template.setOutputContentType(null);
             }
-            
+
             // save template
             WebloggerFactory.getWeblogger().getWeblogManager().savePage(template);
-
-
-            //save template code
-            WeblogTemplateCode templateCode = WebloggerFactory.getWeblogger().getWeblogManager().
-                    getTemplateCodeByType(template.getId(),getBean().getType());
-            templateCode.setTemplate(getBean().getContents());
-
-            WebloggerFactory.getWeblogger().getWeblogManager().saveTemplateCode(templateCode);
+            log.debug("Saved template: " + template.getId());
 
             //flush
-             WebloggerFactory.getWeblogger().flush();
+            WebloggerFactory.getWeblogger().flush();
 
             // notify caches
             CacheManager.invalidate(template);
 
-           // synchronizeThemes();
-            
+            // synchronizeThemes();
+
             // success message
             addMessage("pageForm.save.success", template.getName());
-            
-        } catch (WebloggerException ex) {
-            log.error("Error updating page - "+getBean().getId(), ex);
-            // TODO: i18n
-            addError("Error saving template");
-        }
-        
-        return INPUT;
-    }
 
-
-    public String loadMobileTheme(){
-         if(getTemplate() == null) {
+        } catch (Exception ex) {
+            log.error("Error updating page - " + getBean().getId(), ex);
             // TODO: i18n
-            addError("Unable to locate specified template");
-            return LIST;
-        }
-
-             WeblogTemplate mobile = null;
-
-        try {
-                mobile = WebloggerFactory.getWeblogger().getWeblogManager().getPageByName(getActionWeblog(),
-                    template.getName()+".mobile");
-        } catch (WebloggerException e) {
-            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
-        }
-
-         if(mobile == null){
-            addError("Unable to locate specified template");
-            return LIST;
-         }
-        getBean().copyFrom(mobile);
-
-
-        // empty content-type indicates that page uses auto content-type detection
-        if (StringUtils.isEmpty(mobile.getOutputContentType())) {
-            getBean().setAutoContentType(Boolean.TRUE);
-        } else {
-            getBean().setAutoContentType(Boolean.FALSE);
-            getBean().setManualContentType(mobile.getOutputContentType());
+            addError("Error saving template");
         }
 
+        log.debug("Leaving save()");
         return INPUT;
     }
 
-
-    
     private void myValidate() {
-        
+
         // if name changed make sure there isn't a conflict
-        if(!getTemplate().getName().equals(getBean().getName())) {
+        if (!getTemplate().getName().equals(getBean().getName())) {
             try {
-                if(WebloggerFactory.getWeblogger().getWeblogManager().getPageByName(getActionWeblog(), getBean().getName()) != null) {
+                if (WebloggerFactory.getWeblogger().getWeblogManager()
+                    .getPageByName(getActionWeblog(), getBean().getName()) != null) {
                     addError("pagesForm.error.alreadyExists", getBean().getName());
                 }
             } catch (WebloggerException ex) {
@@ -269,11 +174,12 @@ public class TemplateEdit extends UIActi
             }
         }
 
-      // if link changed make sure there isn't a conflict
-        if(!StringUtils.isEmpty(getBean().getLink()) &&
+        // if link changed make sure there isn't a conflict
+        if (!StringUtils.isEmpty(getBean().getLink()) &&
                 !getBean().getLink().equals(getTemplate().getLink())) {
             try {
-                if(WebloggerFactory.getWeblogger().getWeblogManager().getPageByLink(getActionWeblog(), getBean().getLink()) != null) {
+                if (WebloggerFactory.getWeblogger().getWeblogManager()
+                        .getPageByLink(getActionWeblog(), getBean().getLink()) != null) {
                     addError("pagesForm.error.alreadyExists", getBean().getLink());
                 }
             } catch (WebloggerException ex) {
@@ -281,15 +187,14 @@ public class TemplateEdit extends UIActi
             }
         }
     }
-    
-    
+
     public List getTemplateLanguages() {
-        String langs = WebloggerConfig.getProperty("rendering.templateLanguages","velocity");
+        String langs = WebloggerConfig.getProperty("rendering.templateLanguages", "velocity");
         String[] langsArray = Utilities.stringToStringArray(langs, ",");
         return Arrays.asList(langsArray);
     }
-    
-    
+
+
     public TemplateEditBean getBean() {
         return bean;
     }

Modified: roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEditBean.java
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEditBean.java?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEditBean.java (original)
+++ roller/trunk/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/TemplateEditBean.java Sun Nov 13 15:01:36 2011
@@ -18,21 +18,27 @@
 
 package org.apache.roller.weblogger.ui.struts2.editor;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.weblogger.WebloggerException;
+import org.apache.roller.weblogger.business.WebloggerFactory;
 import org.apache.roller.weblogger.pojos.WeblogTemplate;
-import org.apache.struts2.components.If;
+import org.apache.roller.weblogger.pojos.WeblogTemplateCode;
 
 
 /**
  * Form bean for TemplateEdit action.
  */
 public class TemplateEditBean {
-    
+    private static Log log = LogFactory.getLog(TemplateEdit.class);
+ 
     private String id = null;
     private String name = null;
     private String action = null;
     private String description = null;
     private String link = null;
-    private String contents = null;
+    private String contentsStandard = null;
+    private String contentsMobile = null;
     private String templateLanguage = null;
     private boolean navbar= false;
     private boolean hidden = false;
@@ -87,12 +93,20 @@ public class TemplateEditBean {
         this.link = link;
     }
     
-    public String getContents() {
-        return this.contents;
+    public String getContentsStandard() {
+        return this.contentsStandard;
     }
 
-    public void setContents( String contents ) {
-        this.contents = contents;
+    public void setContentsStandard( String contents ) {
+        this.contentsStandard = contents;
+    }
+    
+     public String getContentsMobile() {
+        return this.contentsMobile;
+    }
+
+    public void setContentsMobile( String contents ) {
+        this.contentsMobile = contents;
     }
     
     public String getTemplateLanguage() {
@@ -136,12 +150,29 @@ public class TemplateEditBean {
     }
     
     
-    public void copyTo(WeblogTemplate dataHolder) {
+    public void copyTo(WeblogTemplate dataHolder) throws WebloggerException {
+
+        if (dataHolder.getTemplateCode("standard") != null) {
+            // if we have a template, then set it
+            WeblogTemplateCode tc = dataHolder.getTemplateCode("standard");
+            tc.setTemplate(contentsStandard);
+            WebloggerFactory.getWeblogger().getWeblogManager().saveTemplateCode(tc);
+        } else { 
+            // otherwise create it, then set it
+            WeblogTemplateCode tc = new WeblogTemplateCode(dataHolder.getId(), "standard");
+			tc.setTemplate(dataHolder.getContents());
+            WebloggerFactory.getWeblogger().getWeblogManager().saveTemplateCode(tc);
+        }
+
+        if (dataHolder.getTemplateCode("mobile") != null) {
+            WeblogTemplateCode tc = dataHolder.getTemplateCode("mobile");
+            tc.setTemplate(contentsMobile);
+        } else {
+            WeblogTemplateCode tc = new WeblogTemplateCode(dataHolder.getId(), "mobile");
+			tc.setTemplate(""); // empty, we've got no default mobile template 
+            WebloggerFactory.getWeblogger().getWeblogManager().saveTemplateCode(tc);
+        }
 
-        // change the default content of template if we are changing standard type code
-        if("standard".equals(getType()))
-        dataHolder.setContents(getContents());
-        
         // the rest of the template properties can only be modified when
         // dealing with a CUSTOM weblog template
         if(dataHolder.isCustom()) {
@@ -156,14 +187,23 @@ public class TemplateEditBean {
     }
     
     
-    public void copyFrom(WeblogTemplate dataHolder) {
-        
+    public void copyFrom(WeblogTemplate dataHolder) throws WebloggerException {
         this.id = dataHolder.getId();
         this.name = dataHolder.getName();
         this.action = dataHolder.getAction();
         this.description = dataHolder.getDescription();
         this.link = dataHolder.getLink();
-        this.contents = dataHolder.getContents();
+
+        if (dataHolder.getTemplateCode("standard") != null) {
+            this.contentsStandard = dataHolder.getTemplateCode("standard").getTemplate();
+        } else {
+            this.contentsStandard = dataHolder.getContents();
+        }
+        if (dataHolder.getTemplateCode("mobile") != null) {
+            this.contentsMobile = dataHolder.getTemplateCode("mobile").getTemplate();
+        }
+		log.debug("Standard: " + this.contentsStandard + " Mobile: " + this.contentsMobile); 
+
         this.navbar = dataHolder.isNavbar();
         this.hidden = dataHolder.isHidden();
         this.templateLanguage = dataHolder.getTemplateLanguage();

Modified: roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileEdit.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileEdit.jsp?rev=1201435&r1=1201434&r2=1201435&view=diff
==============================================================================
--- roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileEdit.jsp (original)
+++ roller/trunk/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/MediaFileEdit.jsp Sun Nov 13 15:01:36 2011
@@ -19,9 +19,9 @@
 <%@ page import="org.apache.roller.weblogger.config.WebloggerConfig" %>
 
 <script type="text/javascript" src='<s:url value="/roller-ui/scripts/jquery-1.4.2.min.js" />'></script>
-<script type="text/javascript" src='<s:url value="/custom-ui/ZeroClipboard.js" />'></script>
 
 <%-- 
+<script type="text/javascript" src='<s:url value="/custom-ui/ZeroClipboard.js" />'></script>
 <!-- Can't distribute ZeroClipboard with Roller, LGPL violates ASF policy -->
 <!-- (1/2) For ZeroClipboard you would add this: -->
 <style type="text/css">



Mime
View raw message