01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/tool-lib/src/java/org/theospi/portfolio/shared/tool/ToolBase.java $
03: * $Id:ToolBase.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.shared.tool;
21:
22: import java.text.MessageFormat;
23: import java.util.Iterator;
24:
25: import javax.faces.application.FacesMessage;
26: import javax.faces.component.UIComponent;
27: import javax.faces.component.UIInput;
28: import javax.faces.component.UIViewRoot;
29: import javax.faces.context.FacesContext;
30: import javax.faces.model.SelectItem;
31:
32: import org.sakaiproject.util.ResourceLoader;
33:
34: /**
35: * Created by IntelliJ IDEA.
36: * User: John Ellis
37: * Date: Dec 12, 2005
38: * Time: 1:30:16 PM
39: * To change this template use File | Settings | File Templates.
40: */
41: public class ToolBase {
42: //private ResourceBundle toolBundle;
43: private ResourceLoader toolBundle;
44:
45: public Object createSelect(Object id, String description) {
46: SelectItem item = new SelectItem(id, description);
47: return item;
48: }
49:
50: public String getMessageFromBundle(String key, Object[] args) {
51: return MessageFormat.format(getMessageFromBundle(key), args);
52: }
53:
54: public FacesMessage getFacesMessageFromBundle(String key,
55: Object[] args) {
56: return new FacesMessage(getMessageFromBundle(key, args));
57: }
58:
59: public String getMessageFromBundle(String key) {
60: if (toolBundle == null) {
61: String bundle = FacesContext.getCurrentInstance()
62: .getApplication().getMessageBundle();
63: toolBundle = new ResourceLoader(bundle);
64: /* Locale requestLocale = FacesContext.getCurrentInstance().getExternalContext().getRequestLocale();
65: if (requestLocale != null) {
66: toolBundle = ResourceBundle.getBundle(
67: bundle, requestLocale);
68: }
69: else {
70: toolBundle = ResourceBundle.getBundle(bundle);
71: }*/
72: }
73: return toolBundle.getString(key);
74: }
75:
76: protected void processChildCancel(UIComponent component) {
77: if (component instanceof UIInput) {
78: UIInput input = (UIInput) component;
79: input.setSubmittedValue(null);
80: }
81:
82: for (Iterator i = component.getChildren().iterator(); i
83: .hasNext();) {
84: UIComponent child = (UIComponent) i.next();
85: processChildCancel(child);
86: }
87: }
88:
89: protected void cancelBoundValues() {
90: FacesContext facesContext = FacesContext.getCurrentInstance();
91: UIViewRoot viewRoot = facesContext.getViewRoot();
92: processChildCancel(viewRoot);
93: }
94:
95: }
|