Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Implement permission unmarshalling for pages
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Jun 26, 2013
1 parent d69177e commit 2e2c40e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion component/portal/src/main/java/gatein_objects_2_0.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="display-name" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="layout" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:group ref="permissionsGroup"/>
<xs:element name="layout" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="zone" type="zoneType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
*/
public class ModelUnmarshaller {

/** . */
private static final String[] EMPTY_STRINGS = new String[0];

private static <E extends Enum<E>> StaxNavigator<E> createStaxNav(InputStream in, Class<E> type) throws XMLStreamException {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty("javax.xml.stream.isCoalescing", true);
Expand Down Expand Up @@ -233,6 +236,8 @@ public static Page.PageSet parsePageSet(StaxNavigator<PageElement> nav) {
for (StaxNavigator<PageElement> pageNav : nav.fork(PageElement.page)) {
validate(pageNav.child(PageElement.name));
String name = pageNav.getContent();
String[] accessPermission = pageNav.sibling(PageElement.access_permission) ? new String[]{pageNav.getContent()} : EMPTY_STRINGS;
String editPermission = pageNav.sibling(PageElement.edit_permission) ? pageNav.getContent() : null;
String layout;
if (pageNav.sibling(PageElement.layout)) {
layout = pageNav.getContent();
Expand All @@ -241,6 +246,8 @@ public static Page.PageSet parsePageSet(StaxNavigator<PageElement> nav) {
}
Page page = new Page();
page.setName(name);
page.setAccessPermissions(accessPermission);
page.setEditPermission(editPermission);
page.setFactoryId(layout);
while (pageNav.sibling(PageElement.zone)) {
StaxNavigator<PageElement> zoneNav = pageNav.fork();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;

Expand Down Expand Up @@ -270,6 +271,8 @@ public void testPage2_0() throws Exception {

//
Page foo = set.getPages().get(0);
assertEquals(Collections.singletonList("abc"), Arrays.asList(foo.getAccessPermissions()));
assertEquals("def", foo.getEditPermission());
assertEquals("foo", foo.getName());
assertEquals(1, foo.getChildren().size());
assertEquals("1", foo.getFactoryId());
Expand Down
2 changes: 2 additions & 0 deletions component/portal/src/test/resources/xml/pages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
xmlns="http://www.gatein.org/xml/ns/gatein_objects_2_0">
<page>
<name>foo</name>
<access-permission>abc</access-permission>
<edit-permission>def</edit-permission>
<layout>1</layout>
<zone>
<id>1</id>
Expand Down

0 comments on commit 2e2c40e

Please sign in to comment.