Package org.apache.jetspeed.portal

Examples of org.apache.jetspeed.portal.Portlet


    }

    public Object processView(GenericMVCContext context)
    {

        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);
                } */

                JspService service = (JspService) 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
                service.handleRequest(data, locatedTemplate);

            }
            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


     */
    public void doDefault(RunData rundata, Context context)
    {                   
        // we should first retrieve the portlet to customize and its parameters
        // definition
        Portlet p = ((JetspeedRunData) rundata).getCustomized();

        // Update paramaters
        try
        {
            PortletInstance instance = PersistenceManager.getInstance(p, rundata);

            instance.removeAllAttributes();

            try
            {
                ((JetspeedRunData) rundata).getCustomizedProfile().store();
            }
            catch (Exception e)
            {
                logger.error("Unable to save profile ",e);
            }

            //FIXME: this hack is due to the corrupted lifecycle of the portlet in the
            //current API when caching is activated
            try
            {
                org.apache.jetspeed.util.PortletSessionState.setPortletConfigChanged(p, rundata);
                p.init();
            }
            catch (PortletException e)
            {
                logger.error("Customizer failed to reinitialize the portlet "+p.getName(), e);
            }

            // we're done, make sure clean up the
            // session
            doCancel(rundata, context);
View Full Code Here

        // get the customization state for this page
        SessionState customizationState = ((JetspeedRunData)rundata).getPageSessionState();

        // we should first retrieve the portlet to customize and its parameters
        // definition
        Portlet p = ((JetspeedRunData)rundata).getCustomized();
        Vector params = (Vector) customizationState.getAttribute("customize-parameters");
        String newSecurityParent = rundata.getParameters().getString("_security_ref");
        String newSkinName = (String) rundata.getParameters().getString("_skin");
        String newTitle = (String) rundata.getParameters().getString("current_title");

        boolean changeRequested = ( (params != null) || (newSkinName != null) || (newSecurityParent != null) || (newTitle != null));
        boolean madePsChange = false;
        boolean madePcChange = false;

        if ((p==null) || (changeRequested == false ))
        {
            doCancel(rundata, context);
            return;
        }
        PortletConfig pc = p.getPortletConfig();
        Profile profile = ((JetspeedRunData)rundata).getCustomizedProfile();
        Entry entry = profile.getDocument().getEntryById(p.getID());

        // Only update the security ref if the parent changed
        if ((newSecurityParent != null))
        {
            boolean securityChanged = false;
            SecurityReference currentSecurityRef = pc.getSecurityRef();
            if (currentSecurityRef != null)
            {
                securityChanged = (newSecurityParent.equals(currentSecurityRef.getParent()) == false);
            }
            else
            {
                securityChanged = (newSecurityParent.trim().length() > 0);
            }
            if (securityChanged == true)
            {
                SecurityReference securityRef = null;
                if ((newSecurityParent.trim().length() > 0))
                {
                    securityRef = new BaseSecurityReference();
                    securityRef.setParent( newSecurityParent);
                }
                // Note: setting the portlet's config may not be a good idea -
                // it might be used as the Portlet for other PSMLDocument Entries that
                // have a different idea of security - and the caching of Portlets does
                // NOT include security -ggolden.
                pc.setSecurityRef(securityRef);
                entry.setSecurityRef(securityRef);
                madePcChange = true;
            }
        }

        // Only update the skin if the name changed
        if (newSkinName != null)
        {
            boolean skinChanged = false;
            String currentSkinName = null;

            if  (pc.getSkin() != null)
                currentSkinName = pc.getPortletSkin().getName();

            if (currentSkinName != null)
            {
                skinChanged = (newSkinName.equals(currentSkinName) == false);
            }
            else
            {
                skinChanged = (newSkinName.trim().length() > 0);
            }

            if (skinChanged == true)
            {
                PortletSkin skin = null;
                if ((newSkinName.trim().length() > 0))
                {
                    skin = PortalToolkit.getSkin(newSkinName);
                    if (skin != null)
                    {
                        // Note: setting the portlet's config may not be a good idea -
                        // it might be used as the Portlet for other PSMLDocument Entries that
                        // have a different idea of skin - and the caching of Portlets does
                        // NOT include skin -ggolden.
                        pc.setPortletSkin(skin);

                        Skin psmlSkin = entry.getSkin();
                        if (psmlSkin == null)
                        {
                            entry.setSkin(new PsmlSkin());
                        }
                        entry.getSkin().setName(newSkinName);
                    }
                    else
                    {
                        logger.warn( "Unable to update skin for portlet entry " + entry.getId() + " because skin " + skin + " does not exist.");
                    }
                }
                else
                {
                    // Note: setting the portlet's config may not be a good idea -
                    // it might be used as the Portlet for other PSMLDocument Entries that
                    // have a different idea of skin - and the caching of Portlets does
                    // NOT include skin -ggolden.
                    pc.setPortletSkin( null);
                    entry.setSkin(null);
                }
                madePcChange = true;
            }
        }

        // Only update the title if the title changed
        if (newTitle != null)
        {
            boolean titleChanged = false;
            String currentTitle = entry.getTitle();

            MetaData md = pc.getMetainfo();
            if  (currentTitle == null && md != null && md.getTitle() != null)
                currentTitle = md.getTitle();

            if (currentTitle != null)
            {
                titleChanged = (newTitle.equals(currentTitle) == false);
            }
            else
            {
                titleChanged = (newTitle.trim().length() > 0);
            }

            if (titleChanged == true)
            {

                if ((newTitle.trim().length() > 0))
                {
                    // Note: setting the portlet's config may not be a good idea -
                    // it might be used as the Portlet for other PSMLDocument Entries that
                    // have a different idea of title - and the caching of Portlets does
                    // NOT include title -ggolden.
                    if (md == null) {
                        md = new MetaData();
                        pc.setMetainfo(md);
                    }
                    md.setTitle(newTitle);
                    entry.setTitle(newTitle);
                    madePcChange = true;
                }
            }
        }

        // Update paramaters
        try
        {
            PortletInstance instance = PersistenceManager.getInstance(p, rundata);
            PortletEntry regEntry = (PortletEntry) Registry.getEntry(Registry.PORTLET, p.getName());

            Iterator i = params.iterator();

            //System.out.println("==========================================");
            while(i.hasNext())
            {
                Parameter param = (Parameter)i.next();
                String name = param.getName();
                String newValue = null;
                String[] testArray = rundata.getParameters().getStrings(name);
                if (testArray != null && testArray.length > 1)
                {
                    newValue = org.apache.jetspeed.util.StringUtils.arrayToString(testArray, ",");
                }
                else
                {
                    newValue = rundata.getParameters().getString(name);
                    if (newValue == null)
                    {
                        newValue = "";
                    }
                }
                String regValue = regEntry.getParameter(name).getValue(); //param.getValue();
                String psmlValue = instance.getAttribute(name);

                //System.out.println(name + "= [" + psmlValue + "] in psml");
                //System.out.println(name + "= [" + regValue + "] in registry");

                // New value for this parameter exists
                if (newValue != null)
                {
                    //System.out.println(name + "= [" + newValue + "] in request");
                    // New value differs from registry - record it in psml
                    if (!regValue.equals(newValue) || !psmlValue.equals(newValue))
                    {
                        instance.setAttribute(name, newValue);
                        psmlValue = newValue;
                        //System.out.println("setting attribute for [" + name + "] to [" + newValue + "]");
                    }
                    madePsChange = true;
                }
                // Remove duplicate parameters from psml
                if (psmlValue != null && psmlValue.equals(regValue))
                {
                    //System.out.println("removing attribute for [" + name + "]");
                    instance.removeAttribute(name);
                    madePsChange = true;
                }

            }

            // save all the changes
            if ((madePsChange == true) || (madePcChange == true))
            {
                try
                {
                    JetspeedRunData jdata = (JetspeedRunData) rundata;
                    profile.store();
                    //FIXME: this hack is due to the corrupted lifecycle of the portlet in the
                    //current API when caching is activated
                    p.init();
                    org.apache.jetspeed.util.PortletSessionState.setPortletConfigChanged(p, rundata);
                }
                catch (PortletException e)
                {
                    logger.error("Customizer failed to reinitialize the portlet "+p.getName(), e);
                }
                catch (Exception e)
                {
                    logger.error("Unable to save profile ",e);
                }
View Full Code Here

    {
        // customization state info is in the page's session state
        SessionState customizationState = getPageSessionState();
        Stack stack = (Stack)customizationState.getAttribute("customize-stack");

        Portlet p = null;

        if ((stack!=null)&&(!stack.empty()))
        {
            p = (Portlet)stack.peek();
        }

        /**
         * Save the title of this currently selected portlet
         * --------------------------------------------------------------------------
         * last modified: 11/06/01
         * Andreas Kempf, Siemens ICM S CP PE, Munich
         */
        if ((p != null) && (stack.size() > 1))
          customizationState.setAttribute ("customize-paneName", (String)p.getTitle());
        else
          customizationState.setAttribute ("customize-paneName", "*");

        return (Portlet)p;
    }
View Full Code Here

        }
        else
        {
          if (stack.size () > 0)
          {
            Portlet last = (Portlet)stack.peek();


            if ((last!=null) && (p.getName().equals(last.getName())) && (p.getTitle().equals(last.getTitle())))
            {
                //System.out.println ("Portlet already used!!!");
            }
            else
              stack.push(p);
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

            String message = "Could not find given entry ";
            logger.error( message );
            return new StringElement( message );
        }

        Portlet portlet = null;
        try {
            portlet = PortletFactory.getPortlet( portletName, "0" );
        } catch (PortletException e) {
            logger.error("Exception",  e);
            return new StringElement( e.getMessage() );
        }

        Table t = new Table();
       
        t.addElement( this.getRow"Portlet name: " + portlet.getName() ) );

        String url = portlet.getPortletConfig().getURL();
        if ( url != null ) {
            t.addElement( this.getRow( "From URL: " + url ) );

            try {
                long urlUpdated = JetspeedDiskCache.getInstance().getEntry( url ).getLastModified();
                t.addElement( this.getRow( "URL last updated:  " + df.format( new Date(urlUpdated) ) ) );
                long urlExpires = JetspeedDiskCache.getInstance().getEntry( url ).getExpirationTime();
                t.addElement( this.getRow( "URL expires:  " + df.format( new Date(urlExpires) ) ) );
            } catch ( IOException e ) {
                logger.error("Exception",  e);
            }
        }

        t.addElement( this.getRow( "Portlet last updated:  " + df.format( new Date(portlet.getCreationTime()) ) ) );



        //BEGIN 3RD PARTY REPL


        t.addElement( new TR().addElement( new TD()
            .addElement( new B().addElement( "Actions:" ) ) ) );
           
        String internal = null;
        JetspeedLink jsLink = null;

        try
        {
            jsLink = JetspeedLinkFactory.getInstance(rundata);
            String mtype = rundata.getParameters().getString("mtype");
            if (mtype != null)
            {
                jsLink.setMediaType(mtype);
                jsLink.addQueryData("mtype", mtype);
            }
            String js_peid = rundata.getParameters().getString("js_peid");
            // FIX ME: If the portlet is viewed in Avantgo and then portlet info is restored, the portlet will
            // be maximized (similar to customizing certain portlet types. The desired effect would be to
            // set the portlet's mode to normal.
            internal = jsLink.addPathInfo("js_peid", js_peid).setAction("controls.Maximize").toString();
        }
        catch (Exception e)
        {
            logger.error("Exception",  e);
        }
        JetspeedLinkFactory.putInstance(jsLink);

        StringBuffer external = new StringBuffer( getPortletConfig().getInitParameter( THIRDPARTY_PORTLETRENDERER_URL_KEY ) );

        //this is the parameters of what so specify to the 3rd party provider
        external.append("&title=" + URLEncoder.encode( portlet.getTitle() ) );
        external.append("&url=" + URLEncoder.encode(internal));

        String message = getPortletConfig().getInitParameter( THIRDPARTY_PORTLETRENDERER_CAPTION_KEY );

        t.addElement( new TR()
            .addElement( new TD()
                .addElement( new A( external.toString() ).setTarget("_blank").addElement( message ) ) ) );

        //END 3RD PARTY REPL

           
        // BEGIN MIME TYPE SUPPORT
        /* RL: Temporarily disable mime support while changing registry
         t.addElement( new TR().addElement( new TD()
            .addElement( new B().addElement( "Mime Types:" ) ) ) );

        MimeType[] mts = portlet.getPortletConfig().getCapabilityMap().getMimeTypes();
           
        for ( int i = 0; i < mts.length; ++i ) {
               
            t.addElement( new TR()
                .addElement( new TD( mts[i].toString() ) ) );
               
        }
         */     

        //END MIME TYPE SUPPORT
           
        //BEGIN PROPERTIES SECTION
                               
        Iterator names= portlet.getPortletConfig().getInitParameterNames();

        if ( names.hasNext() ) {
            //OK... add the Properties from the Portet to this info set...
            t.addElement( new TR().addElement( new TD()
                .addElement( new B().addElement( "Properties:" ) ) ) );

        }
           
        while ( names.hasNext() ) {
               
            String name = (String)names.next();
            String value = (String)portlet.getPortletConfig().getInitParameter( name );

            t.addElement( new TR()
                .addElement( new TD( name + ":  " + value ) ) );
               
        }
View Full Code Here

        PanedPortletController cont = (PanedPortletController)controller;
       
        PortletSet myPortlets = cont.getPortlets();
        PortletControllerConfig conf = cont.getConfig();

        Portlet portlet = null;
        String paneID = null;
        String paneName = rundata.getParameters().getString( JetspeedResources.PATH_PANENAME_KEY );

        if (null != paneName)       
        {
            portlet = myPortlets.getPortletByName(paneName);
            if (portlet != null)
            {
                paneID = portlet.getID();
                rundata.getParameters().setString(JetspeedResources.PATH_PANEID_KEY, paneID);
            }
        }

        if (null == portlet)
View Full Code Here

                rundata.setScreenTemplate("Home");
                return new JetspeedClearElement("");
            }
            //return new JetspeedClearElement("You must specify portlet to preview using [previewedPortletName] parameter");
        }
        Portlet portlet = null;

        try
        {
            portlet = PortletFactory.getPortlet(portletName, "PreviewPortlet");
            PortletControl control = controlName == null ? PortalToolkit.getControl((String)null) :
                                     PortalToolkit.getControl(controlName);
            control = null;
            if ( control != null )
            {
                JetspeedRunData jdata = (JetspeedRunData)rundata;
                // Use the profile's skin
                //portlet.getPortletConfig().setSkin(PortalToolkit.getSkin(jdata.getProfile().getDocument().getPortlets().getSkin()));
                control.setPortlet(portlet);
                control.init();
                result = control.getContent(rundata);
            }
            else if ( portlet != null )
            {
                result = portlet.getContent(rundata);
            }

            if ( result != null && !result.toString().equals("") )
            {
                /*String html =  result.toString();
View Full Code Here

        Iterator eItr = portlets.getEntriesIterator();
        while(eItr.hasNext())
        {
            Object obj =  eItr.next();
            Entry entry = (Entry)obj;
            Portlet portlet = PortletFactory.getPortlet(entry);
            entries.add(new JetspeedPortletInstance(portlet, profile));
        }
       
        //Now if there are child levels, drill down recursively
        if(portlets.getPortletsCount() > 0)
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.