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);