// Portlet name
requiresSibling(navigator, Element.PORTLET_REF);
String portletRef = getRequiredContent(navigator, true);
// Preferences
PortletBuilder portletBuilder = null;
if (navigator.sibling() == Element.PREFERENCES) {
requiresChild(navigator, Element.PREFERENCE);
portletBuilder = new PortletBuilder();
for (StaxNavigator<Element> fork : navigator.fork(Element.PREFERENCE)) {
// Preference name
requiresChild(fork, Element.NAME);
String prefName = getRequiredContent(fork, false);
// Preference values
List<String> values = null;
while (fork.sibling() == Element.PREFERENCE_VALUE) {
if (values == null)
values = new ArrayList<String>();
values.add(getContent(fork, false));
}
if (values == null) {
values = Collections.singletonList(null);
}
// Preference readonly
Boolean readOnly = null;
if (fork.getName() == Element.PREFERENCE_READONLY) {
readOnly = parseRequiredContent(fork, ValueType.BOOLEAN);
}
// Ensure nothing is left.
if (fork.next() != null) {
throw unexpectedElement(fork);
}
if (readOnly == null) {
portletBuilder.add(prefName, values);
} else {
portletBuilder.add(prefName, values, readOnly);
}
}
}
TransientApplicationState<Portlet> state = new TransientApplicationState<Portlet>(applicationRef + "/" + portletRef);
if (portletBuilder != null) {
state.setContentState(portletBuilder.build());
}
return state;
}