Package org.apache.jetspeed.om.page

Examples of org.apache.jetspeed.om.page.FragmentReference


                BaseFragmentElement pageRootFragment = pageOrTemplate.getRootFragment();
                if (pageRootFragment instanceof FragmentReference)
                {
                    // consume top level page fragment reference and build fragment
                    // hierarchy from referenced fragment
                    FragmentReference fragmentReferenceFragment = (FragmentReference)pageRootFragment;
                    contentFragmentId += CONTENT_FRAGMENT_ID_SEPARATOR+fragmentReferenceFragment.getId();
                    Fragment [] fragmentFragment = new Fragment[]{null};
                    contentFragmentImpl = newContentFragment(contentFragmentId, pageOrTemplate, fragmentDefinitions, pageOrTemplate, fragmentReferenceFragment, template, fragmentFragment);
                    // inherit page fragment attributes
                    mergeContentFragmentAttributes(contentFragmentImpl, pageFragmentFragment);
                    // inherit fragment reference attributes
                    mergeContentFragmentAttributes(contentFragmentImpl, fragmentReferenceFragment);
                    // set content fragment security constraints
                    setContentFragmentSecurityConstraints(contentFragmentImpl, fragmentReferenceFragment);
                    // test resolved reference id
                    if (fragmentFragment[0] != null)
                    {
                        // merge content fragment attributes
                        mergeContentFragmentAttributes(contentFragmentImpl, fragmentFragment[0]);
                    }
                    else
                    {
                        // constructed content fragment for fragment reference
                        // since reference id was not resolved
                        contentFragmentImpl.setType(ContentFragment.REFERENCE);                       
                    }
                }
                else if (pageRootFragment instanceof Fragment)
                {
                    // construct content fragment to reflect page fragment hierarchy
                    Fragment fragmentFragment = (Fragment)pageRootFragment;
                    contentFragmentId += CONTENT_FRAGMENT_ID_SEPARATOR+fragmentFragment.getId();
                    contentFragmentImpl = newContentFragment(contentFragmentId, pageOrTemplate, fragmentDefinitions, pageOrTemplate, fragmentFragment, null, null, false, false);
                    // inherit page fragment attributes
                    mergeContentFragmentAttributes(contentFragmentImpl, pageFragmentFragment);
                    // merge content fragment attributes
                    mergeContentFragmentAttributes(contentFragmentImpl, fragmentFragment);
                    // set content fragment security constraints
                    setContentFragmentSecurityConstraints(contentFragmentImpl, fragmentFragment);
                }
                // ensure that page/fragment hierarchy page root is a
                // layout portlet by generating a transient locked
                // parent layout fragment if necessary
                if (!contentFragmentImpl.getType().equals(ContentFragment.LAYOUT))
                {
                    ContentFragmentImpl layoutContentFragmentImpl = newContentFragment("", pageOrTemplate, null, null, null, null, false, true);
                    layoutContentFragmentImpl.setType(ContentFragment.LAYOUT);
                    layoutContentFragmentImpl.setName(defaultLayoutPortletName);
                    layoutContentFragmentImpl.getFragments().add(contentFragmentImpl);
                    contentFragmentImpl = layoutContentFragmentImpl;               
                }
            }
            else
            {
                // construct content fragment for page fragment
                contentFragmentImpl = newContentFragment(contentFragmentId, pageOrTemplate, definition, pageFragmentFragment, null, null, template, true);
                contentFragmentImpl.setType(ContentFragment.PAGE);
                // set content fragment attributes
                mergeContentFragmentAttributes(contentFragmentImpl, pageFragmentFragment);
                // set content fragment security constraints
                setContentFragmentSecurityConstraints(contentFragmentImpl, pageFragmentFragment);
            }
        }
        else if (fragment instanceof FragmentReference)
        {
            // consume fragment reference and build fragment hierarchy from
            // referenced fragment
            FragmentReference fragmentReferenceFragment = (FragmentReference)fragment;
            contentFragmentId = ((parentId != null) ? parentId+CONTENT_FRAGMENT_ID_SEPARATOR+fragmentReferenceFragment.getId() : fragmentReferenceFragment.getId());
            Fragment [] fragmentFragment = new Fragment[]{null};
            contentFragmentImpl = newContentFragment(contentFragmentId, pageOrTemplate, fragmentDefinitions, definition, fragmentReferenceFragment, template, fragmentFragment);
            // inherit fragment reference attributes
            mergeContentFragmentAttributes(contentFragmentImpl, fragmentReferenceFragment);
            // set content fragment security constraints
View Full Code Here


    /* (non-Javadoc)
     * @see org.apache.jetspeed.page.PageManager#newFragmentReference()
     */
    public FragmentReference newFragmentReference()
    {
        FragmentReference fragment = null;
        try
        {
            fragment = (FragmentReference)createObject(this.fragmentReferenceClass);
            fragment.setId(generator.getNextPeid());
        }
        catch (ClassCastException e)
        {
            String message = "Failed to create page object for " + this.fragmentReferenceClass;
            log.error(message, e);
View Full Code Here

                copyFragment.getFragments().add(copiedFragment);
            }
        }
        else if (source instanceof FragmentReference)
        {
            FragmentReference copyFragment = (FragmentReference)copy;
            FragmentReference sourceFragment = (FragmentReference)source;
            copyFragment.setRefId(sourceFragment.getRefId());           
        }

        return copy;
    }
View Full Code Here

           
            // check for edit permission
            fragment.checkAccess(JetspeedActions.EDIT);

            // create fragment reference and add to layout fragment
            FragmentReference newFragmentReference = pageManager.newFragmentReference();
            newFragmentReference.setRefId(id);
            if (!Utils.isNull(row))
            {
                newFragmentReference.setLayoutRow(row);
            }
            if (!Utils.isNull(column))
            {
                newFragmentReference.setLayoutColumn(column);
            }
            fragment.getFragments().add(newFragmentReference);

            // update page in page manager
            updatePage(pageOrTemplate);
View Full Code Here

            // check for edit permission
            fragment.checkAccess(JetspeedActions.EDIT);
           
            // create fragment reference and add to layout root fragment
            FragmentReference newFragmentReference = pageManager.newFragmentReference();
            newFragmentReference.setRefId(id);
            fragment.getFragments().add(newFragmentReference);

            // update page in page manager
            updatePage(pageOrTemplate);
View Full Code Here

            }
            if (!(fragment instanceof FragmentReference))
            {
                throw new IllegalArgumentException("Fragment reference required");               
            }
            FragmentReference fragmentReference = (FragmentReference)fragment;

            // check for edit permission
            fragmentReference.checkAccess(JetspeedActions.EDIT);           

            // update fragment reference in page manager
            boolean update = false;
            if (!refId.equals(fragmentReference.getRefId()))
            {
                fragmentReference.setRefId(refId);
                update = true;
            }
            if (update)
            {
                updatePage(pageOrTemplate);
View Full Code Here

        assertNotNull(f.getFragments());
        assertTrue(f.getFragments().size() == 2);

        bf = testpage.getFragmentById("f003");
        assertTrue(bf instanceof FragmentReference);
        FragmentReference fr = (FragmentReference)bf;
        assertTrue(fr.getId().equals("f003"));
        assertTrue(fr.getRefId().equals("test001"));

        List fragments = testpage.getFragmentsByName("JMXPortlet");
        assertNotNull(fragments);
        assertEquals(1, fragments.size());
        assertTrue(((Fragment)fragments.get(0)).getId().equals("pe002"));
        assertTrue(((Fragment)fragments.get(0)).getName().equals("JMXPortlet"));
        assertTrue(((Fragment)fragments.get(0)).getType().equals(Fragment.PORTLET));
        List fragmentsByInterface = testpage.getFragmentsByInterface(null);
        assertNotNull(fragmentsByInterface);
        assertEquals(7, fragmentsByInterface.size());
        fragmentsByInterface = testpage.getFragmentsByInterface(FragmentReference.class);
        assertNotNull(fragmentsByInterface);
        assertEquals(1, fragmentsByInterface.size());

        PageTemplate testpagetemplate = pageManager.getPageTemplate("/test001.tpsml");
        assertNotNull(testpagetemplate);
        assertTrue(testpagetemplate.getId().equals("/test001.tpsml"));
        assertTrue(testpagetemplate.getTitle().equals("Test Page Template"));
        assertTrue(testpagetemplate.getSkin().equals("test-template-skin"));
        assertTrue(testpagetemplate.getDefaultDecorator(Fragment.LAYOUT).equals("test-template-layout"));
        assertTrue(testpagetemplate.getDefaultDecorator(Fragment.PORTLET).equals("test-template-portlet"));
        assertTrue(testpagetemplate.getVersion().equals("2.77"));   
        md = testpagetemplate.getMetadata();
        descriptions = md.getFields("description");
        assertNotNull(descriptions);
        assertEquals(1, descriptions.size());
        rootFragmentElement = testpagetemplate.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
        root = (Fragment)rootFragmentElement;
        assertNotNull(root);
        assertTrue(root.getId().equals("pt-f001"));
        assertTrue(root.getName().equals("TwoColumns"));
        assertTrue(root.getType().equals(Fragment.LAYOUT));
        assertNotNull(root.getFragments());
        assertTrue(root.getFragments().size() == 3);
        f = (Fragment)root.getFragments().get(0);
        assertTrue(f.getId().equals("pt-f002"));
        assertTrue(f.getName().equals("TemplatePortlet"));
        assertTrue(f.getType().equals(Fragment.PORTLET));
        bf = testpagetemplate.getFragmentById("pt-f003");
        assertTrue(bf instanceof PageFragment);
        PageFragment pf = (PageFragment)bf;
        assertTrue(pf.getId().equals("pt-f003"));
        bf = testpagetemplate.getFragmentById("pt-f004");
        assertTrue(bf instanceof FragmentReference);
        fr = (FragmentReference)bf;
        assertTrue(fr.getId().equals("pt-f004"));
        assertTrue(fr.getRefId().equals("test001"));

        DynamicPage testdynamicpage = pageManager.getDynamicPage("/test001.dpsml");
        assertTrue(testdynamicpage.getId().equals("/test001.dpsml"));
        assertTrue(testdynamicpage.getContentType().equals("default"));       
        assertTrue(testdynamicpage.isInheritable());       
        assertTrue(testdynamicpage.getTitle().equals("Test Dynamic Page"));
        assertTrue(testdynamicpage.getVersion().equals("2.77"));
        rootFragmentElement = testdynamicpage.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
        root = (Fragment)rootFragmentElement;
        assertNotNull(root);
        assertTrue(root.getId().equals("dp-f001"));
        assertTrue(root.getName().equals("TwoColumns"));
        assertTrue(root.getType().equals(Fragment.LAYOUT));
        assertNotNull(root.getFragments());
        assertTrue(root.getFragments().size() == 2);
        f = (Fragment)root.getFragments().get(0);
        assertTrue(f.getId().equals("dp-f002"));
        assertTrue(f.getName().equals("HelloPortlet"));
        assertTrue(f.getType().equals(Fragment.PORTLET));
        bf = testdynamicpage.getFragmentById("dp-f003");
        assertTrue(bf instanceof FragmentReference);
        fr = (FragmentReference)bf;
        assertTrue(fr.getId().equals("dp-f003"));
        assertTrue(fr.getRefId().equals("test001"));
   
        FragmentDefinition testfragmentdefinition = pageManager.getFragmentDefinition("/test001.fpsml");
        assertTrue(testfragmentdefinition.getId().equals("/test001.fpsml"));
        assertTrue(testfragmentdefinition.getTitle().equals("Test Fragment Definition"));
        assertTrue(testfragmentdefinition.getVersion().equals("2.77"));
View Full Code Here

        f.setLayoutY(100.0F);
        f.setProperty("custom-0", null, null, "custom-value-0");
        f.setProperty("custom-1", null, null, "custom-value-1");
        f.setProperty("custom-2", null, null, "custom-value-2");
        root.getFragments().add(f);
        FragmentReference fr = pageManager.newFragmentReference();
        fr.setRefId("test002");
        root.getFragments().add(fr);

        SecurityConstraints constraints = page.newSecurityConstraints();
        constraints.setOwner("new-user");
        List constraintsList = new ArrayList(1);
        SecurityConstraint constraint = page.newSecurityConstraint();
        constraint.setUsers(Shared.makeListFromCSV("user10,user11"));
        constraint.setRoles(Shared.makeListFromCSV("*"));
        constraint.setPermissions(Shared.makeListFromCSV(JetspeedActions.EDIT + "," + JetspeedActions.VIEW));
        constraintsList.add(constraint);
        constraints.setSecurityConstraints(constraintsList);
        List constraintsRefsList = new ArrayList(1);
        constraintsRefsList.add("public-view");
        constraints.setSecurityConstraintsRefs(constraintsRefsList);
        page.setSecurityConstraints(constraints);

        try
        {
            pageManager.updatePage(page);
        }
        catch (Exception e)
        {
            String errmsg = "Exception in page update: " + e.toString();
            e.printStackTrace();
            System.err.println(errmsg);
            assertNotNull(errmsg, null);
        }
       
        final Fragment userFragment = (Fragment)((Fragment)page.getRootFragment()).getFragments().get(0);
        Exception userException = (Exception)JSSubject.doAsPrivileged(constructUserSubject(), new PrivilegedAction()
        {
            public Object run()
            {
                try
                {
                    userFragment.setProperty("custom-1", Fragment.USER_PROPERTY_SCOPE, "user", "custom-value-user-1");
                    userFragment.setProperty("custom-2", Fragment.USER_PROPERTY_SCOPE, null, "custom-value-user-2");

                    try
                    {
                        pageManager.updateFragmentProperties(userFragment, PageManager.USER_PROPERTY_SCOPE);
                    }
                    catch (Exception e)
                    {
                        String errmsg = "Exception in page fragment properties update: " + e.toString();
                        e.printStackTrace();
                        System.err.println(errmsg);
                        assertNotNull(errmsg, null);
                    }
                    return null;
                }
                catch (Exception e)
                {
                    return e;
                }
                finally
                {
                    JSSubject.clearSubject();
                }
            }
        }, null);
        if (userException != null)
        {
            throw userException;
        }

        page = pageManager.getPage("/test002.psml");
        assertNotNull(page);
        assertTrue(page.getId().equals("/test002.psml"));
        assertEquals("Created Page", page.getTitle());
        assertEquals("Created Page de PSML", page.getTitle(Locale.FRENCH));
        assertEquals("Created \u3078\u3088\u3046\u3053\u305d", page.getTitle(Locale.JAPANESE));
        assertNotNull(page.getRootFragment());
        rootFragmentElement = page.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
        root = (Fragment)rootFragmentElement;
        assertTrue(root.getName().equals("TestLayout"));
        assertTrue(root.getFragments().size() == 2);
        BaseFragmentElement bf = (BaseFragmentElement)root.getFragments().get(0);
        assertTrue(bf instanceof Fragment);
        f = (Fragment)bf;
        assertNotNull(f.getProperties());
        assertEquals(0, f.getIntProperty(Fragment.ROW_PROPERTY_NAME));
        assertTrue((99.9F < f.getLayoutX()) && (100.1F > f.getLayoutX()));
        assertEquals("custom-value-0", f.getProperty("custom-0"));
        assertEquals("custom-value-1", f.getProperty("custom-1"));
        final Fragment userFragment2 = f;
        Exception userException2 = (Exception)JSSubject.doAsPrivileged(constructUserSubject(), new PrivilegedAction()
        {
            public Object run()
            {
                try
                {
                    assertEquals("custom-value-0", userFragment2.getProperty("custom-0"));
                    assertEquals("custom-value-user-1", userFragment2.getProperty("custom-1"));
                    assertEquals("custom-value-user-2", userFragment2.getProperty("custom-2"));
                    return null;
                }
                catch (Exception e)
                {
                    return e;
                }
                finally
                {
                    JSSubject.clearSubject();
                }
            }
        }, null);
        if (userException2 != null)
        {
            throw userException2;
        }

        PageTemplate pagetemplate = pageManager.newPageTemplate("/test002.tpsml");
        pagetemplate.setTitle("Created Page Template");
        metadata = pagetemplate.getMetadata();
        metadata.addField(null, "description", "Page Template Description");
        rootFragmentElement = pagetemplate.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
        root = (Fragment)rootFragmentElement;
        root.setName("TestLayout");
        f = pageManager.newFragment();
        f.setType(Fragment.PORTLET);
        f.setName("TestPortlet");
        properties = f.getProperties();
        fp = pageManager.newFragmentProperty();
        fp.setName(Fragment.ROW_PROPERTY_NAME);
        fp.setValue("1");
        properties.add(fp);
        fp = pageManager.newFragmentProperty();
        fp.setName(Fragment.COLUMN_PROPERTY_NAME);
        fp.setValue("1");
        properties.add(fp);
        root.getFragments().add(f);
        fr = pageManager.newFragmentReference();
        fr.setRefId("test002");
        root.getFragments().add(fr);
        PageFragment pf = pageManager.newPageFragment();
        root.getFragments().add(pf);       
        constraints = pagetemplate.newSecurityConstraints();
        constraints.setOwner("new-user");
        pagetemplate.setSecurityConstraints(constraints);
        try
        {
            pageManager.updatePageTemplate(pagetemplate);
        }
        catch (Exception e)
        {
            String errmsg = "Exception in page template update: " + e.toString();
            e.printStackTrace();
            System.err.println(errmsg);
            assertNotNull(errmsg, null);
        }
        pagetemplate = pageManager.getPageTemplate("/test002.tpsml");
        assertNotNull(pagetemplate);
        assertTrue(pagetemplate.getId().equals("/test002.tpsml"));
        assertEquals("Created Page Template", pagetemplate.getTitle());
        assertNotNull(pagetemplate.getRootFragment());
        rootFragmentElement = pagetemplate.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
        root = (Fragment)rootFragmentElement;
        assertTrue(root.getName().equals("TestLayout"));
        assertTrue(root.getType().equals(Fragment.LAYOUT));
        assertTrue(root.getFragments().size() == 3);
        bf = (BaseFragmentElement)root.getFragments().get(0);
        assertTrue(bf instanceof Fragment);
        f = (Fragment)bf;
        assertTrue(f.getName().equals("TestPortlet"));
        assertTrue(f.getType().equals(Fragment.PORTLET));
        assertNotNull(f.getProperties());
        assertEquals(1, f.getIntProperty(Fragment.ROW_PROPERTY_NAME));
        bf = (BaseFragmentElement)root.getFragments().get(1);
        assertTrue(bf instanceof FragmentReference);
        fr = (FragmentReference)bf;
        assertTrue(fr.getRefId().equals("test002"));
        bf = (BaseFragmentElement)root.getFragments().get(2);
        assertTrue(bf instanceof PageFragment);

        DynamicPage dynamicpage = pageManager.newDynamicPage("/test002.dpsml");
        dynamicpage.setContentType("default");       
        dynamicpage.setInheritable(false);       
        dynamicpage.setTitle("Created Dynamic Page");
        rootFragmentElement = dynamicpage.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
        root = (Fragment)rootFragmentElement;
        root.setName("TestLayout");
        f = pageManager.newFragment();
        f.setType(Fragment.PORTLET);
        f.setName("TestPortlet");
        root.getFragments().add(f);       
        fr = pageManager.newFragmentReference();
        fr.setRefId("test002");
        root.getFragments().add(fr);       
        try
        {
            pageManager.updateDynamicPage(dynamicpage);
        }
        catch (Exception e)
        {
            String errmsg = "Exception in dynamic page update: " + e.toString();
            e.printStackTrace();
            System.err.println(errmsg);
            assertNotNull(errmsg, null);
        }
        dynamicpage = pageManager.getDynamicPage("/test002.dpsml");
        assertNotNull(dynamicpage);
        assertTrue(dynamicpage.getId().equals("/test002.dpsml"));
        assertEquals("default", dynamicpage.getContentType());
        assertFalse(dynamicpage.isInheritable());
        assertEquals("Created Dynamic Page", dynamicpage.getTitle());
        assertNotNull(dynamicpage.getRootFragment());
        rootFragmentElement = dynamicpage.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
        root = (Fragment)rootFragmentElement;
        assertTrue(root.getName().equals("TestLayout"));
        assertTrue(root.getType().equals(Fragment.LAYOUT));
        assertTrue(root.getFragments().size() == 2);
        bf = (BaseFragmentElement)root.getFragments().get(0);
        assertTrue(bf instanceof Fragment);
        f = (Fragment)bf;
        assertTrue(f.getName().equals("TestPortlet"));
        assertTrue(f.getType().equals(Fragment.PORTLET));
        bf = (BaseFragmentElement)root.getFragments().get(1);
        assertTrue(bf instanceof FragmentReference);
        fr = (FragmentReference)bf;
        assertTrue(fr.getRefId().equals("test002"));

        FragmentDefinition fragmentdefinition = pageManager.newFragmentDefinition("/test002.fpsml");
        fragmentdefinition.setTitle("Created Fragment Definition");
        rootFragmentElement = fragmentdefinition.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
View Full Code Here

        assertTrue(bf instanceof PageFragment);
        PageFragment pf = (PageFragment)bf;
        assertFalse(pf.getId().equals("cpt-f003"));
        bf = (BaseFragmentElement)root.getFragments().get(2);
        assertTrue(bf instanceof FragmentReference);
        FragmentReference fr = (FragmentReference)bf;
        assertFalse(fr.getId().equals("cpt-f004"));
        assertTrue(fr.getRefId().equals("ctest001"));

        DynamicPage testdynamicpage = pageManager.getDynamicPage("/clonetest.dpsml");
        assertNotNull(testdynamicpage);
        DynamicPage clonedynamicpage = pageManager.copyDynamicPage(testdynamicpage, "/cloned.dpsml");
        assertNotNull(clonedynamicpage);
        assertTrue(clonedynamicpage.getId().equals("/cloned.dpsml"));
        assertTrue(clonedynamicpage.getContentType().equals("default"));       
        assertTrue(clonedynamicpage.isInheritable());       
        assertTrue(clonedynamicpage.getTitle().equals("Clone Test Dynamic Page"));
        rootFragmentElement = clonedynamicpage.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
        root = (Fragment)rootFragmentElement;
        assertNotNull(root);
        assertFalse(root.getId().equals("cdp-f001"));
        assertTrue(root.getName().equals("TwoColumns"));
        assertTrue(root.getType().equals(Fragment.LAYOUT));
        assertNotNull(root.getFragments());
        assertTrue(root.getFragments().size() == 2);
        f = (Fragment)root.getFragments().get(0);
        assertFalse(f.getId().equals("cdp-f002"));
        assertTrue(f.getName().equals("HelloPortlet"));
        assertTrue(f.getType().equals(Fragment.PORTLET));
        bf = (BaseFragmentElement)root.getFragments().get(1);
        assertTrue(bf instanceof FragmentReference);
        fr = (FragmentReference)bf;
        assertFalse(fr.getId().equals("cdp-f003"));
        assertTrue(fr.getRefId().equals("ctest001"));   

        FragmentDefinition testfragmentdefinition = pageManager.getFragmentDefinition("/clonetest.fpsml");
        assertNotNull(testfragmentdefinition);
        FragmentDefinition clonefragmentdefinition = pageManager.copyFragmentDefinition(testfragmentdefinition, "/cloned.fpsml");
        assertNotNull(clonefragmentdefinition);
View Full Code Here

        portlet.setLayoutHeight(55.55F);
        SecurityConstraints fragmentConstraints = portlet.newSecurityConstraints();
        fragmentConstraints.setOwner("user");
        portlet.setSecurityConstraints(fragmentConstraints);
        root.getFragments().add(portlet);
        FragmentReference fragmentReference = pageManager.newFragmentReference();
        fragmentReference.setRefId("fragment-definition");
        root.getFragments().add(fragmentReference);

        pageManager.updatePage(page);

        assertNotNull(page.getParent());
        assertEquals(page.getParent().getId(), folder.getId());
        assertNotNull(folder.getPages());
        assertEquals(1, folder.getPages().size());
        assertNotNull(pageManager.getPages(folder));
        assertEquals(1, pageManager.getPages(folder).size());
       
        final Fragment userRootFragment = (Fragment)page.getRootFragment();
        Exception userException = (Exception)JSSubject.doAsPrivileged(constructUserSubject(), new PrivilegedAction()
        {
            public Object run()
            {
                try
                {
                    if (FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
                    {
                        userRootFragment.setProperty("custom-1", FragmentProperty.ROLE_PROPERTY_SCOPE, "role", "custom-value-role-1");
                        userRootFragment.setProperty("custom-2", FragmentProperty.ROLE_PROPERTY_SCOPE, "role", "custom-value-role-2");
                        userRootFragment.setProperty("custom-2", FragmentProperty.GROUP_PROPERTY_SCOPE, "group", "custom-value-group-2");
                        userRootFragment.setProperty("custom-3", FragmentProperty.ROLE_PROPERTY_SCOPE, "role", "custom-value-role-3");
                        userRootFragment.setProperty("custom-3", FragmentProperty.GROUP_PROPERTY_SCOPE, "group", "custom-value-group-3");
                    }
                    userRootFragment.setProperty("custom-3", FragmentProperty.USER_PROPERTY_SCOPE, "user", "custom-value-user-3");

                    if (FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
                    {
                        pageManager.updateFragmentProperties(userRootFragment, PageManager.ROLE_PROPERTY_SCOPE);
                        pageManager.updateFragmentProperties(userRootFragment, PageManager.GROUP_PROPERTY_SCOPE);
                    }
                    pageManager.updateFragmentProperties(userRootFragment, PageManager.USER_PROPERTY_SCOPE);
                    return null;
                }
                catch (Exception e)
                {
                    return e;
                }
                finally
                {
                    JSSubject.clearSubject();
                }
            }
        }, null);
        if (userException != null)
        {
            throw userException;
        }

        page = pageManager.newPage("/another-page.psml");
        assertEquals("Another Page", page.getTitle());
        page.setTitle("Another Page");
        pageManager.updatePage(page);
        assertNotNull(page.getParent());
        assertEquals(page.getParent().getId(), folder.getId());
        page = pageManager.newPage("/some-other-page.psml");
        assertEquals("Some Other Page", page.getTitle());
        page.setTitle("Some Other Page");
        pageManager.updatePage(page);
        assertNotNull(page.getParent());
        assertEquals(page.getParent().getId(), folder.getId());
        assertEquals(3, folder.getPages().size());
        assertEquals(3, pageManager.getPages(folder).size());

        Link link = pageManager.newLink("/default.link");
        assertEquals("Default", link.getTitle());
        link.setTitle("Default Link");
        link.setVersion("1.23");
        link.setShortTitle("Default");
        link.setTarget("top");
        link.setUrl("http://www.default.org/");
        metadata = link.getMetadata();
        metadata.addField(Locale.FRENCH, "title", "[fr] Default Link");
        metadata.addField(Locale.GERMAN, "title", "[de] Default Link");
        SecurityConstraints linkConstraints = link.newSecurityConstraints();
        linkConstraints.setOwner("user");
        List inlineLinkConstraints = new ArrayList(1);
        SecurityConstraint linkConstraint = link.newSecurityConstraint();
        linkConstraint.setUsers(Shared.makeListFromCSV("jetspeed"));
        linkConstraint.setPermissions(Shared.makeListFromCSV("edit"));
        inlineLinkConstraints.add(linkConstraint);
        linkConstraints.setSecurityConstraints(inlineLinkConstraints);
        List linkConstraintsRefs = new ArrayList(1);
        linkConstraintsRefs.add("manager-edit");
        linkConstraints.setSecurityConstraintsRefs(linkConstraintsRefs);
        link.setSecurityConstraints(linkConstraints);

        pageManager.updateLink(link);

        assertNotNull(link.getParent());
        assertEquals(link.getParent().getId(), folder.getId());
        assertNotNull(folder.getLinks());
        assertEquals(1, folder.getLinks().size());
        assertNotNull(pageManager.getLinks(folder));
        assertEquals(1, pageManager.getLinks(folder).size());

        PageSecurity pageSecurity = pageManager.newPageSecurity();
        List constraintsDefs = new ArrayList(2);
        SecurityConstraintsDef constraintsDef = pageManager.newSecurityConstraintsDef();
        constraintsDef.setName("public-view");
        List defConstraints = new ArrayList(1);
        SecurityConstraint defConstraint = pageSecurity.newSecurityConstraint();
        defConstraint.setUsers(Shared.makeListFromCSV("*"));
        defConstraint.setPermissions(Shared.makeListFromCSV("view"));
        defConstraints.add(defConstraint);
        constraintsDef.setSecurityConstraints(defConstraints);
        constraintsDefs.add(constraintsDef);
        constraintsDef = pageSecurity.newSecurityConstraintsDef();
        constraintsDef.setName("admin-all");
        defConstraints = new ArrayList(2);
        defConstraint = pageSecurity.newSecurityConstraint();
        defConstraint.setRoles(Shared.makeListFromCSV("admin"));
        defConstraint.setPermissions(Shared.makeListFromCSV("view,edit"));
        defConstraints.add(defConstraint);
        defConstraint = pageSecurity.newSecurityConstraint();
        defConstraint.setRoles(Shared.makeListFromCSV("nobody"));
        defConstraints.add(defConstraint);
        constraintsDef.setSecurityConstraints(defConstraints);
        constraintsDefs.add(constraintsDef);
        pageSecurity.setSecurityConstraintsDefs(constraintsDefs);
        List globalConstraintsRefs = new ArrayList(2);
        globalConstraintsRefs.add("admin-all");
        globalConstraintsRefs.add("public-view");
        pageSecurity.setGlobalSecurityConstraintsRefs(globalConstraintsRefs);

        pageManager.updatePageSecurity(pageSecurity);

        assertNotNull(pageSecurity.getParent());
        assertEquals(pageSecurity.getParent().getId(), folder.getId());
        assertNotNull(folder.getPageSecurity());

        PageTemplate pageTemplate = pageManager.newPageTemplate("/page-template.tpsml");
        pageTemplate.setTitle("Created Page Template");
        metadata = pageTemplate.getMetadata();
        metadata.addField(null, "description", "Page Template Description");
        rootFragmentElement = pageTemplate.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
        root = (Fragment)rootFragmentElement;
        root.setName("jetspeed-layouts::VelocityTwoColumns");
        portlet = pageManager.newFragment();
        portlet.setType(Fragment.PORTLET);
        portlet.setName("templates::MenusTemplatePortlet");
        portlet.setLayoutRow(1);
        portlet.setLayoutColumn(1);
        root.getFragments().add(portlet);
        fragmentReference = pageManager.newFragmentReference();
        fragmentReference.setRefId("fragment-definition");
        root.getFragments().add(fragmentReference);
        PageFragment pageFragment = pageManager.newPageFragment();
        root.getFragments().add(pageFragment);       
        SecurityConstraints constraints = pageTemplate.newSecurityConstraints();
        constraints.setOwner("admin");
        pageTemplate.setSecurityConstraints(constraints);

        pageManager.updatePageTemplate(pageTemplate);

        DynamicPage dynamicPage = pageManager.newDynamicPage("/dynamic-page.dpsml");
        dynamicPage.setContentType("default");
        assertTrue(dynamicPage.isInheritable());
        dynamicPage.setInheritable(false);       
        dynamicPage.setTitle("Created Dynamic Page");
        rootFragmentElement = dynamicPage.getRootFragment();
        assertTrue(rootFragmentElement instanceof Fragment);
        root = (Fragment)rootFragmentElement;
        root.setName("jetspeed-layouts::VelocityTwoColumns");
        portlet = pageManager.newFragment();
        portlet.setType(Fragment.PORTLET);
        portlet.setName("content-app::ContentPortlet");
        root.getFragments().add(portlet);       
        fragmentReference = pageManager.newFragmentReference();
        fragmentReference.setRefId("fragment-definition");
        root.getFragments().add(fragmentReference);       

        pageManager.updateDynamicPage(dynamicPage);

        FragmentDefinition fragmentDefinition = pageManager.newFragmentDefinition("/fragment-definition.fpsml");
View Full Code Here

TOP

Related Classes of org.apache.jetspeed.om.page.FragmentReference

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.