001: /*
002: * (C) Copyright 2005 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.taglib;
022:
023: import javax.portlet.PortletSession;
024: import javax.portlet.RenderRequest;
025: import javax.servlet.jsp.JspException;
026: import javax.servlet.jsp.JspWriter;
027: import javax.servlet.jsp.tagext.TagSupport;
028:
029: import com.nabhinc.portlet.mvcportlet.core.Constants;
030:
031: /**
032: *
033: *
034: * @author Padmanabh Dabke
035: * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
036: * @since 0.9
037: */
038: public class AttribTag extends TagSupport {
039: private String ptName = null;
040: private String ptScope = Constants.PORTLET_SESSION_SCOPE;
041:
042: public void release() {
043: super .release();
044: ptName = null;
045: ptScope = Constants.PORTLET_SESSION_SCOPE;
046: }
047:
048: public String getName() {
049: return ptName;
050: }
051:
052: public void setName(String name) {
053: ptName = name;
054: }
055:
056: public String getScope() {
057: return ptScope;
058: }
059:
060: public void setScope(String sc) {
061: if (Constants.REQUEST_SCOPE.equals(sc)
062: || Constants.PORTLET_SESSION_SCOPE.equals(sc)
063: || Constants.APPLICATION_SESSION_SCOPE.equals(sc)
064: || Constants.PORTLET_CONTEXT_SCOPE.equals(sc)) {
065: ptScope = sc;
066: } else {
067: throw new IllegalArgumentException(
068: "Invalid scope attribute: "
069: + sc
070: + ". Attribute scope must be one of: request, portlet_session, application_session, portlet_context");
071: }
072: }
073:
074: public int doStartTag() throws JspException {
075:
076: try {
077: RenderRequest request = (RenderRequest) pageContext
078: .getRequest().getAttribute("javax.portlet.request");
079: JspWriter out = pageContext.getOut();
080: Object value = null;
081:
082: if (Constants.REQUEST_SCOPE.equals(ptScope)) {
083: value = request.getAttribute(ptName);
084: } else if (Constants.PORTLET_SESSION_SCOPE.equals(ptScope)) {
085: value = request.getPortletSession()
086: .getAttribute(ptName);
087: } else if (Constants.APPLICATION_SESSION_SCOPE
088: .equals(ptScope)) {
089: value = request.getPortletSession().getAttribute(
090: ptName, PortletSession.APPLICATION_SCOPE);
091: } else {
092: value = request.getPortletSession().getPortletContext()
093: .getAttribute(ptName);
094: }
095: if (value != null) {
096: out.print(value.toString());
097: out.flush();
098: }
099: } catch (Exception ex) {
100: throw new JspException(ex);
101: }
102:
103: return SKIP_BODY;
104: }
105:
106: public int doEndTag() {
107: return EVAL_PAGE;
108: }
109:
110: }
|