writer.writeEndElement();
}
}
private PortalConfig unmarshalPortalConfig(StaxNavigator<Element> navigator) throws XMLStreamException {
PortalConfig portalConfig = new PortalConfig();
Container portalLayout = null;
Element current = navigator.child();
while (current != null) {
switch (current) {
case PORTAL_NAME:
portalConfig.setName(navigator.getContent());
current = navigator.sibling();
break;
case LOCALE:
portalConfig.setLocale(navigator.getContent());
current = navigator.sibling();
break;
case LABEL:
portalConfig.setLabel(navigator.getContent());
current = navigator.sibling();
break;
case DESCRIPTION:
portalConfig.setDescription(navigator.getContent());
current = navigator.sibling();
break;
case SKIN:
portalConfig.setSkin(navigator.getContent());
current = navigator.sibling();
break;
case PROPERTIES:
Properties properties = new Properties();
if (navigator.navigate(Axis.CHILD, Element.PROPERTIES_ENTRY)) {
for (StaxNavigator<Element> fork : navigator.fork(Element.PROPERTIES_ENTRY)) {
String key = getRequiredAttribute(fork, Attribute.PROPERTIES_KEY.getLocalName());
String value = getRequiredContent(fork, false);
properties.put(key, value);
}
} else {
throw expectedElement(navigator, Element.PROPERTIES_ENTRY);
}
portalConfig.setProperties(properties);
current = navigator.next();
break;
case ACCESS_PERMISSIONS:
portalConfig.setAccessPermissions(unmarshalAccessPermissions(navigator, false));
current = navigator.sibling();
break;
case EDIT_PERMISSION:
portalConfig.setEditPermission(unmarshalEditPermission(navigator));
current = navigator.sibling();
break;
case PORTAL_REDIRECTS:
portalConfig.setPortalRedirects((ArrayList<PortalRedirect>) redirectXmlHandler.read(navigator.fork()));
current = navigator.sibling();
break;
case PORTAL_LAYOUT:
portalLayout = new Container();
current = navigator.child();
break;
case MOVE_APPLICATIONS_PERMISSIONS:
if (portalLayout == null) {
throw expectedElement(navigator, Element.PORTAL_LAYOUT);
}
portalLayout.setMoveAppsPermissions(unmarshalPermissions(navigator, false));
current = navigator.sibling();
break;
case MOVE_CONTAINERS_PERMISSIONS:
if (portalLayout == null) {
throw expectedElement(navigator, Element.PORTAL_LAYOUT);
}
portalLayout.setMoveContainersPermissions(unmarshalPermissions(navigator, false));
current = navigator.sibling();
break;
case PAGE_BODY:
if (portalLayout == null) {
throw expectedElement(navigator, Element.PORTAL_LAYOUT);
}
portalLayout.getChildren().add(new PageBody());
current = navigator.sibling();
break;
case PORTLET_APPLICATION:
if (portalLayout == null) {
throw expectedElement(navigator, Element.PORTAL_LAYOUT);
}
portalLayout.getChildren().add(unmarshalPortletApplication(navigator.fork()));
current = navigator.sibling();
break;
case GADGET_APPLICATION:
if (portalLayout == null) {
throw expectedElement(navigator, Element.PORTAL_LAYOUT);
}
portalLayout.getChildren().add(unmarshalGadgetApplication(navigator.fork()));
current = navigator.sibling();
break;
case CONTAINER:
if (portalLayout == null) {
throw expectedElement(navigator, Element.PORTAL_LAYOUT);
}
portalLayout.getChildren().add(unmarshalContainer(navigator.fork()));
current = navigator.sibling();
break;
case UNKNOWN:
throw unknownElement(navigator);
default:
throw unexpectedElement(navigator);
}
}
// TODO: We should raise this exception as soon as we know so location is accurate
if (portalConfig.getAccessPermissions() == null)
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);
return portalConfig;
}