001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/podcasts/tags/sakai_2-4-1/podcasts-app/src/java/org/sakaiproject/tool/podcasts/podOptionsBean.java $
003: * $Id: podOptionsBean.java 14691 2006-09-15 12:36:27Z 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: import javax.faces.model.SelectItem;
028:
029: import org.sakaiproject.api.app.podcasts.PodcastService;
030:
031: public class podOptionsBean {
032: private int podOption;
033:
034: /** Used to acccess podcast service functions */
035: private PodcastService podcastService;
036:
037: /** Used to access message bundle */
038: private final String MESSAGE_BUNDLE = "org.sakaiproject.api.podcasts.bundle.Messages";
039:
040: private static final int PUBLIC = 0;
041: private static final int SITE = 1;
042: private static final String OPTIONS_PUBLIC = "options_public";
043: private static final String OPTIONS_SITE = "options_site";
044: private static final String CHANGE_TO_SITE = "option_change_confirm";
045:
046: private SelectItem[] displayItems = new SelectItem[] {
047: new SelectItem(new Integer(PUBLIC),
048: getMessageString(OPTIONS_PUBLIC)),
049: new SelectItem(new Integer(SITE),
050: getMessageString(OPTIONS_SITE)) };
051:
052: public podOptionsBean() {
053: podOption = 0;
054: }
055:
056: /** Returns whether podcast folder is PUBLIC (0) or SITE (1) **/
057: public int getPodOption() {
058: return podcastService.getOptions();
059: }
060:
061: /** Set whether the podcast folder is PUBLIC (0) or SITE (1) **/
062: public void setPodOption(int option) {
063: podOption = option;
064: }
065:
066: /** Returns the options of what the podcast folder can be set to **/
067: public SelectItem[] getDisplayItems() {
068: return displayItems;
069: }
070:
071: /**
072: * Set the podcast folder to either:
073: * 0 Display to non-members (PUBLIC)
074: * 1 Display to Site (SITE)
075: * @return String
076: * Used for navigation to go back to main page
077: */
078: public String processOptionChange() {
079:
080: podcastService.reviseOptions(podOption == PUBLIC);
081:
082: if (podOption == SITE) {
083: // Set the display message because changed to Display to Site
084: setErrorMessage(CHANGE_TO_SITE);
085:
086: }
087:
088: return "cancel";
089: }
090:
091: /** Returns back to main page with no changes **/
092: public String processOptionCancel() {
093: return "cancel";
094: }
095:
096: /**
097: * Returns the message pulled from the MessageBundle using
098: * the name passed in
099: *
100: * @param key
101: * The name in the MessageBundle for the message wanted
102: * @return String
103: * The string that is the value of the message
104: */
105: private String getMessageString(String key) {
106: ResourceBundle rb = ResourceBundle.getBundle(MESSAGE_BUNDLE);
107: return rb.getString(key);
108:
109: }
110:
111: /**
112: * @param podcastService The podcastService to set.
113: */
114: public void setPodcastService(PodcastService podcastService) {
115: this .podcastService = podcastService;
116: }
117:
118: /**
119: * Passes an error message to the Spring framework to display on page.
120: *
121: * @param alertMsg The key to get the message from the message bundle
122: */
123: private void setErrorMessage(String alertMsg) {
124: FacesContext.getCurrentInstance()
125: .addMessage(
126: null,
127: new FacesMessage("Alert: "
128: + getMessageString(alertMsg)));
129: }
130:
131: }
|