roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agillil...@apache.org
Subject svn commit: r522129 - in /incubator/roller/trunk/src/org/apache/roller: pojos/WebsiteData.java ui/authoring/struts/actions/ThemeEditorAction.java ui/rendering/servlets/PreviewResourceServlet.java ui/rendering/servlets/ResourceServlet.java
Date Sat, 24 Mar 2007 23:42:26 GMT
Author: agilliland
Date: Sat Mar 24 16:42:25 2007
New Revision: 522129

URL: http://svn.apache.org/viewvc?view=rev&rev=522129
Log:
adding method getTheme() to WebsiteData pojo to provide a more convenient and consistent way
of accessing a weblog's theme.


Modified:
    incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java
    incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/ThemeEditorAction.java
    incubator/roller/trunk/src/org/apache/roller/ui/rendering/servlets/PreviewResourceServlet.java
    incubator/roller/trunk/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java

Modified: incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java?view=diff&rev=522129&r1=522128&r2=522129
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java (original)
+++ incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java Sat Mar 24 16:42:25
2007
@@ -182,83 +182,51 @@
         permissions.remove(perms);
     }
     
+    
     /**
-     * Lookup the default page for this website.
+     * Get the Theme object in use by this weblog, or null if no theme selected.
      */
-    public Template getDefaultPage() throws RollerException {
+    public Theme getTheme() throws RollerException {
         
-        Template template = null;
-        
-        // first check if this user has selected a theme
-        // if so then return the themes Weblog template
-        if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
+        // if theme is custom or null then just return null
+        if(getEditorTheme() == null || Theme.CUSTOM.equals(getEditorTheme())) {
+            return null;
+        } else {
             try {
                 ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
-                Theme usersTheme = themeMgr.getTheme(this.editorTheme);
-                
-                // this is a bit iffy :/
-                // we assume that all theme use "Weblog" for a default template
-                template = usersTheme.getTemplate("Weblog");
-                
+                return themeMgr.getTheme(getEditorTheme());
             } catch(ThemeNotFoundException tnfe) {
                 // i sure hope not!
-                log.error(tnfe);
+                log.error("Unable to find theme = "+getEditorTheme(), tnfe);
+                return null;
             }
         }
-        
-        // if we didn't get the Template from a theme then look in the db
-        if(template == null) {
-            UserManager userMgr = RollerFactory.getRoller().getUserManager();
-            template = userMgr.getPage(this.defaultPageId);
-        }
-        
-        if(template != null)
-            log.debug("returning default template id ["+template.getId()+"]");
-        
-        return template;
     }
     
     
     /**
-     * Lookup a Template for this website by id.
+     * Lookup the default page for this website.
      */
-    public Template getPageById(String id) throws RollerException {
-        
-        if(id == null)
-            return null;
+    public Template getDefaultPage() throws RollerException {
         
         Template template = null;
         
         // first check if this user has selected a theme
-        // if so then return the proper theme template
-        if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
-            
-            // we don't actually expect to get lookups for theme pages by id
-            // but we have to be thorough and check anyways
-            String[] split = id.split(":",  2);
-            
-            // only continue if this looks like a theme id
-            // and the theme name matches this users current theme
-            if(split.length == 2 && split[0].equals(this.editorTheme)) {
-                try {
-                    ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
-                    Theme usersTheme = themeMgr.getTheme(this.editorTheme);
-                    template = usersTheme.getTemplate(split[1]);
-                    
-                } catch(ThemeNotFoundException tnfe) {
-                    // i sure hope not!
-                    log.error(tnfe);
-                }
-            }
-            
+        // if so then return the themes Weblog template
+        Theme weblogTheme = getTheme();
+        if(weblogTheme != null) {
+            template = weblogTheme.getTemplateByAction(Template.ACTION_WEBLOG);
         }
         
         // if we didn't get the Template from a theme then look in the db
         if(template == null) {
             UserManager userMgr = RollerFactory.getRoller().getUserManager();
-            template = userMgr.getPageByName(this, name);
+            template = userMgr.getPage(this.defaultPageId);
         }
         
+        if(template != null)
+            log.debug("returning default template id ["+template.getId()+"]");
+        
         return template;
     }
     
@@ -279,18 +247,9 @@
         
         // first check if this user has selected a theme
         // if so then return the proper theme template
-        if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
-            
-            try {
-                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
-                Theme usersTheme = themeMgr.getTheme(this.editorTheme);
-                template = usersTheme.getTemplateByAction(action);
-                
-            } catch(ThemeNotFoundException tnfe) {
-                // i sure hope not!
-                log.error(tnfe);
-            }
-            
+        Theme weblogTheme = getTheme();
+        if(weblogTheme != null) {
+            template = weblogTheme.getTemplateByAction(action);
         } else {
         
             // NOTE: we specifically do *NOT* return templates by action from the
@@ -322,18 +281,9 @@
         
         // first check if this user has selected a theme
         // if so then return the proper theme template
-        if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
-            
-            try {
-                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
-                Theme usersTheme = themeMgr.getTheme(this.editorTheme);
-                template = usersTheme.getTemplate(name);
-                
-            } catch(ThemeNotFoundException tnfe) {
-                // i sure hope not!
-                log.error(tnfe);
-            }
-            
+        Theme weblogTheme = getTheme();
+        if(weblogTheme != null) {
+            template = weblogTheme.getTemplate(name);
         }
         
         // if we didn't get the Template from a theme then look in the db
@@ -364,18 +314,9 @@
         
         // first check if this user has selected a theme
         // if so then return the proper theme template
-        if(this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
-            
-            try {
-                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
-                Theme usersTheme = themeMgr.getTheme(this.editorTheme);
-                template = usersTheme.getTemplateByLink(link);
-                
-            } catch(ThemeNotFoundException tnfe) {
-                // i sure hope not!
-                log.error(tnfe);
-            }
-            
+        Theme weblogTheme = getTheme();
+        if(weblogTheme != null) {
+            template = weblogTheme.getTemplateByLink(link);
         }
         
         // if we didn't get the Template from a theme then look in the db
@@ -415,12 +356,11 @@
         
         
         // now get theme pages if needed and put them in place of db pages
-        if (this.editorTheme != null && !this.editorTheme.equals(Theme.CUSTOM)) {
-            try {
+        try {
+            Theme weblogTheme = getTheme();
+            if(weblogTheme != null) {
                 Template template = null;
-                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
-                Theme usersTheme = themeMgr.getTheme(this.editorTheme);
-                Iterator themePages = usersTheme.getTemplates().iterator();
+                Iterator themePages = weblogTheme.getTemplates().iterator();
                 while(themePages.hasNext()) {
                     template = (Template) themePages.next();
                     
@@ -428,10 +368,10 @@
                     // pages in the pages list, which is what we want
                     pages.put(template.getName(), template);
                 }
-            } catch(Exception e) {
-                // how??
-                log.error(e);
             }
+        } catch(Exception e) {
+            // how??
+            log.error(e);
         }
         
         return new ArrayList(pages.values());

Modified: incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/ThemeEditorAction.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/ThemeEditorAction.java?view=diff&rev=522129&r1=522128&r2=522129
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/ThemeEditorAction.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/authoring/struts/actions/ThemeEditorAction.java
Sat Mar 24 16:42:25 2007
@@ -117,7 +117,7 @@
                     currentTheme.setId(Theme.CUSTOM);
                     currentTheme.setName(Theme.CUSTOM);
                 } else {
-                    currentTheme = themeMgr.getTheme(website.getEditorTheme());
+                    currentTheme = website.getTheme();
                 }
                 
                 // this checks if the website has a default page template
@@ -194,7 +194,7 @@
                     currentTheme.setId(Theme.CUSTOM);
                     currentTheme.setName(Theme.CUSTOM);
                 } else {
-                    currentTheme = themeMgr.getTheme(website.getEditorTheme());
+                    currentTheme = website.getTheme();
                 }
                 
                 // this checks if the website has a default page template
@@ -388,7 +388,7 @@
                 String username = rses.getAuthenticatedUser().getUserName();
                 
                 try {
-                    Theme usersTheme = themeMgr.getTheme(website.getEditorTheme());
+                    Theme usersTheme = website.getTheme();
                     
                     // only if custom themes are allowed
                     if(RollerRuntimeConfig.getBooleanProperty("themes.customtheme.allowed"))
{

Modified: incubator/roller/trunk/src/org/apache/roller/ui/rendering/servlets/PreviewResourceServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/servlets/PreviewResourceServlet.java?view=diff&rev=522129&r1=522128&r2=522129
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/rendering/servlets/PreviewResourceServlet.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/rendering/servlets/PreviewResourceServlet.java
Sat Mar 24 16:42:25 2007
@@ -106,19 +106,22 @@
         if(resourceRequest.getThemeName() != null) {
             Theme theme = resourceRequest.getTheme();
             File resource = theme.getResource(resourceRequest.getResourcePath());
-            resourceLastMod = resource.lastModified();
-            resourceStream = new FileInputStream(resource);
+            if(resource != null) {
+                resourceLastMod = resource.lastModified();
+                resourceStream = new FileInputStream(resource);
+            }
         }
         
         // second, see if resource comes from weblog's configured shared theme
-        if(resourceStream == null && !Theme.CUSTOM.equals(weblog.getEditorTheme()))
{
+        if(resourceStream == null) {
             try {
-                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
-                Theme weblogTheme = themeMgr.getTheme(weblog.getEditorTheme());
-                File resource = weblogTheme.getResource(resourceRequest.getResourcePath());
-                if(resource != null) {
-                    resourceLastMod = resource.lastModified();
-                    resourceStream = new FileInputStream(resource);
+                Theme weblogTheme = weblog.getTheme();
+                if(weblogTheme != null) {
+                    File resource = weblogTheme.getResource(resourceRequest.getResourcePath());
+                    if(resource != null) {
+                        resourceLastMod = resource.lastModified();
+                        resourceStream = new FileInputStream(resource);
+                    }
                 }
             } catch (Exception ex) {
                 // hmmm, some kind of error getting theme.  that's an error.

Modified: incubator/roller/trunk/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java
URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java?view=diff&rev=522129&r1=522128&r2=522129
==============================================================================
--- incubator/roller/trunk/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java
(original)
+++ incubator/roller/trunk/src/org/apache/roller/ui/rendering/servlets/ResourceServlet.java
Sat Mar 24 16:42:25 2007
@@ -104,20 +104,19 @@
         InputStream resourceStream = null;
         
         // first see if resource comes from weblog's shared theme
-        if(!Theme.CUSTOM.equals(weblog.getEditorTheme())) {
-            try {
-                ThemeManager themeMgr = RollerFactory.getRoller().getThemeManager();
-                Theme weblogTheme = themeMgr.getTheme(weblog.getEditorTheme());
+        try {
+            Theme weblogTheme = weblog.getTheme();
+            if(weblogTheme != null) {
                 File resource = weblogTheme.getResource(resourceRequest.getResourcePath());
                 if(resource != null) {
                     resourceLastMod = resource.lastModified();
                     resourceStream = new FileInputStream(resource);
                 }
-            } catch (Exception ex) {
-                // hmmm, some kind of error getting theme.  that's an error.
-                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-                return;
             }
+        } catch (Exception ex) {
+            // hmmm, some kind of error getting theme.  that's an error.
+            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            return;
         }
         
         // if not from theme then see if resource is in weblog's upload dir



Mime
View raw message