Author: agilliland Date: Mon Apr 2 11:00:47 2007 New Revision: 524859 URL: http://svn.apache.org/viewvc?view=rev&rev=524859 Log: preliminary support for weblog custom stylesheets. this commit implements just the functional parts of the proposal ...
http://cwiki.apache.org/confluence/display/ROLLER/Proposal+Stylesheet+Overrides+for+Weblogs the UI controls will be added in subsequent commits. Added: incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeParsingException.java Modified: incubator/roller/trunk/metadata/database/tmpls/3xx-to-400-migration.vm incubator/roller/trunk/metadata/database/tmpls/createdb.vm incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeManagerImpl.java incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeMetadata.java incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeMetadataParser.java incubator/roller/trunk/src/org/apache/roller/pojos/Theme.java incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java incubator/roller/trunk/src/org/apache/roller/pojos/wrapper/WebsiteDataWrapper.java Modified: incubator/roller/trunk/metadata/database/tmpls/3xx-to-400-migration.vm URL: http://svn.apache.org/viewvc/incubator/roller/trunk/metadata/database/tmpls/3xx-to-400-migration.vm?view=diff&rev=524859&r1=524858&r2=524859 ============================================================================== --- incubator/roller/trunk/metadata/database/tmpls/3xx-to-400-migration.vm (original) +++ incubator/roller/trunk/metadata/database/tmpls/3xx-to-400-migration.vm Mon Apr 2 11:00:47 2007 @@ -10,6 +10,9 @@ #addColumnNotNull("webpage" "action" "varchar(16)" "'custom'") update webpage set action = 'weblog' where name = 'Weblog'; +-- add new custom stylesheet column to website table +#addColumnNull("website" "customstylesheet" "varchar(128)") + -- remove old id column of group subscription table alter table rag_group_subscription drop column id; Modified: incubator/roller/trunk/metadata/database/tmpls/createdb.vm URL: http://svn.apache.org/viewvc/incubator/roller/trunk/metadata/database/tmpls/createdb.vm?view=diff&rev=524859&r1=524858&r2=524859 ============================================================================== --- incubator/roller/trunk/metadata/database/tmpls/createdb.vm (original) +++ incubator/roller/trunk/metadata/database/tmpls/createdb.vm Mon Apr 2 11:00:47 2007 @@ -117,7 +117,8 @@ lastmodified $db.TIMESTAMP_SQL_TYPE, pagemodels varchar(255) default null, enablemultilang $db.BOOLEAN_SQL_TYPE_FALSE not null, - showalllangs $db.BOOLEAN_SQL_TYPE_TRUE not null + showalllangs $db.BOOLEAN_SQL_TYPE_TRUE not null, + customstylesheet varchar(128) ); create index ws_userid_idx on website(userid); create index ws_isenabled_idx on website(isenabled); Modified: incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeManagerImpl.java URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeManagerImpl.java?view=diff&rev=524859&r1=524858&r2=524859 ============================================================================== --- incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeManagerImpl.java (original) +++ incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeManagerImpl.java Mon Apr 2 11:00:47 2007 @@ -137,13 +137,13 @@ UserManager userMgr = RollerFactory.getRoller().getUserManager(); Iterator iter = theme.getTemplates().iterator(); - ThemeTemplate theme_template = null; + ThemeTemplate themeTemplate = null; while ( iter.hasNext() ) { - theme_template = (ThemeTemplate) iter.next(); + themeTemplate = (ThemeTemplate) iter.next(); WeblogTemplate template = null; - if(theme_template.getAction().equals(WeblogTemplate.ACTION_WEBLOG)) { + if(themeTemplate.getAction().equals(WeblogTemplate.ACTION_WEBLOG)) { // this is the main Weblog template try { template = userMgr.getPageByAction(website, WeblogTemplate.ACTION_WEBLOG); @@ -152,7 +152,7 @@ } } else { // any other template - template = userMgr.getPageByName(website, theme_template.getName()); + template = userMgr.getPageByName(website, themeTemplate.getName()); } // TODO: in order to ensure that left over templates don't cause @@ -161,21 +161,21 @@ if (template != null) { // User already has page by that name, so overwrite it. - template.setContents(theme_template.getContents()); - template.setLink(theme_template.getLink()); + template.setContents(themeTemplate.getContents()); + template.setLink(themeTemplate.getLink()); } else { // User does not have page by that name, so create new page. template = new WeblogTemplate(); template.setWebsite(website); - template.setAction(theme_template.getAction()); - template.setName(theme_template.getName()); - template.setDescription(theme_template.getDescription()); - template.setContents(theme_template.getContents()); - template.setHidden(theme_template.isHidden()); - template.setNavbar(theme_template.isNavbar()); - template.setTemplateLanguage(theme_template.getTemplateLanguage()); - template.setDecoratorName(theme_template.getDecoratorName()); + template.setAction(themeTemplate.getAction()); + template.setName(themeTemplate.getName()); + template.setDescription(themeTemplate.getDescription()); + template.setContents(themeTemplate.getContents()); + template.setHidden(themeTemplate.isHidden()); + template.setNavbar(themeTemplate.isNavbar()); + template.setTemplateLanguage(themeTemplate.getTemplateLanguage()); + template.setDecoratorName(themeTemplate.getDecoratorName()); template.setLastModified(new Date()); // save it @@ -183,14 +183,15 @@ // we just created and saved the default page for the first // time so we need to set website.defaultpageid - if(theme_template.getName().equals(WeblogTemplate.DEFAULT_PAGE)) { + if(themeTemplate.getName().equals(WeblogTemplate.DEFAULT_PAGE)) { website.setDefaultPageId(template.getId()); } } } - // always update this weblog's theme to custom and then save + // always update this weblog's theme and customStylesheet, then save website.setEditorTheme(Theme.CUSTOM); + website.setCustomStylesheetPath(theme.getCustomStylesheet()); userMgr.saveWebsite(website); @@ -300,6 +301,7 @@ theme.setName(themeMetadata.getName()); theme.setDescription(themeMetadata.getName()); theme.setAuthor(themeMetadata.getAuthor()); + theme.setCustomStylesheet(themeMetadata.getCustomStylesheet()); theme.setLastModified(new Date()); theme.setEnabled(true); Modified: incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeMetadata.java URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeMetadata.java?view=diff&rev=524859&r1=524858&r2=524859 ============================================================================== --- incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeMetadata.java (original) +++ incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeMetadata.java Mon Apr 2 11:00:47 2007 @@ -31,6 +31,7 @@ private String name = null; private String author = null; private String previewImage = null; + private String customStylesheet = null; private Set templates = new HashSet(); private Set resources = new HashSet(); @@ -93,6 +94,14 @@ public void setAuthor(String author) { this.author = author; + } + + public String getCustomStylesheet() { + return customStylesheet; + } + + public void setCustomStylesheet(String customStylesheet) { + this.customStylesheet = customStylesheet; } } Modified: incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeMetadataParser.java URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeMetadataParser.java?view=diff&rev=524859&r1=524858&r2=524859 ============================================================================== --- incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeMetadataParser.java (original) +++ incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeMetadataParser.java Mon Apr 2 11:00:47 2007 @@ -41,7 +41,7 @@ * set of Java objects. **/ public ThemeMetadata unmarshall(InputStream instream) - throws IOException, JDOMException { + throws ThemeParsingException, IOException, JDOMException { if(instream == null) throw new IOException("InputStream is null!"); @@ -59,7 +59,17 @@ // now grab the preview image path Element previewImage = root.getChild("preview-image"); - theme.setPreviewImage(previewImage.getAttributeValue("path")); + if(previewImage != null) { + theme.setPreviewImage(previewImage.getAttributeValue("path")); + } else { + throw new ThemeParsingException("No preview image specified"); + } + + // grab the custom stylesheet path + Element customStylesheet = root.getChild("custom-stylesheet"); + if(customStylesheet != null) { + theme.setCustomStylesheet(customStylesheet.getAttributeValue("path")); + } // now grab the static resources List resources = root.getChildren("resource"); Added: incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeParsingException.java URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeParsingException.java?view=auto&rev=524859 ============================================================================== --- incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeParsingException.java (added) +++ incubator/roller/trunk/src/org/apache/roller/business/themes/ThemeParsingException.java Mon Apr 2 11:00:47 2007 @@ -0,0 +1,46 @@ +/* + * 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.business.themes; + +import org.apache.roller.RollerException; + + +/** + * Thrown when there is a problem parsing a given theme xml descriptor. + */ +public class ThemeParsingException extends RollerException { + + + public ThemeParsingException(String s,Throwable t) { + super(s, t); + } + + public ThemeParsingException(Throwable t) { + super(t); + } + + public ThemeParsingException(String s) { + super(s); + } + + public ThemeParsingException() { + super(); + } + +} Modified: incubator/roller/trunk/src/org/apache/roller/pojos/Theme.java URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/Theme.java?view=diff&rev=524859&r1=524858&r2=524859 ============================================================================== --- incubator/roller/trunk/src/org/apache/roller/pojos/Theme.java (original) +++ incubator/roller/trunk/src/org/apache/roller/pojos/Theme.java Mon Apr 2 11:00:47 2007 @@ -44,6 +44,7 @@ private String name = null; private String description = null; private String author = null; + private String customStylesheet = null; private Date lastModified = null; private boolean enabled = false; @@ -181,6 +182,14 @@ this.author = author; } + public String getCustomStylesheet() { + return customStylesheet; + } + + public void setCustomStylesheet(String customStylesheet) { + this.customStylesheet = customStylesheet; + } + public Date getLastModified() { return lastModified; } @@ -220,5 +229,5 @@ Theme other = (Theme) o; return getName().compareTo(other.getName()); } - + } 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=524859&r1=524858&r2=524859 ============================================================================== --- incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java (original) +++ incubator/roller/trunk/src/org/apache/roller/pojos/WebsiteData.java Mon Apr 2 11:00:47 2007 @@ -94,6 +94,7 @@ private String pageModels = new String(); private boolean enableMultiLang = false; private boolean showAllLangs = true; + private String customStylesheetPath = null; // Associated objects @@ -1049,6 +1050,37 @@ /** + * The path under the weblog's resources to a stylesheet override. + * + * @hibernate.property column="customstylesheet" not-null="false" + */ + public String getCustomStylesheetPath() { + return customStylesheetPath; + } + + public void setCustomStylesheetPath(String customStylesheetPath) { + this.customStylesheetPath = customStylesheetPath; + } + + + public String getCustomStylesheet() { + try { + Theme weblogTheme = getTheme(); + if(weblogTheme != null) { + return weblogTheme.getCustomStylesheet(); + } else { + return getCustomStylesheetPath(); + } + } catch(RollerException re) { + // hmmm, some exception getting theme + return null; + } + } + + // no-op to please xdoclet + public void setCustomStylesheet(String noop) {} + + /** * Get initialized plugins for use during rendering process. */ public Map getInitializedPlugins() { @@ -1375,8 +1407,3 @@ public void setEntryCount(int ignored) {} } - - - - - Modified: incubator/roller/trunk/src/org/apache/roller/pojos/wrapper/WebsiteDataWrapper.java URL: http://svn.apache.org/viewvc/incubator/roller/trunk/src/org/apache/roller/pojos/wrapper/WebsiteDataWrapper.java?view=diff&rev=524859&r1=524858&r2=524859 ============================================================================== --- incubator/roller/trunk/src/org/apache/roller/pojos/wrapper/WebsiteDataWrapper.java (original) +++ incubator/roller/trunk/src/org/apache/roller/pojos/wrapper/WebsiteDataWrapper.java Mon Apr 2 11:00:47 2007 @@ -419,6 +419,12 @@ return this.pojo.isShowAllLangs(); } + + public String getCustomStylesheet() { + return this.pojo.getCustomStylesheet(); + } + + /** * pojo method tagged with @roller.wrapPojoMethod type="simple" *
