001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/podcasts/tags/sakai_2-4-1/podcasts-app/src/java/org/sakaiproject/tool/podcasts/podFeedBean.java $
003: * $Id: podFeedBean.java 18624 2006-12-04 20:15:46Z josrodri@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2003, 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.tool.podcasts;
021:
022: import java.util.Locale;
023: import java.util.ResourceBundle;
024:
025: import javax.faces.application.FacesMessage;
026: import javax.faces.context.FacesContext;
027:
028: import org.sakaiproject.api.app.podcasts.PodfeedService;
029:
030: public class podFeedBean {
031:
032: /** Used to pull messages from the bundle **/
033: public static final String PODFEED_TITLE_MSG = "feed_title";
034: public static final String PODFEED_DESC1 = "feed_desc1";
035: public static final String PODFEED_DESC2 = "feed_desc2";
036: public static final String NO_TITLE_ALERT = "notitle";
037:
038: private final String MESSAGE_BUNDLE = "org.sakaiproject.api.podcasts.bundle.Messages";
039:
040: // inject podfeedService into here to use
041: private PodfeedService podfeedService;
042:
043: // Used by podFeedRevise for global feed info
044: private String podfeedTitle;
045: private String podfeedDescription;
046: private String feedCopyright;
047: private String feedGenerator;
048: private String language;
049:
050: /**
051: * Returns the global podcast title
052: *
053: * @return String
054: * The global podcast title
055: */
056: public String getPodfeedTitle() {
057: podfeedTitle = podfeedService.getPodfeedTitle();
058:
059: return podfeedTitle;
060: }
061:
062: /**
063: * Setter for global podcast title
064: *
065: * @param podFeedTitle
066: * The podFeedTitle to set.
067: */
068: public void setPodfeedTitle(String podFeedTitle) {
069: this .podfeedTitle = podFeedTitle;
070:
071: }
072:
073: /**
074: * Returns the global podcast description
075: *
076: * @return String
077: * Returns the podFeedDescription.
078: */
079: public String getPodfeedDescription() {
080: podfeedDescription = podfeedService.getPodfeedDescription();
081:
082: return podfeedDescription;
083: }
084:
085: /**
086: * Setter for the global podcast description.
087: *
088: * @param podFeedDescription
089: * The podFeedDescription to set.
090: */
091: public void setPodfeedDescription(String podFeedDescription) {
092: this .podfeedDescription = podFeedDescription;
093:
094: }
095:
096: /**
097: * Determine if revisions made to global feed info and apply changes.
098: *
099: * @return String to control navigation
100: */
101: public String processRevisePodcast() {
102: String whereToGo = "cancel";
103:
104: final String oldTitle = podfeedService.getPodfeedTitle();
105:
106: if (podfeedTitle != null && !podfeedTitle.equals(oldTitle)) {
107: if (podfeedTitle.equals("")) {
108: setErrorMessage(NO_TITLE_ALERT);
109: whereToGo = "podfeedRevise";
110: } else {
111: // Replace with this title
112: podfeedService.setPodfeedTitle(podfeedTitle);
113: }
114: }
115:
116: final String oldDescription = podfeedService
117: .getPodfeedDescription();
118:
119: if (podfeedDescription != null
120: && !podfeedDescription.equals(oldDescription)) {
121: // Replace with this description
122: podfeedService.setPodfeedDescription(podfeedDescription);
123: }
124:
125: if (feedCopyright != null || !"".equals(feedCopyright)) {
126: podfeedService.setPodfeedCopyright(feedCopyright);
127: }
128:
129: if (feedGenerator != null || !"".equals(feedGenerator)) {
130: podfeedService.setPodfeedGenerator(feedGenerator);
131: }
132:
133: return whereToGo;
134: }
135:
136: /**
137: * Cancels revising global podfeed information
138: *
139: * @return String Sent to return to the main page
140: */
141: public String processCancelPodfeedRevise() {
142: podfeedTitle = "";
143: podfeedDescription = "";
144:
145: return "cancel";
146: }
147:
148: /**
149: * @return Returns the podfeedService.
150: */
151: public PodfeedService getPodfeedService() {
152: return podfeedService;
153: }
154:
155: /**
156: * @param podfeedService The podfeedService to set.
157: */
158: public void setPodfeedService(PodfeedService podfeedService) {
159: this .podfeedService = podfeedService;
160: }
161:
162: /**
163: * Passes an error message to the Spring framework to display on page.
164: *
165: * @param alertMsg
166: * The key to get the message from the message bundle
167: */
168: private void setErrorMessage(String alertMsg) {
169: FacesContext.getCurrentInstance().addMessage(
170: null,
171: new FacesMessage("Alert: "
172: + getErrorMessageString(alertMsg)));
173: }
174:
175: /**
176: * Sets the Faces error message by pulling the message from the
177: * MessageBundle using the name passed in
178: *
179: * @param key
180: * The name in the MessageBundle for the message wanted
181: *
182: * @return String
183: * The string that is the value of the message
184: */
185: private String getErrorMessageString(String key) {
186: ResourceBundle rb = ResourceBundle.getBundle(MESSAGE_BUNDLE);
187: return rb.getString(key);
188:
189: }
190:
191: public String getFeedCopyright() {
192: feedCopyright = podfeedService.getPodfeedCopyright();
193:
194: return feedCopyright;
195: }
196:
197: public void setFeedCopyright(String feedCopyright) {
198: this .feedCopyright = feedCopyright;
199: }
200:
201: public String getFeedGenerator() {
202: feedGenerator = podfeedService.getPodfeedGenerator();
203:
204: return feedGenerator;
205: }
206:
207: public void setFeedGenerator(String feedGenerator) {
208: this .feedGenerator = feedGenerator;
209: }
210:
211: public String getLanguage() {
212: return language;
213: }
214:
215: public void setLanguage(String language) {
216: this.language = language;
217: }
218:
219: }
|