customizesetaction.java

来自「jetspeed源代码」· Java 代码 · 共 1,280 行 · 第 1/4 页

JAVA
1,280
字号
                    if (addIt)
                    {
                      Entry p = new PsmlEntry();
                      // add the ClearPortletControl to wml entries      
                      //if (isWML)
                      //  p.setControl (ctrl);
                    
                      p.setParent(pnames[i]);
                      p.setId(JetspeedIdGenerator.getNextPeid());
//                      SecurityReference defaultRef = PortalToolkit.getDefaultSecurityRef(
//                          ((JetspeedRunData) rundata).getCustomizedProfile());
//                      if (defaultRef != null)
//                      {
//                          if (Log.getLogger().isDebugEnabled())
//                          {
//                              Log.debug("CustomizeSetAction: setting default portlet security to [" + defaultRef.getParent() + "]");
//                          }
//                          p.setSecurityRef(defaultRef);
//                      }
                      portlets.addEntry(p);
                    }
                }
            }
        }
        // --------------------------------------------------------------------------

        SessionState customizationState = ((JetspeedRunData) rundata).getPageSessionState();
        customizationState.setAttribute("customize-mode", "layout");

        /** 
         * Save changed wml profile
         * --------------------------------------------------------------------------
         * last modified: 10/31/01
         * Andreas Kempf, Siemens ICM S CP PE, Munich
         * mailto: A.Kempf@web.de
        if (isWML)
        {
          ((JetspeedRunData)rundata).getCustomizedProfile().store();
          //rundata.save();
        }
         */
        
    }

    /** Add new Reference in the customized set */
    public void doAddref(RunData rundata, Context context) throws Exception
    {
        PortletSet set = (PortletSet) ((JetspeedRunData) rundata).getCustomized();
        String[] refNames = rundata.getParameters().getStrings("refname");
        
        // Create a ClearPortletControl
        Control ctrl = new PsmlControl();
        ctrl.setName ("ClearPortletControl");

        
        if ((refNames != null) && (set != null))
        {
            Portlets portlets = ((JetspeedRunData) rundata).getCustomizedProfile()
                                                           .getDocument()
                                                           .getPortletsById(set.getID());

            for (int i = 0; i < refNames.length; i++)
            {
                SecurityReference sref = getSecurityReference(rundata, refNames[i]);
                if (sref != null)
                {
                    Reference ref = new PsmlReference();
                    ref.setPath(refNames[i]);              
                    ref.setSecurityRef(sref);
                    portlets.addReference(ref);
                }
                else
                {
                    String tmpl = CustomLocalization.getString("CUSTOMIZER_ADD_REF_ERROR", rundata);
                    Object[] args = {
                        refNames[i]
                    };
                    String message = MessageFormat.format(tmpl, args).toString();

                    rundata.addMessage(message.concat("<br>"));
                    if (logger.isWarnEnabled())
                    {
                        logger.warn(message);
                    }
                }
            }
        }
        SessionState customizationState = ((JetspeedRunData) rundata).getPageSessionState();
        customizationState.setAttribute("customize-mode", "layout");
    }

    /**
     * Get the security reference from the outer portlet set
     *
     * @param path the psml locator path
     * @return the security reference of the referenced resource     
     */
    protected SecurityReference getSecurityReference(RunData rundata, String path)
    {
        try
        {
            ProfileLocator locator = Profiler.createLocator();
            locator.createFromPath(path);
            Profile profile = Profiler.getProfile(locator);
            if (profile != null)
            {
                PSMLDocument doc = profile.getDocument();
                if (doc != null)
                {
                    Portlets rootSet = doc.getPortlets();
                    /*
                    There is no way to do a check on a Portlets element, only a Entry element.
                    This can easily be added, but Im just under a release right now and it 
                    could be perceived as too destabilizing -- david
                    
                    if (JetspeedSecurity.checkPermission((JetspeedUser) rundata.getUser(),
                                                         rootSet,
                                                         JetspeedSecurity.PERMISSION_VIEW))
                    {
                    */
                        return rootSet.getSecurityRef();    
        //            }
                }
            }
        }
        catch (ProfileException e)
        {
            logger.error("Exception", e);
        }
        return null;
    }
    
    /** Sets the metainfo for this entry */
    public void doMetainfo(RunData rundata, Context context)
    {
        PortletSet set = (PortletSet) ((JetspeedRunData) rundata).getCustomized();
        String title = rundata.getParameters().getString("title");
        String description = rundata.getParameters().getString("description");

        if (set != null)
        {
            Portlets portlets = ((JetspeedRunData) rundata).getCustomizedProfile()
                                                           .getDocument()
                                                           .getPortletsById(set.getID());
            
            if (portlets != null)
            {
                MetaInfo meta = portlets.getMetaInfo();
                if (meta == null)
                {
                    meta = new PsmlMetaInfo();
                    portlets.setMetaInfo(meta);
                }
            
                if (title != null)
                {
                    meta.setTitle(title);
                    set.setTitle(title);
                }

                if(description != null)
                {
                    meta.setDescription(description);
                    set.setDescription(description);
                }
            }
        }
    }

    /** Updates the customized portlet entry */
    public void doLayout(RunData rundata, Context context)
    {
        // we should first retrieve the portlet to customize and its parameters
        // definition
        PortletSet set = (PortletSet) ((JetspeedRunData) rundata).getCustomized();
        
        try
        {            
            String controller = rundata.getParameters().getString("controller");
            
            if (controller != null)
            {
                Profile profile = ((JetspeedRunData) rundata).getCustomizedProfile();
                PortletController pc = PortalToolkit.getController(controller);

                if (pc != null)
                {
                    set.setController(pc);

                    Portlets portlets = profile.getDocument().getPortletsById(set.getID());

                    Controller c = portlets.getController();
                    if (c == null)
                    {
                        c = new PsmlController();
                        portlets.setController(c);
                    }
                    c.setName(controller);
                    
                    String linkedControl = pc.getConfig().getInitParameter("control");

                    if (linkedControl != null)
                    {
                        Control ctl = new PsmlControl();
                        ctl.setName(linkedControl);
                        portlets.setControl(ctl);
                    }
                    else
                    {
                        portlets.setControl(null);
                    }
                }
            }
        }
        catch (Exception e)
        {
            logger.error("Exception", e);
        }
        
    }

    /**
     * Set the skin in the PSML and the current PortletConfig
     * using the HTML parameter "skin".  If the parmeter is
     * missing or 'blank', then the skin is set to null.
     *
     */

    /**
     * Set the skin in the PSML and the current PortletConfig
     * using the HTML parameter "skin".  If the parmeter is
     * missing or 'blank', then the skin is set to null.
     *
     */
    public void doSkin(RunData rundata, Context context)
    {
        // we should first retrieve the portlet to customize and its parameters
        // definition
        PortletSet set = (PortletSet) ((JetspeedRunData) rundata).getCustomized();
        
        try
        {            
            String skin = rundata.getParameters().getString("skin");
            Profile profile = ((JetspeedRunData) rundata).getCustomizedProfile();
            Portlets portlets = profile.getDocument().getPortletsById(set.getID());
            
            // skin is neither null nor zero-length
            if ((skin != null) && (skin.trim().length() > 0))
            {
                PortletSkin s = PortalToolkit.getSkin(skin);

                if (s != null)
                {
                    set.getPortletConfig().setPortletSkin(s);

                    Skin psmlSkin = portlets.getSkin();
                    if (psmlSkin == null)
                    {
                        portlets.setSkin(new PsmlSkin());
                    }
                    portlets.getSkin().setName(skin);
                }
                else
                {
                    logger.warn("Unable to update skin for portlet set " 
                             + set.getID() + " because skin " + skin 
                             + " does not exist.");
                    return;
                }
            }
            else
            {
              // skin is either null or zero-length
              String custPortletSetID = portlets.getId();
              String rootPortletSetID = profile.getRootSet().getID();
              
              // set system default skin for root PSML element
              if (custPortletSetID != null && rootPortletSetID != null &&
                  custPortletSetID.equals(rootPortletSetID))
              {
                // get system default skin
                String defaultSkinName = JetspeedResources.getString("services.PortalToolkit.default.skin");
                PortletSkin defaultSkin = PortalToolkit.getSkin(defaultSkinName);
                
                if (defaultSkin != null)
                {
                  set.getPortletConfig().setPortletSkin((PortletSkin) defaultSkin);
                  Skin psmlSkin = portlets.getSkin();
                  
                  if (psmlSkin == null)
                  {
                    portlets.setSkin(new PsmlSkin());
                  }
                
                  portlets.getSkin().setName(defaultSkin.getName());
                }
                else
                {
                    logger.warn("Unable to set default skin for root portlet set " 
                             + set.getID() + " because skin " + skin 
                             + " does not exist.");
                    return;
                }
              }
              else
              {
                // By setting the skin to null, the parent's skin will be used.
                set.getPortletConfig().setPortletSkin((PortletSkin) null);
                portlets.setSkin(null);
              }
            }
        }
        catch (Exception e)
        {
            logger.error(e);
        }        
    }

    /**
     * Set the SecuirtyRef in the PSML and the current PortletConfig

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?