roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From she...@apache.org
Subject svn commit: r1150792 - in /roller/branches/roller_mobile: weblogger-business/src/main/java/org/apache/roller/weblogger/business/ weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/ weblogger-business/src/main/java/org/apache/roll...
Date Mon, 25 Jul 2011 17:19:59 GMT
Author: shelan
Date: Mon Jul 25 17:19:55 2011
New Revision: 1150792

URL: http://svn.apache.org/viewvc?rev=1150792&view=rev
Log:
adding desing changes of WeblogThemeAssoc & WeblogTemplateCode with test

Added:
    roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogTemplateCode.java
    roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogThemeAssoc.java
    roller/branches/roller_mobile/weblogger-business/src/test/java/org/apache/roller/weblogger/business/WeblogTemplateCodeTest.java
Modified:
    roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/WeblogManager.java
    roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
    roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManager.java
    roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
    roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/Template.java
    roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java
    roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogTemplate.java
    roller/branches/roller_mobile/weblogger-business/src/main/resources/META-INF/persistence.xml
    roller/branches/roller_mobile/weblogger-business/src/main/resources/sql/createdb.vm
    roller/branches/roller_mobile/weblogger-business/src/main/resources/sql/droptables.sql
    roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PageServlet.java
    roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/core/CreateWeblog.java
    roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java

Modified: roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/WeblogManager.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/WeblogManager.java?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/WeblogManager.java
(original)
+++ roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/WeblogManager.java
Mon Jul 25 17:19:55 2011
@@ -22,9 +22,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.pojos.User;
-import org.apache.roller.weblogger.pojos.Weblog;
-import org.apache.roller.weblogger.pojos.WeblogTemplate;
+import org.apache.roller.weblogger.pojos.*;
 
 
 /**
@@ -44,6 +42,13 @@ public interface WeblogManager {
      * Store a single weblog.
      */
     public void saveWeblog(Weblog data) throws WebloggerException;
+
+    /**
+     * Save new theme associativity for Weblog
+     * @param themeAssoc
+     * @throws WebloggerException
+     */
+    public void saveThemeAssoc(WeblogThemeAssoc themeAssoc) throws WebloggerException;
     
     
     /**
@@ -176,8 +181,18 @@ public interface WeblogManager {
      */
     public List<WeblogTemplate> getPagesByLink(Weblog w, String p)
         throws WebloggerException;
-    
-    
+
+    /**
+     * Get template code by Type.
+     */
+    public WeblogTemplateCode getTemplateCodeByType(String template, String type)
+            throws WebloggerException ;
+
+    /**
+     * Save template code
+     */
+     public void saveTemplateCode(WeblogTemplateCode templateCode) throws WebloggerException;
+
     /**
      * Get website's pages
      */
@@ -194,4 +209,9 @@ public interface WeblogManager {
      * Release any resources held by manager.
      */
     public void release();
+
+    /**
+     *   get Theme Associativity object for type
+     */
+    public WeblogThemeAssoc getThemeAssoc(Weblog weblog , String type) throws WebloggerException;
 }

Modified: roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
(original)
+++ roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/jpa/JPAWeblogManagerImpl.java
Mon Jul 25 17:19:55 2011
@@ -98,6 +98,17 @@ public class JPAWeblogManagerImpl implem
         WeblogEntryManager emgr = roller.getWeblogEntryManager();
         BookmarkManager    bmgr = roller.getBookmarkManager();
         MediaFileManager   mmgr = roller.getMediaFileManager();
+
+        //remove theme Assocs
+
+        Query themeAssocQuery = strategy.getNamedQuery("WeblogThemeAssoc.getThemeAssocsByWeblog");
+        themeAssocQuery.setParameter(1,website);
+         List assocResults = themeAssocQuery.getResultList();
+
+        for(Iterator iter = assocResults.iterator(); iter.hasNext();) {
+            WeblogThemeAssoc themeAssoc = (WeblogThemeAssoc) iter.next();
+            this.strategy.remove(themeAssoc);
+        }
         
         // remove tags
         Query tagQuery = strategy.getNamedQuery("WeblogEntryTag.getByWeblog");
@@ -172,6 +183,10 @@ public class JPAWeblogManagerImpl implem
         List pages = pageQuery.getResultList();
         for (Iterator iter = pages.iterator(); iter.hasNext();) {
             WeblogTemplate page = (WeblogTemplate) iter.next();
+
+            //remove associated templateCode objects
+            this.removeTemplateCodeObjs(page);
+
             this.strategy.remove(page);
         }
         
@@ -241,10 +256,17 @@ public class JPAWeblogManagerImpl implem
         // update weblog last modified date.  date updated by saveWebsite()
         roller.getWeblogManager().saveWeblog(page.getWebsite());
     }
+
+    public void saveTemplateCode(WeblogTemplateCode templateCode) throws WebloggerException
{
+        this.strategy.store(templateCode);
+        // update of the template should happen by saving template page.
+    }
     
     public void removePage(WeblogTemplate page) throws WebloggerException {
+        //remove template code objects
+       this.removeTemplateCodeObjs(page);
+
         this.strategy.remove(page);
-        
         // update weblog last modified date.  date updated by saveWebsite()
         roller.getWeblogManager().saveWeblog(page.getWebsite());
     }
@@ -458,6 +480,28 @@ public class JPAWeblogManagerImpl implem
         
         return query.getResultList();
     }
+
+    public WeblogThemeAssoc getThemeAssoc(Weblog weblog , String type) throws WebloggerException
{
+
+        if(weblog == null){
+            throw new WebloggerException("Weblog is null");
+        }
+        if(type == null){
+            throw new WebloggerException("Type is null");
+        }
+        Query query = strategy.getNamedQuery("WeblogThemeAssoc.getThemeAssocByType") ;
+        query.setParameter(1,weblog);
+        query.setParameter(2,type);
+
+        return (WeblogThemeAssoc) query.getSingleResult();
+    }
+
+    public void saveThemeAssoc(WeblogThemeAssoc themeAssoc) throws WebloggerException {
+          this.strategy.store(themeAssoc);
+
+        // update weblog last modified date.  date updated by saveWebsite()
+        roller.getWeblogManager().saveWeblog(themeAssoc.getWeblog());
+    }
         
     public List getUserWeblogs(User user, boolean enabledOnly) throws WebloggerException
{
         List weblogs = new ArrayList();
@@ -562,7 +606,25 @@ public class JPAWeblogManagerImpl implem
             return null;
         }
     }
-    
+
+    public WeblogTemplateCode getTemplateCodeByType(String templateId, String type) throws
WebloggerException{
+         if(templateId == null)
+             throw new WebloggerException("Template Id is null");
+
+        if(type == null){
+            throw  new WebloggerException("Type is null");
+        }
+
+        Query query = strategy.getNamedQuery("WeblogThemplateCode.getTemplateCodeByType");
+        query.setParameter(1, templateId);
+        query.setParameter(2, type);
+        try {
+            return (WeblogTemplateCode)query.getSingleResult();
+        } catch (NoResultException e) {
+            return null;
+        }
+    }
+
     /**
      * @see org.apache.roller.weblogger.model.UserManager#getPages(Weblog)
      */
@@ -665,4 +727,16 @@ public class JPAWeblogManagerImpl implem
         return ret;
     }
 
+    private void removeTemplateCodeObjs(WeblogTemplate page) throws WebloggerException {
+        Query codeQuery = strategy.getNamedQuery("WeblogThemplateCode.getTemplateCodesByTemplateId");
+        codeQuery.setParameter(1, page.getId());
+        List codeList = codeQuery.getResultList();
+
+        for (Iterator itr = codeList.iterator(); itr.hasNext(); ) {
+            WeblogTemplateCode templateCode = (WeblogTemplateCode) itr.next();
+            this.strategy.remove(templateCode);
+        }
+
+    }
+
 }

Modified: roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManager.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManager.java?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManager.java
(original)
+++ roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManager.java
Mon Jul 25 17:19:55 2011
@@ -93,17 +93,10 @@ public interface ThemeManager {
 	 */
 	public boolean reLoadThemeFromDisk(String reloadTheme);
 
-    /**
-     * To return the list of Mobile themes in themes list
-     *
-     * @return  ListofMobileThemes
-     */
-    public List getEnabledMobileThemeList();
 
     /**
-     * To return the list of Standard themes in themes list
-     *
+     *   To return the list of Themes for a given type
      * @return
      */
-    public List getEnabledStandardThemeList();
+    public List getEnabledThemesList(String type);
 }

Modified: roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
(original)
+++ roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/ThemeManagerImpl.java
Mon Jul 25 17:19:55 2011
@@ -411,37 +411,20 @@ public class ThemeManagerImpl implements
 
     }
 
-    public List getEnabledMobileThemeList() {
-        List all_themes = new ArrayList(this.themes.values());
-        List mobileThemes = new ArrayList();
+    public List getEnabledThemesList(String type){
+             List all_themes = new ArrayList(this.themes.values());
+        List themes = new ArrayList();
 
         for(int i = 0 ; i<all_themes.size(); i++){
             Theme theme = (Theme) all_themes.get(i);
 
-           if("mobile".equals(theme.getType())){
-               mobileThemes.add(theme);
+           if(type.equals(theme.getType())){
+               themes.add(theme);
            }
         }
         // sort 'em ... default ordering for themes is by name
-        Collections.sort(mobileThemes);
+        Collections.sort(themes);
 
-        return mobileThemes;
-    }
-
-    public List getEnabledStandardThemeList() {
-       List all_themes = new ArrayList(this.themes.values());
-        List standardThemes = new ArrayList();
-
-        for(int i = 0 ; i<all_themes.size(); i++){
-            Theme theme = (Theme) all_themes.get(i);
-
-           if("standard".equals(theme.getType())){
-               standardThemes.add(theme);
-           }
-        }
-        // sort 'em ... default ordering for themes is by name
-        Collections.sort(standardThemes);
-
-        return standardThemes;
+        return themes;
     }
 }

Modified: roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/Template.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/Template.java?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/Template.java
(original)
+++ roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/Template.java
Mon Jul 25 17:19:55 2011
@@ -68,6 +68,8 @@ public interface Template {
      *
      * type of the template , eg: standard , mobile etc.
      */
+    //TODO need to remove this type from weblog template as one template acts in different
types
+
     public String getType();
     
 }

Modified: roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java
(original)
+++ roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/Weblog.java
Mon Jul 25 17:19:55 2011
@@ -1281,4 +1281,19 @@ public class Weblog implements Serializa
         // TODO: maybe we should return a default theme in this case?
         return null;
     }
+
+    public Theme getTheme(String type){
+        WeblogThemeAssoc themeAssoc;
+        Theme theme = null;
+        try {
+            //get Theme Associativity object so we can get the ThemeName for the type given
+            themeAssoc = WebloggerFactory.getWeblogger().getWeblogManager().getThemeAssoc(this
,type);
+            if(themeAssoc != null)
+                // get the Theme from theme manager
+              theme = WebloggerFactory.getWeblogger().getThemeManager().getTheme(themeAssoc.getName());
+        } catch (WebloggerException e) {
+            log.error("Error getting Weblog Theme type -"+type+"for weblog "+getHandle(),e);
+        }
+        return theme;
+    }
 }

Modified: roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogTemplate.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogTemplate.java?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogTemplate.java
(original)
+++ roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogTemplate.java
Mon Jul 25 17:19:55 2011
@@ -24,6 +24,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.roller.util.UUIDGenerator;
 import org.apache.roller.weblogger.WebloggerException;
+import org.apache.roller.weblogger.business.WebloggerFactory;
 
 import java.io.Serializable;
 import java.util.Date;
@@ -62,8 +63,7 @@ public class WeblogTemplate implements T
     
     // associations
     private Weblog weblog = null;
-    
-    
+
     static {
         requiredTemplates = new HashSet();
         requiredTemplates.add("Weblog");
@@ -104,7 +104,6 @@ public class WeblogTemplate implements T
         this.weblog = website;
     }
     
-    
     public String getAction() {
         return action;
     }
@@ -233,7 +232,19 @@ public class WeblogTemplate implements T
     public boolean isCustom() {
         return ACTION_CUSTOM.equals(getAction()) && !isRequired();
     }
-    
+
+    public WeblogTemplateCode getTemplateCode(String type) throws WebloggerException {
+        return WebloggerFactory.getWeblogger().getWeblogManager().getTemplateCodeByType(this.id,
type);
+    }
+
+      public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
     
     //------------------------------------------------------- Good citizenship
 
@@ -266,11 +277,4 @@ public class WeblogTemplate implements T
             .toHashCode();
     }
 
-    public String getType() {
-        return type;
-    }
-
-    public void setType(String type) {
-        this.type = type;
-    }
 }

Added: roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogTemplateCode.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogTemplateCode.java?rev=1150792&view=auto
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogTemplateCode.java
(added)
+++ roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogTemplateCode.java
Mon Jul 25 17:19:55 2011
@@ -0,0 +1,129 @@
+/*
+* 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.pojos;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.roller.util.UUIDGenerator;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+/**
+ * A pojo that will maintain different template codes for one template
+ */
+
+@Entity
+@Table(name = "rol_templatecode")
+@NamedQueries({
+@NamedQuery(name = "WeblogThemplateCode.getTemplateCodeByType",
+        query = "SELECT c FROM WeblogTemplateCode c WHERE c.templateId = ?1 AND c.type =?2"),
+
+     @NamedQuery(name = "WeblogThemplateCode.getTemplateCodesByTemplateId",
+        query = "SELECT c FROM WeblogTemplateCode c WHERE c.templateId = ?1 ")
+})
+public class WeblogTemplateCode implements Serializable {
+
+
+    private static final long serialVersionUID = -1497618963802805151L;
+    private String id = UUIDGenerator.generateUUID();
+    private String templateId = null;
+    //template contents
+    private String template = null;
+    private String type = null;
+
+    public WeblogTemplateCode(String templateId, String type){
+        this.templateId = templateId;
+        this.type = type;
+    }
+
+    public WeblogTemplateCode() {
+    }
+
+    @Id
+    @Column(nullable = false, updatable = false)
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    @Basic
+    @Column(nullable = false, updatable = true, insertable = true)
+    public String getTemplate() {
+        return template;
+    }
+
+    public void setTemplate(String template) {
+        this.template = template;
+    }
+
+    @Basic
+    @Column(nullable = false, updatable = true, insertable = true)
+    public String getTemplateId() {
+        return templateId;
+    }
+
+    public void setTemplateId(String templateId) {
+        this.templateId = templateId;
+    }
+
+    @Basic
+    @Column(nullable = false, updatable = true, insertable = true)
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+ //------------------------------------------------------- Good citizenship
+
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+        buf.append("{");
+        buf.append(this.id);
+        buf.append(", ").append(this.templateId);
+        buf.append(", [ ").append(this.template);
+        buf.append("] , ").append(this.type);
+        buf.append("}");
+        return buf.toString();
+    }
+
+    public boolean equals(Object other) {
+        if (other == this) return true;
+        if (other instanceof WeblogTemplateCode != true) return false;
+        WeblogTemplateCode o = (WeblogTemplateCode)other;
+        return new EqualsBuilder()
+            .append(templateId, o.getTemplateId())
+            .append(template, o.getTemplate())
+            .isEquals();
+    }
+
+    public int hashCode() {
+        return new HashCodeBuilder()
+            .append(getTemplateId())
+            .append(getTemplate())
+            .toHashCode();
+    }
+
+}

Added: roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogThemeAssoc.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogThemeAssoc.java?rev=1150792&view=auto
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogThemeAssoc.java
(added)
+++ roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/pojos/WeblogThemeAssoc.java
Mon Jul 25 17:19:55 2011
@@ -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.pojos;
+
+import org.apache.commons.lang.builder.EqualsBuilder;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.roller.util.UUIDGenerator;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+/**
+ * pojo that will keep the Associativity of Themes for a weblog
+ */
+
+@Entity
+@Table(name="rol_weblogtheme")
+@NamedQueries({
+        @NamedQuery(name = "WeblogThemeAssoc.getThemeAssocByType" ,
+                query = "SELECT a FROM WeblogThemeAssoc a WHERE a.weblog = ?1 AND a.type
=?2"
+        ),
+        @NamedQuery(name = "WeblogThemeAssoc.getThemeAssocsByWeblog" ,
+                query = "SELECT a FROM WeblogThemeAssoc a WHERE a.weblog = ?1"
+        )
+}
+)
+public class WeblogThemeAssoc implements Serializable{
+
+
+    private static final long serialVersionUID = 2145018660522423453L;
+    private String id = UUIDGenerator.generateUUID();
+    private Weblog weblog = null;
+    private String name = null;
+    private boolean isCustom = false;
+    private String type = null;
+
+    public WeblogThemeAssoc() {
+    }
+
+    public WeblogThemeAssoc(Weblog weblog ,String themeId, boolean isCustom , String type
){
+       this.weblog = weblog;
+       this.name = themeId;
+       this.isCustom = isCustom;
+       this.type = type;
+    }
+
+    public static long getSerialVersionUID() {
+        return serialVersionUID;
+    }
+    @Id
+    @Column(nullable=false,updatable=false)
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+     @ManyToOne
+    @JoinColumn(name="weblogid",nullable=false,updatable=true, insertable=true)
+    public Weblog getWeblog() {
+        return weblog;
+    }
+
+    public void setWeblog(Weblog weblog) {
+        this.weblog = weblog;
+    }
+     @Basic
+     @Column(nullable = false,updatable = true,insertable = true)
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+      @Basic
+     @Column(nullable = false,updatable = true,insertable = true)
+    public boolean isCustom() {
+        return isCustom;
+    }
+
+    public void setCustom(boolean custom) {
+        isCustom = custom;
+    }
+    @Basic
+     @Column(nullable = false,updatable = true,insertable = true)
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+     public String toString() {
+        StringBuffer buf = new StringBuffer();
+        buf.append("{");
+        buf.append(this.id);
+        buf.append("}");
+        return buf.toString();
+    }
+
+    public boolean equals(Object other) {
+        if (other == this) return true;
+        if (other instanceof WeblogThemeAssoc != true) return false;
+        WeblogThemeAssoc o = (WeblogThemeAssoc) other;
+        return new EqualsBuilder()
+            .append(getId(), o.getId())
+            .append(getWeblog(), o.getWeblog())
+            .append(getName(), o.getName())
+            .append(getType(), o.getType())
+            .isEquals();
+    }
+
+    public int hashCode() {
+        return new HashCodeBuilder().append(getId()).toHashCode();
+    }
+}

Modified: roller/branches/roller_mobile/weblogger-business/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/resources/META-INF/persistence.xml?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/resources/META-INF/persistence.xml
(original)
+++ roller/branches/roller_mobile/weblogger-business/src/main/resources/META-INF/persistence.xml
Mon Jul 25 17:19:55 2011
@@ -28,5 +28,7 @@
         <mapping-file>org/apache/roller/weblogger/pojos/MediaFileTag.orm.xml      
     </mapping-file>	
         <mapping-file>org/apache/roller/weblogger/pojos/MediaFileDirectory.orm.xml
     </mapping-file>
         <class>org.apache.roller.weblogger.pojos.AutoPing</class>
+        <class>org.apache.roller.weblogger.pojos.WeblogThemeAssoc</class>
+        <class>org.apache.roller.weblogger.pojos.WeblogTemplateCode</class>
     </persistence-unit>  
 </persistence>

Modified: roller/branches/roller_mobile/weblogger-business/src/main/resources/sql/createdb.vm
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/resources/sql/createdb.vm?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/resources/sql/createdb.vm (original)
+++ roller/branches/roller_mobile/weblogger-business/src/main/resources/sql/createdb.vm Mon
Jul 25 17:19:55 2011
@@ -142,6 +142,22 @@ alter table website add constraint ws_ha
 -- This index is not necessary because of handle is already a primary key.
 -- create index ws_handle_idx    on website(handle);
 
+
+create table rol_weblogtheme (
+    id              varchar(48)  not null primary key,
+    weblogid varchar(48) not null,
+    name            varchar(255)  not null,
+    custom          $db.BOOLEAN_SQL_TYPE_FALSE not null,
+    #columnNotNullWithDefault('type' 'varchar(16)' 'standard')
+);
+
+create table rol_templatecode (
+    id                 varchar(48)  not null primary key,
+    templateid varchar(48) not null,
+    template     $db.TEXT_SQL_TYPE not null,
+    #columnNotNullWithDefault('type' 'varchar(16)' 'standard')
+);
+
 create table folder (
     id               varchar(48) not null primary key,
     name             varchar(255) not null,

Modified: roller/branches/roller_mobile/weblogger-business/src/main/resources/sql/droptables.sql
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/resources/sql/droptables.sql?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/main/resources/sql/droptables.sql
(original)
+++ roller/branches/roller_mobile/weblogger-business/src/main/resources/sql/droptables.sql
Mon Jul 25 17:19:55 2011
@@ -55,6 +55,8 @@ drop table weblogentry;
 drop table weblogcategoryassoc;
 drop table weblogcategory;
 drop table webpage;
+drop table rol_weblogtheme;
+drop table rol_templatecode;
 
 -- core platform tables
 drop table roller_permission;

Added: roller/branches/roller_mobile/weblogger-business/src/test/java/org/apache/roller/weblogger/business/WeblogTemplateCodeTest.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/test/java/org/apache/roller/weblogger/business/WeblogTemplateCodeTest.java?rev=1150792&view=auto
==============================================================================
--- roller/branches/roller_mobile/weblogger-business/src/test/java/org/apache/roller/weblogger/business/WeblogTemplateCodeTest.java
(added)
+++ roller/branches/roller_mobile/weblogger-business/src/test/java/org/apache/roller/weblogger/business/WeblogTemplateCodeTest.java
Mon Jul 25 17:19:55 2011
@@ -0,0 +1,172 @@
+/*
+* 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.business;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.roller.weblogger.TestUtils;
+import org.apache.roller.weblogger.pojos.User;
+import org.apache.roller.weblogger.pojos.Weblog;
+import org.apache.roller.weblogger.pojos.WeblogTemplate;
+import org.apache.roller.weblogger.pojos.WeblogTemplateCode;
+
+public class WeblogTemplateCodeTest extends TestCase{
+    public static Log log = LogFactory.getLog(WeblogPageTest.class);
+
+       User testUser = null;
+       Weblog testWeblog = null;
+       WeblogTemplate testPage = null;
+       WeblogTemplateCode standardCode = null;
+       WeblogTemplateCode mobileCode = null;
+
+
+       public WeblogTemplateCodeTest(String name) {
+           super(name);
+       }
+
+
+       public static Test suite() {
+           return new TestSuite(WeblogTemplateCodeTest.class);
+       }
+
+
+       /**
+        * All tests in this suite require a user and a weblog.
+        */
+       public void setUp() throws Exception {
+
+           // setup weblogger
+           TestUtils.setupWeblogger();
+
+           try {
+               testUser = TestUtils.setupUser("wtTestUser");
+               testWeblog = TestUtils.setupWeblog("wtTestWeblog", testUser);
+               TestUtils.endSession(true);
+           } catch (Exception ex) {
+               log.error(ex);
+               throw new Exception("Test setup failed", ex);
+           }
+
+           testPage = new WeblogTemplate();
+           testPage.setAction(WeblogTemplate.ACTION_WEBLOG);
+           testPage.setName("testTemplate");
+           testPage.setDescription("Test Weblog Template");
+           testPage.setLink("testTemp");
+           testPage.setContents("a test weblog template.");
+           testPage.setLastModified(new java.util.Date());
+           testPage.setWebsite(TestUtils.getManagedWebsite(testWeblog));
+           testPage.setTemplateLanguage("velocity");
+           testPage.setType("standard");
+
+
+
+
+       }
+
+       public void tearDown() throws Exception {
+
+           try {
+               TestUtils.teardownWeblog(testWeblog.getId());
+               TestUtils.teardownUser(testUser.getUserName());
+               TestUtils.endSession(true);
+           } catch (Exception ex) {
+               log.error(ex);
+               throw new Exception("Test teardown failed", ex);
+           }
+
+           testPage = null;
+       }
+
+
+       /**
+        * Test basic persistence operations ... Create, Update, Delete
+        */
+       public void testTemplateCRUD() throws Exception {
+
+           WeblogManager mgr = WebloggerFactory.getWeblogger().getWeblogManager();
+
+
+           // create template
+           mgr.savePage(testPage);
+
+
+           //create standard template coce
+           WeblogTemplateCode standardTemplateCode = new WeblogTemplateCode(testPage.getId(),"standard");
+           standardTemplateCode.setTemplate("standard.template.code");
+           mgr.saveTemplateCode(standardTemplateCode);
+            //TestUtils.endSession(true);
+           //create mobile code
+           WeblogTemplateCode mobileTemplateCode = new WeblogTemplateCode(testPage.getId(),"mobile");
+           mobileTemplateCode.setTemplate("mobile.template.code");
+           mgr.saveTemplateCode(mobileTemplateCode);
+             TestUtils.endSession(true);
+
+
+           // check that create was successful
+            standardCode = mgr.getTemplateCodeByType(testPage.getId(), "standard");
+           assertNotNull(standardCode);
+           assertEquals(standardTemplateCode.getTemplate() ,standardCode.getTemplate());
+
+            mobileCode = mgr.getTemplateCodeByType(testPage.getId(), "mobile");
+           assertNotNull(mobileCode);
+           assertEquals(mobileTemplateCode.getTemplate() ,mobileCode.getTemplate());
+
+           // update template Code
+           standardCode = null;
+           standardCode = mgr.getTemplateCodeByType(testPage.getId(), "standard");
+           standardCode.setTemplate("update.standard.template");
+           mgr.saveTemplateCode(standardCode);
+
+           mobileCode = null;
+           mobileCode = mgr.getTemplateCodeByType(testPage.getId(), "mobile");
+           mobileCode.setTemplate("update.mobile.template");
+           mgr.saveTemplateCode(mobileCode);
+
+           TestUtils.endSession(true);
+
+           // check that update was successful
+           standardCode =null;
+            standardCode = mgr.getTemplateCodeByType(testPage.getId(), "standard");
+            assertEquals("update.standard.template",standardCode.getTemplate());
+
+           mobileCode =null;
+           mobileCode = mgr.getTemplateCodeByType(testPage.getId(), "mobile");
+           assertEquals("update.mobile.template",mobileCode.getTemplate());
+
+           WeblogTemplate page = mgr.getPage(testPage.getId());
+           mgr.removePage(page);
+           TestUtils.endSession(true);
+
+           // check that update was successful
+           standardCode =null;
+            standardCode = mgr.getTemplateCodeByType(testPage.getId(), "standard");
+            assertNull(standardCode);
+
+           mobileCode =null;
+           mobileCode = mgr.getTemplateCodeByType(testPage.getId(), "mobile");
+           assertNull(mobileCode);
+
+       }
+
+
+
+}

Modified: roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PageServlet.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PageServlet.java?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PageServlet.java
(original)
+++ roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/rendering/servlets/PageServlet.java
Mon Jul 25 17:19:55 2011
@@ -245,11 +245,8 @@ public class PageServlet extends HttpSer
         // figure out what template to use
         ThemeTemplate page = null;
 
-        if(MobileDeviceRepository.isMobileDevice(request)){
-           // setting the editor theme as mobile theme to render for mobile device
-            weblog.setEditorTheme(weblog.getMobileThemeName()) ;
-
-        }
+        //if request is coming from mobile
+        boolean isMobileRequest = MobileDeviceRepository.isMobileDevice(request);
 
         // If this is a popup request, then deal with it specially
         // TODO: do we really need to keep supporting this?
@@ -310,7 +307,12 @@ public class PageServlet extends HttpSer
         // if we haven't found a page yet then try our default page
         if (page == null) {
             try {
-                page = weblog.getTheme().getDefaultTemplate();
+             //   page = weblog.getTheme().getDefaultTemplate();
+                if (isMobileRequest) {
+                    page = weblog.getTheme("mobile").getDefaultTemplate();
+                } else {
+                    page = weblog.getTheme("standard").getDefaultTemplate();
+                }
             } catch (Exception e) {
                 log.error("Error getting default page for weblog = " + weblog.getHandle(),
e);
             }
@@ -433,7 +435,6 @@ public class PageServlet extends HttpSer
             // Load models for pages
             String pageModels = WebloggerConfig.getProperty("rendering.pageModels");
             ModelLoader.loadModels(pageModels, model, initData, true);
-
             // Load special models for site-wide blog
             if (WebloggerRuntimeConfig.isSiteWideWeblog(weblog.getHandle())) {
                 String siteModels = WebloggerConfig.getProperty("rendering.siteModels");

Modified: roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/core/CreateWeblog.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/core/CreateWeblog.java?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/core/CreateWeblog.java
(original)
+++ roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/core/CreateWeblog.java
Mon Jul 25 17:19:55 2011
@@ -31,6 +31,7 @@ import org.apache.roller.weblogger.confi
 import org.apache.roller.weblogger.pojos.User;
 import org.apache.roller.weblogger.pojos.Weblog;
 import org.apache.roller.weblogger.pojos.WeblogPermission;
+import org.apache.roller.weblogger.pojos.WeblogThemeAssoc;
 import org.apache.roller.weblogger.ui.struts2.util.UIAction;
 import org.apache.roller.weblogger.util.Utilities;
 import org.apache.struts2.interceptor.validation.SkipValidation;
@@ -128,10 +129,17 @@ public class CreateWeblog extends UIActi
             String def = WebloggerRuntimeConfig.getProperty("users.editor.pages");
             String[] defs = Utilities.stringToStringArray(def,",");
             wd.setEditorPage(defs[0]);
-            
+
+            //Create Theme associativity objects for theme types.
+            WeblogThemeAssoc themeAssocStandard = new WeblogThemeAssoc(wd,getBean().getTheme()
, false ,"standard");
+            WeblogThemeAssoc themeAssocMobile= new WeblogThemeAssoc(wd,getBean().getTheme()
, false ,"mobile");
+
+
             try {
                 // add weblog and flush
                 WebloggerFactory.getWeblogger().getWeblogManager().addWeblog(wd);
+                WebloggerFactory.getWeblogger().getWeblogManager().saveThemeAssoc(themeAssocStandard);
+                WebloggerFactory.getWeblogger().getWeblogManager().saveThemeAssoc(themeAssocMobile);
                 WebloggerFactory.getWeblogger().flush();
                 
                 // tell the user their weblog was created
@@ -187,14 +195,15 @@ public class CreateWeblog extends UIActi
         return themeMgr.getEnabledThemesList();
     }
 
+
     public List getMobileThemes(){
        ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
-        return themeMgr.getEnabledMobileThemeList();
+        return themeMgr.getEnabledThemesList("mobile");
     }
 
     public List getStandardThemes(){
             ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
-        return themeMgr.getEnabledStandardThemeList();
+        return themeMgr.getEnabledThemesList("standard");
     }
     
     

Modified: roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
URL: http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java?rev=1150792&r1=1150791&r2=1150792&view=diff
==============================================================================
--- roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
(original)
+++ roller/branches/roller_mobile/weblogger-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
Mon Jul 25 17:19:55 2011
@@ -76,8 +76,8 @@ public class ThemeEdit extends UIAction 
     
     public void myPrepare() {
         ThemeManager themeMgr = WebloggerFactory.getWeblogger().getThemeManager();
-        setThemes(themeMgr.getEnabledStandardThemeList());
-        setMobileThemes(themeMgr.getEnabledMobileThemeList());
+        setThemes(themeMgr.getEnabledThemesList("standard"));
+        setMobileThemes(themeMgr.getEnabledThemesList("mobile"));
     }
     
     
@@ -182,11 +182,17 @@ public class ThemeEdit extends UIAction 
             }
             
             if(!hasActionErrors()) try {
+                WeblogThemeAssoc themeAssoc = WebloggerFactory.getWeblogger().getWeblogManager().
+                        getThemeAssoc(getActionWeblog(),"standard");
+                themeAssoc.setName(getThemeId());
+                //TODO remove this setting editor theme
                 weblog.setEditorTheme(getThemeId());
+
                 log.debug("Saving theme "+getThemeId()+" for weblog "+weblog.getHandle());
                 
                 // save updated weblog and flush
                 WebloggerFactory.getWeblogger().getWeblogManager().saveWeblog(weblog);
+                WebloggerFactory.getWeblogger().getWeblogManager().saveThemeAssoc(themeAssoc);
                 WebloggerFactory.getWeblogger().flush();
                 
                 // make sure to flush the page cache so ppl can see the change
@@ -238,10 +244,15 @@ public class ThemeEdit extends UIAction 
             
             if(!hasActionErrors()) try {
                 weblog.setMobileThemeName(getMobileThemeId());
+                WeblogThemeAssoc themeAssoc = WebloggerFactory.getWeblogger().getWeblogManager().
+                        getThemeAssoc(getActionWeblog(),"mobile");
+                themeAssoc.setName(getMobileThemeId());
+
                 log.debug("Saving theme "+getMobileThemeId()+" for weblog "+weblog.getHandle());
                 
                 // save updated weblog and flush
                 WebloggerFactory.getWeblogger().getWeblogManager().saveWeblog(weblog);
+                WebloggerFactory.getWeblogger().getWeblogManager().saveThemeAssoc(themeAssoc);
                 WebloggerFactory.getWeblogger().flush();
                 
                 // make sure to flush the page cache so ppl can see the change



Mime
View raw message