001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. The ASF licenses this file to You
004: * under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License. For additional information regarding
015: * copyright in this work, please see the NOTICE file in the top level
016: * directory of this distribution.
017: */
018: /*
019: * Created on Feb 14, 2004
020: */
021: package org.apache.roller.ui.authoring.struts.formbeans;
022:
023: import java.sql.Timestamp;
024: import java.util.Date;
025: import org.apache.commons.lang.StringUtils;
026: import org.apache.roller.RollerException;
027: import org.apache.roller.business.RollerFactory;
028: import org.apache.roller.business.WeblogManager;
029: import org.apache.roller.pojos.WeblogCategoryData;
030: import org.apache.roller.pojos.WebsiteData;
031: import org.apache.roller.ui.authoring.struts.forms.WebsiteForm;
032: import org.apache.roller.util.DateUtil;
033:
034: /**
035: * @struts.form name="websiteFormEx"
036: */
037: public class WebsiteFormEx extends WebsiteForm {
038: private String bloggerCategoryId;
039: private String defaultCategoryId;
040: private String[] defaultPluginsArray;
041: private Boolean applyCommentDefaults = Boolean.FALSE;
042:
043: /**
044: * @return Returns the bloggerCategoryId.
045: */
046: public String getBloggerCategoryId() {
047: return bloggerCategoryId;
048: }
049:
050: /**
051: * @param bloggerCategoryId The bloggerCategoryId to set.
052: */
053: public void setBloggerCategoryId(String bloggerCategoryId) {
054: this .bloggerCategoryId = bloggerCategoryId;
055: }
056:
057: /**
058: * @return Returns the defeaultCategoryId.
059: */
060: public String getDefaultCategoryId() {
061: return defaultCategoryId;
062: }
063:
064: /**
065: * @param defeaultCategoryId The defeaultCategoryId to set.
066: */
067: public void setDefaultCategoryId(String defeaultCategoryId) {
068: this .defaultCategoryId = defeaultCategoryId;
069: }
070:
071: /**
072: * @return
073: */
074: public String[] getDefaultPluginsArray() {
075: return defaultPluginsArray;
076: }
077:
078: /**
079: * @param strings
080: */
081: public void setDefaultPluginsArray(String[] strings) {
082: defaultPluginsArray = strings;
083: }
084:
085: public Boolean getApplyCommentDefaults() {
086: return applyCommentDefaults;
087: }
088:
089: public void setApplyCommentDefaults(Boolean applyCommentDefaults) {
090: this .applyCommentDefaults = applyCommentDefaults;
091: }
092:
093: /**
094: * @see org.apache.roller.ui.authoring.struts.forms.WebsiteForm#copyFrom(org.apache.roller.pojos.WebsiteData)
095: */
096: public void copyFrom(WebsiteData dataHolder, java.util.Locale locale)
097: throws RollerException {
098: super .copyFrom(dataHolder, locale);
099: if (dataHolder.getDefaultCategory() != null) {
100: defaultCategoryId = dataHolder.getDefaultCategory().getId();
101: }
102: if (dataHolder.getBloggerCategory() != null) {
103: bloggerCategoryId = dataHolder.getBloggerCategory().getId();
104: }
105: if (dataHolder.getDefaultPlugins() != null) {
106: defaultPluginsArray = StringUtils.split(dataHolder
107: .getDefaultPlugins(), ",");
108: }
109: }
110:
111: /**
112: * Utility to convert from String to Date.
113: */
114: public void setDateCreatedAsString(String value) {
115: if (value == null || value.trim().length() == 0) {
116: this .setDateCreated(null);
117: } else {
118: try {
119: Date pubDate = DateUtil.parse(value, DateUtil
120: .friendlyTimestampFormat());
121: this .setDateCreated(new Timestamp(pubDate.getTime()));
122: } catch (java.text.ParseException pe) {
123: // wasn't properly formatted
124: throw new RuntimeException("improperly formatted date",
125: pe);
126: }
127: }
128: }
129:
130: /**
131: * Returns a formatted pubTime string.
132: */
133: public String getDateCreatedAsString() {
134: return DateUtil.friendlyTimestamp(this .getDateCreated());
135: }
136:
137: /**
138: * @see org.apache.roller.ui.authoring.struts.forms.WebsiteForm#copyTo(org.apache.roller.pojos.WebsiteData)
139: */
140: public void copyTo(WebsiteData dataHolder, java.util.Locale locale)
141: throws RollerException {
142: Date dateCreated = dataHolder.getDateCreated();
143:
144: super .copyTo(dataHolder, locale);
145:
146: dataHolder.setDateCreated(dateCreated);
147: dataHolder.setDefaultPlugins(StringUtils.join(
148: this .defaultPluginsArray, ","));
149:
150: // checkboxes return no value when not checked
151: if (getAllowComments() == null) {
152: dataHolder.setAllowComments(Boolean.FALSE);
153: }
154: if (getEmailComments() == null) {
155: dataHolder.setEmailComments(Boolean.FALSE);
156: }
157: if (getEnableBloggerApi() == null) {
158: dataHolder.setEnableBloggerApi(Boolean.FALSE);
159: }
160: if (getDefaultAllowComments() == null) {
161: dataHolder.setDefaultAllowComments(Boolean.FALSE);
162: }
163: if (getModerateComments() == null) {
164: dataHolder.setModerateComments(Boolean.FALSE);
165: }
166: if (this .getActive() == null) {
167: dataHolder.setActive(Boolean.FALSE);
168: }
169:
170: WeblogManager wmgr = RollerFactory.getRoller()
171: .getWeblogManager();
172:
173: if (getDefaultCategoryId() != null) {
174: WeblogCategoryData defaultCat = wmgr
175: .getWeblogCategory(getDefaultCategoryId());
176: dataHolder.setDefaultCategory(defaultCat);
177: }
178:
179: if (getBloggerCategoryId() != null) {
180: WeblogCategoryData bloggerCat = wmgr
181: .getWeblogCategory(getBloggerCategoryId());
182: dataHolder.setBloggerCategory(bloggerCat);
183: }
184: }
185:
186: public void reset(org.apache.struts.action.ActionMapping mapping,
187: javax.servlet.ServletRequest request) {
188: doReset(mapping, request);
189: defaultPluginsArray = new String[0];
190: applyCommentDefaults = Boolean.FALSE;
191: }
192:
193: public void reset(org.apache.struts.action.ActionMapping mapping,
194: javax.servlet.http.HttpServletRequest request) {
195: doReset(mapping, request);
196: defaultPluginsArray = new String[0];
197: applyCommentDefaults = Boolean.FALSE;
198: }
199:
200: }
|