roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r543346 - in /roller/trunk/apps/weblogger: src/java/org/apache/roller/weblogger/business/themes/ src/java/org/apache/roller/weblogger/ui/rendering/servlets/ web/WEB-INF/ web/WEB-INF/jsps/core/ web/WEB-INF/jsps/editor/
Date Fri, 01 Jun 2007 01:19:44 GMT
Author: agilliland
Date: Thu May 31 18:19:42 2007
New Revision: 543346

URL: http://svn.apache.org/viewvc?view=rev&rev=543346
Log:
serve theme preview images directly out of our themes rather than the old hacky way of having
to put the preview images in a specific folder in the webapp.


Added:
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/servlets/PreviewThemeImageServlet.java
Modified:
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/SharedTheme.java
    roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/SharedThemeFromDir.java
    roller/trunk/apps/weblogger/web/WEB-INF/jsps/core/CreateWeblog.jsp
    roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/ThemeEdit.jsp
    roller/trunk/apps/weblogger/web/WEB-INF/web.xml

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/SharedTheme.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/SharedTheme.java?view=diff&rev=543346&r1=543345&r2=543346
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/SharedTheme.java
(original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/SharedTheme.java
Thu May 31 18:19:42 2007
@@ -48,6 +48,8 @@
     
     public abstract List getResources();
     
+    public abstract ThemeResource getPreviewImage();
+    
     
     /**
      * @see java.lang.Comparable#compareTo(java.lang.Object)

Modified: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/SharedThemeFromDir.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/SharedThemeFromDir.java?view=diff&rev=543346&r1=543345&r2=543346
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/SharedThemeFromDir.java
(original)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/business/themes/SharedThemeFromDir.java
Thu May 31 18:19:42 2007
@@ -48,6 +48,9 @@
     // the filesystem directory where we should read this theme from
     private String themeDir = null;
     
+    // the theme preview image
+    private ThemeResource previewImage = null;
+    
     // we keep templates in a Map for faster lookups by name
     // the Map contains ... (template name, ThemeTemplate)
     private Map templatesByName = new HashMap();
@@ -76,6 +79,14 @@
 
     
     /**
+     * Get a resource representing the preview image for this theme.
+     */
+    public ThemeResource getPreviewImage() {
+        return this.previewImage;
+    }
+    
+    
+    /**
      * Get the collection of all templates associated with this Theme.
      */
     public List getTemplates() {
@@ -200,6 +211,14 @@
         setCustomStylesheet(themeMetadata.getCustomStylesheet());
         setLastModified(new Date());
         setEnabled(true);
+        
+        // load resource representing preview image
+        File previewFile = new File(this.themeDir + File.separator + themeMetadata.getPreviewImage());
+        if(!previewFile.exists() || !previewFile.canRead()) {
+            log.warn("Couldn't read preview image file ["+themeMetadata.getPreviewImage()+"]");
+        } else {
+            this.previewImage = new SharedThemeResourceFromDir(themeMetadata.getPreviewImage(),
previewFile);
+        }
         
         // go through static resources and add them to the theme
         String resourcePath = null;

Added: roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/servlets/PreviewThemeImageServlet.java
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/servlets/PreviewThemeImageServlet.java?view=auto&rev=543346
==============================================================================
--- roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/servlets/PreviewThemeImageServlet.java
(added)
+++ roller/trunk/apps/weblogger/src/java/org/apache/roller/weblogger/ui/rendering/servlets/PreviewThemeImageServlet.java
Thu May 31 18:19:42 2007
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+
+package org.apache.roller.weblogger.ui.rendering.servlets;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.weblogger.business.RollerFactory;
+import org.apache.roller.weblogger.business.themes.SharedTheme;
+import org.apache.roller.weblogger.business.themes.ThemeManager;
+import org.apache.roller.weblogger.pojos.ThemeResource;
+import org.apache.roller.weblogger.ui.rendering.util.ModDateHeaderUtil;
+
+/**
+ * Special previewing servlet which serves files uploaded by users as well as 
+ * static resources in shared themes.  This servlet differs from the normal
+ * ResourceServlet because it can accept urls parameters which affect how it
+ * behaves which are used for previewing.
+ */
+public class PreviewThemeImageServlet extends HttpServlet {
+
+    private static Log log = LogFactory.getLog(PreviewThemeImageServlet.class);
+    
+    private ServletContext context = null;
+
+
+    public void init(ServletConfig config) throws ServletException {
+
+        super.init(config);
+
+        log.info("Initializing PreviewThemeImageServlet");
+        
+        this.context = config.getServletContext();
+    }
+
+
+    /**
+     * Handles requests for user uploaded resources.
+     */
+    public void doGet(HttpServletRequest request, HttpServletResponse response)
+            throws ServletException, IOException {
+        
+        String theme = request.getParameter("theme");
+        
+        log.debug("Theme requested ["+theme+"]");
+        
+        long resourceLastMod = 0;
+        InputStream resourceStream = null;
+        String previewImagePath = null;
+        
+        // try looking up selected theme
+        try {
+            ThemeManager tmgr = RollerFactory.getRoller().getThemeManager();
+            SharedTheme previewTheme = tmgr.getTheme(theme);
+            ThemeResource previewImage = previewTheme.getPreviewImage();
+            if(previewImage != null) {
+                previewImagePath = previewImage.getPath();
+                resourceLastMod = previewImage.getLastModified();
+                resourceStream = previewImage.getInputStream();
+            }
+        } catch (Exception ex) {
+            log.debug("error looking up preview image", ex);
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+        
+        // if we don't have a stream to the file then we can't continue
+        if(resourceStream == null) {
+            log.debug("Unable to get theme preview for theme - "+theme);
+            response.sendError(HttpServletResponse.SC_NOT_FOUND);
+            return;
+        }
+        
+        // Respond with 304 Not Modified if it is not modified.
+        if (ModDateHeaderUtil.respondIfNotModified(request, response, resourceLastMod)) {
+            return;
+        } else {
+            // set last-modified date
+            ModDateHeaderUtil.setLastModifiedHeader(response, resourceLastMod);
+        }
+        
+        log.debug("Everything is cool, sending image");
+        
+        // set the content type based on whatever is in our web.xml mime defs
+        response.setContentType(this.context.getMimeType(previewImagePath));
+        
+        OutputStream out = null;
+        try {
+            // ok, lets serve up the file
+            byte[] buf = new byte[8192];
+            int length = 0;
+            out = response.getOutputStream();
+            while((length = resourceStream.read(buf)) > 0) {
+                out.write(buf, 0, length);
+            }
+            
+            // cleanup
+            out.close();
+            resourceStream.close();
+            
+        } catch (Exception ex) {
+            log.error("Error writing resource file", ex);
+            if(!response.isCommitted()) {
+                response.reset();
+                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            }
+        }
+
+    }
+
+}

Modified: roller/trunk/apps/weblogger/web/WEB-INF/jsps/core/CreateWeblog.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/web/WEB-INF/jsps/core/CreateWeblog.jsp?view=diff&rev=543346&r1=543345&r2=543346
==============================================================================
--- roller/trunk/apps/weblogger/web/WEB-INF/jsps/core/CreateWeblog.jsp (original)
+++ roller/trunk/apps/weblogger/web/WEB-INF/jsps/core/CreateWeblog.jsp Thu May 31 18:19:42
2007
@@ -20,7 +20,7 @@
 <script type="text/javascript">
 <!--
 function previewImage(theme) {
-    document.preview.src="<s:property value="siteURL" />/themes/" + theme + "/sm-theme-"
+ theme + ".png";
+    document.preview.src="<s:property value="siteURL" />/roller-ui/authoring/previewtheme?theme="+theme;
 }
 function handlePreview(handle) {
     previewSpan = document.getElementById("handlePreview");

Modified: roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/ThemeEdit.jsp
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/ThemeEdit.jsp?view=diff&rev=543346&r1=543345&r2=543346
==============================================================================
--- roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/ThemeEdit.jsp (original)
+++ roller/trunk/apps/weblogger/web/WEB-INF/jsps/editor/ThemeEdit.jsp Thu May 31 18:19:42
2007
@@ -20,7 +20,7 @@
 <script type="text/javascript">
 <!--
 function previewImage(element, theme) {
-    element.src="<s:property value="siteURL" />/themes/" + theme + "/sm-theme-" + theme
+ ".png";
+    element.src="<s:property value="siteURL" />/roller-ui/authoring/previewtheme?theme="+theme;
 }
 
 function fullPreview(selector) {

Modified: roller/trunk/apps/weblogger/web/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/roller/trunk/apps/weblogger/web/WEB-INF/web.xml?view=diff&rev=543346&r1=543345&r2=543346
==============================================================================
--- roller/trunk/apps/weblogger/web/WEB-INF/web.xml (original)
+++ roller/trunk/apps/weblogger/web/WEB-INF/web.xml Thu May 31 18:19:42 2007
@@ -241,6 +241,12 @@
     </servlet>
     
     <servlet>
+        <servlet-name>PreviewThemeImageServlet</servlet-name>
+        <servlet-class>org.apache.roller.weblogger.ui.rendering.servlets.PreviewThemeImageServlet</servlet-class>
+        <load-on-startup>9</load-on-startup>
+    </servlet>
+    
+    <servlet>
         <servlet-name>RedirectServlet</servlet-name>
         <servlet-class>org.apache.roller.weblogger.ui.rendering.velocity.deprecated.RedirectServlet</servlet-class>
         <load-on-startup>9</load-on-startup>
@@ -343,6 +349,11 @@
         <url-pattern>/roller-ui/authoring/previewresource/*</url-pattern>
     </servlet-mapping>
     
+    <servlet-mapping>
+        <servlet-name>PreviewThemeImageServlet</servlet-name>
+        <url-pattern>/roller-ui/authoring/previewtheme</url-pattern>
+    </servlet-mapping>
+    
     
     <!-- Servlets for supporting Ajax -->
     <servlet-mapping>
@@ -451,22 +462,12 @@
     
     <error-page>
         <exception-type>java.lang.Exception</exception-type>
-        <location>/roller-ui/error.rol</location>
-    </error-page>
-    
-    <error-page>
-        <error-code>403</error-code>
-        <location>/roller-ui/403.rol</location>
+        <location>/WEB-INF/jsps/errors/error.jsp</location>
     </error-page>
     
     <error-page>
         <error-code>404</error-code>
-        <location>/roller-ui/404.rol</location>
-    </error-page>
-    
-    <error-page>
-        <error-code>400</error-code>
-        <location>/roller-ui/login-redirect.rol</location>
+        <location>/WEB-INF/jsps/errors/404.jsp</location>
     </error-page>
     
 



Mime
View raw message