psmlmanageraction.java

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

JAVA
1,653
字号
                    if (path == null)
                    {
                        context.put(CATEGORY_NAME, Profiler.PARAM_USER);
                        context.put("categoryValue", Profiler.PARAM_ANON);
                        context.put("copyFrom",
                                    root +
                                    File.separator +
                                    Profiler.PARAM_USER +
                                    File.separator +
                                    Profiler.PARAM_ANON +
                                    File.separator +
                                    Profiler.PARAM_MEDIA_TYPE +
                                    File.separator +
                                    "html" +
                                    File.separator +
                                    Profiler.PARAM_PAGE +
                                    File.separator +
                                    Profiler.FULL_DEFAULT_PROFILE);
                    }
                    else
                    {
                        ProfileLocator tmpLocator = Profiler.createLocator();
                        tmpLocator.createFromPath(path);
                        Profile profile = Profiler.getProfile(tmpLocator);
                        if (profile != null)
                        {
                            rundata.getUser().setTemp(TEMP_LOCATOR, tmpLocator);
                            context.put("profile", profile);
                        }
                        String categoryName = Profiler.PARAM_GROUP;
                        String categoryValue = tmpLocator.getGroupName();
                        if (categoryValue == null)
                        {
                            categoryName = Profiler.PARAM_ROLE;
                            categoryValue = tmpLocator.getRoleName();
                            if (categoryValue == null)
                            {
                                categoryName = Profiler.PARAM_USER;
                                categoryValue = tmpLocator.getUserName();
                                if (categoryValue == null)
                                {
                                    categoryName = Profiler.PARAM_USER;
                                    categoryValue = Profiler.PARAM_ANON;
                                }
                            }

                        }
                        context.put(CATEGORY_NAME, categoryName);
                        context.put("categoryValue", categoryValue);
                        String filePath = this.mapLocatorToFile(tmpLocator);
                        context.put("copyFrom", root + File.separator + filePath.toString());
                    }
                }
                else
                {
                    context.put(CATEGORY_NAME, rundata.getUser().getTemp(CATEGORY_NAME));
                    context.put(CATEGORY_VALUE, rundata.getUser().getTemp(CATEGORY_VALUE));
                    context.put(COPY_FROM, rundata.getUser().getTemp(COPY_FROM));
                }
            }

            if (mode != null && mode.equals("import_all"))
            {
                if (msgid == null)
                {
                    // get the PSML Root Directory
                    ResourceService serviceConf = ((TurbineServices) TurbineServices.getInstance())
                                                  .getResources(PsmlManagerService.SERVICE_NAME);
                    String root = serviceConf.getString("root", "/WEB-INF/psml");
                    context.put(COPY_FROM, TurbineServlet.getRealPath(root));
                }
                else
                {
                    context.put(COPY_FROM, rundata.getUser().getTemp(COPY_FROM));
                }
            }

        }
        catch (Exception e)
        {
            logger.error("Exception", e);
            rundata.setMessage("Error in PsmlUpdateAction: " + e.toString());
            rundata.setStackTrace(StringUtils.stackTrace(e), e);
            rundata.setScreenTemplate(JetspeedResources.getString("template.error", "Error"));
        }
    }

    /**
     * Database Insert Action for Psml.
     *
     * @param rundata The turbine rundata context for this request.
     * @param context The velocity context for this request.
     */
    public void doInsert(RunData rundata, Context context)
    throws Exception
    {
        Profile profile = null;
        ProfileLocator locator = null;
        String categoryName = null;
        String categoryValue = null;
        String copyFrom = null;
        String name = null;
        String title = null;

        try
        {
            categoryName = rundata.getParameters().getString("CategoryName");
            categoryValue = rundata.getParameters().getString("CategoryValue");
            copyFrom = rundata.getParameters().getString("CopyFrom");
            name = rundata.getParameters().getString("name");
            title = rundata.getParameters().getString("title");
            //
            //create a new locator and set its values according to users input
            //
            locator = Profiler.createLocator();
            if (categoryName.equalsIgnoreCase(Profiler.PARAM_GROUP))
            {
                locator.setGroupByName(categoryValue);
            }
            else if (categoryName.equalsIgnoreCase(Profiler.PARAM_ROLE))
            {
                locator.setRoleByName(categoryValue);
            }
            else if (categoryName.equalsIgnoreCase(Profiler.PARAM_USER))
            {
                locator.setUser(JetspeedSecurity.getUser(categoryValue));
            }
            else
            {
                locator.setAnonymous(true);
            }

            String tempVar = rundata.getParameters().getString("MediaType");
            if (tempVar != null && tempVar.trim().length() > 0)
            {
                locator.setMediaType(tempVar);
            }

            tempVar = rundata.getParameters().getString("Language");
            if (tempVar != null && tempVar.trim().length() > 0)
            {
                locator.setLanguage(tempVar);
            }

            tempVar = rundata.getParameters().getString("Country");
            if (tempVar != null && tempVar.trim().length() > 0)
            {
                locator.setCountry(tempVar);
            }

            if (!name.endsWith(Profiler.DEFAULT_EXTENSION))
            {
                name = name + Profiler.DEFAULT_EXTENSION;
            }
            locator.setName(name);

            //check if profile to be created already exists
            if (PsmlManager.getDocument(locator) != null)
            {
                throw new EntityExistsException("Profile:"+locator.getPath()+" Already Exists!");            
            }

            //
            // validate that its not an 'blank' profile -- not allowed
            //
            if (name == null || name.trim().length() == 0)
            {
                JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
                DynamicURI duri = link.addPathInfo(SecurityConstants.PARAM_MODE,
                                                   SecurityConstants.PARAM_MODE_INSERT)
                                  .addPathInfo(SecurityConstants.PARAM_MSGID,
                                               SecurityConstants.MID_INVALID_ENTITY_NAME);
                JetspeedLinkFactory.putInstance(link);
                rundata.setRedirectURI(duri.toString());

                //save user entered values
                if (locator != null)
                    rundata.getUser().setTemp(TEMP_LOCATOR, locator);
                if (categoryName != null)
                    rundata.getUser().setTemp(CATEGORY_NAME, categoryName);
                if (categoryValue != null)
                    rundata.getUser().setTemp(CATEGORY_VALUE, categoryValue);
                if (copyFrom != null)
                    rundata.getUser().setTemp(COPY_FROM, copyFrom);
                return;
            }

            //
            // retrieve the profile to clone
            //
            Profile baseProfile = null;
            if (copyFrom != null && !copyFrom.equals("none"))
            {
                ProfileLocator baseLocator = Profiler.createLocator();
                baseLocator.createFromPath(copyFrom);
                baseProfile = Profiler.getProfile(baseLocator);
            }

            //
            // create a new profile
            //

            // AT THIS POINT "portlet" is null ????
            //Portlet portlet = (Portlet) context.get("portlet");
            //PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName());

            if (copyFrom.equals("none"))
            {
                profile = Profiler.createProfile(locator, null);
                profile.getDocument().getPortlets().setTitle(title);
                profile.store();
                //System.out.println("Profile title: " + profile.getDocument().getPortlets().getTitle() + " for " + profile.getDocument().getPortlets());
                setRefreshPsmlFlag(rundata, TRUE);
            }
            else if (baseProfile != null)
            {
                PSMLDocument doc = baseProfile.getDocument();
                if (doc != null)
                {
                    Portlets portlets = doc.getPortlets();
                    
                    Portlets clonedPortlets = (Portlets) SerializationUtils.clone(portlets);
                    org.apache.jetspeed.util.PortletUtils.regenerateIds(clonedPortlets);
                    profile = Profiler.createProfile(locator, clonedPortlets);
                }
                else
                {
                    profile = Profiler.createProfile(locator, null);
                }
                setRefreshPsmlFlag(rundata, TRUE);
            }
            else
            {
                logger.error("Profile listed in Copy From Not Found!");
            }

            goBackToBrowser(rundata);
        }
        catch (EntityExistsException e)
        {
            // log the error msg
            logger.error("Exception", e);

            //
            // dup key found - display error message - bring back to same screen
            //
            JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
            DynamicURI duri = link.addPathInfo(SecurityConstants.PARAM_MODE,
                                               SecurityConstants.PARAM_MODE_INSERT)
                              .addPathInfo(SecurityConstants.PARAM_MSGID,
                                           SecurityConstants.MID_ENTITY_ALREADY_EXISTS);
            JetspeedLinkFactory.putInstance(link);
            rundata.setRedirectURI(duri.toString());
        }
        catch (Exception e)
        {
            // log the error msg
            logger.error("Exception", e);

            //
            // dup key found - display error message - bring back to same screen
            //
            JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
            DynamicURI duri = link.addPathInfo(SecurityConstants.PARAM_MODE,
                                               SecurityConstants.PARAM_MODE_INSERT)
                              .addPathInfo(SecurityConstants.PARAM_MSGID,
                                           SecurityConstants.MID_UPDATE_FAILED);
            JetspeedLinkFactory.putInstance(link);
            rundata.setRedirectURI(duri.toString());
        }
        // save values that user just entered so they don't have to re-enter
        if (locator != null)
            rundata.getUser().setTemp(TEMP_LOCATOR, locator);
        if (categoryName != null)
            rundata.getUser().setTemp(CATEGORY_NAME, categoryName);
        if (categoryValue != null)
            rundata.getUser().setTemp(CATEGORY_VALUE, categoryValue);
        if (copyFrom != null)
            rundata.getUser().setTemp(COPY_FROM, copyFrom);

    }

    /**
     * Delete Psml entry
     * 
     * @param rundata
     * @param context
     * @exception Exception
     */
    public void doDelete(RunData rundata, Context context) throws Exception
    {
        try
        {
            ProfileLocator locator = (ProfileLocator)rundata.getUser().getTemp(TEMP_LOCATOR);
            if (locator != null)
            {
                Profiler.removeProfile(locator);
                setRefreshPsmlFlag(rundata, TRUE);
            }
            else
            {
                logger.error("ProfileLocator not found!");
            }
        }
        catch (Exception e)
        {
            // log the error msg
            logger.error("Exception", e);

            //
            // dup key found - display error message - bring back to same screen
            //
            JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
            DynamicURI duri = link.addPathInfo(SecurityConstants.PARAM_MODE, SecurityConstants.PARAM_MODE_DELETE)
                              .addPathInfo(SecurityConstants.PARAM_MSGID,
                                           SecurityConstants.MID_DELETE_FAILED);
            JetspeedLinkFactory.putInstance(link);
            rundata.setRedirectURI(duri.toString());
        }

    }

    /**
     * 
     * @param rundata
     * @param value
     */
    private void setRefreshPsmlFlag(RunData rundata, String value)
    {
        rundata.getUser().setTemp(PSML_REFRESH_FLAG, value);
        if (value.equals(TRUE))

⌨️ 快捷键说明

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