Package javax.portlet

Examples of javax.portlet.Portlet


      try
      {
         log.debug("Loading portlet class " + className);
         Class portletClass = application.getContext().getClassLoader().loadClass(className);
         log.debug("Creating portlet object " + className);
         Portlet portlet = (Portlet)portletClass.newInstance();
         log.debug("Created portlet object " + className);
         initPortlet(portlet, config);
         log.debug("Initialized portlet object " + className);

         // We are safe, update state
View Full Code Here


     */
    public final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
        String portletName = null;
        Integer method = ContainerConstants.METHOD_NOOP;
        Portlet portlet = null;
        boolean destroyPortlet = false;
        boolean isParallelMode = false;
       
        try
        {
            isParallelMode = CurrentWorkerContext.getParallelRenderingMode();

            if (isParallelMode)
            {
                method = (Integer) CurrentWorkerContext.getAttribute(ContainerConstants.METHOD_ID);
            }
            else
            {
                method = (Integer) request.getAttribute(ContainerConstants.METHOD_ID);
            }
            if (method == ContainerConstants.METHOD_NOOP)
            {
                return;
            }
            if (isParallelMode)
            {
                portlet = (Portlet) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET);
                portletName = (String) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_NAME);
            }
            else
            {
                portlet = (Portlet)request.getAttribute(ContainerConstants.PORTLET);
                portletName = (String)request.getAttribute(ContainerConstants.PORTLET_NAME);
                request.removeAttribute(ContainerConstants.PORTLET);
            }

            if (method == ContainerConstants.METHOD_ACTION)
            {
                ActionRequest actionRequest = (ActionRequest) request.getAttribute(ContainerConstants.PORTLET_REQUEST);
                ActionResponse actionResponse = (ActionResponse) request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
                // inject the current request into the actionRequest handler (o.a.j.engine.servlet.ServletRequestImpl)
                ((HttpServletRequestWrapper)((HttpServletRequestWrapper)actionRequest).getRequest()).setRequest(request);

                portlet.processAction(actionRequest, actionResponse);
            }
            else if (method == ContainerConstants.METHOD_RENDER)
            {
                RenderRequest renderRequest = null;
                RenderResponse renderResponse =  null;

                if (isParallelMode)
                {
                    renderRequest = (RenderRequest) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_REQUEST);
                    renderResponse = (RenderResponse) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_RESPONSE);
                }
                else
                {
                    renderRequest = (RenderRequest) request.getAttribute(ContainerConstants.PORTLET_REQUEST);
                    renderResponse = (RenderResponse) request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
                }               
                // inject the current request into the renderRequest handler (o.a.j.engine.servlet.ServletRequestImpl)
                ((HttpServletRequestWrapper)((HttpServletRequestWrapper)renderRequest).getRequest()).setRequest(request);
                portlet.render(renderRequest, renderResponse);
            }

            // if we get this far we are home free
            return;
        }
        catch (Throwable t)
        {
            if ( t instanceof UnavailableException )
            {
                // destroy the portlet in the finally clause
                destroyPortlet = true;
            }
           
            if (method != ContainerConstants.METHOD_ACTION)
            {
                ServletContext context = getServletContext();
                context.log(JCS + "Error rendering portlet \"" + portletName + "\": " + t.toString(), t);
                try
                {
                    String errorTemplate = getInitParameter("portal.error.page");
                    if (errorTemplate == null)
                    {
                        errorTemplate = "/WEB-INF/templates/generic/html/error.vm";
                    }
                    if (null != context.getResource(errorTemplate))
                    {
                        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(errorTemplate);
                        request.setAttribute("e", t);
                        StringWriter stackTrace = new StringWriter();
                        t.printStackTrace(new PrintWriter(stackTrace));
                        request.setAttribute("stacktrace", stackTrace.toString());
                        dispatcher.include(request, response);
                    }
                    else
                    {
                        displayPortletNotAvailableMessage(t, response, portletName);
                    }
                }
                catch (Throwable e)
                {
                    displayPortletNotAvailableMessage(t, response, portletName);
                }
                finally
                {
                    t.printStackTrace();
                }
            }
            else
            {
                if ( t instanceof RuntimeException )
                {
                    throw (RuntimeException)t;
                }
                else if (t instanceof IOException )
                {
                    throw (IOException)t;
                }
                else if (t instanceof ServletException)
                {
                    throw (ServletException)t;
                }
                else
                {
                    throw new ServletException(t);
                }
            }
        }
        finally
        {
            if ( destroyPortlet )
            {
                // portlet throwed UnavailableException: take it out of service
                try
                {
                    portlet.destroy();
                }
                catch (Exception e)
                {
                    // never mind, it won't be used anymore.                
                }
View Full Code Here

                    Iterator portletDefinitions = pa.getPortletDefinitions().iterator();
                    while (portletDefinitions.hasNext())
                    {
                        PortletDefinition pd = (PortletDefinition) portletDefinitions.next();
                        String pdId = pd.getId().toString();
                        Portlet portlet = (Portlet) portletCache.remove(pdId);
                        if (portlet != null)
                        {
                            try
                            {
                                Thread.currentThread().setContextClassLoader(cl);
                                portlet.destroy();
                            }
                            finally
                            {
                                Thread.currentThread().setContextClassLoader(currentContextClassLoader);
                            }
View Full Code Here

     */
    public final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
        String portletName = null;
        Integer method = ContainerConstants.METHOD_NOOP;
        Portlet portlet = null;
        boolean destroyPortlet = false;
        boolean isParallelMode = false;
       
        try
        {
            isParallelMode = (Thread.currentThread() instanceof Worker || CurrentWorkerContext.getCurrentWorkerContextUsed());

            if (isParallelMode)
            {
                method = (Integer) CurrentWorkerContext.getAttribute(ContainerConstants.METHOD_ID);
            }
            else
            {
                method = (Integer) request.getAttribute(ContainerConstants.METHOD_ID);
            }
            if (method == ContainerConstants.METHOD_NOOP)
            {
                return;
            }
            if (isParallelMode)
            {
                portlet = (Portlet) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET);
                portletName = (String) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_NAME);
            }
            else
            {
                portlet = (Portlet)request.getAttribute(ContainerConstants.PORTLET);
                portletName = (String)request.getAttribute(ContainerConstants.PORTLET_NAME);
                request.removeAttribute(ContainerConstants.PORTLET);
            }

            if (method == ContainerConstants.METHOD_ACTION)
            {
                ActionRequest actionRequest = (ActionRequest) request.getAttribute(ContainerConstants.PORTLET_REQUEST);
                ActionResponse actionResponse = (ActionResponse) request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
                // inject the current request into the actionRequest handler (o.a.j.engine.servlet.ServletRequestImpl)
                ((HttpServletRequestWrapper)((HttpServletRequestWrapper)actionRequest).getRequest()).setRequest(request);

                portlet.processAction(actionRequest, actionResponse);
            }
            else if (method == ContainerConstants.METHOD_RENDER)
            {
                RenderRequest renderRequest = null;
                RenderResponse renderResponse =  null;

                if (isParallelMode)
                {
                    renderRequest = (RenderRequest) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_REQUEST);
                    renderResponse = (RenderResponse) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_RESPONSE);
                }
                else
                {
                    renderRequest = (RenderRequest) request.getAttribute(ContainerConstants.PORTLET_REQUEST);
                    renderResponse = (RenderResponse) request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
                }               
                // inject the current request into the renderRequest handler (o.a.j.engine.servlet.ServletRequestImpl)
                ((HttpServletRequestWrapper)((HttpServletRequestWrapper)renderRequest).getRequest()).setRequest(request);
                portlet.render(renderRequest, renderResponse);
            }

            // if we get this far we are home free
            return;
        }
        catch (Throwable t)
        {
            if ( t instanceof UnavailableException )
            {
                // destroy the portlet in the finally clause
                destroyPortlet = true;
            }
           
            if (method != ContainerConstants.METHOD_ACTION)
            {
                ServletContext context = getServletContext();
                context.log(JCS + "Error rendering portlet \"" + portletName + "\": " + t.toString(), t);
                try
                {
                    String errorTemplate = getInitParameter("portal.error.page");
                    if (errorTemplate == null)
                    {
                        errorTemplate = "/WEB-INF/templates/generic/html/error.vm";
                    }
                    if (null != context.getResource(errorTemplate))
                    {
                        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(errorTemplate);
                        request.setAttribute("e", t);
                        StringWriter stackTrace = new StringWriter();
                        t.printStackTrace(new PrintWriter(stackTrace));
                        request.setAttribute("stacktrace", stackTrace.toString());
                        dispatcher.include(request, response);
                    }
                    else
                    {
                        displayPortletNotAvailableMessage(t, response, portletName);
                    }
                }
                catch (Throwable e)
                {
                    displayPortletNotAvailableMessage(t, response, portletName);
                }
                finally
                {
                    t.printStackTrace();
                }
            }
            else
            {
                if ( t instanceof RuntimeException )
                {
                    throw (RuntimeException)t;
                }
                else if (t instanceof IOException )
                {
                    throw (IOException)t;
                }
                else if (t instanceof ServletException)
                {
                    throw (ServletException)t;
                }
                else
                {
                    throw new ServletException(t);
                }
            }
        }
        finally
        {
            if ( destroyPortlet )
            {
                // portlet throwed UnavailableException: take it out of service
                try
                {
                    portlet.destroy();
                }
                catch (Exception e)
                {
                    // never mind, it won't be used anymore.                
                }
View Full Code Here

                PortletWindow portletWindow = getPortletWindowAccessor().getPortletWindow( fragment );
                PortletDefinition pd = portletWindow.getPortletEntity().getPortletDefinition();
                if ( pd != null && getPortletFactory().isPortletApplicationRegistered((PortletApplication)pd.getPortletApplicationDefinition() ) )
                {
                    String portletApplicationContextPath = pd.getPortletApplicationDefinition().getWebApplicationDefinition().getContextRoot();
                    Portlet portlet = getPortletFactory().getPortletInstance( context.getConfig().getServletContext().getContext( portletApplicationContextPath ), pd ).getRealPortlet();           
                    if ( portlet != null && portlet instanceof SupportsHeaderPhase )
                    {
                        log.debug( "renderHeaderFragment: " + pd.getName() + " supports header phase" );
                       
                        HeaderResource hr = getHeaderResourceFactory().getHeaderResource( context, this.baseUrlAccess, isDesktop(), getHeaderConfiguration() );
View Full Code Here

                    if (instanceCache != null)
                    {
                        Iterator instances = instanceCache.values().iterator();
                        while (instances.hasNext())
                        {
                            Portlet portlet = (Portlet)instances.next();
                            try
                            {
                                Thread.currentThread().setContextClassLoader(cl);
                                portlet.destroy();
                            }
                            finally
                            {
                                Thread.currentThread().setContextClassLoader(currentContextClassLoader);
                            }
View Full Code Here

                    Iterator portletDefinitions = pa.getPortletDefinitions().iterator();
                    while (portletDefinitions.hasNext())
                    {
                        PortletDefinition pd = (PortletDefinition) portletDefinitions.next();
                        String pdId = pd.getId().toString();
                        Portlet portlet = (Portlet) portletCache.remove(pdId);
                        if (portlet != null)
                        {
                            try
                            {
                                Thread.currentThread().setContextClassLoader(cl);
                                portlet.destroy();
                            }
                            finally
                            {
                                Thread.currentThread().setContextClassLoader(currentContextClassLoader);
                            }
View Full Code Here

     */
    public final void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
    {
        String portletName = null;
        Integer method = ContainerConstants.METHOD_NOOP;
        Portlet portlet = null;
        boolean destroyPortlet = false;
        boolean isParallelMode = false;
       
        try
        {
            isParallelMode = (Thread.currentThread() instanceof Worker);

            if (isParallelMode)
            {
                method = (Integer) CurrentWorkerContext.getAttribute(ContainerConstants.METHOD_ID);
            }
            else
            {
                method = (Integer) request.getAttribute(ContainerConstants.METHOD_ID);
            }
            if (method == ContainerConstants.METHOD_NOOP)
            {
                return;
            }
            if (isParallelMode)
            {
                portlet = (Portlet) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET);
                portletName = (String) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_NAME);
            }
            else
            {
                portlet = (Portlet)request.getAttribute(ContainerConstants.PORTLET);
                portletName = (String)request.getAttribute(ContainerConstants.PORTLET_NAME);
                request.removeAttribute(ContainerConstants.PORTLET);
            }

            if (method == ContainerConstants.METHOD_ACTION)
            {
                ActionRequest actionRequest = (ActionRequest) request.getAttribute(ContainerConstants.PORTLET_REQUEST);
                ActionResponse actionResponse = (ActionResponse) request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
                // inject the current request into the actionRequest handler (o.a.j.engine.servlet.ServletRequestImpl)
                ((HttpServletRequestWrapper)((HttpServletRequestWrapper)actionRequest).getRequest()).setRequest(request);

                portlet.processAction(actionRequest, actionResponse);
            }
            else if (method == ContainerConstants.METHOD_RENDER)
            {
                RenderRequest renderRequest = null;
                RenderResponse renderResponse =  null;

                if (isParallelMode)
                {
                    renderRequest = (RenderRequest) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_REQUEST);
                    renderResponse = (RenderResponse) CurrentWorkerContext.getAttribute(ContainerConstants.PORTLET_RESPONSE);
                }
                else
                {
                    renderRequest = (RenderRequest) request.getAttribute(ContainerConstants.PORTLET_REQUEST);
                    renderResponse = (RenderResponse) request.getAttribute(ContainerConstants.PORTLET_RESPONSE);
                }               
                // inject the current request into the renderRequest handler (o.a.j.engine.servlet.ServletRequestImpl)
                ((HttpServletRequestWrapper)((HttpServletRequestWrapper)renderRequest).getRequest()).setRequest(request);
                portlet.render(renderRequest, renderResponse);
            }

            // if we get this far we are home free
            return;
        }
        catch (Throwable t)
        {
            if ( t instanceof UnavailableException )
            {
                // destroy the portlet in the finally clause
                destroyPortlet = true;
            }
           
            if (method != ContainerConstants.METHOD_ACTION)
            {
                ServletContext context = getServletContext();
                context.log(JCS + "Error rendering portlet \"" + portletName + "\": " + t.toString(), t);
                try
                {
                    String errorTemplate = getInitParameter("portal.error.page");
                    if (errorTemplate == null)
                    {
                        errorTemplate = "/WEB-INF/templates/generic/html/error.vm";
                    }
                    if (null != context.getResource(errorTemplate))
                    {
                        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(errorTemplate);
                        request.setAttribute("e", t);
                        StringWriter stackTrace = new StringWriter();
                        t.printStackTrace(new PrintWriter(stackTrace));
                        request.setAttribute("stacktrace", stackTrace.toString());
                        dispatcher.include(request, response);
                    }
                    else
                    {
                        displayPortletNotAvailableMessage(t, response, portletName);
                    }
                }
                catch (Throwable e)
                {
                    displayPortletNotAvailableMessage(t, response, portletName);
                }
                finally
                {
                    t.printStackTrace();
                }
            }
            else
            {
                if ( t instanceof RuntimeException )
                {
                    throw (RuntimeException)t;
                }
                else if (t instanceof IOException )
                {
                    throw (IOException)t;
                }
                else if (t instanceof ServletException)
                {
                    throw (ServletException)t;
                }
                else
                {
                    throw new ServletException(t);
                }
            }
        }
        finally
        {
            if ( destroyPortlet )
            {
                // portlet throwed UnavailableException: take it out of service
                try
                {
                    portlet.destroy();
                }
                catch (Exception e)
                {
                    // never mind, it won't be used anymore.                
                }
View Full Code Here

                PortletWindow portletWindow = getPortletWindowAccessor().getPortletWindow( fragment );
                PortletDefinition pd = portletWindow.getPortletEntity().getPortletDefinition();
                if ( pd != null && getPortletFactory().isPortletApplicationRegistered((PortletApplication)pd.getPortletApplicationDefinition() ) )
                {
                    String portletApplicationContextPath = pd.getPortletApplicationDefinition().getWebApplicationDefinition().getContextRoot();
                    Portlet portlet = getPortletFactory().getPortletInstance( context.getConfig().getServletContext().getContext( portletApplicationContextPath ), pd ).getRealPortlet();           
                    if ( portlet != null && portlet instanceof SupportsHeaderPhase )
                    {
                        log.debug( "renderHeaderFragment: " + pd.getName() + " supports header phase" );
                       
                        HeaderResource hr = getHeaderResourceFactory().getHeaderResource( context, this.baseUrlAccess, isDesktop(), getHeaderConfiguration() );
View Full Code Here

                    Iterator portletDefinitions = pa.getPortletDefinitions().iterator();
                    while (portletDefinitions.hasNext())
                    {
                        PortletDefinition pd = (PortletDefinition) portletDefinitions.next();
                        String pdId = pd.getId().toString();
                        Portlet portlet = (Portlet) portletCache.remove(pdId);
                        if (portlet != null)
                        {
                            try
                            {
                                Thread.currentThread().setContextClassLoader(cl);
                                portlet.destroy();
                            }
                            finally
                            {
                                Thread.currentThread().setContextClassLoader(currentContextClassLoader);
                            }
View Full Code Here

TOP

Related Classes of javax.portlet.Portlet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.