Package org.apache.jetspeed.portal

Examples of org.apache.jetspeed.portal.Portlet


    {

        //record the begining of the portlet creation
        long begin = System.currentTimeMillis();

        Portlet portlet = null;
        Class portletClass = null;
        String handle = null;
       
        try
        {
            portletClass = Class.forName(classname);
        }
        catch (Exception e)
        {
            throw new PortletException( "PortletFactory: Unable to load class " + classname );
        }
       
        if (enableCache)
        {
            try
            {
                // try to invoke a static getHandle() for this class
                Class[] signatureParams = { Object.class };
                Object[] methodParams = { pc };
                handle = (String)portletClass.getMethod("getHandle",signatureParams)
                                             .invoke(null,methodParams);
                // make sure the handle is differenciated by class
                handle = String.valueOf(classname.hashCode())+handle;
            }
            catch (NoSuchMethodException e)
            {
                // ignore, this simply means the portlet is not cacheable
            }
            catch (Exception e)
            {
                // invocation failed or security exception, in both case
                // log the error and treat the class as non cacheable
                logger.error("PortletFactory: failed to get cache handle",e);
            }
        }
       
        try {

            if (enableCache && (handle != null))
            {
                portlet = (Portlet)PortletCache.getCacheable( handle );

                //portlet in cache but expired, remove it from cache
                if ((portlet!=null) && ((Cacheable)portlet).getExpire().isExpired() )
                {
                    logger.info( "The portlet (" + handle + ") is expired" );
                    PortletCache.removeCacheable(handle);
                    if ( logger.isDebugEnabled() )
                    {
                        logger.debug( "After removal of object(" + handle + ")." );
                    }
                    portlet = null;
                }
            }

            // we found a portlet in the cache
            if ( (portlet != null)
                 && ( portlet instanceof Cacheable )
                 && (! ((Cacheable)portlet).getExpire().isExpired()) )
            {
                // update the config for the portlet to the current one
                // Note: this is what was used to find the cached portlet.
                // Note: the init params may have changed in the psml since caching,
                //       this will update the portlet to use them.
                portlet.setPortletConfig( pc );
                portlet.setID( id );
                portlet.setName( pc.getName() );

                //FIXME: we now avoid to override metainfo when nothing is set
                //in the markup, so that cached portlets can keep their metainfo
                //This may lead to an incorrect metainfo retrieved if the first
                //instance of the portlet, which is put in the cache, has some
                //special metainfo defined in the markup

                MetaData meta = pc.getMetainfo();
               
                if ( meta != null)
                {

                    if (!DEFAULT_TITLE.equals( meta.getTitle() ) )
                    {
                        portlet.setTitle( meta.getTitle() );
                    }
   
                    if (!DEFAULT_DESCRIPTION.equals( meta.getDescription() ) )
                    {
                        portlet.setDescription( meta.getDescription() );
                    }
                }

                //FIXME: Notice here we are putting the portlet without wrapper
                //in the cache, and we must wrap it on return.
                //Security implications: the portletcache should not be
                //publicly accessible.
                //Alternative: we could wrap the portlet before putting
                //it in the cache.

                //now compute the time it took to instantate and log it...
                // time in millis, sugested by Thomas Schaeck (schaeck@de.ibm.com)
                long milliseconds = ( System.currentTimeMillis() - begin );
       
                if (logger.isDebugEnabled())
                    logger.debug( "PortletFactory.getPortlet(): found in cache in "
                        + milliseconds + " ms - handle: " + handle );

                return PortletWrapper.wrap( portlet );
            }

            // if not found in the cache, instanciate a new Portlet
            portlet = (Portlet)portletClass.newInstance();

        }
        catch ( Throwable t )
        {
            logger.error("Throwable", t);
            throw new PortletException( t.getMessage() );
        }

        // save the current meta-info
        String title = null;
        String description = null;
        MetaData metainfo = pc.getMetainfo();
       
        if ( metainfo != null ) {
            title=metainfo.getTitle();
            description=metainfo.getDescription();
        }
       
       
        // init the portlet, it may override its PSML defined markup if
        // it doesn't check for it
        portlet.setID( id );
        portlet.setName( pc.getName() );
        portlet.setPortletConfig( pc );
        portlet.setCreationTime( System.currentTimeMillis() );
        portlet.init();

        //force the title and description from markup metadata
        //in case the portlet overwrote some values

        if ( metainfo != null)
        {
            if (!DEFAULT_TITLE.equals(title) )
            {
                portlet.setTitle( title );
            }

            if (!DEFAULT_DESCRIPTION.equals(description) )
            {
                portlet.setDescription( description );
            }
        }

        if (enableCache && (portlet instanceof Cacheable))
        {
View Full Code Here


     * @deprecated Use getPortletById()
     */
    public ConcreteElement getPortlet(String name)
    {
        ConcreteElement result = null;
        Portlet found = null;
        Stack sets = new Stack();
        sets.push(rundata.getProfile().getRootSet());

        while ((sets.size() > 0) && (found == null))
        {
            PortletSet set = (PortletSet) sets.pop();

            if (set.getName().equals(name))
            {
                found = set;
            }
            else
            {
                Enumeration en = set.getPortlets();
                while ((found == null) && en.hasMoreElements())
                {
                    Portlet p = (Portlet) en.nextElement();

                    // unstack the controls to find the real PortletSets
                    Portlet real = p;
                    while (real instanceof PortletControl)
                    {
                        real = ((PortletControl) p).getPortlet();
                    }

View Full Code Here

     @param data the RunData for this request
     *  @return the portlet object of the appropriate customizer
     */
    public static Portlet getCustomizer(Portlet p)
    {
        Portlet customizer = p;

        while (p instanceof PortletControl)
        {
            p = ((PortletControl) p).getPortlet();
        }

        // if the portlet cannot customize itself...
        if (!p.providesCustomization())
        {

            //look for the customizer name in the portlet
            //config (from Registry definition)

            String name = p.getPortletConfig().getInitParameter("_customizer");

            if (name == null)
            {
                String key =
                    (p instanceof PortletSet) ? "PortletSet" : "Portlet";

                name =
                    JetspeedResources.getString(
                        "customizer." + key,
                        key + "Customizer");
            }

            try
            {
                customizer =
                    PortletFactory.getPortlet(name, p.getID() + "customize");
                customizer.getPortletConfig().setPortletSkin(
                    p.getPortletConfig().getPortletSkin());
                PortletControl control =
                    PortalToolkit.getControl((String) null);
                if (control != null)
                {
View Full Code Here

      @param data the RunData for this request
      *  @return the portlet object of the appropriate customizer
      */
    public static Portlet getPortletInfoPortlet(RunData data)
    {
        Portlet info = null;

        String name =
            JetspeedResources.getString(
                "PortletInfoPortlet.name",
                "PortletInfoPortlet");

        try
        {

            if (null != data)
            {
                JetspeedRunData jdata = (JetspeedRunData) data;
                Profile profile = jdata.getProfile();

                if (null == profile)
                {
                    logger.warn("JetspeedTool: profile is null");
                    profile = Profiler.getProfile(jdata);
                    jdata.setProfile(profile);
                }

                Portlet source = findPortlet(data);
                if (source != null)
                {
                    jdata.setPortlet(source.getName());
                    info =
                        PortletFactory.getPortlet(name, "PortletInfoPortlet");
                    info.getPortletConfig().setPortletSkin(
                        source.getPortletConfig().getPortletSkin());
                    PortletControl control =
                        PortalToolkit.getControl((String) null);
                    if (control != null)
                    {
                        control.setPortlet(info);
View Full Code Here

     * @return portlet identified by js_peid
     */
    private static Portlet findPortlet(RunData rundata)
    {

        Portlet found = null;
        JetspeedRunData jdata = (JetspeedRunData) rundata;
        String peid = jdata.getJs_peid();
        if (peid != null)
        {
            Stack sets = new Stack();
            sets.push(jdata.getProfile().getRootSet());

            while ((found == null) && (sets.size() > 0))
            {
                PortletSet set = (PortletSet) sets.pop();

                if (set.getID().equals(peid))
                {
                    found = set;
                }
                else
                {
                    Enumeration en = set.getPortlets();
                    while ((found == null) && en.hasMoreElements())
                    {
                        Portlet p = (Portlet) en.nextElement();

                        // unstack the controls to find the real PortletSets
                        Portlet real = p;
                        while (real instanceof PortletControl)
                        {
                            real = ((PortletControl) p).getPortlet();
                        }

                        if (real instanceof PortletSet)
                        {
                            if (real.getID().equals(peid))
                            {
                                found = real;
                            }
                            else
                            {
View Full Code Here

    public Object processView(GenericMVCContext context)
    {
      String result = "";
     
        Portlet portlet = (Portlet) context.get("portlet");
        RunData data = (RunData) context.get("data");
        HttpServletRequest request = data.getRequest();
        String template = (String) context.get("template");
        logger.info("JSPViewProcessor - processing template " + template);

        try
        {

            // Allow access to portlet from .jsp template
            request.setAttribute("portlet", portlet);

            // put context in attribute so you can get to it from .jsp template
            request.setAttribute("context", context);

            // Add js_peid out of convenience
            request.setAttribute("js_peid", portlet.getID());

            // Add rundata out of convenience (JspService.RUNDATA differs from GenericMVCPortlet.RUNDATA)
            request.setAttribute(JspService.RUNDATA, data);

            // Retrieve the URL. For backward compatibility, use the URL first
            // and then fallback to "template" parameter
            PortletEntry pe = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName());

            // Files referenced from default templates folder will be processed
            // using JspService. Otherwise, they will be loaded using EcsServletElement
            // from where ever they came from.
            if (pe.getURL() == null || pe.getURL().trim().length() == 0)
            {

                if (template != null && -1 == template.indexOf(".jsp"))
                {
                    template = template + ".jsp";
                }

                logger.info("JSPViewProcessor - locating template - " + data.toString()
                         + " - " + template);

                //we use the template locator to translate the template
                String locatedTemplate = TemplateLocator.locatePortletTemplate(data, template);
                logger.info("JSPViewProcessor - located template: " + locatedTemplate);

                /*if (locatedTemplate == null)
                {
                    locatedTemplate = TemplateLocator.locateScreenTemplate(data, template);
                    if (locatedTemplate != null)
                    {
                        locatedTemplate = "/screens" + locatedTemplate;
                    }
                    logger.debug("JSPViewProcessor - located screen template: " + locatedTemplate);
                } */

                JetspeedJspService service = (JetspeedJspService) ServiceUtil.getServiceByName(JspService.SERVICE_NAME);

                // this is only necessary if we don't run in a JSP page environment
                // but better be safe than sorry...
                service.addDefaultObjects(data);

                // handle request
                result = service.handleBufferedRequest(data, locatedTemplate, false);

            }
            else
            {
                // Build parameter list to be passed with the jsp
                Iterator names = portlet.getPortletConfig().getInitParameterNames();
                while (names.hasNext())
                {
                    String name = (String) names.next();
                    String value = (String) portlet.getPortletConfig().getInitParameter(name);
                    data.getParameters().setString(name, value);
                }

                template = pe.getURL();

View Full Code Here

                        result =
                            new StringElement("not implemented - PortletElement");
                    }
                    else
                    {
                        Portlet p = PortletFactory.getPortlet(entry);
                        if (p != null)
                        {
                            result = p.getContent(rundata);
                        }
                        else
                            result =
                                new StringElement("Error retrieving PortletElement");
View Full Code Here

        while ( portlets.hasMoreElements() ) {

            PortletEntry entry = (PortletEntry)portlets.nextElement();
           
            String url = PortletURIManager.getPortletMaxURI( entry, data ).toString();
            Portlet portlet = null;
            try {
                portlet = PortletFactory.getPortlet(entry.getName(), "0");
            } catch (PortletException e) {
                continue;
            }
            A anchor = new A( url ).addElement( portlet.getTitle() );
            table.addElement( new TR().addElement( new TD().addElement( anchor ) ) );
            table.addElement( new TR().addElement( new TD().addElement( portlet.getDescription() ) ) );
        }

        return table;

    }
View Full Code Here

     * @return the rendered content of the portlet
     */
    public ConcreteElement getPortletById(String peid, boolean returnNull)
    {
        ConcreteElement result = null;
        Portlet found = null;
        Stack sets = new Stack();
        sets.push(rundata.getProfile().getRootSet());

        while ((sets.size() > 0) && (found == null))
        {
            PortletSet set = (PortletSet) sets.pop();

            if (set.getID().equals(peid))
            {
                found = set;
            }
            else
            {
                Enumeration en = set.getPortlets();
                while ((found == null) && en.hasMoreElements())
                {
                    Portlet p = (Portlet) en.nextElement();

                    // unstack the controls to find the real PortletSets
                    Portlet real = p;
                    while (real instanceof PortletControl)
                    {
                        real = ((PortletControl) p).getPortlet();
                    }

View Full Code Here

     */
    public ConcreteElement getPortletFromRegistry(RunData data)
    {

        ConcreteElement result = null;
        Portlet p = null;
        String portletName = data.getParameters().getString("p");
        String controlName = data.getParameters().getString("c");

        try
        {

            // Retrieve registry entry
            PortletEntry entry =
                (PortletEntry) Registry.getEntry(Registry.PORTLET, portletName);

            // Verify security for the parameter
            boolean canAccess =
                JetspeedSecurity.checkPermission(
                    (JetspeedUser) data.getUser(),
                    new PortalResource(entry),
                    JetspeedSecurity.PERMISSION_CUSTOMIZE);

            if (canAccess)
            {
                // Always set portlet id to "preview" so each preview request gets it from the cache.
                // At least, I think that's how it works.
                p = PortletFactory.getPortlet(portletName, "preview");
                PortletControl control =
                    controlName == null
                        ? PortalToolkit.getControl((String) null)
                        : PortalToolkit.getControl(controlName);
                if (control != null)
                {
                    JetspeedRunData jdata = (JetspeedRunData) rundata;
                    // Use the profile's skin
                    p.getPortletConfig().setPortletSkin(
                        PortalToolkit.getSkin(
                            jdata
                                .getProfile()
                                .getDocument()
                                .getPortlets()
                                .getSkin()));
                    control.setPortlet(p);
                    control.init();
                    result = control.getContent(rundata);
                }
                else if (p != null)
                {
                    result = p.getContent(rundata);
                }
            }
            else
            {
                result =
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.portal.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.