Package org.apache.jetspeed.portal

Examples of org.apache.jetspeed.portal.Portlet


        }

        int count = 0;
        for (Enumeration en = portlets.getPortlets(); en.hasMoreElements(); count++)
        {
            Portlet p = (Portlet) en.nextElement();
            PortalResource portalResource = new PortalResource(p);

            // Secure the tabs
            try
            {
                JetspeedLink jsLink = JetspeedLinkFactory.getInstance(rundata);
                portalResource.setOwner(jsLink.getUserName());
                JetspeedLinkFactory.putInstance(jsLink);
            }
            catch (Exception e)
            {
                logger.warn(e.toString(), e);
                portalResource.setOwner(null);
            }
            JetspeedRunData jdata = (JetspeedRunData) rundata;
            boolean hasView = JetspeedSecurity.checkPermission((JetspeedUser) jdata.getUser(),
                                                                portalResource,
                                                                JetspeedSecurity.PERMISSION_VIEW);
            if (!hasView)
            {
                continue;
            }
            // skip any closed portlet
            if ((p instanceof PortletState) && (((PortletState) p).isClosed(rundata)))
            {
                continue;
            }           

            String mstate = p.getAttribute("_menustate", null, rundata);
            PortletConfig pc= p.getPortletConfig();
            if (mstate == null && pc != null)
            {
                mstate = pc.getInitParameter("_menustate", "open");
            }
           
            if (mstate.equals("closed"))
            {
                continue;
            }

            PortletTab tab = new PortletTab();
           
            // Handle the portlet title
            String title = null;           
            PortletInstance pi = PersistenceManager.getInstance(p, rundata);
            if (pi != null)
            {
                title = pi.getTitle();
                if (title == null)
                {
                    title = (p.getTitle() != null) ? p.getTitle() : p.getName();
                }
            }
            tab.setTitle(title);

            tab.setPosition(p.getPortletConfig().getPosition());
            if (tabs.contains(tab))
            {
                PortletTab lastTab = (PortletTab) tabs.last();
                int nextPos = lastTab.getPosition() + 1;
                tab.setPosition(nextPos);           
View Full Code Here


     
        //see if any or the Portlets you want to add have a larger column or
        //row number than that defined in PSML
        while ( en.hasMoreElements() ) {

            Portlet portlet = (Portlet)en.nextElement();

            calculateControllerLayout( portlet );
           
        }

        setWidth( pc.getLayout( "width", getWidth() ) );

        int rows = getRow();
        int cols = getColumn();

        if (0 == rows || 0 == cols)
            return base; // empty container

        Table t = new Table()
                       .setWidth( this.getWidth() )
                       .setCellPadding( this.getPadding() )
                       .setAlign("center");

        base.addElement( t );

        ElementContainer[][] elements = new ElementContainer[rows][cols];

        for( int i = 0; i < rows; i++ )  {
            for ( int j = 0 ; j < cols; j++ ) {
                elements[i][j]=new ElementContainer();
            }
        }

        // populate the elements array
        en = portlets.getPortlets();
        while (en.hasMoreElements() ) {

            Portlet p = (Portlet)en.nextElement();
            PortletConfig pConf = p.getPortletConfig();

            Integer colObj = pConf.getConstraints().getColumn();
            Integer rowObj = pConf.getConstraints().getRow();
            int colnum = (colObj!=null)?colObj.intValue():0;
            int rownum = (rowObj!=null)?rowObj.intValue():0;

            elements[rownum % rows][colnum % cols]
                .addElement( p.getContent( rundata ) );

        }

        // build the table
View Full Code Here

     *
     * @param rundata the RunData for the request
     */
    public ConcreteElement getContent(RunData rundata)
    {
        Portlet portlet = getPortlet();
        if (portlet == null)
        {
            return new ElementContainer();
        }
       
        // Check to see if the portlet allows view
        // If the current security context disallows view,
        // do not display the portlet OR the control decorator
        if (portlet instanceof PortletWrapper)
        {
            PortletWrapper wrapper = (PortletWrapper)portlet;
            if (!wrapper.getAllowView(rundata))
            {
                if (JetspeedResources.getBoolean("defaultportletcontrol.hide.decorator", true))
                {
                    return new StringElement("");
                }
            }
        }
       
        return portlet.getContent( rundata );
    }
View Full Code Here

    /**
     * Handles the content generation for this control using Velocity
     */
    public ConcreteElement getContent( RunData rundata )
    {
        Portlet portlet = getPortlet();
        JetspeedRunData jdata = (JetspeedRunData)rundata;
       
        // Check to see if the portlet allows view
        // If the current security context disallows view,
        // do not display the portlet OR the control decorator
        if (portlet instanceof PortletWrapper)
        {
            PortletWrapper wrapper = (PortletWrapper)portlet;
            if (!wrapper.getAllowView(rundata))
            {
                if (JetspeedResources.getBoolean("defaultportletcontrol.hide.decorator", true))
                {               
                    return new StringElement("");
                }
            }
        }

        // Create a new Velocity context and load default
        // application pull tools
        Context context = TurbineVelocity.getContext();
       
        context.put("data", rundata );
        context.put("actions", buildActionList( rundata, portlet ) );
        context.put("conf", getConfig() );
        context.put("skin", portlet.getPortletConfig().getPortletSkin() );

        // Put the request and session based contexts
        TurbinePull.populateContext(context, rundata);
       
        if ( portlet.getName().equals(jdata.getCustomized())
             && (!portlet.providesCustomization()) )
        {           
            context.put("portlet",JetspeedTool.getCustomizer(portlet));
            context.put("portlet_instance",JetspeedTool.getCustomizer(portlet));
        }
        else
View Full Code Here

    /**
    */
    public ConcreteElement getContent( RunData rundata )
    {
        // Get the data here to allow the portlet to change some internal state
        Portlet portlet = getPortlet();
        String  portletName = portlet.getName();
        ConcreteElement portletContent = portlet.getContent( rundata );

        // default links for buttons (means non visible)
        String hrefConfigure = "";
        String hrefMinimize  = "";
        String hrefRestore   = "";
        String hrefMaximize  = "";
        String hrefClose     = "";

        // i don't like this, but ...
        if( portlet instanceof AbstractVTLPortlet)
        {
            // only AbstractVTLPortlet gives me this functionality
            AbstractVTLPortlet xPortlet = (AbstractVTLPortlet)portlet;
   
            // configure button
            if( xPortlet.getAllowEdit( rundata ) )
            {
                hrefConfigure=new DynamicURI( rundata )
                                    .addPathInfo("portlet", portletName)
                                    .addPathInfo("button","configure")
                                    .toString();
            }
   
            // minimize/restore button
            if( xPortlet.getAllowMinimize( rundata ) )
            {
                if( xPortlet.isMinimized( rundata ) )
                {
                    hrefRestore=new DynamicURI( rundata )
                                    .addPathInfo("action", "portlets.RestorePortlet")
                                    .addPathInfo("portletName", portletName)
                                    .toString();
                }
                else
                {
                    hrefMinimize=new DynamicURI( rundata )
                                    .addPathInfo("action", "portlets.MinimizePortlet")
                                    .addPathInfo("portletName", portletName)
                                    .toString();
                }
            }
   
            // maximize button
            if( xPortlet.getAllowMaximize( rundata ) )
            {
                hrefMaximize=new DynamicURI( rundata )
                                    .addPathInfo("portlet", portletName)
                                    .addPathInfo("button","maximize")
                                    .toString();
            }
   
            // close button
            if( xPortlet.getAllowClose( rundata ) )
            {
                hrefClose=new DynamicURI( rundata )
                                    .addPathInfo("action", "portlets.ClosePortlet")
                                    .addPathInfo("portletName", portletName)
                                    .toString();
            }
        }

        // Hmmm, let's works like TitlePortletControl
        else
        {
            if ( portlet.getAllowEdit( rundata ) )
            {
                try
                {
                      hrefConfigure = URILookup.getURI( URILookup.TYPE_INFO,
                                                        URILookup.SUBTYPE_MARK,
                                                        portlet, rundata );
                }
                catch (JetspeedException e) {}
            }

            if ( portlet.getAllowMaximize( rundata ) )
            {
                try
                {
                      hrefMaximize = URILookup.getURI( URILookup.TYPE_HOME,
                                                       URILookup.SUBTYPE_MAXIMIZE,
View Full Code Here

        context.put(
            "securitys",
            CustomizeSetAction.buildList(rundata, Registry.SECURITY));

        // we should first retrieve the portlet to customize
        Portlet p = ((JetspeedRunData) rundata).getCustomized();

        context.put("action", "portlets.CustomizeAction");

        PortletInstance instance = PersistenceManager.getInstance(p, rundata);
        context.put(
            "portlet_instance",
            PersistenceManager.getInstance(p, rundata));

        if (p == null)
            return;

        // retrieve the portlet parameters
        PortletEntry entry =
            (PortletEntry) Registry.getEntry(Registry.PORTLET, p.getName());
        // save the entry in the session
        Vector params = new Vector();
        Iterator i = entry.getParameterNames();

        //System.out.println("==========================================");
        while (i.hasNext())
        {
            String name = (String) i.next();
            Parameter param = entry.getParameter(name);

            // filter some "system" and hidden parameters
            if ((!param.isHidden()) && (name.charAt(0) != '_'))
            {
                // check the user role
                if (JetspeedSecurity
                    .checkPermission(
                        (JetspeedUser) rundata.getUser(),
                        new PortalResource(entry, param),
                        JetspeedSecurity.PERMISSION_CUSTOMIZE))
                {
                    // Implementation of clone() is missing so we have do it "by hand"
                    Parameter clone = new BaseParameter();
                    clone.setName(param.getName());
                    clone.setTitle(param.getTitle());
                    clone.setDescription(param.getDescription());
                    clone.setType(param.getType());
                    if (instance.getAttribute(name, null) != null)
                    {
                        clone.setValue(instance.getAttribute(name));
                        //System.out.println("Adding value from instance [" + name + "] = [" + clone.getValue() + "]");
                    }
                    else if (
                        p.getPortletConfig().getInitParameter(name) != null)
                    {
                        clone.setValue(
                            p.getPortletConfig().getInitParameter(name));
                        //System.out.println("Adding value from init [" + name + "] = [" + clone.getValue() + "]");
                    }
                    else
                    {
                        clone.setValue(param.getValue());
                        //System.out.println("Adding value from registry [" + name + "] = [" + clone.getValue() + "]");
                    }
                    params.add(clone);
                }
            }
        }

        // get the customization state for this page
        SessionState customizationState =
            ((JetspeedRunData) rundata).getPageSessionState();
        customizationState.setAttribute("customize-parameters", params);

        // populate the customizer context
        context.put("parameters", params);
        context.put("portlet", p);
        context.put("customizer", portlet);

        if (p.getPortletConfig().getSecurityRef() != null)
            context.put(
                "security_ref",
                p.getPortletConfig().getSecurityRef().getParent());
        if (p.getPortletConfig().getSkin() != null)
            context.put(
                "current_skin",
                p.getPortletConfig().getPortletSkin().getName());

        Entry psmlEntry =
            ((JetspeedRunData) rundata)
                .getProfile()
                .getDocument()
                .getEntryById(
                p.getID());
        if (psmlEntry.getControl() != null)
            context.put("current_control", psmlEntry.getControl().getName());

        Profile profile = ((JetspeedRunData) rundata).getCustomizedProfile();
        String currentTitle =
            profile.getDocument().getEntryById(p.getID()).getTitle();
        if (currentTitle == null && p.getPortletConfig().getMetainfo() != null)
        {
            currentTitle = p.getPortletConfig().getMetainfo().getTitle();
        }
        context.put("current_title", currentTitle);

    }
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
View Full Code Here

        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");
        String newControlName =
            (String) rundata.getParameters().getString("_control");

        boolean changeRequested =
            ((params != null)
                || (newSkinName != null)
                || (newSecurityParent != null)
                || (newTitle != null)
                || (newControlName != 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;
                }
            }
        }

    // Only update the control if the name changed
    if (newControlName != null)
    {
      boolean controlChanged = false;
      String currentControlName = null;

      if (entry.getControl() != null)
        currentControlName = entry.getControl().getName();

      if (currentControlName != null)
      {
        controlChanged = (newControlName.equals(currentControlName) == false);
      }
      else
      {
        controlChanged = (newControlName.trim().length() > 0);
      }

      if (controlChanged == true)
      {
        PortletControl control = null;
        if ((newControlName.trim().length() > 0))
        {
          control = PortalToolkit.getControl(newControlName);
          if (control != null)
          {
            Control psmlControl = new PsmlControl();
            psmlControl.setName(newControlName);
            entry.setControl(psmlControl);
          }
          else
          {
            logger.warn(
              "Unable to update control for portlet entry "
                + entry.getId()
                + " because control "
                + newControlName
                + " does not exist.");
          }
        }
        else
        {
          entry.setControl(null);
        }
        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

        Enumeration en = set.getPortlets();
        int row = 0;
        int col = 0;
        while (en.hasMoreElements())
        {
            Portlet p = (Portlet) en.nextElement();

            PortletSet.Constraints
                constraints = p.getPortletConfig().getConstraints();

            if ((constraints != null)
                 && (constraints.getColumn() != null)
                 && (constraints.getRow() != null))
            {
                col = constraints.getColumn().intValue();
                if (col > colNum)
                {
                    constraints.setColumn(new Integer(col % colNum));
                }

                row = constraints.getRow().intValue();
                if (row > rowNum)
                {
                    rowNum = row;
                }
            }
        }
        row = (int) Math.ceil(set.size() / colNum);
        if (row > rowNum)
        {
            rowNum = row;
        }

        if ( logger.isDebugEnabled() ) {
            logger.debug("Controller calculated setSize " + set.size() + " row " + row + " colNum: " + colNum +  " rowNum: " + rowNum);
        }
        // initialize the result position table and the work list
        List[] table = new List[colNum];
        List filler = Collections.nCopies(rowNum + 1, null);
        for (int i = 0; i < colNum; i++)
        {
            table[i] = new ArrayList();
            table[i].addAll(filler);
        }

        List work = new ArrayList();

        //position the constrained elements and keep a reference to the
        //others
        for (int i = 0; i < set.size(); i++)
        {
            Portlet p = set.getPortletAt(i);

            PortletSet.Constraints
                constraints = p.getPortletConfig().getConstraints();

            if ((constraints != null)
                 && (constraints.getColumn() != null)
                 && (constraints.getRow() != null)
                 && (constraints.getColumn().intValue() < colNum))
View Full Code Here

                PortletEntry entry =
                    (PortletEntry) Registry.getEntry(Registry.PORTLET, psmlEntry.getParent());

                if (entry != null)
                {
                    Portlet p = PortletFactory.getPortlet(psmlEntry);

                    if (p != null)
                    {
                        Map constraints = getParameters(psmlEntry.getLayout());
                        int position = getPosition(psmlEntry.getLayout());
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.