Package org.apache.jetspeed.om.folder

Examples of org.apache.jetspeed.om.folder.Folder


        try
        {
            Iterator foldersIter = getSearchFolders().iterator();
            while (foldersIter.hasNext())
            {
                Folder folder = ((SearchFolder)foldersIter.next()).folder;
                String name = folder.getName();
                String title = folder.getTitle();
                String shortTitle = folder.getShortTitle();
                GenericMetadata folderMetadata = folder.getMetadata();
                if (((title != null) && !title.equalsIgnoreCase(name)) ||
                    ((shortTitle != null) && !shortTitle.equalsIgnoreCase(name)) ||
                    ((folderMetadata != null) && (folderMetadata.getFields() != null) && !folderMetadata.getFields().isEmpty()))
                {
                    return folder;
View Full Code Here


            boolean fallbackDefaultPageNotFound = false;
            Iterator foldersIter = getSearchFolders().iterator();
            while (foldersIter.hasNext())
            {
                // get folder default page name or look for fallback default name
                Folder folder = ((SearchFolder)foldersIter.next()).folder;
                String defaultPageName = folder.getDefaultPage();
                if (defaultPageName != null)
                {
                    // validate and return default page or folder
                    // if it exists as child in this folder
                    if (defaultPageName.equals(".."))
View Full Code Here

            Iterator foldersIter = getSearchFolders().iterator();
            while (foldersIter.hasNext())
            {
                // aggregate folders
                SearchFolder searchFolder = (SearchFolder)foldersIter.next();
                Folder folder = searchFolder.folder;
                String locatorName = searchFolder.locatorName;

                // create and save proxies for concrete children
                NodeSet children = folder.getAll();
                Iterator childrenIter = children.iterator();
                while (childrenIter.hasNext())
                {
                    Node child = (Node)childrenIter.next();
                    String childName = child.getName();

                    // filter profiling property folders unless forced; they are
                    // normally accessed only via SiteView search path aggregation
                    // that directly utilizes the current view page manager
                    boolean visible = (forceReservedVisible || (!(child instanceof Folder) ||
                                                                (!childName.startsWith(Folder.RESERVED_SUBSITE_FOLDER_PREFIX) &&
                                                                 !childName.startsWith(Folder.RESERVED_FOLDER_PREFIX))));
                    if (visible)
                    {
                        // test child name uniqueness
                        boolean childUnique = true ;
                        Iterator allChildrenIter = allChildren.iterator();
                        while (childUnique && allChildrenIter.hasNext())
                        {
                            childUnique = !childName.equals(((Node)allChildrenIter.next()).getName());                           
                        }

                        // add uniquely named children proxies
                        if (childUnique)
                        {
                            if (child instanceof Folder)
                            {
                                allChildren.add(FolderProxy.newInstance(getView(), locatorName, (Folder)proxy, (Folder)child, forceReservedVisible));
                            }
                            else if (child instanceof Page)
                            {
                                allChildren.add(PageProxy.newInstance(getView(), locatorName, (Folder)proxy, (Page)child));
                            }
                            else if (child instanceof PageTemplate)
                            {
                                allChildren.add(PageTemplateProxy.newInstance(getView(), locatorName, (Folder)proxy, (PageTemplate)child));
                            }
                            else if (child instanceof DynamicPage)
                            {
                                allChildren.add(DynamicPageProxy.newInstance(getView(), locatorName, (Folder)proxy, (DynamicPage)child));
                            }
                            else if (child instanceof FragmentDefinition)
                            {
                                allChildren.add(FragmentDefinitionProxy.newInstance(getView(), locatorName, (Folder)proxy, (FragmentDefinition)child));
                            }
                            else if (child instanceof Link)
                            {
                                allChildren.add(LinkProxy.newInstance(getView(), locatorName, (Folder)proxy, (Link)child));
                            }
                        }
                    }
                }

                // capture most specific document ordering
                if (folderDocumentOrder == null)
                {
                    List documentOrder = folder.getDocumentOrder();
                    if ((documentOrder != null) && !documentOrder.isEmpty())
                    {
                        folderDocumentOrder = documentOrder;
                    }
                }
View Full Code Here

                // get existing folders from PageManager, create
                // corresponding search folder objects, and add to
                // search folders list
                try
                {
                    Folder folder = getView().getPageManager().getFolder(path);
                    if (folder != null)
                    {
                        searchFolders.add(new SearchFolder(folder, searchPath.getLocatorName()));
                    }
                }
View Full Code Here

     */
    public void testPageManagerSetup() throws Exception
    {
        // validate test setup
        assertNotNull(pageManager);
        Folder folder = pageManager.getFolder("/");
        assertNotNull(folder);
        Page page = pageManager.getPage("/page.psml");
        assertNotNull(page);
        DynamicPage docPage = pageManager.getDynamicPage("/docpage.dpsml");       
        assertNotNull(docPage);
View Full Code Here

                                userManager.updateUser(innerUser);
                            }                                        
                            // create user's home folder                       
                            // deep copy from the default folder template tree, creating a deep-copy of the template
                            // in the new user's folder tree
                            Folder source = innerPageManager.getFolder(innerFolderTemplate);
                            innerPageManager.deepCopyFolder(source, innerUserFolderPath, innerUserName);
                            Folder newFolder = pageManager.getFolder(innerUserFolderPath);                           
                            newFolder.setTitle("My Home Space");
                            newFolder.setShortTitle("My Space");                            
                            return null;
                        }
                        catch (SecurityException s1)
                        {
                            return s1;
View Full Code Here

     * @throws InvalidFolderException
     */
    public Folder getFolder(String folderPath) throws FolderNotFoundException, InvalidFolderException, NodeException
    {
        // get folder and check access before returning
        Folder folder = folderHandler.getFolder(folderPath);
        folder.checkAccess(JetspeedActions.VIEW);
        return folder;
    }
View Full Code Here

                        try
                        {
                            // reset page manager to initial state
                            try
                            {
                                Folder removeRootFolder = pageManager.getFolder("/");
                                pageManager.removeFolder(removeRootFolder);
                                pageManager.reset();
                            }
                            catch (FolderNotFoundException e)
                            {
                            }

                            // create test documents and folders
                            Folder folder = pageManager.newFolder("/");
                            SecurityConstraints constraints = pageManager.newSecurityConstraints();
                            constraints.setOwner("admin");
                            List constraintsRefs = new ArrayList(1);
                            constraintsRefs.add("public-view");
                            constraints.setSecurityConstraintsRefs(constraintsRefs);
                            folder.setSecurityConstraints(constraints);
                            pageManager.updateFolder(folder);
                       
                            PageSecurity pageSecurity = pageManager.newPageSecurity();
                            List constraintsDefs = new ArrayList(2);
                            SecurityConstraintsDef constraintsDef = pageManager.newSecurityConstraintsDef();
                            constraintsDef.setName("public-view");
                            List defConstraints = new ArrayList(1);
                            SecurityConstraint defConstraint = pageManager.newPageSecuritySecurityConstraint();
                            defConstraint.setUsers(Shared.makeListFromCSV("*"));
                            defConstraint.setPermissions(Shared.makeListFromCSV("view"));
                            defConstraints.add(defConstraint);
                            constraintsDef.setSecurityConstraints(defConstraints);
                            constraintsDefs.add(constraintsDef);
                            constraintsDef = pageManager.newSecurityConstraintsDef();
                            constraintsDef.setName("admin-all");
                            defConstraints = new ArrayList(1);
                            defConstraint = pageManager.newPageSecuritySecurityConstraint();
                            defConstraint.setRoles(Shared.makeListFromCSV("admin"));
                            defConstraint.setPermissions(Shared.makeListFromCSV("view,edit"));
                            defConstraints.add(defConstraint);
                            constraintsDef.setSecurityConstraints(defConstraints);
                            constraintsDefs.add(constraintsDef);
                            pageSecurity.setSecurityConstraintsDefs(constraintsDefs);
                            List globalConstraintsRefs = new ArrayList(1);
                            globalConstraintsRefs.add("admin-all");
                            pageSecurity.setGlobalSecurityConstraintsRefs(globalConstraintsRefs);
                            pageManager.updatePageSecurity(pageSecurity);
                       
                            Page page = pageManager.newPage("/default-page.psml");
                            constraints = pageManager.newSecurityConstraints();
                            constraints.setOwner("admin");
                            List inlineConstraints = new ArrayList(1);
                            SecurityConstraint constraint = pageManager.newPageSecurityConstraint();
                            constraint.setRoles(Shared.makeListFromCSV("manager"));
                            constraint.setPermissions(Shared.makeListFromCSV("edit"));
                            inlineConstraints.add(constraint);
                            constraints.setSecurityConstraints(inlineConstraints);
                            constraintsRefs = new ArrayList(1);
                            constraintsRefs.add("public-view");
                            constraints.setSecurityConstraintsRefs(constraintsRefs);
                            page.setSecurityConstraints(constraints);                       
                            Fragment root = page.getRootFragment();
                            root.setName("jetspeed-layouts::VelocityTwoColumns");
                            Fragment portlet = pageManager.newPortletFragment();
                            portlet.setName("security::LoginPortlet");
                            root.getFragments().add(portlet);
                            portlet = pageManager.newPortletFragment();
                            portlet.setName("some-app::SomePortlet");
                            SecurityConstraints fragmentConstraints = pageManager.newSecurityConstraints();
                            fragmentConstraints.setOwner("user");
                            portlet.setSecurityConstraints(fragmentConstraints);
                            root.getFragments().add(portlet);
                            pageManager.updatePage(page);
                            TestCase.assertNotNull(page.getRootFragment());
                            TestCase.assertNotNull(page.getRootFragment().getFragments());
                            TestCase.assertEquals(2, page.getRootFragment().getFragments().size());
                            TestCase.assertEquals("some-app::SomePortlet", ((Fragment)page.getRootFragment().getFragments().get(1)).getName());
                            TestCase.assertFalse("0".equals(((Fragment)page.getRootFragment().getFragments().get(1)).getId()));
                            somePortletId[0] = ((Fragment)page.getRootFragment().getFragments().get(1)).getId();
                       
                            page = pageManager.newPage("/user-page.psml");
                            constraints = pageManager.newSecurityConstraints();
                            inlineConstraints = new ArrayList(1);
                            constraint = pageManager.newPageSecurityConstraint();
                            constraint.setUsers(Shared.makeListFromCSV("user"));
                            constraint.setPermissions(Shared.makeListFromCSV("view,edit"));
                            inlineConstraints.add(constraint);
                            constraints.setSecurityConstraints(inlineConstraints);
                            page.setSecurityConstraints(constraints);
                            pageManager.updatePage(page);

                            Link link = pageManager.newLink("/default.link");
                            link.setUrl("http://www.default.org/");
                            constraints = pageManager.newSecurityConstraints();
                            constraints.setOwner("admin");
                            inlineConstraints = new ArrayList(1);
                            constraint = pageManager.newLinkSecurityConstraint();
                            constraint.setRoles(Shared.makeListFromCSV("manager"));
                            constraint.setPermissions(Shared.makeListFromCSV("edit"));
                            inlineConstraints.add(constraint);
                            constraints.setSecurityConstraints(inlineConstraints);
                            link.setSecurityConstraints(constraints);                       
                            pageManager.updateLink(link);

                            return null;
                        }
                        catch (Exception e)
                        {
                            return e;
                        }
                    }
                }, null);
            if (setup != null)
            {
                throw setup;
            }

            // reset page manager cache
            pageManager.reset();

            // access test as admin user
            Exception adminAccess = (Exception)JSSubject.doAsPrivileged(adminSubject, new PrivilegedAction()
                {
                    public Object run()
                    {
                        try
                        {
                            // test view access
                            Folder folder = pageManager.getFolder("/");
                            TestCase.assertNotNull(folder.getPageSecurity());
                            TestCase.assertNotNull(folder.getPages());
                            TestCase.assertEquals(2, folder.getPages().size());
                            TestCase.assertNotNull(pageManager.getPages(folder));
                            TestCase.assertEquals(2, pageManager.getPages(folder).size());
                            PageSecurity pageSecurity = pageManager.getPageSecurity();
                            Page page0 = pageManager.getPage("/default-page.psml");
                            TestCase.assertNotNull(page0.getRootFragment());
                            TestCase.assertNotNull(page0.getRootFragment().getFragments());
                            TestCase.assertEquals(2, page0.getRootFragment().getFragments().size());
                            TestCase.assertNotNull(page0.getFragmentById(somePortletId[0]));
                            TestCase.assertNotNull(page0.getFragmentsByName("some-app::SomePortlet"));
                            TestCase.assertEquals(1, page0.getFragmentsByName("some-app::SomePortlet").size());
                            Page page1 = pageManager.getPage("/user-page.psml");
                            Link link = pageManager.getLink("/default.link");
                            // test edit access
                            pageManager.updateFolder(folder);
                            pageManager.updatePageSecurity(pageSecurity);
                            pageManager.updatePage(page0);
                            pageManager.updatePage(page1);
                            pageManager.updateLink(link);
                            return null;
                        }
                        catch (Exception e)
                        {
                            return e;
                        }
                    }
                }, null);
            if (adminAccess != null)
            {
                throw adminAccess;
            }

            // access test as user user
            Exception userAccess = (Exception)JSSubject.doAsPrivileged(userSubject, new PrivilegedAction()
                {
                    public Object run()
                    {
                        try
                        {
                            // test view access
                            Folder folder = pageManager.getFolder("/");
                            TestCase.assertNotNull(folder.getPageSecurity());
                            TestCase.assertNotNull(folder.getPages());
                            TestCase.assertEquals(2, folder.getPages().size());
                            PageSecurity pageSecurity = pageManager.getPageSecurity();
                            Page page0 = pageManager.getPage("/default-page.psml");
                            TestCase.assertNotNull(page0.getRootFragment());
                            TestCase.assertNotNull(page0.getRootFragment().getFragments());
                            TestCase.assertEquals(2, page0.getRootFragment().getFragments().size());
                            TestCase.assertNotNull(page0.getFragmentById(somePortletId[0]));
                            TestCase.assertNotNull(page0.getFragmentsByName("some-app::SomePortlet"));
                            TestCase.assertEquals(1, page0.getFragmentsByName("some-app::SomePortlet").size());
                            Page page1 = pageManager.getPage("/user-page.psml");
                            Link link = pageManager.getLink("/default.link");
                            // test edit access
                            try
                            {
                                pageManager.updateFolder(folder);
                                TestCase.assertTrue("Folder / not editable for user", false);
                            }
                            catch (SecurityException se)
                            {
                            }
                            try
                            {
                                pageManager.updatePageSecurity(pageSecurity);
                                TestCase.assertTrue("PageSecurity not editable for user", false);
                            }
                            catch (SecurityException se)
                            {
                            }
                            try
                            {
                                pageManager.updatePage(page0);
                                TestCase.assertTrue("Page /default-page.psml not editable for user", false);
                            }
                            catch (SecurityException se)
                            {
                            }
                            pageManager.updatePage(page1);
                            try
                            {
                                pageManager.updateLink(link);
                                TestCase.assertTrue("Page /default.link not editable for user", false);
                            }
                            catch (SecurityException se)
                            {
                            }
                            return null;
                        }
                        catch (Exception e)
                        {
                            return e;
                        }
                    }
                }, null);
            if (userAccess != null)
            {
                throw userAccess;
            }

            // access test as manager user
            Exception managerAccess = (Exception)JSSubject.doAsPrivileged(managerSubject, new PrivilegedAction()
                {
                    public Object run()
                    {
                        try
                        {
                            // test view access
                            Folder folder = pageManager.getFolder("/");
                            TestCase.assertNotNull(folder.getPageSecurity());
                            TestCase.assertNotNull(folder.getPages());
                            TestCase.assertEquals(1, folder.getPages().size());
                            PageSecurity pageSecurity = pageManager.getPageSecurity();
                            Page page0 = pageManager.getPage("/default-page.psml");
                            TestCase.assertNotNull(page0.getRootFragment());
                            TestCase.assertNotNull(page0.getRootFragment().getFragments());
                            TestCase.assertEquals(1, page0.getRootFragment().getFragments().size());
                            TestCase.assertNull(page0.getFragmentById(somePortletId[0]));
                            TestCase.assertTrue(page0.getFragmentsByName("some-app::SomePortlet").isEmpty());
                            Link link = pageManager.getLink("/default.link");
                            try
                            {
                                pageManager.getPage("/user-page.psml");
                                TestCase.assertTrue("Page /user-page.psml not viewable for manager", false);
                            }
                            catch (SecurityException se)
                            {
                            }                       
                            // test edit access
                            try
                            {
                                pageManager.updateFolder(folder);
                                TestCase.assertTrue("Folder / not editable for manager", false);
                            }
                            catch (SecurityException se)
                            {
                            }
                            try
                            {
                                pageManager.updatePageSecurity(pageSecurity);
                                TestCase.assertTrue("PageSecurity not editable for manager", false);
                            }
                            catch (SecurityException se)
                            {
                            }
                            pageManager.updatePage(page0);
                            pageManager.updateLink(link);
                            return null;
                        }
                        catch (Exception e)
                        {
                            return e;
                        }
                    }
                }, null);
            if (managerAccess != null)
            {
                throw managerAccess;
            }

            // access test as guest user
            Exception guestAccess = (Exception)JSSubject.doAsPrivileged(guestSubject, new PrivilegedAction()
                {
                    public Object run()
                    {
                        try
                        {
                            // test view access
                            Folder folder = pageManager.getFolder("/");
                            TestCase.assertNotNull(folder.getPageSecurity());
                            TestCase.assertNotNull(folder.getPages());
                            TestCase.assertEquals(1, folder.getPages().size());
                            PageSecurity pageSecurity = pageManager.getPageSecurity();
                            Page page0 = pageManager.getPage("/default-page.psml");
                            TestCase.assertNotNull(page0.getRootFragment());
                            TestCase.assertNotNull(page0.getRootFragment().getFragments());
                            TestCase.assertEquals(1, page0.getRootFragment().getFragments().size());
                            TestCase.assertNull(page0.getFragmentById(somePortletId[0]));
                            TestCase.assertTrue(page0.getFragmentsByName("some-app::SomePortlet").isEmpty());
                            Link link = pageManager.getLink("/default.link");
                            try
                            {
                                pageManager.getPage("/user-page.psml");
                                TestCase.assertTrue("Page /user-page.psml not viewable for guest", false);
                            }
                            catch (SecurityException se)
                            {
                            }                       
                            // test edit access
                            try
                            {
                                pageManager.updateFolder(folder);
                                TestCase.assertTrue("Folder / not editable for guest", false);
                            }
                            catch (SecurityException se)
                            {
                            }
                            try
                            {
                                pageManager.updatePageSecurity(pageSecurity);
                                TestCase.assertTrue("PageSecurity not editable for guest", false);
                            }
                            catch (SecurityException se)
                            {
                            }
                            try
                            {
                                pageManager.updatePage(page0);
                                TestCase.assertTrue("Page /default-page.psml not editable for guest", false);
                            }
                            catch (SecurityException se)
                            {
                            }
                            try
                            {
                                pageManager.updateLink(link);
                                TestCase.assertTrue("Page /default.link not editable for guest", false);
                            }
                            catch (SecurityException se)
                            {
                            }
                            return null;
                        }
                        catch (Exception e)
                        {
                            return e;
                        }
                    }
                }, null);
            if (guestAccess != null)
            {
                throw guestAccess;
            }

            // reset page manager cache
            pageManager.reset();

            // cleanup test as admin user
            Exception cleanup = (Exception)JSSubject.doAsPrivileged(adminSubject, new PrivilegedAction()
                {
                    public Object run()
                    {
                        try
                        {
                            // cleanup by removing root folder
                            try
                            {
                                Folder remove = pageManager.getFolder("/");
                                TestCase.assertEquals("/", remove.getPath());
                                pageManager.removeFolder(remove);
                            }
                            catch (FolderNotFoundException e)
                            {
                                TestCase.assertTrue("Folder / NOT FOUND", false);
View Full Code Here

                String jsPageShortTitle = request.getParameter("jsPageShortTitle");
                if ( jsPageName != null && jsPageName.length() > 0 && jsPageName.indexOf(Folder.PATH_SEPARATOR) == -1 )
                {
                    try
                    {               
                        Folder parent = (Folder)requestPage.getParent();
                        if (parent != null)
                        {
                            String path = parent.getPath();
                            if (path.endsWith(Folder.PATH_SEPARATOR))
                            {
                                path = path + getEscapedName(jsPageName);
                            }
                            else
                            {
                                path = path + Folder.PATH_SEPARATOR
                                        + getEscapedName(jsPageName);
                            }
                            Page page = pageManager.newPage(path);
                            if ( layout == null || layout.length() == 0 )
                            {
                                layout = requestPage.getRootFragment().getName();
                            }
                            page.getRootFragment().setName(layout);
                            page.setDefaultDecorator(requestPage.getDefaultDecorator(Fragment.LAYOUT), Fragment.LAYOUT);
                            page.setDefaultDecorator(requestPage.getDefaultDecorator(Fragment.PORTLET), Fragment.PORTLET);
                            page.setTitle(jsPageTitle != null && !jsPageTitle.equals("") ? jsPageTitle : jsPageName);
                            page.setShortTitle(jsPageShortTitle != null
                                            && !jsPageShortTitle.equals("") ? jsPageShortTitle
                                            : jsPageName);
                            pageManager.updatePage(page);
                            clearLayoutAttributes(request);                           
                            List orderList = parent.getDocumentOrder();
                            if (orderList != null)
                            {
                                String name = page.getName();
                                if (orderList.indexOf(name) < 0)
                                {
                                    orderList.add(name);
                                    parent.setDocumentOrder(orderList);
                                    pageManager.updateFolder(parent);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        throw new PortletException("Unable to access page for editing: "+e.getMessage(), e);
                    }                       
                }
                return;
            }

            if (request.getParameter("jsChangePageName") != null)
            {
                String jsPageTitle = request.getParameter("jsPageTitle");
                String jsPageShortTitle = request
                        .getParameter("jsPageShortTitle");
                try
                {
                    if (jsPageTitle != null && !jsPageTitle.equals(""))
                    {
                        requestPage.setTitle(jsPageTitle);
                    }
                    if (jsPageShortTitle != null
                            && !jsPageShortTitle.equals(""))
                    {
                        requestPage.setShortTitle(jsPageShortTitle);
                    }
                    pageManager.updatePage(requestPage);
                }
                catch (Exception e)
                {
                    throw new PortletException(
                            "Unable to access page for editing: "
                                    + e.getMessage(), e);
                }
                return;
            }

            if ( request.getParameter("jsDeletePage" ) != null )
            {
                try
                {
                    Folder parent = (Folder)requestPage.getParent();
                    if (parent != null)
                    {
                        List orderList = parent.getDocumentOrder();
                        if (orderList != null)
                        {
                            String name = requestPage.getName();
                            if (orderList.indexOf(name) > -1)
                            {
                                orderList.remove(name);
                                parent.setDocumentOrder(orderList);
                                pageManager.updateFolder(parent);
                            }
                        }
                    }

                    pageManager.removePage(requestPage);
                }
                catch (Exception e)
                {
                    throw new PortletException("Unable to access page for removing: "+e.getMessage(), e);
                }
                return;
            }

            if (request.getParameter("jsMovePageLeft") != null)
            {
                try
                {
                    Folder parent = (Folder) requestPage.getParent();
                    if (parent != null)
                    {
                        List orderList = parent.getDocumentOrder();
                        String name = requestPage.getName();
                        if (orderList != null)
                        {
                            int index = orderList.indexOf(name);
                            if (index > -1)
                            {
                                String type = requestPage.getType();
                                int i = index - 1;
                                while (i >= 0)
                                {
                                    String value = (String) orderList.get(i);
                                    if (value.endsWith(type))
                                    {
                                        orderList.remove(index);
                                        orderList.add(i, name);
                                        parent.setDocumentOrder(orderList);
                                        pageManager.updateFolder(parent);
                                        break;
                                    }
                                    i--;
                                }
                            }
                            else
                            {
                                orderList.add(name);
                                parent.setDocumentOrder(orderList);
                                pageManager.updateFolder(parent);
                            }
                        }
                        else
                        {
                            orderList = new ArrayList(4);
                            orderList.add(name);
                            parent.setDocumentOrder(orderList);
                            pageManager.updateFolder(parent);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new PortletException(
                            "Unable to access page for changing the document order: "
                                    + e.getMessage(), e);
                }
                return;
            }

            if (request.getParameter("jsMovePageRight") != null)
            {
                try
                {
                    Folder parent = (Folder) requestPage.getParent();
                    if (parent != null)
                    {
                        List orderList = parent.getDocumentOrder();
                        String name = requestPage.getName();
                        if (orderList != null)
                        {
                            int index = orderList.indexOf(name);
                            if (index > -1)
                            {
                                String type = requestPage.getType();
                                int i = index + 1;
                                while (i < orderList.size())
                                {
                                    String value = (String) orderList.get(i);
                                    if (value.endsWith(type))
                                    {
                                        orderList.remove(index);
                                        orderList.add(i, name);
                                        parent.setDocumentOrder(orderList);
                                        pageManager.updateFolder(parent);
                                        break;
                                    }
                                    i++;
                                }
                            }
                            else
                            {
                                orderList.add(name);
                                parent.setDocumentOrder(orderList);
                                pageManager.updateFolder(parent);
                            }
                        }
                        else
                        {
                            orderList = new ArrayList(4);
                            orderList.add(name);
                            parent.setDocumentOrder(orderList);
                            pageManager.updateFolder(parent);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new PortletException(
                            "Unable to access page for changing the document order: "
                                    + e.getMessage(), e);
                }
                return;
            }           

            if (request.getParameter("jsSubmitFolder") != null)
            {
                String jsFolderName = request.getParameter("jsFolderName");
                String jsFolderTitle = request.getParameter("jsFolderTitle");
                String jsFolderShortTitle = request.getParameter("jsFolderShortTitle");
                if (jsFolderName != null && jsFolderName.length() > 0
                        && jsFolderName.indexOf(Folder.PATH_SEPARATOR) == -1)
                {
                    try
                    {
                        Folder parent = (Folder) requestPage.getParent();
                        if (parent != null)
                        {
                            String path = parent.getPath();
                            if (path.endsWith(Folder.PATH_SEPARATOR))
                            {
                                path = path + getEscapedName(jsFolderName);
                            }
                            else
                            {
                                path = path + Folder.PATH_SEPARATOR
                                        + getEscapedName(jsFolderName);
                            }
                            Folder folder = pageManager.newFolder(path);
                            if (layout == null || layout.length() == 0)
                            {
                                layout = requestPage.getRootFragment()
                                        .getName();
                            }
                            folder.setDefaultDecorator(requestPage
                                    .getDefaultDecorator(Fragment.LAYOUT),
                                    Fragment.LAYOUT);
                            folder.setDefaultDecorator(requestPage
                                    .getDefaultDecorator(Fragment.PORTLET),
                                    Fragment.PORTLET);
                            folder
                                    .setTitle(jsFolderTitle != null
                                            && !jsFolderTitle.equals("") ? jsFolderTitle
                                            : jsFolderName);
                            folder
                                    .setShortTitle(jsFolderShortTitle != null
                                            && !jsFolderShortTitle.equals("") ? jsFolderShortTitle
                                            : jsFolderName);
                            pageManager.updateFolder(folder);

                            List orderList = parent.getDocumentOrder();
                            if (orderList != null)
                            {
                                String name = folder.getName();
                                if (orderList.indexOf(name) < 0)
                                {
                                    orderList.add(name);
                                    parent.setDocumentOrder(orderList);
                                    pageManager.updateFolder(parent);
                                }
                            }

                            // add default page
                            path = folder.getPath();
                            if (path.endsWith(Folder.PATH_SEPARATOR))
                            {
                                path = path + getEscapedName("default-page");
                            }
                            else
                            {
                                path = path + Folder.PATH_SEPARATOR
                                        + getEscapedName("default-page");
                            }
                            Page page = pageManager.newPage(path);
                            if (layout == null || layout.length() == 0)
                            {
                                layout = requestPage.getRootFragment()
                                        .getName();
                            }
                            page.getRootFragment().setName(layout);
                            page.setDefaultDecorator(requestPage
                                    .getDefaultDecorator(Fragment.LAYOUT),
                                    Fragment.LAYOUT);
                            page.setDefaultDecorator(requestPage
                                    .getDefaultDecorator(Fragment.PORTLET),
                                    Fragment.PORTLET);
                            page.setTitle(jsFolderName);
                            pageManager.updatePage(page);

                            orderList = folder.getDocumentOrder();
                            if (orderList != null)
                            {
                                String name = page.getName();
                                if (orderList.indexOf(name) < 0)
                                {
                                    orderList.add(name);
                                    folder.setDocumentOrder(orderList);
                                    pageManager.updateFolder(folder);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        throw new PortletException(
                                "Unable to access folder for editing: "
                                        + e.getMessage(), e);
                    }
                }
                return;
            }

            if (request.getParameter("jsChangeFolderName") != null)
            {
                String jsFolderTitle = request.getParameter("jsFolderTitle");
                String jsFolderShortTitle = request
                        .getParameter("jsFolderShortTitle");
                try
                {
                    Folder parent = (Folder) requestPage.getParent();
                    if (parent != null)
                    {
                        if (jsFolderTitle != null && !jsFolderTitle.equals(""))
                        {
                            parent.setTitle(jsFolderTitle);
                        }
                        if (jsFolderShortTitle != null
                                && !jsFolderShortTitle.equals(""))
                        {
                            parent.setShortTitle(jsFolderShortTitle);
                        }
                        pageManager.updateFolder(parent);
                    }

                }
                catch (Exception e)
                {
                    throw new PortletException(
                            "Unable to access folder for editing: "
                                    + e.getMessage(), e);
                }
                return;
            }
           
            if (request.getParameter("jsDeleteFolder") != null)
            {
                try
                {
                    Folder targetFolder = (Folder) requestPage.getParent();
                    Folder parent = (Folder) targetFolder.getParent();
                    if (parent != null)
                    {
                        List orderList = parent.getDocumentOrder();
                        if (orderList != null)
                        {
                            String name = targetFolder.getName();
                            if (orderList.indexOf(name) > -1)
                            {
                                orderList.remove(name);
                                parent.setDocumentOrder(orderList);
                                pageManager.updateFolder(parent);
                            }
                        }

                        // do not remove if the folder is root.
                        pageManager.removeFolder(targetFolder);
                    }
                }
                catch (Exception e)
                {
                    throw new PortletException(
                            "Unable to access folder for removing: "
                                    + e.getMessage(), e);
                }
                return;
            }

            if (request.getParameter("jsMoveFolderLeft") != null)
            {
                try
                {
                    Folder targetFolder = (Folder) requestPage.getParent();
                    Folder parent = (Folder) targetFolder.getParent();
                    if (parent != null)
                    {
                        List orderList = parent.getDocumentOrder();
                        String name = targetFolder.getName();
                        if (orderList != null)
                        {
                            int index = orderList.indexOf(name);
                            if (index > -1)
                            {
                                int i = index - 1;
                                while (i >= 0)
                                {
                                    String value = (String) orderList.get(i);
                                    if (!value.endsWith(".psml")
                                            && !value.endsWith(".link"))
                                    {
                                        orderList.remove(index);
                                        orderList.add(i, name);
                                        parent.setDocumentOrder(orderList);
                                        pageManager.updateFolder(parent);
                                        break;
                                    }
                                    i--;
                                }
                            }
                            else
                            {
                                orderList.add(name);
                                parent.setDocumentOrder(orderList);
                                pageManager.updateFolder(parent);
                            }
                        }
                        else
                        {
                            orderList = new ArrayList(4);
                            orderList.add(name);
                            parent.setDocumentOrder(orderList);
                            pageManager.updateFolder(parent);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new PortletException(
                            "Unable to access folder for changing the document order: "
                                    + e.getMessage(), e);
                }
                return;
            }

            if (request.getParameter("jsMoveFolderRight") != null)
            {
                try
                {
                    Folder targetFolder = (Folder) requestPage.getParent();
                    Folder parent = (Folder) targetFolder.getParent();
                    if (parent != null)
                    {
                        List orderList = parent.getDocumentOrder();
                        String name = targetFolder.getName();
                        if (orderList != null)
                        {
                            int index = orderList.indexOf(name);
                            if (index > -1)
                            {
                                int i = index + 1;
                                while (i < orderList.size())
                                {
                                    String value = (String) orderList.get(i);
                                    if (!value.endsWith(".psml")
                                            && !value.endsWith(".link"))
                                    {
                                        orderList.remove(index);
                                        orderList.add(i, name);
                                        parent.setDocumentOrder(orderList);
                                        pageManager.updateFolder(parent);
                                        break;
                                    }
                                    i++;
                                }
                            }
                            else
                            {
                                orderList.add(name);
                                parent.setDocumentOrder(orderList);
                                pageManager.updateFolder(parent);
                            }
                        }
                        else
                        {
                            orderList = new ArrayList(4);
                            orderList.add(name);
                            parent.setDocumentOrder(orderList);
                            pageManager.updateFolder(parent);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new PortletException(
                            "Unable to access folder for changing the document order: "
                                    + e.getMessage(), e);
                }
                return;
            }

            String theme = request.getParameter("theme");
            if ( theme != null && theme.length() > 0 && !theme.equals(requestPage.getDefaultDecorator(Fragment.LAYOUT)) )
            {
                requestPage.setDefaultDecorator(theme, Fragment.LAYOUT);
                try
                {
                    pageManager.updatePage(requestPage);
                }
                catch (Exception e)
                {
                    throw new PortletException("Unable to update page: "+e.getMessage(), e);
                }
                return;
            }
           
            String fragmentId = request.getParameter("fragment");
            if ( fragmentId != null && fragmentId.length() > 0 )
            {
                String move = request.getParameter("move");
                if ( move != null && move.length() > 0 )
                {
                    int moveCode = Integer.parseInt(move);                   
                    PortletWindow window = requestContext.getActionWindow();
                    Fragment currentFragment = requestPage.getFragmentById(window.getId().toString());
                    Fragment fragmentToMove = requestPage.getFragmentById(fragmentId);
                   
                    if ( currentFragment == null || fragmentToMove == null )
                    {
                        // ignore no longer consistent page definition
                        return;
                    }
                   
                    ColumnLayout columnLayout;
                    try
                    {
                        columnLayout = new ColumnLayout(numColumns, layoutType, currentFragment.getFragments(), null);
                        columnLayout.addLayoutEventListener(new PageManagerLayoutEventListener(pageManager, requestPage, layoutType));
                    }
                    catch (LayoutEventException e1)
                    {
                        throw new PortletException("Failed to build ColumnLayout "+e1.getMessage(), e1);
                    }

                    try
                    {               
                        switch (moveCode)
                        {
                        case LayoutEvent.MOVED_UP:
                            columnLayout.moveUp(fragmentToMove);
                            break;
                        case LayoutEvent.MOVED_DOWN:
                            columnLayout.moveDown(fragmentToMove);
                            break;
                        case LayoutEvent.MOVED_RIGHT:
                            columnLayout.moveRight(fragmentToMove);
                            break;
                        case LayoutEvent.MOVED_LEFT:
                            columnLayout.moveLeft(fragmentToMove);
                            break;
                        default:
                            throw new PortletException("Invalid movement code " + moveCode);
                        }
                      
                    }
                    catch (SecurityException se)
                    {
                        // ignore page security constraint violations, only
                        // permitted users can edit managed pages; page
                        // update will remain transient
                        log.info("Unable to update page " + requestPage.getId() + " layout due to security permission/constraint.", se);
                    }
                    catch (Exception e)
                    {
                        if (e instanceof PortletException)
                        {
                            throw (PortletException)e;
                        }
                        else
                        {
                            throw new PortletException("Unable to process layout for page " + requestPage.getId() + " layout: " + e.toString(), e);
                        }
                    }
                    return;
                }
               
                String remove = request.getParameter("remove");
                if ( remove != null && remove.length() > 0 )
                {
                    Page page = null;
                    try
                    {
                        // TODO: for now retrieve the real Page instead of ContentPage
                        //       because removing fragments isn't working through the ContentFragment wrapping
                        page = pageManager.getPage(requestPage.getPath());
                    }
                    catch (Exception e)
                    {
                        throw new PortletException("Unable to retrieve page "+requestPage.getId(),e);
                    }

                    PortletWindow window = requestContext.getActionWindow();
                    Fragment currentFragment = page.getFragmentById(window.getId().toString());

                    if ( currentFragment == null )
                    {
                        // ignore no longer consistent page definition
                        return;
                    }
                   
                    removeFragment(page, currentFragment, fragmentId);
                    return;
                }
               
                String decorator = request.getParameter("decorator");
                if ( decorator != null )
                {
                    Fragment fragment = requestPage.getFragmentById(fragmentId);

                    if ( fragment == null )
                    {
                        // ignore no longer consistent page definition
                        return;
                    }
                   
                    if (decorator.trim().length() == 0)
                        fragment.setDecorator(null);
                    else
                        fragment.setDecorator(decorator);
                    try
                    {
                        pageManager.updatePage(requestPage);
                    }
                    catch (Exception e)
                    {
                        throw new PortletException("Unable to update page for fragment decorator: "+e.getMessage(), e);
                    }
                    return;
                }
            }
            // change style for all pages in user folder
            String jsChangeUserPagesTheme = request.getParameter("jsChangeUserPagesTheme");
            if ( jsChangeUserPagesTheme != null )
            {
               String user_pages_theme = request.getParameter("user_pages_theme");
               try
                {
                   Folder f = pageManager.getUserFolder(request.getRemoteUser());
                   applyStyle(f,user_pages_theme,Fragment.LAYOUT);
                }
                catch (Exception e)
                {
                   throw new PortletException("Unable to update folder for defUserLayoutDeco decorator: "+e.getMessage(), e);
                }
                return;
            }               
            String jsChangeUserPortletsDeco = request.getParameter("jsChangeUserPortletsDeco");
            if ( jsChangeUserPortletsDeco != null )
            {                 
               String user_portlets_deco = request.getParameter("user_portlets_deco");
               try
                {
                   Folder f = pageManager.getUserFolder(request.getRemoteUser());
                   applyStyle(f,user_portlets_deco,Fragment.PORTLET);
                }
               catch (Exception e)
                {
                    throw new PortletException("Unable to update folder for defUserPortletDeco decorator: "+e.getMessage(), e);
View Full Code Here

           pageManager.updatePage(pp);
       }                      
       Iterator userFoldersIter = pageManager.getFolders(f).iterator();
       while(userFoldersIter.hasNext())
       {
           Folder ff = (Folder) userFoldersIter.next();
           applyStyle(ff,theme,theme_type);
       }
    }   
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.om.folder.Folder

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.