Package org.apache.jetspeed.om.profile

Examples of org.apache.jetspeed.om.profile.ProfileLocator


    {
        if (Log.getLogger().isDebugEnabled())
        {
            Log.debug("PsmlUpdateAction.createFromPath: processing path = " + path);
        }
        ProfileLocator result = Profiler.createLocator();

        // Tokenize the file path into elements
        StringTokenizer tok = new StringTokenizer(path, File.separator);

        // Load path elements into a vector for random access
        Vector tokens = new Vector();
        while (tok.hasMoreTokens())
        {
            tokens.add(tok.nextToken());
        }

        // Assume that 1st element is the profile type (user|role|group) and 2nd is the name
        if (tokens.size() > 1)
        {
            String type = (String) tokens.elementAt(0);
            String name = (String) tokens.elementAt(1);
            if (type.equals(Profiler.PARAM_USER))
            {
                result.setUser(JetspeedSecurity.getUser(name));
            }
            else if (type.equals(Profiler.PARAM_GROUP))
            {
                result.setGroup(JetspeedSecurity.getGroup(name));
            }
            else if (type.equals(Profiler.PARAM_ROLE))
            {
                result.setRole(JetspeedSecurity.getRole(name));
            }
        }

        // Assume that the last element is the page name
        if (tokens.size() > 0)
        {
            result.setName((String) tokens.lastElement());
        }

        // Based on the number of path elements set the other profile attributes
        switch (tokens.size())
        {
        case 3: // user|role|group/name/page.psml
            break;
        case 4: // user|role|group/name/media-type/page.psml
            result.setMediaType((String) tokens.elementAt(2));
            break;
        case 5: // user|role|group/name/media-type/language/page.psml
            result.setMediaType((String) tokens.elementAt(2));
            result.setLanguage((String) tokens.elementAt(3));
            break;
        case 6: // user|role|group/name/media-type/language/country/page.psml
            result.setMediaType((String) tokens.elementAt(2));
            result.setLanguage((String) tokens.elementAt(3));
            result.setCountry((String) tokens.elementAt(4));
            break;
        default:
            throw new Exception("Path must contain 3 to 6 elements: [" + path + "], and the size was: " + tokens.size());
        }
View Full Code Here


     */
    private void appendNewRoleProfile(JetspeedRunData jdata, JetspeedUser user, Role role)
    throws Exception
    {
        // Retrieve the role profile
        ProfileLocator roleLocator = Profiler.createLocator();
        roleLocator.setRole(role);
        roleLocator.setMediaType(jdata.getCapability().getPreferredMediaType());
        roleLocator.setName("default.psml");
        Profile roleProfile = Profiler.getProfile(roleLocator);
        if (roleProfile != null)
        {
            if (Log.getLogger().isDebugEnabled())
            {
                Log.debug("UserRoleUpdateAction: retrieved profile for role: " + roleProfile.getPath());
            }
        }

        // Retrieve the user profile
        ProfileLocator userLocator = Profiler.createLocator();
        userLocator.setUser(user);
        userLocator.setMediaType(jdata.getCapability().getPreferredMediaType());
        userLocator.setName("default.psml");
        Profile userProfile = Profiler.getProfile(userLocator);
        if (userProfile != null)
        {
            if (Log.getLogger().isDebugEnabled())
            {
View Full Code Here

     */
    private void appendNewRoleProfile(JetspeedRunData jdata, JetspeedUser user, Role role)
    throws Exception
    {
        // Retrieve the role profile
        ProfileLocator roleLocator = Profiler.createLocator();
        roleLocator.setRole(role);
        roleLocator.setMediaType(jdata.getCapability().getPreferredMediaType());
        roleLocator.setName("default.psml");
        Profile roleProfile = Profiler.getProfile(roleLocator);
        if (roleProfile != null)
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("UserGroupRoleUpdateAction: retrieved profile for role: " + roleProfile.getPath());
            }
        }

        // Retrieve the user profile
        ProfileLocator userLocator = Profiler.createLocator();
        userLocator.setUser(user);
        userLocator.setMediaType(jdata.getCapability().getPreferredMediaType());
        userLocator.setName("default.psml");
        Profile userProfile = Profiler.getProfile(userLocator);
        if (userProfile != null)
        {
            if (logger.isDebugEnabled())
            {
View Full Code Here

                int id = Integer.parseInt(msgid);
                if (id < SecurityConstants.MESSAGES.length)
                    context.put(SecurityConstants.PARAM_MSG, SecurityConstants.MESSAGES[id]);

                // get the bad entered data and put it back for convenient update
                 ProfileLocator locator = (ProfileLocator)rundata.getUser().getTemp(TEMP_LOCATOR);
                if (locator != null)
                    context.put("profile", Profiler.createProfile(locator));
            }

            String mode = rundata.getParameters().getString(SecurityConstants.PARAM_MODE);
            context.put(SecurityConstants.PARAM_MODE, mode);
            String path = rundata.getParameters().getString(SecurityConstants.PARAM_ENTITY_ID);

            if(mode != null && mode.equals(SecurityConstants.PARAM_MODE_DELETE))
            {
                ProfileLocator locator = Profiler.createLocator();
                locator.createFromPath(path);
                Profile profile = Profiler.getProfile(locator);
               if (profile != null)
               {
                   rundata.getUser().setTemp(TEMP_LOCATOR, locator);
                   context.put("profile", profile);
               }
               else
                   logger.error("Profile for Path:"+path+" Not Found!");
            }

            if(mode != null && mode.equals(SecurityConstants.PARAM_MODE_INSERT))
            {
                org.apache.jetspeed.om.registry.Registry mediaTypes = Registry.get(Registry.MEDIA_TYPE);
                context.put("mediaTypes", mediaTypes.listEntryNames());
                if (msgid == null)
                {
                    if(path == null)
                    {
                        context.put(CATEGORY_NAME, "user");
                        context.put("categoryValue", "anon");
                        context.put("copyFrom", "user/anon/media-type/html/page/default.psml");
                    }
                    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 = "group";
                        String categoryValue = tmpLocator.getGroupName();
                        if (categoryValue == null)
                        {
                            categoryName = "role";
                            categoryValue = tmpLocator.getRoleName();
                            if (categoryValue == null)
                            {
                                categoryName = "user";
                                categoryValue = tmpLocator.getUserName();
                                if (categoryValue == null)
                                {
                                    categoryName = "user";
                                    categoryValue = "anon";
                                }
                            }

                        }
                        context.put(CATEGORY_NAME, categoryName);
                        context.put("categoryValue", categoryValue);
                        context.put("copyFrom", path);
                    }
                }
                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("export"))
            {
                if (msgid == null)
                {
                    String tmpPath = JetspeedResources.getString(JetspeedResources.TEMP_DIRECTORY_KEY, "/tmp");
                    String exportPath = JetspeedResources.getString("psml.export.default.path",
                                                                    TurbineServlet.getRealPath(tmpPath));
                    if(path == null)
                    {
                        context.put(COPY_TO, exportPath);
                        context.put(COPY_FROM,
                                    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(COPY_TO, exportPath + File.separator + tmpLocator.getName());
                        context.put(COPY_FROM, path);
                    }
                }
                else
                {
                    context.put(COPY_TO, rundata.getUser().getTemp(COPY_TO));
                    context.put(COPY_FROM, rundata.getUser().getTemp(COPY_FROM));
                }
            }

            if(mode != null && mode.equals("export_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_TO, TurbineServlet.getRealPath(root));
                }
                else
                {
                    context.put(COPY_TO, rundata.getUser().getTemp(COPY_TO));
                }
            }

            if(mode != null && mode.equals("import"))
            {
                org.apache.jetspeed.om.registry.Registry mediaTypes = Registry.get(Registry.MEDIA_TYPE);
                context.put("mediaTypes", mediaTypes.listEntryNames());
                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");
                    root = TurbineServlet.getRealPath(root);

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

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

        try
        {
            categoryName = rundata.getParameters().getString("CategoryName");
            categoryValue = rundata.getParameters().getString("CategoryValue");
            copyFrom = rundata.getParameters().getString("CopyFrom");
            name = rundata.getParameters().getString("name");
            //
            //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("psml_mediatype");
            if (tempVar != null && tempVar.trim().length() > 0)
            {
                locator.setMediaType(tempVar);
            }

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

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

            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.getPaneByName(PSML_UPDATE_PANE)
                                      .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
            //
            ProfileLocator baseLocator = Profiler.createLocator();
            baseLocator.createFromPath(copyFrom);
            Profile baseProfile = Profiler.getProfile(baseLocator);

            //
            // create a new profile
            //
View Full Code Here

     */
    private void appendNewRoleProfile(JetspeedRunData jdata, JetspeedUser user, Role role)
    throws Exception
    {
        // Retrieve the role profile
        ProfileLocator roleLocator = Profiler.createLocator();
        roleLocator.setRole(role);
        roleLocator.setMediaType(jdata.getCapability().getPreferredMediaType());
        roleLocator.setName("default.psml");
        Profile roleProfile = Profiler.getProfile(roleLocator);
        if (roleProfile != null)
        {
            if (logger.isDebugEnabled())
            {
                logger.debug("UserRoleUpdateAction: retrieved profile for role: " + roleProfile.getPath());
            }
        }

        // Retrieve the user profile
        ProfileLocator userLocator = Profiler.createLocator();
        userLocator.setUser(user);
        userLocator.setMediaType(jdata.getCapability().getPreferredMediaType());
        userLocator.setName("default.psml");
        Profile userProfile = Profiler.getProfile(userLocator);
        if (userProfile != null)
        {
            if (logger.isDebugEnabled())
            {
View Full Code Here

     */
    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);
            }
View Full Code Here

     */
    public void doExport(RunData rundata, Context context)
        throws Exception
    {
        Profile profile = null;
        ProfileLocator locator = null;
        String copyTo = null;
        String copyFrom = null;

        try
        {
            copyFrom = rundata.getParameters().getString("CopyFrom");
            copyTo = rundata.getParameters().getString("CopyTo");

            //
            // retrieve the profile to clone
            //
            ProfileLocator baseLocator = Profiler.createLocator();
            baseLocator.createFromPath(copyFrom);
            Profile baseProfile = Profiler.getProfile(baseLocator);

            //
            // Export profile
            //
View Full Code Here

     */
    public void doImport(RunData rundata, Context context)
        throws Exception
    {
        Profile profile = null;
        ProfileLocator locator = null;
        String categoryName = null;
        String categoryValue = null;
        String copyFrom = null;
        String name = null;

        try
        {
            categoryName = rundata.getParameters().getString("CategoryName");
            categoryValue = rundata.getParameters().getString("CategoryValue");
            copyFrom = rundata.getParameters().getString("CopyFrom");
            name = rundata.getParameters().getString("name");
            //
            //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("psml_mediatype");
            if (tempVar != null && tempVar.trim().length() > 0)
            {
                locator.setMediaType(tempVar);
            }

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

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

            locator.setName(name);

            //
            // validate that its not an 'blank' profile -- not allowed
            //
            if (name == null || name.trim().length() == 0)
            {
                JetspeedLink link = JetspeedLinkFactory.getInstance(rundata);
                DynamicURI duri = link.getPaneByName(PSML_UPDATE_PANE)
                                      .addPathInfo(SecurityConstants.PARAM_MODE,
                                                   "import")
                                      .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 document to import
            //
            PSMLDocument doc = this.loadDocument(copyFrom);

            //
            // create a new profile
            //
            if(doc != null)
            {
                Portlets portlets = doc.getPortlets();
                //
                // Profiler does not provide update capability - must remove before replacing
                //
                if (PsmlManager.getDocument(locator) != null)
                {
                    Profiler.removeProfile(locator);
                }
               
                Portlets clonedPortlets = (Portlets) SerializationUtils.clone(portlets);
                org.apache.jetspeed.util.PortletUtils.regenerateIds(clonedPortlets);
               
                profile = Profiler.createProfile(locator, clonedPortlets);
            }
            else
            {
                throw new Exception("Failed to load PSML document from disk");
            }
            rundata.addMessage("Profile for [" + locator.getPath() + "] has been imported from file [" + copyFrom + "]<br>");
            setRefreshPsmlFlag(rundata, TRUE);

        }
        catch (Exception e)
        {
View Full Code Here

                String path = null;
                try
                {
                    String psml = ((File) it.next()).getPath();
                    path = psml.substring(copyFrom.length() + 1);
                    ProfileLocator locator = this.mapFileToLocator(path);

                    PSMLDocument doc = this.loadDocument(psml);

                    //
                    // create a new profile
                    //
                    if(doc != null)
                    {
                        Portlets portlets = doc.getPortlets();
                        //
                        // Profiler does not provide update capability - must remove before replacing
                        //
                        if (PsmlManager.getDocument(locator) != null)
                        {
                            Profiler.removeProfile(locator);
                        }
                        Profiler.createProfile(locator, portlets);
                    }
                    else
                    {
                        throw new Exception("Failed to load PSML document [" + psml + "] from disk");
                    }
                    rundata.addMessage("Profile for [" + locator.getPath() + "] has been imported from file [" + psml + "]<br>");
                    setRefreshPsmlFlag(rundata, TRUE);
                }
                catch (Exception ouch)
                {
                    logger.error("Exception", ouch);
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.om.profile.ProfileLocator

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.