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

GTNPORTAL-3267 MOP unmarshalling with page-layout inside a container #669

Open
wants to merge 1 commit into
base: 3.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ protected Container unmarshalContainer(StaxNavigator<Element> navigator) throws
container.getChildren().add(unmarshalGadgetApplication(navigator.fork()));
current = navigator.sibling();
break;
case PAGE_BODY:
if (container.getChildren() == null) {
container.setChildren(new ArrayList<ModelObject>());
}
container.getChildren().add(new PageBody());
current = navigator.sibling();
break;
case UNKNOWN:
throw unknownElement(navigator);
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ private PortalConfig unmarshalPortalConfig(StaxNavigator<Element> navigator) thr
throw expectedElement(navigator, Element.ACCESS_PERMISSIONS);
if (portalLayout == null) {
portalLayout = PortalConfig.DEFAULT_LAYOUT;
} else {
int count = countPageBodyElements(portalLayout, 0);
if (count < 1) {
throw new StaxNavException("No page-body element found.");
} else if (count > 1) {
throw new StaxNavException("Multiple page-body elements found.");
}
}

portalConfig.setPortalLayout(portalLayout);
Expand All @@ -253,4 +260,17 @@ public String getLocalName() {
return name;
}
}

private static int countPageBodyElements(Container container, int pageBodyCount) {
if (container.getChildren() != null) {
for (ModelObject child : container.getChildren()) {
if (child instanceof PageBody) {
pageBodyCount++;
} else if (child instanceof Container) {
pageBodyCount = countPageBodyElements((Container) child, pageBodyCount);
}
}
}
return pageBodyCount;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,6 @@ public void testPortalDataUnmarshalling() {
assertNull(layout.getAccessPermissions());
List<ModelObject> children = data.getPortalLayout().getChildren();
assertEquals(5, children.size());
int bodyCount = 0;
for (ModelObject component : children) {
if (component instanceof Application) {
} else if (component instanceof PageBody) {
bodyCount++;
} else {
fail("Only application data and one body data should be created for a portal layout.");
}
}
assertEquals(1, bodyCount);

// Verify banner portlet app
{
Expand Down Expand Up @@ -211,4 +201,45 @@ public void testPortalDataMarshalling() {

compareComponents(expected.getPortalLayout().getChildren(), actual.getPortalLayout().getChildren());
}

public void testPortalWithPageBodyInContainer() {
SiteLayoutMarshaller marshaller = new SiteLayoutMarshaller();
PortalConfig data = marshaller.unmarshal(getClass().getResourceAsStream(
"/org/exoplatform/portal/mop/management/portal-pagebody.xml"));
assertNotNull(data);
assertEquals("classic", data.getName());
assertEquals("site-label", data.getLabel());
assertEquals("site-description", data.getDescription());
assertEquals("en", data.getLocale());
assertEquals("Everyone", Utils.join(";", data.getAccessPermissions()));
assertEquals("*:/platform/administrators", data.getEditPermission());
assertNotNull(data.getProperties());
assertEquals(1, data.getProperties().size());
assertTrue(data.getProperties().containsKey("sessionAlive"));
assertEquals("onDemand", data.getProperties().get("sessionAlive"));

// Verify portal layout container only has children
assertNotNull(data.getPortalLayout());
Container layout = data.getPortalLayout();
assertNull(layout.getStorageId());
assertNull(layout.getId());
assertNull(layout.getName());
assertNull(layout.getIcon());
assertNull(layout.getTemplate());
assertNull(layout.getFactoryId());
assertNull(layout.getTitle());
assertNull(layout.getDescription());
assertNull(layout.getWidth());
assertNull(layout.getHeight());
assertNull(layout.getAccessPermissions());
List<ModelObject> children = data.getPortalLayout().getChildren();
assertEquals(5, children.size());

// Verify container w/ page-body
Container container = (Container) layout.getChildren().get(3);
assertNotNull(container.getChildren());
assertEquals(2, container.getChildren().size());
PageBody body = (PageBody) ((Container) container.getChildren().get(0)).getChildren().get(0);
assertNotNull(body);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version='1.0' encoding='UTF-8'?>

<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2012, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<portal-config xmlns="http://www.gatein.org/xml/ns/gatein_objects_1_4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.gatein.org/xml/ns/gatein_objects_1_4 http://www.gatein.org/xml/ns/gatein_objects_1_4">
<portal-name>classic</portal-name>
<label>site-label</label>
<description>site-description</description>
<locale>en</locale>
<access-permissions>Everyone</access-permissions>
<edit-permission>*:/platform/administrators</edit-permission>
<properties>
<entry key="sessionAlive">onDemand</entry>
</properties>
<portal-layout>
<portlet-application>
<portlet>
<application-ref>web</application-ref>
<portlet-ref>BannerPortlet</portlet-ref>
<preferences>
<preference>
<name>template</name>
<value>par:/groovy/groovy/webui/component/UIBannerPortlet.gtmpl</value>
<read-only>false</read-only>
</preference>
</preferences>
</portlet>
<theme>Default:DefaultTheme::Mac:MacTheme::Vista:VistaTheme</theme>
<title>Banner</title>
<access-permissions>*:/platform/administrators;*:/organization/management/executive-board</access-permissions>
<show-info-bar>false</show-info-bar>
<show-application-state>true</show-application-state>
<show-application-mode>false</show-application-mode>
<description>Banner Portlet</description>
<icon>PortletIcon</icon>
<width>250px</width>
<height>350px</height>
</portlet-application>
<portlet-application>
<portlet>
<application-ref>web</application-ref>
<portlet-ref>NavigationPortlet</portlet-ref>
</portlet>
<access-permissions>Everyone</access-permissions>
<show-info-bar>false</show-info-bar>
<show-application-state>true</show-application-state>
<show-application-mode>true</show-application-mode>
</portlet-application>
<portlet-application>
<portlet>
<application-ref>web</application-ref>
<portlet-ref>BreadcumbsPortlet</portlet-ref>
</portlet>
<access-permissions>Everyone</access-permissions>
<show-info-bar>false</show-info-bar>
<show-application-state>true</show-application-state>
<show-application-mode>true</show-application-mode>
</portlet-application>
<container id="913506166" template="system:/groovy/portal/webui/container/UITableColumnContainer.gtmpl">
<access-permissions>Everyone</access-permissions>
<factory-id>TableColumnContainer</factory-id>
<container id="937539559" template="system:/groovy/portal/webui/container/UIColumnContainer.gtmpl">
<access-permissions>Everyone</access-permissions>
<factory-id>ColumnContainer</factory-id>
<page-body/>
</container>
<container id="1139850074" template="system:/groovy/portal/webui/container/UIColumnContainer.gtmpl">
<access-permissions>Everyone</access-permissions>
<factory-id>ColumnContainer</factory-id>
<portlet-application>
<portlet>
<application-ref>exoadmin</application-ref>
<portlet-ref>AccountPortlet</portlet-ref>
</portlet>
<theme>Default:DefaultTheme::Vista:VistaTheme::Mac:MacTheme</theme>
<access-permissions>*:/platform/administrators;*:/organization/management/executive-board</access-permissions>
<show-info-bar>false</show-info-bar>
<show-application-state>true</show-application-state>
<show-application-mode>true</show-application-mode>
<description>New Account</description>
</portlet-application>
</container>
</container>
<portlet-application>
<portlet>
<application-ref>web</application-ref>
<portlet-ref>FooterPortlet</portlet-ref>
<preferences>
<preference>
<name>template</name>
<value>par:/groovy/groovy/webui/component/UIFooterPortlet.gtmpl</value>
<read-only>false</read-only>
</preference>
</preferences>
</portlet>
<access-permissions>Everyone</access-permissions>
<show-info-bar>false</show-info-bar>
<show-application-state>true</show-application-state>
<show-application-mode>true</show-application-mode>
</portlet-application>
</portal-layout>
</portal-config>