AttribTag.java :  » Portal » stringbeans-3.5 » com » nabhinc » portlet » mvcportlet » taglib » Java Open Source

Java Open Source » Portal » stringbeans 3.5 
stringbeans 3.5 » com » nabhinc » portlet » mvcportlet » taglib » AttribTag.java
/*
 * (C) Copyright 2005 Nabh Information Systems, Inc.
 *
 * All copyright notices regarding Nabh's products MUST remain
 * intact in the scripts and in the outputted HTML.
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
package com.nabhinc.portlet.mvcportlet.taglib;

import javax.portlet.PortletSession;
import javax.portlet.RenderRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.nabhinc.portlet.mvcportlet.core.Constants;

/**
 *
 *
 * @author Padmanabh Dabke
 * (c) 2005 Nabh Information Systems, Inc. All Rights Reserved.
 * @since 0.9
 */
public class AttribTag extends TagSupport {
    private String ptName = null;
    private String ptScope = Constants.PORTLET_SESSION_SCOPE;

    public void release() {
      super.release();
      ptName = null;
      ptScope = Constants.PORTLET_SESSION_SCOPE;
    }
    
    public String getName() {
        return ptName;
    }

    public void setName(String name) {
        ptName = name;
    }

    public String getScope() {
      return ptScope;
    }
    
    public void setScope(String sc) {
        if (Constants.REQUEST_SCOPE.equals(sc) || Constants.PORTLET_SESSION_SCOPE.equals(sc)
            || Constants.APPLICATION_SESSION_SCOPE.equals(sc) 
            || Constants.PORTLET_CONTEXT_SCOPE.equals(sc)) {
          ptScope = sc;
        } else {
          throw new IllegalArgumentException("Invalid scope attribute: " + sc +
              ". Attribute scope must be one of: request, portlet_session, application_session, portlet_context");
        }
    }

    public int doStartTag() throws JspException {

        try {
            RenderRequest request = (RenderRequest)
            pageContext.getRequest().getAttribute("javax.portlet.request");
            JspWriter out = pageContext.getOut();
            Object value = null;
            
            if (Constants.REQUEST_SCOPE.equals(ptScope)) {
              value = request.getAttribute(ptName);
            } else if (Constants.PORTLET_SESSION_SCOPE.equals(ptScope)) {
              value = request.getPortletSession().getAttribute(ptName);
            } else if (Constants.APPLICATION_SESSION_SCOPE.equals(ptScope)) {
              value = 
                request.getPortletSession().getAttribute(
                    ptName, PortletSession.APPLICATION_SCOPE);
            } else {
              value = request.getPortletSession().getPortletContext().getAttribute(ptName);
            }
            if (value != null) {
              out.print(value.toString());
              out.flush();
            }
        } catch (Exception ex) {
            throw new JspException(ex);
        }

      return SKIP_BODY;
   }

   public int doEndTag() {
      return EVAL_PAGE;
   }



}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.