use of javax.xml.stream.events.Attribute in project uPortal by Jasig.
the class PortletWindowRegistryImpl method getPortletWindow.
@Override
public Tuple<IPortletWindow, StartElement> getPortletWindow(HttpServletRequest request, StartElement element) {
// Check if the layout node explicitly specifies the window id
final Attribute windowIdAttribute = element.getAttributeByName(PORTLET_WINDOW_ID_ATTR_NAME);
if (windowIdAttribute != null) {
final String windowIdStr = windowIdAttribute.getValue();
final IPortletWindowId portletWindowId = this.getPortletWindowId(request, windowIdStr);
final IPortletWindow portletWindow = this.getPortletWindow(request, portletWindowId);
return new Tuple<>(portletWindow, element);
}
// No explicit window id, look it up based on the layout node id
final Attribute nodeIdAttribute = element.getAttributeByName(IUserLayoutManager.ID_ATTR_NAME);
final String layoutNodeId = nodeIdAttribute.getValue();
IPortletWindow portletWindow = this.getOrCreateDefaultPortletWindowByLayoutNodeId(request, layoutNodeId);
if (portletWindow == null) {
// No window for the layout node, return null
return null;
}
final IPortalRequestInfo portalRequestInfo = this.urlSyntaxProvider.getPortalRequestInfo(request);
if (portalRequestInfo.getUrlState() == UrlState.DETACHED) {
/*
* We want to handle DETACHED portlet windows differently/explicitly,
* but we need to be aware there may be other portlets on the page
* besides the targeted one. These would be portlets in regions
* (Respondr theme) -- such as DynamicRespondrSkin.
*
* We need to confirm, therefore, that this is actually the portlet
* in DETACHED. If it is, we'll send back a 'stateless' PortletWindow.
*/
if (portalRequestInfo.getTargetedPortletWindowId().toString().contains("_" + layoutNodeId + "_")) {
final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId();
portletWindow = this.getOrCreateStatelessPortletWindow(request, portletWindowId);
}
}
element = this.addPortletWindowId(element, portletWindow.getPortletWindowId());
return new Tuple<>(portletWindow, element);
}
use of javax.xml.stream.events.Attribute in project uPortal by Jasig.
the class PortletWindowRegistryImpl method addPortletWindowId.
protected StartElement addPortletWindowId(StartElement element, IPortletWindowId portletWindowId) {
final Attribute windowIdAttribute = xmlEventFactory.createAttribute(PORTLET_WINDOW_ID_ATTR_NAME, portletWindowId.getStringId());
// Clone the start element to add the new attribute
final QName name = element.getName();
final String prefix = name.getPrefix();
final String namespaceURI = name.getNamespaceURI();
final String localPart = name.getLocalPart();
@SuppressWarnings("unchecked") final Iterator<Attribute> attributes = element.getAttributes();
@SuppressWarnings("unchecked") final Iterator<Namespace> namespaces = element.getNamespaces();
final NamespaceContext namespaceContext = element.getNamespaceContext();
// Create a new iterator of the existing attributes + the new window id attribute
final Iterator<Attribute> newAttributes = Iterators.concat(attributes, Iterators.forArray(windowIdAttribute));
return xmlEventFactory.createStartElement(prefix, namespaceURI, localPart, newAttributes, namespaces, namespaceContext);
}
use of javax.xml.stream.events.Attribute in project uPortal by Jasig.
the class TransientUserLayoutXMLEventReader method getAdditionalEvents.
/**
* Examines the current token and when appropriate creates and returns dynamically created
* content. If dynamic content is not created, return null.
*
* @param event The current event
* @return Dynamic content to inject into document, else null if no additional dynamic content
* was created.
*/
@Override
protected Deque<XMLEvent> getAdditionalEvents(XMLEvent event) {
if (event.isStartElement()) {
final StartElement startElement = event.asStartElement();
// All following logic requires an ID attribute, ignore any element without one
final Attribute idAttribute = startElement.getAttributeByName(IUserLayoutManager.ID_ATTR_NAME);
if (idAttribute == null) {
return null;
}
// Create and return a transient (dynamically created) folder that includes a transient
// channel
// if we are processing the tart element of the root node
// iff the subscribeId is present and describes a transient channel and not a regular
// layout channel.
final String subscribeId = this.userLayoutManager.getFocusedId();
if (this.rootFolderId.equals(idAttribute.getValue()) && subscribeId != null && !subscribeId.equals("") && this.userLayoutManager.isTransientChannel(subscribeId)) {
IPortletDefinition chanDef = null;
try {
chanDef = this.userLayoutManager.getChannelDefinition(subscribeId);
} catch (Exception e) {
logger.error("Could not obtain IChannelDefinition for subscribe id: {}", subscribeId, e);
}
if (chanDef != null) {
final QName name = startElement.getName();
final String namespaceURI = name.getNamespaceURI();
final String prefix = name.getPrefix();
final Deque<XMLEvent> transientEventBuffer = new LinkedList<XMLEvent>();
final Collection<Attribute> transientFolderAttributes = new LinkedList<Attribute>();
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("ID", TransientUserLayoutManagerWrapper.TRANSIENT_FOLDER_ID));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("name", chanDef != null ? chanDef.getTitle() : "Temporary"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("type", "regular"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("hidden", "false"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("immutable", "true"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:addChildAllowed", "false"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:deleteAllowed", "false"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:editAllowed", "false"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:moveAllowed", "false"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("dlm:precedence", "100.0"));
transientFolderAttributes.add(EVENT_FACTORY.createAttribute("transient", "true"));
final StartElement transientFolder = EVENT_FACTORY.createStartElement(prefix, namespaceURI, IUserLayoutManager.FOLDER, transientFolderAttributes.iterator(), null);
transientEventBuffer.add(transientFolder);
// TODO Move IChannelDefinition/IPortletDefinition -> StAX events code somewhere
// reusable
final Collection<Attribute> channelAttrs = new LinkedList<Attribute>();
channelAttrs.add(EVENT_FACTORY.createAttribute("ID", subscribeId));
channelAttrs.add(EVENT_FACTORY.createAttribute("typeID", Integer.toString(chanDef.getType().getId())));
channelAttrs.add(EVENT_FACTORY.createAttribute("hidden", "false"));
channelAttrs.add(EVENT_FACTORY.createAttribute("unremovable", "true"));
channelAttrs.add(EVENT_FACTORY.createAttribute("dlm:deleteAllowed", "false"));
channelAttrs.add(EVENT_FACTORY.createAttribute("dlm:moveAllowed", "false"));
channelAttrs.add(EVENT_FACTORY.createAttribute("name", chanDef.getName()));
channelAttrs.add(EVENT_FACTORY.createAttribute("description", chanDef.getDescription()));
channelAttrs.add(EVENT_FACTORY.createAttribute("title", chanDef.getTitle()));
channelAttrs.add(EVENT_FACTORY.createAttribute("chanID", chanDef.getPortletDefinitionId().getStringId()));
channelAttrs.add(EVENT_FACTORY.createAttribute("fname", chanDef.getFName()));
channelAttrs.add(EVENT_FACTORY.createAttribute("timeout", Integer.toString(chanDef.getTimeout())));
channelAttrs.add(EVENT_FACTORY.createAttribute("transient", "true"));
final StartElement startChannel = EVENT_FACTORY.createStartElement(prefix, namespaceURI, IUserLayoutManager.CHANNEL, channelAttrs.iterator(), null);
transientEventBuffer.offer(startChannel);
// add channel parameter elements
for (final IPortletDefinitionParameter parm : chanDef.getParameters()) {
final Collection<Attribute> parameterAttrs = new LinkedList<Attribute>();
parameterAttrs.add(EVENT_FACTORY.createAttribute("name", parm.getName()));
parameterAttrs.add(EVENT_FACTORY.createAttribute("value", parm.getValue()));
final StartElement startParameter = EVENT_FACTORY.createStartElement(prefix, namespaceURI, IUserLayoutManager.PARAMETER, parameterAttrs.iterator(), null);
transientEventBuffer.offer(startParameter);
final EndElement endParameter = EVENT_FACTORY.createEndElement(prefix, namespaceURI, IUserLayoutManager.PARAMETER, null);
transientEventBuffer.offer(endParameter);
}
final EndElement endChannel = EVENT_FACTORY.createEndElement(prefix, namespaceURI, IUserLayoutManager.CHANNEL, null);
transientEventBuffer.offer(endChannel);
final EndElement endFolder = EVENT_FACTORY.createEndElement(prefix, namespaceURI, IUserLayoutManager.FOLDER, null);
transientEventBuffer.offer(endFolder);
return transientEventBuffer;
} else {
// I don't think subscribeId could be null, but log warning if so.
logger.warn("Unable to resolve portlet definition for subscribe ID {}", subscribeId);
}
}
}
return null;
}
use of javax.xml.stream.events.Attribute in project uPortal by Jasig.
the class PortletWindowAttributeSource method getAdditionalAttributes.
@Override
public final Iterator<Attribute> getAdditionalAttributes(HttpServletRequest request, HttpServletResponse response, StartElement event) {
final QName eventName = event.getName();
final String localEventName = eventName.getLocalPart();
// Only pay attention to channel events
if (!IUserLayoutManager.CHANNEL.equals(localEventName)) {
return null;
}
final Tuple<IPortletWindow, StartElement> portletWindowAndElement = this.portletWindowRegistry.getPortletWindow(request, event);
if (portletWindowAndElement == null) {
this.logger.warn("No IPortletWindow could be found or created for element: " + event);
return null;
}
// Lookup the portlet window for the layout node
final IPortletWindow portletWindow = portletWindowAndElement.first;
// Create the attributes
final Collection<Attribute> attributes = new LinkedList<Attribute>();
// Add window state data
final WindowState windowState = getWindowState(request, portletWindow);
final Attribute windowStateAttribute = xmlEventFactory.createAttribute("windowState", windowState.toString());
attributes.add(windowStateAttribute);
// Add portlet mode data
final PortletMode portletMode = portletWindow.getPortletMode();
final Attribute portletModeAttribute = xmlEventFactory.createAttribute("portletMode", portletMode.toString());
attributes.add(portletModeAttribute);
return attributes.iterator();
}
use of javax.xml.stream.events.Attribute in project uPortal by Jasig.
the class StaticAttributeSource method getAdditionalAttributes.
/* (non-Javadoc)
* @see org.apereo.portal.rendering.AttributeSource#getAdditionalAttributes(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, javax.xml.stream.events.StartElement)
*/
@Override
public Iterator<Attribute> getAdditionalAttributes(HttpServletRequest request, HttpServletResponse response, StartElement event) {
if (this.attributes == null) {
return null;
}
final QName eventName = event.getName();
final String localPart = eventName.getLocalPart();
final Map<String, String> attributes = this.attributes.get(localPart);
if (attributes == null || attributes.size() == 0) {
return null;
}
final List<Attribute> newAttributes = new ArrayList<Attribute>(attributes.size());
for (final Map.Entry<String, String> attributeEntry : attributes.entrySet()) {
final String key = attributeEntry.getKey();
final String value = attributeEntry.getValue();
final Attribute attribute = xmlEventFactory.createAttribute(key, value);
newAttributes.add(attribute);
}
return newAttributes.iterator();
}
Aggregations