ContentFragment pageContentFragment4 = pageContentPage.getFragmentByFragmentId("fake-portlet");
assertNotNull(pageContentFragment4);
assertEquals("fake-template__fake-page-fragment__fake__fake-portlet", pageContentFragment4.getId());
// create and validate content pages for concrete dynamic pages
DynamicPage docPage = pageManager.getDynamicPage("/docpage.dpsml");
assertNotNull(docPage);
ContentPage docPageContentPage = pageLayout.newContentPage(docPage, template, fragmentDefinitions);
assertNotNull(docPageContentPage);
assertEquals("/docpage.dpsml", docPageContentPage.getTitle());
assertEquals("doc-type", docPageContentPage.getContentType());
assertTrue(docPageContentPage.isInheritable());
pageContentFragment0 = docPageContentPage.getFragmentByFragmentId("fake-template");
assertNotNull(pageContentFragment0);
assertEquals("fake-template", pageContentFragment0.getId());
pageContentFragment1 = docPageContentPage.getFragmentByFragmentId("fake-fragment-definition-0");
assertNotNull(pageContentFragment1);
assertEquals("fake-template__fake-fragment-reference__fake-fragment-definition-0", pageContentFragment1.getId());
assertEquals("fake-fragment-definition-0", pageContentFragment1.getRefId());
pageContentFragment2 = docPageContentPage.getFragmentByFragmentId("fake");
assertNotNull(pageContentFragment2);
assertEquals("fake-template__fake-page-fragment__fake", pageContentFragment2.getId());
DynamicPage contentPage = pageManager.getDynamicPage("/contentpage.dpsml");
assertNotNull(contentPage);
ContentPage contentPageContentPage = pageLayout.newContentPage(contentPage, template, fragmentDefinitions);
assertNotNull(contentPageContentPage);
assertEquals("/contentpage.dpsml", contentPageContentPage.getTitle());
assertEquals("*", contentPageContentPage.getContentType());
assertTrue(contentPageContentPage.isInheritable());
pageContentFragment0 = contentPageContentPage.getFragmentByFragmentId("fake-template");
assertNotNull(pageContentFragment0);
assertEquals("fake-template", pageContentFragment0.getId());
pageContentFragment1 = contentPageContentPage.getFragmentByFragmentId("fake-fragment-definition-0");
assertNotNull(pageContentFragment1);
assertEquals("fake-template__fake-fragment-reference__fake-fragment-definition-0", pageContentFragment1.getId());
assertEquals("fake-fragment-definition-0", pageContentFragment1.getRefId());
pageContentFragment2 = contentPageContentPage.getFragmentByFragmentId("fake");
assertNotNull(pageContentFragment2);
assertEquals("fake-template__fake-page-fragment__fake", pageContentFragment2.getId());
// create and validate content page for page template
ContentPage templateContentPage = pageLayout.newContentPage(template, template, fragmentDefinitions);
assertNotNull(templateContentPage);
assertEquals("/template.tpsml", templateContentPage.getTitle());
ContentFragment templateContentFragment0 = templateContentPage.getFragmentByFragmentId("fake-template", true);
assertNotNull(templateContentFragment0);
assertEquals("fake-template__fake-page-fragment__fake-template", templateContentFragment0.getId());
ContentFragment templateContentFragment1 = templateContentPage.getFragmentByFragmentId("fake-page-fragment", true);
assertNotNull(templateContentFragment1);
assertEquals("fake-template__fake-page-fragment__fake-template__fake-page-fragment", templateContentFragment1.getId());
ContentFragment templateContentFragment2 = templateContentPage.getFragmentByFragmentId("fake-fragment-definition-0", true);
assertNotNull(templateContentFragment2);
assertEquals("fake-template__fake-page-fragment__fake-template__fake-fragment-reference__fake-fragment-definition-0", templateContentFragment2.getId());
assertEquals("fake-fragment-definition-0", templateContentFragment2.getRefId());
// create and validate content page for page template
ContentPage fragmentDefinitionContentPage = pageLayout.newContentPage(definition0, template, fragmentDefinitions);
assertNotNull(fragmentDefinitionContentPage);
assertEquals("/definition0.fpsml", fragmentDefinitionContentPage.getTitle());
ContentFragment fragmentDefinitionContentFragment0 = fragmentDefinitionContentPage.getFragmentByFragmentId("fake-fragment-definition-0");
assertNotNull(fragmentDefinitionContentFragment0);
assertEquals("fake-template__fake-page-fragment__fake-fragment-definition-0", fragmentDefinitionContentFragment0.getId());
// create new PSML pages, content pages, templates, and fragment definitions
fragmentDefinitionContentPage.newSiblingFragmentDefinition("newdefinition1", null, "new-fake-fragment-definition-1", "/newdefinition1.fpsml", "/newdefinition1.fpsml");
fragmentDefinitionContentPage.newSiblingFragmentDefinition("newdefinition0", "new-fake-fragment-definition-0", "new-fake-fragment-definition-0", "/newdefinition0.fpsml", "/newdefinition0.fpsml");
templateContentPage.newSiblingPageTemplate("newtemplate", "new-fake-template", "/newtemplate.tpsml", "/newtemplate.tpsml");
contentPageContentPage.newSiblingDynamicPage("newcontentpage", "*", "new-fake", "/newcontentpage.dpsml", "/newcontentpage.dpsml");
pageContentPage.newSiblingPage("newpage", "new-fake", "/newpage.psml", "/newpage.psml");
Map newFragmentDefinitions = new HashMap();
FragmentDefinition newDefinition1 = pageManager.getFragmentDefinition("/newdefinition1.fpsml");
assertNotNull(newDefinition1);
String newDefinition1Id = newDefinition1.getRootFragment().getId();
newFragmentDefinitions.put(newDefinition1Id, newDefinition1);
FragmentDefinition newDefinition0 = pageManager.getFragmentDefinition("/newdefinition0.fpsml");
assertNotNull(newDefinition0);
assertEquals("new-fake-fragment-definition-0", newDefinition0.getRootFragment().getId());
newFragmentDefinitions.put("new-fake-fragment-definition-0", newDefinition0);
PageTemplate newTemplate = pageManager.getPageTemplate("/newtemplate.tpsml");
assertNotNull(newTemplate);
DynamicPage newContentPage = pageManager.getDynamicPage("/newcontentpage.dpsml");
assertNotNull(newContentPage);
assertEquals("*", newContentPage.getContentType());
assertTrue(newContentPage.isInheritable());
Page newPage = pageManager.getPage("/newpage.psml");
assertNotNull(newPage);
// create and validate new content pages
ContentPage newFragmentDefinition1ContentPage = pageLayout.newContentPage(newDefinition1, newTemplate, newFragmentDefinitions);
assertNotNull(newFragmentDefinition1ContentPage);
List contentFragments = newFragmentDefinition1ContentPage.getFragmentsByName("new-fake-fragment-definition-1");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
assertEquals(newDefinition1Id, newDefinition1.getDefId());
ContentPage newFragmentDefinition0ContentPage = pageLayout.newContentPage(newDefinition0, newTemplate, newFragmentDefinitions);
assertNotNull(newFragmentDefinition0ContentPage);
contentFragments = newFragmentDefinition0ContentPage.getFragmentsByName("new-fake-fragment-definition-0");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
assertEquals("new-fake-fragment-definition-0", ((ContentFragment)contentFragments.get(0)).getFragmentId());
assertEquals("new-fake-fragment-definition-0", newDefinition0.getDefId());
ContentPage newTemplateContentPage = pageLayout.newContentPage(newTemplate, newTemplate, newFragmentDefinitions);
assertNotNull(newTemplateContentPage);
newTemplateContentPage.addFragmentReference("new-fake-fragment-definition-0");
newTemplateContentPage = pageLayout.newContentPage(newTemplate, newTemplate, newFragmentDefinitions);
ContentPage newContentPageContentPage = pageLayout.newContentPage(newContentPage, newTemplate, newFragmentDefinitions);
assertNotNull(newContentPageContentPage);
ContentPage newPageContentPage = pageLayout.newContentPage(newPage, newTemplate, newFragmentDefinitions);
assertNotNull(newPageContentPage);
contentFragments = newPageContentPage.getFragmentsByName("new-fake");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
ContentFragment newPageRootFragment = (ContentFragment)contentFragments.get(0);
pageLayout.addFragmentReference(newPageRootFragment, newDefinition1Id, 0, 0);
pageLayout.addPortlet(newPageRootFragment, Fragment.PORTLET, "new-fake-portlet", 1, 0);
pageLayout.addFragmentReference(newPageRootFragment, "nonexistent-reference-id", 2, 0);
newPageContentPage = pageLayout.newContentPage(newPage, newTemplate, newFragmentDefinitions);
assertNotNull(newPageContentPage);
// validate new PSML pages, content pages, templates, and fragment definitions
assertEquals("/newpage.psml", newPageContentPage.getTitle());
contentFragments = newPageContentPage.getFragmentsByName("new-fake-template");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
contentFragments = newPageContentPage.getFragmentsByName("new-fake-fragment-definition-0");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
assertEquals("new-fake-fragment-definition-0", ((ContentFragment)contentFragments.get(0)).getRefId());
contentFragments = newPageContentPage.getFragmentsByName("new-fake");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
contentFragments = ((ContentFragment)contentFragments.get(0)).getFragments();
assertNotNull(contentFragments);
assertEquals(3, contentFragments.size());
ContentFragment newPageReferenceContentFragment = null;
Iterator contentFragmentsIter = contentFragments.iterator();
while (contentFragmentsIter.hasNext())
{
ContentFragment contentFragment = (ContentFragment)contentFragmentsIter.next();
if (contentFragment.getType().equals(ContentFragment.PORTLET) && contentFragment.getName().equals("new-fake-portlet"))
{
}
else if (contentFragment.getType().equals(ContentFragment.PORTLET) && contentFragment.getName().equals("new-fake-fragment-definition-1"))
{
assertEquals(newDefinition1Id, contentFragment.getRefId());
}
else if (contentFragment.getType().equals(ContentFragment.REFERENCE))
{
assertEquals("nonexistent-reference-id", contentFragment.getRefId());
newPageReferenceContentFragment = contentFragment;
}
else
{
fail("Unexpected content fragment: "+contentFragment.getType()+"/"+contentFragment.getName());
}
}
assertEquals("/newcontentpage.dpsml", newContentPageContentPage.getTitle());
assertEquals("*", newContentPageContentPage.getContentType());
assertTrue(newContentPageContentPage.isInheritable());
contentFragments = newContentPageContentPage.getFragmentsByName("new-fake-template");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
contentFragments = newContentPageContentPage.getFragmentsByName("new-fake-fragment-definition-0");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
assertEquals("new-fake-fragment-definition-0", ((ContentFragment)contentFragments.get(0)).getRefId());
contentFragments = newContentPageContentPage.getFragmentsByName("new-fake");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
assertEquals("/newtemplate.tpsml", newTemplateContentPage.getTitle());
contentFragments = newTemplateContentPage.getFragmentsByName("new-fake-template", true);
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
contentFragments = ((ContentFragment)contentFragments.get(0)).getFragments();
assertNotNull(contentFragments);
assertEquals(2, contentFragments.size());
contentFragmentsIter = contentFragments.iterator();
while (contentFragmentsIter.hasNext())
{
ContentFragment contentFragment = (ContentFragment)contentFragmentsIter.next();
if (contentFragment.getType().equals(ContentFragment.PAGE))
{
}
else if (contentFragment.getType().equals(ContentFragment.PORTLET) && contentFragment.getName().equals("new-fake-fragment-definition-0"))
{
assertEquals("new-fake-fragment-definition-0", contentFragment.getRefId());
}
else
{
fail("Unexpected content fragment: "+contentFragment.getType()+"/"+contentFragment.getName());
}
}
assertEquals("/newdefinition0.fpsml", newFragmentDefinition0ContentPage.getTitle());
contentFragments = newFragmentDefinition0ContentPage.getFragmentsByName("new-fake-fragment-definition-0");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
assertEquals("new-fake-fragment-definition-0", ((ContentFragment)contentFragments.get(0)).getFragmentId());
assertEquals("new-fake-fragment-definition-0", newFragmentDefinition0ContentPage.getDefId());
assertEquals("/newdefinition1.fpsml", newFragmentDefinition1ContentPage.getTitle());
contentFragments = newFragmentDefinition1ContentPage.getFragmentsByName("new-fake-fragment-definition-1");
assertNotNull(contentFragments);
assertEquals(1, contentFragments.size());
assertEquals(newDefinition1Id, ((ContentFragment)contentFragments.get(0)).getFragmentId());
assertEquals(newDefinition1Id, newFragmentDefinition1ContentPage.getDefId());
// update pages via content pages and fragments
newFragmentDefinition1ContentPage.updateTitles(null, "new-fragment-definition-1-updated");
ContentFragment updateContentFragment = (ContentFragment)(newFragmentDefinition1ContentPage.getFragmentsByName("new-fake-fragment-definition-1").get(0));
updateContentFragment.updateProperty("global-prop", "global-fragment-definition");
updateContentFragment.updateProperty("prop", "global-fragment-definition");
updateContentFragment.updateProperty("prop", "user-fragment-definition", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment.updateProperty("user-prop", "user-fragment-definition", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment.updateProperty("global-fragment-definition-prop", "global-fragment-definition");
updateContentFragment.updateProperty("fragment-definition-prop", "global-fragment-definition");
updateContentFragment.updateProperty("fragment-definition-prop", "user-fragment-definition", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment.updateProperty("user-fragment-definition-prop", "user-fragment-definition", ContentFragment.USER_PROPERTY_SCOPE, "user");
newTemplateContentPage.updateTitles(null, "new-page-template-updated");
updateContentFragment = (ContentFragment)(newTemplateContentPage.getFragmentsByName("new-fake-template", true).get(0));
updateContentFragment.updateProperty("global-prop", "global-template");
updateContentFragment.updateProperty("prop", "global-template");
updateContentFragment.updateProperty("prop", "user-template", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment.updateProperty("user-prop", "user-template", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment = (ContentFragment)(newTemplateContentPage.getFragmentsByName("new-fake-fragment-definition-0", true).get(0));
updateContentFragment.updateProperty("global-prop", "global-template");
updateContentFragment.updateProperty("prop", "global-template");
updateContentFragment.updateProperty("prop", "user-template", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment.updateProperty("user-prop", "user-template", ContentFragment.USER_PROPERTY_SCOPE, "user");
newPageContentPage.updateTitles(null, "new-page-updated");
updateContentFragment = newPageContentPage.getRootFragment();
updateContentFragment.updateProperty("user-prop", "user-page", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment = (ContentFragment)(newPageContentPage.getFragmentsByName("new-fake").get(0));
updateContentFragment.updateProperty("global-prop", "global-page");
updateContentFragment.updateProperty("prop", "global-page");
updateContentFragment.updateProperty("prop", "user-page", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment.updateProperty("user-prop", "user-page", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment = (ContentFragment)(newPageContentPage.getFragmentsByName("new-fake-fragment-definition-0").get(0));
updateContentFragment.updateProperty("user-prop", "user-page", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment = (ContentFragment)(newPageContentPage.getFragmentsByName("new-fake-fragment-definition-1").get(0));
updateContentFragment.updateProperty("global-prop", "global-page");
updateContentFragment.updateProperty("prop", "global-page");
updateContentFragment.updateProperty("prop", "user-page", ContentFragment.USER_PROPERTY_SCOPE, "user");
updateContentFragment.updateProperty("user-prop", "user-page", ContentFragment.USER_PROPERTY_SCOPE, "user");
newPageReferenceContentFragment.updateRefId("fake-fragment-definition-0");
newContentPageContentPage.updateTitles(null, "new-content-page-updated");
newContentPageContentPage.updateContent("new-doc-type", false);
// continue test case as user
Exception exception = (Exception)JSSubject.doAsPrivileged(userSubject, new PrivilegedAction()
{
public Object run()
{
try
{
// reload PSML pages, content pages, templates, and fragment definitions
Map newFragmentDefinitions = new HashMap();
FragmentDefinition definition0 = pageManager.getFragmentDefinition("/definition0.fpsml");
assertNotNull(definition0);
newFragmentDefinitions.put(definition0.getDefId(), definition0);
FragmentDefinition newDefinition1 = pageManager.getFragmentDefinition("/newdefinition1.fpsml");
assertNotNull(newDefinition1);
newFragmentDefinitions.put(newDefinition1.getDefId(), newDefinition1);
FragmentDefinition newDefinition0 = pageManager.getFragmentDefinition("/newdefinition0.fpsml");
assertNotNull(newDefinition0);
newFragmentDefinitions.put(newDefinition0.getDefId(), newDefinition0);
PageTemplate newTemplate = pageManager.getPageTemplate("/newtemplate.tpsml");
assertNotNull(newTemplate);
Page newPage = pageManager.getPage("/newpage.psml");
assertNotNull(newPage);
DynamicPage newContentPage = pageManager.getDynamicPage("/newcontentpage.dpsml");
assertNotNull(newContentPage);
// verify content page and fragment updates
ContentPage newFragmentDefinition1ContentPage = pageLayout.newContentPage(newDefinition1, newTemplate, newFragmentDefinitions);
assertNotNull(newFragmentDefinition1ContentPage);