root.setName("TestLayout");
Fragment f = pageManager.newFragment();
f.setType(Fragment.PORTLET);
f.setName("TestPortlet");
List properties = f.getProperties();
FragmentProperty fp = pageManager.newFragmentProperty();
fp.setName(Fragment.ROW_PROPERTY_NAME);
fp.setValue("0");
properties.add(fp);
fp = pageManager.newFragmentProperty();
fp.setName(Fragment.COLUMN_PROPERTY_NAME);
fp.setValue("0");
properties.add(fp);
f.setLayoutX(100.0F);
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);