use of javax.xml.stream.events.StartElement 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.StartElement in project uPortal by Jasig.
the class JaxbPortalDataHandlerService method importData.
@Override
public final void importData(final Source source, PortalDataKey portalDataKey) {
//Get a StAX reader for the source to determine info about the data to import
final BufferedXMLEventReader bufferedXmlEventReader = createSourceXmlEventReader(source);
//If no PortalDataKey was passed build it from the source
if (portalDataKey == null) {
final StartElement rootElement = StaxUtils.getRootElement(bufferedXmlEventReader);
portalDataKey = new PortalDataKey(rootElement);
bufferedXmlEventReader.reset();
}
final String systemId = source.getSystemId();
//Post Process the PortalDataKey to see if more complex import operations are needed
final IPortalDataType portalDataType = this.dataKeyTypes.get(portalDataKey);
if (portalDataType == null) {
throw new RuntimeException("No IPortalDataType configured for " + portalDataKey + ", the resource will be ignored: " + getPartialSystemId(systemId));
}
final Set<PortalDataKey> postProcessedPortalDataKeys = portalDataType.postProcessPortalDataKey(systemId, portalDataKey, bufferedXmlEventReader);
bufferedXmlEventReader.reset();
//If only a single result from post processing import
if (postProcessedPortalDataKeys.size() == 1) {
this.importOrUpgradeData(systemId, DataAccessUtils.singleResult(postProcessedPortalDataKeys), bufferedXmlEventReader);
} else //If multiple results from post processing ordering is needed
{
//Iterate over the data key order list to run the imports in the correct order
for (final PortalDataKey orderedPortalDataKey : this.dataKeyImportOrder) {
if (postProcessedPortalDataKeys.contains(orderedPortalDataKey)) {
//Reset the to start of the XML document for each import/upgrade call
bufferedXmlEventReader.reset();
this.importOrUpgradeData(systemId, orderedPortalDataKey, bufferedXmlEventReader);
}
}
}
}
use of javax.xml.stream.events.StartElement in project uPortal by Jasig.
the class LayoutPortalDataType method postProcessSinglePortalDataKey.
@SuppressWarnings("deprecation")
@Override
protected PortalDataKey postProcessSinglePortalDataKey(String systemId, PortalDataKey portalDataKey, XMLEventReader reader) {
/* Fragment layouts are differentiated _only_ by file extension; these
* layouts must be imported BEFORE non-fragment layouts (i.e. layouts of
* regular users)
*/
if (systemId.endsWith(".fragment-layout.xml") || systemId.endsWith(".fragment-layout")) /* legacy file extension */
{
/* NOTE: In the future we could consider handling this case
* similarly to how "default" users are handled (below): by reading
* the username attribute and checking it against the list of known
* fragment layout owners.
*/
return convertToFragmentKey(portalDataKey);
}
//Check if the layout is for an older style that includes the profile data (only possible in 2.6 and 3.0 format layout files)
if (IMPORT_26_DATA_KEY.equals(portalDataKey) || IMPORT_30_DATA_KEY.equals(portalDataKey)) {
final StartElement startElement = StaxUtils.getRootElement(reader);
final Attribute usernameAttr = startElement.getAttributeByName(new QName("username"));
if (usernameAttr != null) {
final String username = usernameAttr.getValue();
if (this.userIdentityStore.isDefaultUser(username)) {
return convertToDefaultUserKey(portalDataKey);
}
} else {
logger.warn("No username attribute on StartElement for {}", systemId);
}
}
return portalDataKey;
}
use of javax.xml.stream.events.StartElement in project uPortal by Jasig.
the class FilteringXMLEventReader method internalNext.
protected final XMLEvent internalNext(boolean peek) throws XMLStreamException {
XMLEvent event = null;
if (peekedEvent != null) {
event = peekedEvent;
peekedEvent = null;
return event;
}
do {
event = super.getParent().nextEvent();
//If there are pruned elements in the queue filtering events is still needed
if (!prunedElements.isEmpty()) {
//If another start element add it to the queue
if (event.isStartElement()) {
final StartElement startElement = event.asStartElement();
prunedElements.push(startElement.getName());
} else //If end element pop the newest name of the queue and double check that the start/end elements match up
if (event.isEndElement()) {
final QName startElementName = prunedElements.pop();
final EndElement endElement = event.asEndElement();
final QName endElementName = endElement.getName();
if (!startElementName.equals(endElementName)) {
throw new IllegalArgumentException("Malformed XMLEvent stream. Expected end element for " + startElementName + " but found end element for " + endElementName);
}
}
event = null;
} else {
final XMLEvent filteredEvent = this.filterEvent(event, peek);
//end element need to be removed as well
if (filteredEvent == null && event.isStartElement()) {
final StartElement startElement = event.asStartElement();
final QName name = startElement.getName();
prunedElements.push(name);
}
event = filteredEvent;
}
} while (event == null);
return event;
}
use of javax.xml.stream.events.StartElement in project uPortal by Jasig.
the class PortletPlaceholderEventSource method generateCharacterEvents.
@Override
public void generateCharacterEvents(HttpServletRequest servletRequest, XMLEventReader eventReader, StartElement event, Collection<CharacterEvent> eventBuffer) throws XMLStreamException {
final Tuple<IPortletWindow, StartElement> portletWindowAndElement = this.portletWindowRegistry.getPortletWindow(servletRequest, event);
if (portletWindowAndElement == null) {
this.logger.warn("Could not find IPortletWindow for StartElement " + event + ". No PortletPlaceholderEvent will be generated. " + event.getLocation());
return;
}
final IPortletWindowId portletWindowId = portletWindowAndElement.first.getPortletWindowId();
this.generateCharacterEvents(portletWindowId, eventReader, event, eventBuffer);
}
Aggregations