Author: shelan
Date: Sun Aug 14 10:07:18 2011
New Revision: 1157507
URL: http://svn.apache.org/viewvc?rev=1157507&view=rev
Log:
Added Creating custom theme adding/import for mobile platform
Modified:
roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/SharedThemeFromDir.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-web/src/main/java/org/apache/roller/weblogger/ui/struts2/editor/ThemeEdit.java
roller/branches/roller_mobile/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/TemplateEdit.jsp
roller/branches/roller_mobile/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp
Modified:
roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/SharedThemeFromDir.java
URL:
http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/SharedThemeFromDir.java?rev=1157507&r1=1157506&r2=1157507&view=diff
==============================================================================
---
roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/SharedThemeFromDir.java
(original)
+++
roller/branches/roller_mobile/weblogger-business/src/main/java/org/apache/roller/weblogger/business/themes/SharedThemeFromDir.java
Sun Aug 14 10:07:18 2011
@@ -413,23 +413,13 @@ public class SharedThemeFromDir extends
}
- /**
+ /**
* Set the value for a given template name.
*/
private void addTemplate(ThemeTemplate template) {
this.templatesByName.put(template.getName(), template);
-
- // check if there is an existing template for given link and append
if exists.
- List<ThemeTemplate> templates = new ArrayList<ThemeTemplate>();
- if (!templatesByLink.containsKey(template.getLink())) {
- templates.add(template);
- templatesByLink.put(template.getLink(), templates);
- } else {
- templates = (List<ThemeTemplate>)
templatesByLink.get(template.getLink());
- templates.add(template);
- templatesByLink.put(template.getLink(), templates);
- }
- if (!ThemeTemplate.ACTION_CUSTOM.equals(template.getAction())) {
+ this.templatesByLink.put(template.getLink(), template);
+ if(!ThemeTemplate.ACTION_CUSTOM.equals(template.getAction())) {
this.templatesByAction.put(template.getAction(), template);
}
}
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=1157507&r1=1157506&r2=1157507&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
Sun Aug 14 10:07:18 2011
@@ -93,10 +93,4 @@ public interface ThemeManager {
*/
public boolean reLoadThemeFromDisk(String reloadTheme);
-
- /**
- * To return the list of Themes for a given type
- * @return
- */
- 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=1157507&r1=1157506&r2=1157507&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
Sun Aug 14 10:07:18 2011
@@ -17,29 +17,33 @@
*/
package org.apache.roller.weblogger.business.themes;
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.activation.FileTypeMap;
+import javax.activation.MimetypesFileTypeMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.roller.weblogger.WebloggerException;
-import org.apache.roller.weblogger.business.InitializationException;
-import org.apache.roller.weblogger.business.MediaFileManager;
-import org.apache.roller.weblogger.business.WeblogManager;
-import org.apache.roller.weblogger.business.Weblogger;
+import org.apache.roller.weblogger.business.*;
import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.pojos.*;
import org.apache.roller.weblogger.util.RollerMessages;
-import javax.activation.FileTypeMap;
-import javax.activation.MimetypesFileTypeMap;
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.*;
-
/**
* Base implementation of a ThemeManager.
- *
- * This particular implementation reads theme data off the filesystem
+ *
+ * This particular implementation reads theme data off the filesystem
* and assumes that those themes are not changable at runtime.
*/
@com.google.inject.Singleton
@@ -63,11 +67,17 @@ public class ThemeManagerImpl implements
// the Map contains ... (theme id, Theme)
private Map themes = null;
+ // list of available types for templates
+ private static ArrayList<String> typeList = new ArrayList<String>();
+
@com.google.inject.Inject
protected ThemeManagerImpl(Weblogger roller) {
this.roller = roller;
+ //set the available types that can be used for templates
+ this.addAvailableTypes();
+
// get theme directory from config and verify it
this.themeDir = WebloggerConfig.getProperty("themes.dir");
if (themeDir == null || themeDir.trim().length() < 1) {
@@ -88,13 +98,13 @@ public class ThemeManagerImpl implements
}
}
- public void initialize() throws InitializationException {
+ public void initialize() throws InitializationException {
log.debug("Initializing Theme Manager");
if (themeDir != null) {
// rather than be lazy we are going to load all themes from
- // the disk preemptively and cache them
+ // the disk preemptive and cache them
this.themes = loadAllThemesFromDisk();
log.info("Loaded " + this.themes.size() + " themes from disk.");
@@ -177,20 +187,10 @@ public class ThemeManagerImpl implements
WeblogManager wmgr = roller.getWeblogManager();
MediaFileManager fileMgr = roller.getMediaFileManager();
-
+
MediaFileDirectory root = fileMgr.getMediaFileRootDirectory(website);
log.warn("Weblog " + website.getHandle() + " does not have a root
MediaFile directory");
- theme.setId("custom."+theme.getType());
- WeblogSharedTheme customTheme = new WeblogSharedTheme(website,theme);
- WeblogThemeAssoc themeAssoc =
roller.getWeblogManager().getThemeAssoc(website,customTheme.getType());
- themeAssoc.setCustom(true);
- themeAssoc.setName(customTheme.getName());
- //save theme assoc
- roller.getWeblogManager().saveThemeAssoc(themeAssoc);
-
-
-
Set importedActionTemplates = new HashSet();
ThemeTemplate themeTemplate = null;
ThemeTemplate stylesheetTemplate = theme.getStylesheet();
@@ -237,15 +237,29 @@ public class ThemeManagerImpl implements
// NOTE: decorators are deprecated starting in 4.0
template.setDecoratorName(null);
template.setLastModified(new Date());
- template.setType(themeTemplate.getType());
// save it
wmgr.savePage(template);
+ }
+ // creating template codes
+ for (String type : ThemeManagerImpl.getTypesList()) {
+ WeblogTemplateCode templateCode =
template.getTemplateCode(type);
+ // if there are no template codes create it
+ if (templateCode == null) {
+ WeblogTemplateCode themeTemplateCode =
themeTemplate.getTemplateCode(type);
+
+ if(themeTemplateCode== null){
+ throw new WebloggerException("No templateCode found
for template :"+themeTemplate.getId()+
+ " of type :" +type);
+ }
+ templateCode = new WeblogTemplateCode(template.getId(),
type);
+ templateCode.setTemplate(themeTemplateCode.getTemplate());
+
templateCode.setTemplateLanguage(themeTemplateCode.getTemplateLanguage());
- WeblogTemplateCode templateCode = new
WeblogTemplateCode(template.getId(),theme.getType());
- templateCode.setTemplate(template.getContents());
- wmgr.saveTemplateCode(templateCode);
+
WebloggerFactory.getWeblogger().getWeblogManager().saveTemplateCode(templateCode);
+ }
}
+
}
// now, see if the weblog has left over action templates that
@@ -303,7 +317,7 @@ public class ThemeManagerImpl implements
mdir = fileMgr.getMediaFileRootDirectory(website);
justPath = "";
justName = resourcePath;
-
+
} else {
justPath = resourcePath.substring(0,
resourcePath.lastIndexOf("/"));
if (!justPath.startsWith("/")) justPath = "/" + justPath;
@@ -318,7 +332,7 @@ public class ThemeManagerImpl implements
MediaFile oldmf = fileMgr.getMediaFileByOriginalPath(website,
justPath + "/" + justName);
if (oldmf != null) {
- fileMgr.removeMediaFile(website, oldmf);
+ fileMgr.removeMediaFile(website, oldmf);
}
// save file without file-type, quota checks, etc.
@@ -328,7 +342,7 @@ public class ThemeManagerImpl implements
mf.setWeblog(website);
mf.setName(justName);
mf.setOriginalPath(justPath + "/" + justName);
- mf.setContentType(map.getContentType(justName));
+ mf.setContentType(map.getContentType(justName));
mf.setInputStream(is);
mf.setLength(resource.getLength());
@@ -425,20 +439,14 @@ public class ThemeManagerImpl implements
}
- 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(type.equals(theme.getType())){
- themes.add(theme);
- }
- }
- // sort 'em ... default ordering for themes is by name
- Collections.sort(themes);
-
- return themes;
+ private void addAvailableTypes(){
+ this.getTypesList().add("standard");
+ this.getTypesList().add("mobile");
}
+
+ public static ArrayList<String> getTypesList() {
+ return typeList;
+ }
+
+
}
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=1157507&r1=1157506&r2=1157507&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
Sun Aug 14 10:07:18 2011
@@ -18,6 +18,8 @@
package org.apache.roller.weblogger.ui.struts2.editor;
+import java.util.Collections;
+import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -26,13 +28,14 @@ import org.apache.roller.weblogger.busin
import org.apache.roller.weblogger.business.themes.SharedTheme;
import org.apache.roller.weblogger.business.themes.ThemeManager;
import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
-import org.apache.roller.weblogger.pojos.*;
+import org.apache.roller.weblogger.pojos.Theme;
+import org.apache.roller.weblogger.pojos.WeblogTheme;
+import org.apache.roller.weblogger.pojos.Weblog;
+import org.apache.roller.weblogger.pojos.WeblogPermission;
+import org.apache.roller.weblogger.pojos.WeblogTemplate;
import org.apache.roller.weblogger.ui.struts2.util.UIAction;
import org.apache.roller.weblogger.util.cache.CacheManager;
-import java.util.Collections;
-import java.util.List;
-
/**
* Action for controlling theme selection.
@@ -41,19 +44,14 @@ public class ThemeEdit extends UIAction
private static Log log = LogFactory.getLog(Templates.class);
- // list of available standard themes
+ // list of available themes
private List themes = Collections.EMPTY_LIST;
-
- private List mobileThemes = Collections.EMPTY_LIST;
// type of theme desired, either 'shared' or 'custom'
private String themeType = null;
// the chosen shared theme id
private String themeId = null;
-
- //the chosen mobile theme id
- private String mobileThemeId = null;
// import the selected theme to the action weblog
private boolean importTheme = false;
@@ -76,8 +74,7 @@ public class ThemeEdit extends UIAction
public void myPrepare() {
ThemeManager themeMgr =
WebloggerFactory.getWeblogger().getThemeManager();
- setThemes(themeMgr.getEnabledThemesList("standard"));
- setMobileThemes(themeMgr.getEnabledThemesList("mobile"));
+ setThemes(themeMgr.getEnabledThemesList());
}
@@ -88,7 +85,6 @@ public class ThemeEdit extends UIAction
setThemeId(null);
} else {
setThemeId(getActionWeblog().getTheme().getId());
- // setMobileThemeId(getActionWeblog().getMobileTheme().getId());
setImportThemeId(getActionWeblog().getTheme().getId());
}
@@ -182,17 +178,11 @@ 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
@@ -216,58 +206,6 @@ public class ThemeEdit extends UIAction
return execute();
}
- public String saveMobileTheme(){
-
- Weblog weblog = getActionWeblog();
- // make sure theme is valid and enabled
- Theme newMobileTheme = null;
- if(getThemeId() == null) {
- // TODO: i18n
- addError("No theme specified");
-
- } else {
- try {
- ThemeManager themeMgr =
WebloggerFactory.getWeblogger().getThemeManager();
- newMobileTheme = themeMgr.getTheme(getMobileThemeId());
-
- if(!newMobileTheme.isEnabled()) {
- // TODO: i18n
- addError("Theme not enabled");
- }
-
- } catch(Exception ex) {
- log.warn(ex);
- // TODO: i18n
- addError("Theme not found");
- }
- }
- 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
- CacheManager.invalidate(weblog);
-
- // TODO: i18n
- addMessage("Successfully set Mobile theme to -
"+newMobileTheme.getName());
-
- } catch(WebloggerException re) {
- log.error("Error saving weblog -
"+getActionWeblog().getHandle(), re);
- addError("Error setting theme");
- }
-
- return execute();
-}
-
public boolean isCustomTheme() {
return (WeblogTheme.CUSTOM.equals(getActionWeblog().getEditorTheme()));
@@ -323,20 +261,5 @@ public class ThemeEdit extends UIAction
public void setImportThemeId(String importThemeId) {
this.importThemeId = importThemeId;
}
-
- public List getMobileThemes() {
- return mobileThemes;
- }
-
- public void setMobileThemes(List mobileThemes) {
- this.mobileThemes = mobileThemes;
- }
-
- public String getMobileThemeId() {
- return mobileThemeId;
- }
-
- public void setMobileThemeId(String mobileThemeId) {
- this.mobileThemeId = mobileThemeId;
- }
+
}
Modified:
roller/branches/roller_mobile/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/TemplateEdit.jsp
URL:
http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/TemplateEdit.jsp?rev=1157507&r1=1157506&r2=1157507&view=diff
==============================================================================
---
roller/branches/roller_mobile/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/TemplateEdit.jsp
(original)
+++
roller/branches/roller_mobile/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/TemplateEdit.jsp
Sun Aug 14 10:07:18 2011
@@ -159,8 +159,8 @@
</table>
<%-- ==================================================================
--%>
<%-- Template editing area w/resize buttons --%>
-
- <br />
+
+
<s:textarea name="bean.contents" cols="80" rows="30" cssStyle="width:100%"
/>
<script type="text/javascript"><!--
Modified:
roller/branches/roller_mobile/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp
URL:
http://svn.apache.org/viewvc/roller/branches/roller_mobile/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp?rev=1157507&r1=1157506&r2=1157507&view=diff
==============================================================================
---
roller/branches/roller_mobile/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp
(original)
+++
roller/branches/roller_mobile/weblogger-webapp/src/main/webapp/WEB-INF/jsps/editor/ThemeEdit.jsp
Sun Aug 14 10:07:18 2011
@@ -29,10 +29,9 @@ function fullPreview(selector) {
}
function updateThemeChooser(selected) {
if (selected[0].value == 'shared') {
- $('#sharedChooser').css('background','#CCFFCC');
- $('#sharedChooser').css('border','1px solid #008000');
+ $('#sharedChooser').css('background','#CCFFCC');
+ $('#sharedChooser').css('border','1px solid #008000');
$('#sharedOptioner').show();
- $('#mobileSharedOptioner').show();
$('#customChooser').css('background','#eee');
$('#customChooser').css('border','1px solid #gray');
@@ -45,7 +44,6 @@ function updateThemeChooser(selected) {
$('#sharedChooser').css('background','#eee');
$('#sharedChooser').css('border','1px solid #gray');
$('#sharedOptioner').hide();
- $('#mobileSharedOptioner').hide();
}
}
function toggleImportThemeDisplay() {
@@ -86,11 +84,6 @@ function toggleImportThemeDisplay() {
</tr>
</table>
-
- <table>
- <tr>
- <td>
-
<div id="sharedOptioner" class="optioner" style="display:none;">
<p>
<s:if test="!customTheme">
@@ -134,61 +127,8 @@ function toggleImportThemeDisplay() {
<s:text name="themeEditor.customStylesheetDescription" />
</p>
</s:if>
- <p><s:submit value="%{getText('themeEditor.save')}"/></p>
- </div>
- </td>
- <td>
- <div id="mobileSharedOptioner" class="optioner" style="display:none;">
-
- <p>
- <s:if test="!customTheme">
- <s:text name="themeEditor.yourCurrentTheme"/>:
- <b><s:property value="actionWeblog.mobileTheme.name"/></b>
- </s:if>
- <s:else>
- <s:text name="themeEditor.selectTheme"/>
- </s:else>
- </p>
-
- <p>
- <s:select id="mobileSharedSelector" name="mobileThemeId"
list="mobileThemes"
- listKey="id" listValue="name" size="1"
- onchange="previewImage($('#sharedMobilePreviewImg'),
this[selectedIndex].value)"/>
- </p>
-
- <p>
- <img id="sharedMobilePreviewImg" src=""/>
- <!-- initialize preview image at page load -->
- <script type="text/javascript">
- <s:if test="customTheme">
- previewImage($('#sharedMobilePreviewImg'), '<s:property
value="mobileThemes[0].id"/>');
- </s:if>
- <s:else>
- previewImage($('#sharedMobilePreviewImg'), '<s:property
value="mobileThemeId"/>');
- </s:else>
- </script>
- </p>
- <p>
- » <a href="#"
onclick="fullPreview($('#mobileSharedSelector').get(0))">
- <s:text name="themeEditor.previewLink"/></a><br/>
- <s:text name="themeEditor.previewDescription"/>
- </p>
-
- <s:if test="!customTheme && actionWeblog.theme.customStylesheet !=
null">
- <p>
- <s:url action="stylesheetEdit" id="stylesheetEdit">
- <s:param name="weblog" value="%{actionWeblog.handle}"/>
- </s:url>
- » <s:a href="%{stylesheetEdit}"><s:text
name="themeEditor.customStylesheetLink"/></s:a><br/>
- <s:text name="themeEditor.customStylesheetDescription"/>
- </p>
- </s:if>
- <p><s:submit value="%{getText('themeEditor.save')}"
action="themeEdit!saveMobileTheme"/></p>
+ <p><s:submit value="%{getText('themeEditor.save')}" /></p>
</div>
- </td>
- </tr>
- </table>
-
<div id="customOptioner" class="optioner" style="display:none;">