List of usage examples for javax.xml.stream.events Attribute getValue
public String getValue();
From source file:org.apereo.portal.io.xml.PortalDataKey.java
protected String getAttributeValue(StartElement startElement, QName name) { final Attribute versionAttr = startElement.getAttributeByName(name); if (versionAttr != null) { return versionAttr.getValue(); }//from w ww . ja v a2 s.com return null; }
From source file:org.apereo.portal.portlet.registry.PortletWindowRegistryImpl.java
@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<IPortletWindow, StartElement>(portletWindow, element); }// w w w .j a v a2s.co m //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<IPortletWindow, StartElement>(portletWindow, element); }
From source file:org.jasig.portal.layout.TransientUserLayoutXMLEventReader.java
@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; }// w w w . j a v a 2 s .c o m //Handle adding a transient folder to the root element if (this.rootFolderId.equals(idAttribute.getValue())) { 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("type", "regular")); transientFolderAttributes.add(EVENT_FACTORY.createAttribute("hidden", "true")); transientFolderAttributes.add(EVENT_FACTORY.createAttribute("unremovable", "true")); transientFolderAttributes.add(EVENT_FACTORY.createAttribute("immutable", "true")); transientFolderAttributes.add(EVENT_FACTORY.createAttribute("name", "Transient Folder")); final StartElement transientFolder = EVENT_FACTORY.createStartElement(prefix, namespaceURI, IUserLayoutManager.FOLDER, transientFolderAttributes.iterator(), null); transientEventBuffer.add(transientFolder); //append channel element iff subscribeId describes a transient channel, and not a regular layout channel final String subscribeId = this.userLayoutManager.getFocusedId(); if (null != subscribeId && !subscribeId.equals("") && this.userLayoutManager.isTransientChannel(subscribeId)) { IPortletDefinition chanDef = null; try { chanDef = this.userLayoutManager.getChannelDefinition(subscribeId); } catch (Exception e) { this.logger.error("Could not obtain IChannelDefinition for subscribe id: " + subscribeId, e); } if (chanDef != null) { //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("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; } } return null; }
From source file:org.jasig.portal.portlet.registry.PortletWindowRegistryImpl.java
@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<IPortletWindow, StartElement>(portletWindow, element); }/*ww w .j a v a 2 s . c o m*/ //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) { //Handle detached portlets explicitly //TODO Can we ever have non-targeted portlets render in a detached request? If so should they all be stateless windows anyways? final IPortletWindowId portletWindowId = portletWindow.getPortletWindowId(); portletWindow = this.getOrCreateStatelessPortletWindow(request, portletWindowId); } element = this.addPortletWindowId(element, portletWindow.getPortletWindowId()); return new Tuple<IPortletWindow, StartElement>(portletWindow, element); }
From source file:org.jonross.coercion.v2.BinderSpec.java
/** *//*from w ww .j ava2s.c o m*/ public void parse(Reader input) throws XMLStreamException { // Grab the first element in the binder file and verify that it's // our show; check for binder package name and class name. XMLEventReader reader = inputFactory.createXMLEventReader(input); StartElement start = nextStartElement(reader).asStartElement(); if (!start.getName().equals(CO_UNMARSHALLER)) throw new CoercionException( "Root element must be <" + CO_UNMARSHALLER.getLocalPart() + "> in namespace " + MY_NS); Attribute att = start.getAttributeByName(CO_PACKAGE_NAME); if (att != null) packageName = att.getValue(); att = start.getAttributeByName(CO_CLASS_NAME); if (att != null) className = att.getValue(); else throw new CoercionException("Root <unmarshaller> element is missing className attribute"); root = parse(reader, start.asStartElement()); }
From source file:org.modeldriven.fuml.assembly.adapter.OpaqueExpressionAdapter.java
public Element assembleElement(StreamNode opaqueExpressionNode) { LiteralString literal = new LiteralString(); XmiNode bodyNode = opaqueExpressionNode.findChildByName("body"); String bodyContent = null;/*from w ww . ja v a 2 s . c o m*/ if (bodyNode != null) { bodyContent = bodyNode.getData(); } else { Attribute bodyAttrib = opaqueExpressionNode.getAttribute("body"); if (bodyAttrib != null) bodyContent = bodyAttrib.getValue(); } if (bodyContent != null) { bodyContent = bodyContent.trim(); if (bodyContent.startsWith("\"") && bodyContent.endsWith("\"")) { bodyContent = bodyContent.substring(1, bodyContent.length() - 1); literal.setValue(bodyContent); return literal; // must be a string, no need to continue. } } literal.setValue(bodyContent); if ("true".equalsIgnoreCase(bodyContent) || "false".equalsIgnoreCase(bodyContent)) { LiteralBoolean literalBoolean = new LiteralBoolean(); literalBoolean.setValue(Boolean.valueOf(bodyContent).booleanValue()); return literalBoolean; } else if ("*".equals(bodyContent)) { LiteralUnlimitedNatural literalUnlimitedNatural = new LiteralUnlimitedNatural(); UnlimitedNatural value = new UnlimitedNatural(); value.naturalValue = -1; literalUnlimitedNatural.setValue(value); return literalUnlimitedNatural; } else { String type = findResultPinType(opaqueExpressionNode); if ("UnlimitedNatural".equals(type)) { int intValue = 0; try { intValue = Integer.valueOf(bodyContent).intValue(); } catch (NumberFormatException e) { log.warn("could not parse content as unlimited-natural integer '" + bodyContent + "'"); } LiteralUnlimitedNatural literalUnlimitedNatural = new LiteralUnlimitedNatural(); UnlimitedNatural value = new UnlimitedNatural(); value.naturalValue = intValue; literalUnlimitedNatural.setValue(value); return literalUnlimitedNatural; } try { if (log.isDebugEnabled()) log.debug("parsing expression: '" + bodyContent + "'"); LiteralInteger literalInt = new LiteralInteger(); literalInt.setValue(Integer.valueOf(bodyContent).intValue()); return literalInt; } catch (NumberFormatException e) { if (log.isDebugEnabled()) log.debug("invalid number format: " + e.getMessage()); literal.setValue(bodyContent); } } return literal; }
From source file:org.modeldriven.fuml.assembly.ElementAssembler.java
public void assemleFeatures() { try {//from www. j a v a2s. c o m NamespaceDomain domain = null; // only lookup as needed StreamNode eventNode = (StreamNode) source; Location loc = eventNode.getLocation(); if (log.isDebugEnabled()) log.debug("element line/column: " + loc.getLineNumber() + ":" + loc.getColumnNumber()); // look at XML attributes Iterator<Attribute> attributes = eventNode.getAttributes(); while (attributes != null && attributes.hasNext()) { Attribute xmlAttrib = attributes.next(); QName name = xmlAttrib.getName(); String prefix = name.getPrefix(); if (prefix != null && prefix.length() > 0) continue; // not applicable to current // element/association-end. if ("href".equals(name.getLocalPart())) continue; // FIXME: find/write URI resolver Property property = this.prototype.findProperty(name.getLocalPart()); if (property == null) { if (domain == null) domain = FumlConfiguration.getInstance().findNamespaceDomain(source.getNamespaceURI()); ValidationExemption exemption = FumlConfiguration.getInstance() .findValidationExemptionByProperty(ValidationExemptionType.UNDEFINED_PROPERTY, this.prototype, name.getLocalPart(), source.getNamespaceURI(), domain); if (exemption == null) { throw new ValidationException(new ValidationError(eventNode, name.getLocalPart(), ErrorCode.UNDEFINED_PROPERTY, ErrorSeverity.FATAL)); } else { if (log.isDebugEnabled()) log.debug("undefined property exemption found within domain '" + exemption.getDomain().toString() + "' for property '" + this.prototype.getName() + "." + name.getLocalPart() + "' - ignoring error"); continue; // ignore attrib } } Classifier type = property.getType(); if (this.modelSupport.isReferenceAttribute(property)) { XmiReferenceAttribute reference = new XmiReferenceAttribute(source, xmlAttrib, this.getPrototype()); this.addReference(reference); continue; } String value = xmlAttrib.getValue(); if (value == null || value.length() == 0) { String defaultValue = property.findPropertyDefault(); if (defaultValue != null) { value = defaultValue; if (log.isDebugEnabled()) log.debug("using default '" + String.valueOf(value) + "' for enumeration feature <" + type.getName() + "> " + this.getPrototype().getName() + "." + property.getName()); } } this.assembleNonReferenceFeature(property, value, type); } // look at model properties not found in above attribute set List<Property> properties = this.prototype.getNamedProperties(); for (Property property : properties) { QName name = new QName(property.getName()); String value = eventNode.getAttributeValue(name); if (value != null && value.trim().length() > 0) continue; // handled above String defaultValue = property.findPropertyDefault(); if (defaultValue != null) { Classifier type = property.getType(); if (log.isDebugEnabled()) log.debug("using default: '" + String.valueOf(defaultValue) + "' for enumeration feature <" + type.getName() + "> " + this.getPrototype().getName() + "." + property.getName()); this.assembleNonReferenceFeature(property, defaultValue, type); continue; } if (!property.isRequired()) continue; // don't bother digging further for a value if (eventNode.findChildByName(property.getName()) != null) continue; // it has such a child, let if (this.modelSupport.isReferenceAttribute(property) && FumlConfiguration.getInstance().hasReferenceMapping(this.prototype, property)) { ReferenceMappingType mappingType = FumlConfiguration.getInstance() .getReferenceMappingType(this.prototype, property); if (mappingType == ReferenceMappingType.PARENT) { if (parent != null && parent.getXmiId() != null && parent.getXmiId().length() > 0) { XmiMappedReference reference = new XmiMappedReference(source, property.getName(), new String[] { parent.getXmiId() }, this.prototype); this.addReference(reference); continue; } else log.warn("no parent XMI id found, ignoring mapping for, " + this.prototype.getName() + "." + property.getName()); } else log.warn("unrecognized mapping type, " + mappingType.value() + " ignoring mapping for, " + this.prototype.getName() + "." + property.getName()); } if (!property.isDerived()) { if (domain == null) domain = FumlConfiguration.getInstance().findNamespaceDomain(source.getNamespaceURI()); ValidationExemption exemption = FumlConfiguration.getInstance() .findValidationExemptionByProperty(ValidationExemptionType.REQUIRED_PROPERTY, this.prototype, name.getLocalPart(), source.getNamespaceURI(), domain); if (exemption == null) { if (log.isDebugEnabled()) log.debug("throwing " + ErrorCode.PROPERTY_REQUIRED.toString() + " error for " + this.prototype.getName() + "." + property.getName()); throw new ValidationException(new ValidationError(eventNode, property.getName(), ErrorCode.PROPERTY_REQUIRED, ErrorSeverity.FATAL)); } else { if (log.isDebugEnabled()) log.debug("required property exemption found within domain '" + exemption.getDomain().toString() + "' for property '" + this.prototype.getName() + "." + name.getLocalPart() + "' - ignoring error"); continue; // ignore property } } } } catch (ClassNotFoundException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchMethodException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InvocationTargetException e) { log.error(e.getCause().getMessage(), e.getCause()); throw new AssemblyException(e.getCause()); } catch (IllegalAccessException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (InstantiationException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } catch (NoSuchFieldException e) { log.error(e.getMessage(), e); throw new AssemblyException(e); } }
From source file:org.modeldriven.fuml.xmi.stream.StreamNode.java
public String getXmiType() { QName typeAttrib = new QName(context.getXmiNamespace().getNamespaceURI(), XmiConstants.ATTRIBUTE_XMI_TYPE); Attribute attrib = startElementEvent.asStartElement().getAttributeByName(typeAttrib); if (attrib != null) { String value = attrib.getValue(); return value.substring(context.getUmlNamespace().getPrefix().length() + 1); // prefix + ':' }/*from w w w. ja va 2 s .c o m*/ return null; }
From source file:org.modeldriven.fuml.xmi.stream.StreamNode.java
public String getAttributeValue(QName name) { if (startElementEvent != null) { Attribute attrib = startElementEvent.asStartElement().getAttributeByName(name); if (attrib != null) return attrib.getValue(); }// w w w .j a v a 2 s . com return null; }
From source file:org.modeldriven.fuml.xmi.stream.StreamNode.java
public String getAttributeValue(String name) { if (startElementEvent != null) { Attribute attrib = startElementEvent.asStartElement().getAttributeByName(new QName(name)); if (attrib != null) return attrib.getValue(); }//w w w. jav a 2s . com return null; }