1 18 21 package org.apache.roller.ui.authoring.struts.formbeans; 22 23 import java.sql.Timestamp ; 24 import java.util.Date ; 25 import org.apache.commons.lang.StringUtils; 26 import org.apache.roller.RollerException; 27 import org.apache.roller.model.RollerFactory; 28 import org.apache.roller.model.WeblogManager; 29 import org.apache.roller.pojos.WeblogCategoryData; 30 import org.apache.roller.pojos.WebsiteData; 31 import org.apache.roller.ui.authoring.struts.forms.WebsiteForm; 32 import org.apache.roller.util.DateUtil; 33 34 37 public class WebsiteFormEx extends WebsiteForm { 38 private String bloggerCategoryId; 39 private String defaultCategoryId; 40 private String [] defaultPluginsArray; 41 private Boolean applyCommentDefaults = Boolean.FALSE; 42 43 46 public String getBloggerCategoryId() { 47 return bloggerCategoryId; 48 } 49 50 53 public void setBloggerCategoryId(String bloggerCategoryId) { 54 this.bloggerCategoryId = bloggerCategoryId; 55 } 56 57 60 public String getDefaultCategoryId() { 61 return defaultCategoryId; 62 } 63 64 67 public void setDefaultCategoryId(String defeaultCategoryId) { 68 this.defaultCategoryId = defeaultCategoryId; 69 } 70 71 74 public String [] getDefaultPluginsArray() { 75 return defaultPluginsArray; 76 } 77 78 81 public void setDefaultPluginsArray(String [] strings) { 82 defaultPluginsArray = strings; 83 } 84 85 public Boolean getApplyCommentDefaults() { 86 return applyCommentDefaults; 87 } 88 89 public void setApplyCommentDefaults(Boolean applyCommentDefaults) { 90 this.applyCommentDefaults = applyCommentDefaults; 91 } 92 93 96 public void copyFrom(WebsiteData dataHolder, java.util.Locale locale) throws RollerException { 97 super.copyFrom(dataHolder, locale); 98 if (dataHolder.getDefaultCategory() != null) { 99 defaultCategoryId = dataHolder.getDefaultCategory().getId(); 100 } 101 if (dataHolder.getBloggerCategory() != null) { 102 bloggerCategoryId = dataHolder.getBloggerCategory().getId(); 103 } 104 if (dataHolder.getDefaultPlugins() != null) { 105 defaultPluginsArray = StringUtils.split(dataHolder.getDefaultPlugins(), ","); 106 } 107 } 108 109 112 public void setDateCreatedAsString(String value) { 113 if ( value == null || value.trim().length() == 0 ) { 114 this.setDateCreated(null); 115 } else { 116 try { 117 Date pubDate = DateUtil.parse( 118 value, DateUtil.friendlyTimestampFormat()); 119 this.setDateCreated(new Timestamp (pubDate.getTime())); 120 } catch (java.text.ParseException pe) { 121 throw new RuntimeException ("improperly formatted date", pe); 123 } 124 } 125 } 126 127 130 public String getDateCreatedAsString() { 131 return DateUtil.friendlyTimestamp(this.getDateCreated()); 132 } 133 134 137 public void copyTo(WebsiteData dataHolder, java.util.Locale locale) throws RollerException { 138 Date dateCreated = dataHolder.getDateCreated(); 139 140 super.copyTo(dataHolder, locale); 141 142 dataHolder.setDateCreated(dateCreated); 143 dataHolder.setDefaultPlugins( StringUtils.join(this.defaultPluginsArray,",") ); 144 145 if (getAllowComments() == null) { 147 dataHolder.setAllowComments(Boolean.FALSE); 148 } 149 if (getEmailComments() == null) { 150 dataHolder.setEmailComments(Boolean.FALSE); 151 } 152 if (getEnableBloggerApi() == null) { 153 dataHolder.setEnableBloggerApi(Boolean.FALSE); 154 } 155 if (getDefaultAllowComments() == null) { 156 dataHolder.setDefaultAllowComments(Boolean.FALSE); 157 } 158 if (getModerateComments() == null) { 159 dataHolder.setModerateComments(Boolean.FALSE); 160 } 161 if (this.getActive() == null) { 162 dataHolder.setActive(Boolean.FALSE); 163 } 164 165 WeblogManager wmgr = RollerFactory.getRoller().getWeblogManager(); 166 167 if (getDefaultCategoryId() != null) { 168 WeblogCategoryData defaultCat = 169 wmgr.getWeblogCategory(getDefaultCategoryId()); 170 dataHolder.setDefaultCategory(defaultCat); 171 } 172 173 if (getBloggerCategoryId() != null) { 174 WeblogCategoryData bloggerCat = 175 wmgr.getWeblogCategory(getBloggerCategoryId()); 176 dataHolder.setBloggerCategory(bloggerCat); 177 } 178 } 179 180 public void reset( 181 org.apache.struts.action.ActionMapping mapping, 182 javax.servlet.ServletRequest request) { 183 doReset(mapping, request); 184 defaultPluginsArray = new String [0]; 185 applyCommentDefaults = Boolean.FALSE; 186 } 187 188 public void reset( 189 org.apache.struts.action.ActionMapping mapping, 190 javax.servlet.http.HttpServletRequest request) { 191 doReset(mapping, request); 192 defaultPluginsArray = new String [0]; 193 applyCommentDefaults = Boolean.FALSE; 194 } 195 196 } 197 | Popular Tags |