001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2007, 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.wsrp.producer;
023:
024: import org.jboss.portal.portlet.Portlet;
025: import org.jboss.portal.wsrp.WSRPUtils;
026: import org.jboss.portal.wsrp.core.MarkupType;
027:
028: import java.util.HashSet;
029: import java.util.Locale;
030: import java.util.Set;
031:
032: /**
033: * Wrapper around information needed to perform a Markup invocation.
034: *
035: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
036: * @since 2.6
037: */
038: class MarkupRequest {
039: private String mode;
040: private String windowState;
041: private MarkupType markupType;
042: private String characterSet;
043: private Portlet portlet;
044: private static final String CHARSET_SEPARATOR = "; charset=";
045:
046: public MarkupRequest(MarkupType markupType, String mode,
047: String windowState, String characterSet, Portlet portlet) {
048: this .characterSet = characterSet;
049: this .markupType = markupType;
050: this .mode = mode;
051: this .windowState = windowState;
052: this .portlet = portlet;
053: }
054:
055: public String getMimeTypeWithCharset() {
056: return getMimeType() + CHARSET_SEPARATOR + getCharacterSet();
057: }
058:
059: public String getMimeType() {
060: return markupType.getMimeType();
061: }
062:
063: public String getLocale() {
064: String[] locales = markupType.getLocales();
065: if (locales != null && locales.length != 0) {
066: return locales[0];
067: } else {
068: return WSRPUtils.toString(Locale.ENGLISH); // no locale was provided, use English...
069: }
070: }
071:
072: public String getMode() {
073: return mode;
074: }
075:
076: public String getWindowState() {
077: return windowState;
078: }
079:
080: public MarkupType getMarkupType() {
081: return markupType;
082: }
083:
084: public String getCharacterSet() {
085: return characterSet;
086: }
087:
088: public Portlet getPortlet() {
089: return portlet;
090: }
091:
092: public Set getSupportedModes() {
093: String[] modes = markupType.getModes();
094: int length = modes.length;
095: Set result = new HashSet(length);
096: for (int i = 0; i < length; i++) {
097: result.add(WSRPUtils
098: .getJSR168PortletModeFromWSRPName(modes[i]));
099: }
100: return result;
101: }
102:
103: public Set getSupportedWindowStates() {
104: String[] states = markupType.getWindowStates();
105: int length = states.length;
106: Set result = new HashSet(length);
107: for (int i = 0; i < length; i++) {
108: result.add(WSRPUtils
109: .getJSR168WindowStateFromWSRPName(states[i]));
110: }
111: return result;
112: }
113: }
|