Package org.apache.jetspeed.om.page

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


            Fragment check0 = (Fragment)checkElement0;
            assertEquals("content-app::ContentPortlet", check0.getName());
            assertEquals(Fragment.PORTLET, check0.getType());
            BaseFragmentElement checkElement1 = (BaseFragmentElement)root.getFragments().get(1);
            assertTrue(checkElement1 instanceof FragmentReference);
            FragmentReference check1 = (FragmentReference)checkElement1;
            assertEquals("fragment-definition", check1.getRefId());
        }
        catch (PageNotFoundException e)
        {
            assertTrue("DynamicPage /dynamic-page.dpsml NOT FOUND", false);
        }
        try
        {
            PageTemplate check = pageManager.getPageTemplate("/page-template.tpsml");
            assertNotNull(check);
            assertEquals("Created Page Template", check.getTitle());
            assertNotNull(check.getRootFragment());
            BaseFragmentElement rootFragmentElement = check.getRootFragment();
            assertTrue(rootFragmentElement instanceof Fragment);
            Fragment root = (Fragment)rootFragmentElement;
            assertEquals("jetspeed-layouts::VelocityTwoColumns", root.getName());
            assertEquals(Fragment.LAYOUT, root.getType());
            assertEquals(3, root.getFragments().size());
            BaseFragmentElement checkElement0 = (BaseFragmentElement)root.getFragments().get(0);
            assertTrue(checkElement0 instanceof Fragment);
            Fragment check0 = (Fragment)checkElement0;
            assertEquals("templates::MenusTemplatePortlet", check0.getName());
            assertEquals(Fragment.PORTLET, check0.getType());
            assertEquals(1, check0.getLayoutRow());
            BaseFragmentElement checkElement1 = (BaseFragmentElement)root.getFragments().get(1);
            assertTrue(checkElement1 instanceof FragmentReference);
            FragmentReference check1 = (FragmentReference)checkElement1;
            assertEquals("fragment-definition", check1.getRefId());
            BaseFragmentElement checkElement2 = (BaseFragmentElement)root.getFragments().get(2);
            assertTrue(checkElement2 instanceof PageFragment);
        }
        catch (PageNotFoundException e)
        {
            assertTrue("PageTemplate /page-template.tpsml NOT FOUND", false);
        }
        try
        {
            Page check = pageManager.getPage("/default-page.psml");
            assertEquals("/default-page.psml", check.getPath());
            assertEquals("default-page.psml", check.getName());
            assertEquals("/default-page.psml", check.getUrl());
            assertEquals("Default Page", check.getTitle());
            assertEquals("6.89", check.getVersion());           
            assertEquals("tigris", check.getEffectiveDefaultDecorator(Fragment.LAYOUT));
            assertEquals("tigris", check.getDefaultDecorator(Fragment.LAYOUT));
            assertEquals("blue-gradient", check.getDefaultDecorator(Fragment.PORTLET));
            assertEquals("skin-1", check.getSkin());
            assertEquals("Default", check.getShortTitle());
            assertNotNull(check.getMetadata());
            assertEquals("[fr] Default Page", check.getTitle(Locale.FRENCH));
            assertEquals("[ja] Default Page", check.getTitle(Locale.JAPANESE));
            assertNotNull(check.getSecurityConstraints());
            assertEquals("user", check.getSecurityConstraints().getOwner());
            assertNotNull(check.getSecurityConstraints().getSecurityConstraintsRefs());
            assertEquals(1, check.getSecurityConstraints().getSecurityConstraintsRefs().size());
            assertEquals("manager-edit", (String)check.getSecurityConstraints().getSecurityConstraintsRefs().get(0));
            assertNotNull(check.getSecurityConstraints().getSecurityConstraints());
            assertEquals(1, check.getSecurityConstraints().getSecurityConstraints().size());
            assertEquals("jetspeed", Shared.makeCSVFromList(((SecurityConstraint)check.getSecurityConstraints().getSecurityConstraints().get(0)).getUsers()));
            assertNotNull(check.getMenuDefinitions());
            assertEquals(2, check.getMenuDefinitions().size());
            MenuDefinition checkMenu = (MenuDefinition)check.getMenuDefinitions().get(0);
            assertEquals("page-menu-1", checkMenu.getName());
            assertEquals("The Test Page Menu", checkMenu.getTitle());
            assertEquals("[fr] The Test Page Menu", checkMenu.getTitle(Locale.FRENCH));
            assertNotNull(checkMenu.getMenuElements());
            assertEquals(5,checkMenu.getMenuElements().size());
            assertTrue(checkMenu.getMenuElements().get(0) instanceof MenuSeparatorDefinition);
            assertEquals("-- Page Menu --", ((MenuSeparatorDefinition)checkMenu.getMenuElements().get(0)).getText());
            assertTrue(checkMenu.getMenuElements().get(1) instanceof MenuOptionsDefinition);
            assertEquals("/*.psml", ((MenuOptionsDefinition)checkMenu.getMenuElements().get(1)).getOptions());
            assertTrue(checkMenu.getMenuElements().get(2) instanceof MenuDefinition);
            assertEquals("/*/", ((MenuDefinition)checkMenu.getMenuElements().get(2)).getOptions());
            assertNotNull(((MenuDefinition)checkMenu.getMenuElements().get(2)).getMenuElements());
            assertTrue(((MenuDefinition)checkMenu.getMenuElements().get(2)).getMenuElements().isEmpty());
            assertTrue(checkMenu.getMenuElements().get(3) instanceof MenuExcludeDefinition);
            assertEquals("exclude-menu", ((MenuExcludeDefinition)checkMenu.getMenuElements().get(3)).getName());
            assertTrue(checkMenu.getMenuElements().get(4) instanceof MenuIncludeDefinition);
            assertEquals("include-menu", ((MenuIncludeDefinition)checkMenu.getMenuElements().get(4)).getName());
            checkMenu = (MenuDefinition)check.getMenuDefinitions().get(1);
            assertEquals("page-menu-2", checkMenu.getName());
            assertNotNull(checkMenu.getMenuElements());
            assertTrue(checkMenu.getMenuElements().isEmpty());
            assertNotNull(check.getRootFragment());
            assertEquals("blue-gradient", check.getRootFragment().getDecorator());
            BaseFragmentElement checkRootFragmentElement = check.getRootFragment();
            assertTrue(checkRootFragmentElement instanceof Fragment);
            Fragment checkRootFragment = (Fragment)checkRootFragmentElement;
            assertEquals("jetspeed-layouts::VelocityTwoColumns", checkRootFragment.getName());
            assertEquals("Root", check.getRootFragment().getShortTitle());
            assertEquals("Root Fragment", check.getRootFragment().getTitle());
            assertEquals("Normal", check.getRootFragment().getState());
            assertEquals("50%,50%", check.getRootFragment().getLayoutSizes());
            assertNotNull(check.getRootFragment().getProperties());
            assertEquals("custom-prop-value1", check.getRootFragment().getProperty("custom-prop1"));
            assertEquals("custom-value-0", checkRootFragment.getProperty("custom-0"));
            assertEquals("custom-value-1", checkRootFragment.getProperty("custom-1"));
            assertEquals("custom-value-2", checkRootFragment.getProperty("custom-2"));
            assertEquals("custom-value-3", checkRootFragment.getProperty("custom-3"));
            final Fragment checkUserFragment = checkRootFragment;
            Exception userException = (Exception)JSSubject.doAsPrivileged(constructUserSubject(), new PrivilegedAction()
            {
                public Object run()
                {
                    try
                    {
                        List properties = checkUserFragment.getProperties();
                        assertNotNull(properties);
                        assertEquals((FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED ? 12 : 7), properties.size());
                        assertEquals("50%,50%", checkUserFragment.getProperty(Fragment.SIZES_PROPERTY_NAME));
                        assertEquals("custom-value-0", checkUserFragment.getProperty("custom-0"));
                        assertNull(checkUserFragment.getProperty("custom-0", Fragment.USER_PROPERTY_SCOPE, null));
                        assertNull(checkUserFragment.getProperty("custom-0", Fragment.USER_PROPERTY_SCOPE, "user"));
                        if (FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
                        {
                            assertEquals("custom-value-role-1", checkUserFragment.getProperty("custom-1"));
                            assertNotNull(checkUserFragment.getProperty("custom-1", Fragment.ROLE_PROPERTY_SCOPE, "role"));
                        }
                        else
                        {
                            assertEquals("custom-value-1", checkUserFragment.getProperty("custom-1"));                       
                        }
                        assertNull(checkUserFragment.getProperty("custom-1", Fragment.USER_PROPERTY_SCOPE, "user"));
                        if (FragmentProperty.GROUP_AND_ROLE_PROPERTY_SCOPES_ENABLED)
                        {
                            assertEquals("custom-value-group-2", checkUserFragment.getProperty("custom-2"));
                            assertNotNull(checkUserFragment.getProperty("custom-2", Fragment.GROUP_PROPERTY_SCOPE, "group"));
                        }
                        else
                        {
                            assertEquals("custom-value-2", checkUserFragment.getProperty("custom-2"));                       
                        }
                        assertNull(checkUserFragment.getProperty("custom-2", Fragment.USER_PROPERTY_SCOPE, "user"));
                        assertEquals("custom-value-user-3", checkUserFragment.getProperty("custom-3"));
                        assertNotNull(checkUserFragment.getProperty("custom-3", Fragment.USER_PROPERTY_SCOPE, null));
                        assertNotNull(checkUserFragment.getProperty("custom-3", Fragment.USER_PROPERTY_SCOPE, "user"));
                        return null;
                    }
                    catch (Exception e)
                    {
                        return e;
                    }
                    finally
                    {
                        JSSubject.clearSubject();
                    }
                }
            }, null);
            if (userException != null)
            {
                throw userException;
            }
            assertNotNull(checkRootFragment.getFragments());
            assertEquals(3, checkRootFragment.getFragments().size());
            BaseFragmentElement checkElement0 = (BaseFragmentElement)checkRootFragment.getFragments().get(0);
            assertTrue(checkElement0 instanceof Fragment);
            Fragment check0 = (Fragment)checkElement0;
            assertEquals("security::LoginPortlet", check0.getName());
            assertEquals("Portlet", check0.getShortTitle());
            assertEquals("Portlet Fragment", check0.getTitle());
            assertEquals("Normal", check0.getState());
            assertEquals(88, check0.getLayoutRow());
            assertEquals(88, check0.getIntProperty(Fragment.ROW_PROPERTY_NAME));
            assertEquals(99, check0.getLayoutColumn());
            assertNotNull(check0.getProperty(Fragment.X_PROPERTY_NAME));
            assertTrue(check0.getProperty(Fragment.X_PROPERTY_NAME).startsWith("12.3"));
            assertTrue((check0.getLayoutX() > 12.0F) && (check0.getLayoutX() < 13.0F));
            assertTrue((check0.getFloatProperty(Fragment.X_PROPERTY_NAME) > 12.0F) &&
                       (check0.getFloatProperty(Fragment.X_PROPERTY_NAME) < 13.0F));
            assertTrue((check0.getLayoutY() > 23.0F) && (check0.getLayoutY() < 24.0F));
            assertTrue((check0.getLayoutZ() > 34.0F) && (check0.getLayoutZ() < 35.0F));
            assertTrue((check0.getLayoutWidth() > 45.0F) && (check0.getLayoutWidth() < 46.0F));
            assertTrue((check0.getLayoutHeight() > 56.0F) && (check0.getLayoutWidth() < 57.0F));
            assertNotNull(check0.getPreferences());
            assertEquals(2, check0.getPreferences().size());
            assertEquals("pref0", ((FragmentPreference)check0.getPreferences().get(0)).getName());
            assertTrue(((FragmentPreference)check0.getPreferences().get(0)).isReadOnly());
            assertNotNull(((FragmentPreference)check0.getPreferences().get(0)).getValueList());
            assertEquals(2, ((FragmentPreference)check0.getPreferences().get(0)).getValueList().size());
            assertEquals("pref0-value0", (String)((FragmentPreference)check0.getPreferences().get(0)).getValueList().get(0));
            assertEquals("pref0-value1", (String)((FragmentPreference)check0.getPreferences().get(0)).getValueList().get(1));
            assertEquals("pref1", ((FragmentPreference)check0.getPreferences().get(1)).getName());
            assertFalse(((FragmentPreference)check0.getPreferences().get(1)).isReadOnly());
            assertNotNull(((FragmentPreference)check0.getPreferences().get(1)).getValueList());
            assertEquals(1, ((FragmentPreference)check0.getPreferences().get(1)).getValueList().size());
            assertEquals("pref1-value", (String)((FragmentPreference)check0.getPreferences().get(1)).getValueList().get(0));
            BaseFragmentElement checkElement1 = (BaseFragmentElement)checkRootFragment.getFragments().get(1);
            assertTrue(checkElement1 instanceof Fragment);
            Fragment check1 = (Fragment)checkElement1;
            assertEquals("some-app::SomePortlet", check1.getName());
            assertEquals("Some Portlet", check1.getShortTitle());
            assertEquals("Some Portlet Fragment", check1.getTitle());
            assertEquals("Normal", check1.getState());
            assertEquals(22, check1.getLayoutRow());
            assertEquals(11, check1.getLayoutColumn());
            assertTrue((check1.getLayoutX() > 11.0F) && (check1.getLayoutX() < 12.0F));
            assertTrue((check1.getLayoutY() > 22.0F) && (check1.getLayoutY() < 23.0F));
            assertTrue((check1.getLayoutZ() > 33.0F) && (check1.getLayoutZ() < 34.0F));
            assertTrue((check1.getLayoutWidth() > 44.0F) && (check1.getLayoutWidth() < 45.0F));
            assertTrue((check1.getLayoutHeight() > 55.0F) && (check1.getLayoutWidth() < 56.0F));
            assertNotNull(check1.getSecurityConstraints());
            assertEquals("user", check1.getSecurityConstraints().getOwner());
            assertNotNull(check.getFragmentById(check0.getId()));
            assertNotNull(check.getFragmentsByName("some-app::SomePortlet"));
            assertEquals(1, check.getFragmentsByName("some-app::SomePortlet").size());
            assertNotNull(check.getParent());
            BaseFragmentElement checkElement2 = (BaseFragmentElement)checkRootFragment.getFragments().get(2);
            assertTrue(checkElement2 instanceof FragmentReference);
            FragmentReference checkFragmentReference = (FragmentReference)checkElement2;
            assertTrue(checkFragmentReference.getRefId().equals("fragment-definition"));
            assertNotNull(check.getFragmentsByInterface(null));
            assertEquals(4, check.getFragmentsByInterface(null).size());
            assertNotNull(check.getFragmentsByInterface(FragmentReference.class));
            assertEquals(1, check.getFragmentsByInterface(FragmentReference.class).size());
        }
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

        if ((fragmentReferences != null) && !fragmentReferences.isEmpty())
        {
            Iterator fragmentReferencesIter = fragmentReferences.iterator();
            while (fragmentReferencesIter.hasNext())
            {
                FragmentReference fragmentReference = (FragmentReference)fragmentReferencesIter.next();
                if (fragmentReference.getRefId() != null)
                {
                    refIds.add(fragmentReference.getRefId());
                }
            }
        }       
    }
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

                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

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.