001: /*
002: * (C) Copyright 2004 Nabh Information Systems, Inc.
003: *
004: * All copyright notices regarding Nabh's products MUST remain
005: * intact in the scripts and in the outputted HTML.
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021: package com.nabhinc.portlet.mvcportlet.core;
022:
023: import java.util.HashMap;
024:
025: import javax.portlet.RenderRequest;
026:
027: import com.nabhinc.core.MimeTypes;
028: import com.nabhinc.portlet.mvcportlet.util.ConfigUtil;
029:
030: /**
031: * Configuration associated with an render type, i.e., a
032: * request type used in render method of ControllerPortlet.
033: *
034: * @author Padmanabh Dabke
035: * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
036: */
037: public class RenderConfig extends RequestConfig {
038: private NavigationNode rcNavNode = null;
039: private RenderProcessor rcProcessor = null;
040: private HashMap rcIncludePathMap = new HashMap();
041: private HashMap rcGlobalIncludePathMap = null;
042:
043: public void setControllerPortletConfig(
044: ControllerPortletConfig config) {
045: super .setControllerPortletConfig(config);
046: rcGlobalIncludePathMap = config.getGlobalIncludePathMap();
047: }
048:
049: protected HashMap getIncludePathMap() {
050: return rcIncludePathMap;
051: }
052:
053: /**
054: *
055: * @return
056: */
057: public NavigationNode getNavigationNode() {
058: return rcNavNode;
059: }
060:
061: /**
062: *
063: * @param node
064: */
065: public void setNavigationNode(NavigationNode node) {
066: rcNavNode = node;
067: }
068:
069: /**
070: * @return Returns the RenderProcessor.
071: */
072: public RenderProcessor getRenderProcessor() {
073: return rcProcessor;
074: }
075:
076: /**
077: * @param processor The RenderProcessor to set.
078: */
079: public void setRenderProcessor(RenderProcessor processor) {
080: rcProcessor = processor;
081: }
082:
083: /**
084: * Returns the include path of "default" key name.
085: * @param request
086: * @return
087: */
088: public String getDefaultIncludePath(RenderRequest request) {
089: return getIncludePath(request, "default");
090: }
091:
092: /**
093: * Returns the include path that mapped with the key/name. It will first determine the
094: * type of the display to be generated by checking the mobile clients that understand
095: * XHTML or WML and set the appropriate displayType (xhtmlmp or wml).
096: * If none of the display types is supported, then it assumes window state's display.
097: * It will try to return display-specific include path if specified. Otherwise, global
098: * mapping's include is returned
099: * @param request
100: * @param name The key of the include path.
101: * @return
102: */
103: public String getIncludePath(RenderRequest request, String name) {
104: // Determine the type of display to be generated. We first check for mobile clients that
105: // understand XHTML MP or WML. If not, we check if window state-specific display is specified.
106: // One of the assumptions here is that the display for mobile displays is not dependent on
107: // window state.
108: String acceptHeader = request.getProperty("accept");
109: String displayType = null;
110: if (acceptHeader != null) {
111: if (acceptHeader.indexOf(MimeTypes.XHTML_MP) != -1) {
112: displayType = "xhtmlmp";
113: } else if (acceptHeader.indexOf(MimeTypes.WML) != -1) {
114: displayType = "wml";
115: }
116: }
117:
118: if (displayType == null) {
119: displayType = request.getWindowState().toString();
120: }
121:
122: // First find out if there is a display-specific include. If not look for a general
123: // include.
124: String includePath = (String) rcIncludePathMap.get(ConfigUtil
125: .constructPathKey(name, displayType));
126: if (includePath == null)
127: includePath = (String) rcIncludePathMap.get(name);
128:
129: // If render type specific mapping is not specified check in the global mapping
130: if (includePath == null) {
131: includePath = (String) rcGlobalIncludePathMap
132: .get(ConfigUtil.constructPathKey(name, displayType));
133: }
134: if (includePath == null)
135: includePath = (String) rcGlobalIncludePathMap.get(name);
136: return includePath;
137: }
138:
139: }
|