001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.faces.component.portlet;
023:
024: import org.jboss.portal.Mode;
025: import org.jboss.portal.WindowState;
026: import org.jboss.portal.common.util.Tools;
027: import org.jboss.portal.portlet.spi.PortalContext;
028:
029: import javax.faces.context.FacesContext;
030: import java.util.Collections;
031: import java.util.HashSet;
032: import java.util.Iterator;
033: import java.util.Map;
034: import java.util.Set;
035:
036: /**
037: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
038: * @version $Revision: 8784 $
039: */
040: public class JSFPortalContext implements PortalContext {
041:
042: /** . */
043: private static final Set defaultModes = Collections
044: .unmodifiableSet(Tools.toSet(new Mode[] { Mode.VIEW,
045: Mode.EDIT, Mode.HELP }));
046:
047: /** . */
048: private static final Set defaultWindowStates = Collections
049: .unmodifiableSet(Tools.toSet(new WindowState[] {
050: WindowState.NORMAL, WindowState.MINIMIZED,
051: WindowState.MAXIMIZED }));
052:
053: /** . */
054: private final FacesContext faces;
055:
056: /** . */
057: private final UIPortlet portlet;
058:
059: /** . */
060: private Set modes;
061:
062: /** . */
063: private Set windowStates;
064:
065: public JSFPortalContext(FacesContext faces, UIPortlet portlet) {
066: this .faces = faces;
067: this .portlet = portlet;
068: }
069:
070: public String getInfo() {
071: return "JSF/1.0";
072: }
073:
074: public Set getWindowStates() {
075: if (windowStates == null) {
076: Set tmp = portlet.getSupportedWindowStates();
077: if (tmp != null) {
078: windowStates = new HashSet(tmp.size());
079: for (Iterator i = tmp.iterator(); i.hasNext();) {
080: String windowStateName = (String) i.next();
081: WindowState windowState = WindowState
082: .create(windowStateName);
083: windowStates.add(windowState);
084: }
085: } else {
086: windowStates = defaultWindowStates;
087: }
088: }
089: return windowStates;
090: }
091:
092: public Set getModes() {
093: if (modes == null) {
094: Set tmp = portlet.getSupportedModes();
095: if (tmp != null) {
096: modes = new HashSet(tmp.size());
097: for (Iterator i = tmp.iterator(); i.hasNext();) {
098: String modeName = (String) i.next();
099: Mode windowState = Mode.create(modeName);
100: modes.add(windowState);
101: }
102: } else {
103: modes = defaultModes;
104: }
105: }
106: return modes;
107: }
108:
109: public Map getProperties() {
110: return Collections.EMPTY_MAP;
111: }
112: }
|