use of javax.xml.stream.events.Attribute in project sirix by sirixdb.
the class AbstractSunburstGUI method processAttributes.
/**
* Process attributes for string representation.
*
* @param pBuilder
* the builder instance to use
*/
public void processAttributes(final StringBuilder pBuilder) {
checkNotNull(pBuilder);
for (final Attribute att : mHitItem.getAttributes()) {
if ("name".equals(att.getName().getLocalPart())) {
pBuilder.append(" Attribute: ");
appendString(pBuilder, att.getValue());
break;
}
}
}
use of javax.xml.stream.events.Attribute in project iaf by ibissource.
the class SchemaUtils method mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes.
/**
* @return XSD's when xmlStreamWriter is null, otherwise write to
* xmlStreamWriter
*/
public static Set<XSD> mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes(ClassLoader classLoader, Map<String, Set<XSD>> xsdsGroupedByNamespace, XMLStreamWriter xmlStreamWriter) throws XMLStreamException, IOException, ConfigurationException {
Set<XSD> resultXsds = new HashSet<XSD>();
for (String namespace : xsdsGroupedByNamespace.keySet()) {
Set<XSD> xsds = xsdsGroupedByNamespace.get(namespace);
// Get attributes of root elements and get import elements from all XSD's
List<Attribute> rootAttributes = new ArrayList<Attribute>();
List<Attribute> rootNamespaceAttributes = new ArrayList<Attribute>();
List<XMLEvent> imports = new ArrayList<XMLEvent>();
for (XSD xsd : xsds) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
XMLStreamWriter w = XmlUtils.REPAIR_NAMESPACES_OUTPUT_FACTORY.createXMLStreamWriter(byteArrayOutputStream, XmlUtils.STREAM_FACTORY_ENCODING);
xsdToXmlStreamWriter(xsd, w, false, true, false, false, rootAttributes, rootNamespaceAttributes, imports, true);
}
// Write XSD's with merged root element
XSD resultXsd = null;
XMLStreamWriter w;
if (xmlStreamWriter == null) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
resultXsd = new XSD();
resultXsd.setClassLoader(classLoader);
resultXsd.setNamespace(namespace);
resultXsd.setByteArrayOutputStream(byteArrayOutputStream);
resultXsd.setSourceXsds(xsds);
w = XmlUtils.REPAIR_NAMESPACES_OUTPUT_FACTORY.createXMLStreamWriter(byteArrayOutputStream, XmlUtils.STREAM_FACTORY_ENCODING);
} else {
w = xmlStreamWriter;
}
int i = 0;
for (XSD xsd : xsds) {
i++;
boolean skipFirstElement = true;
boolean skipLastElement = true;
if (xsds.size() == 1) {
skipFirstElement = false;
skipLastElement = false;
} else {
if (i == 1) {
skipFirstElement = false;
} else if (i == xsds.size()) {
skipLastElement = false;
}
}
xsdToXmlStreamWriter(xsd, w, false, true, skipFirstElement, skipLastElement, rootAttributes, rootNamespaceAttributes, imports, false);
}
if (resultXsd != null) {
XSD firstXsd = xsds.iterator().next();
resultXsd.setImportedSchemaLocationsToIgnore(firstXsd.getImportedSchemaLocationsToIgnore());
resultXsd.setUseBaseImportedSchemaLocationsToIgnore(firstXsd.isUseBaseImportedSchemaLocationsToIgnore());
resultXsd.setImportedNamespacesToIgnore(firstXsd.getImportedNamespacesToIgnore());
resultXsd.init();
resultXsds.add(resultXsd);
}
}
return resultXsds;
}
use of javax.xml.stream.events.Attribute in project wildfly by wildfly.
the class SchemaLocationsRewriteTestCase method getAttributeValues.
private List<String> getAttributeValues(URL url, String localPart) throws Exception {
String document = IOUtils.toString(url.openStream());
log.trace(document);
List<String> values = new ArrayList<>();
XMLInputFactory xmlif = XMLInputFactory.newInstance();
XMLEventReader eventReader = xmlif.createXMLEventReader(new ByteArrayInputStream(document.getBytes(StandardCharsets.UTF_8)));
while (eventReader.hasNext()) {
XMLEvent xmlEvent = eventReader.nextEvent();
if (xmlEvent.getEventType() == XMLStreamConstants.START_ELEMENT) {
StartElement startElement = xmlEvent.asStartElement();
Attribute attribute = startElement.getAttributeByName(new QName("", localPart));
if (attribute != null) {
values.add(attribute.getValue());
}
}
}
return values;
}
use of javax.xml.stream.events.Attribute in project uPortal by Jasig.
the class FixedXMLEventStreamReader method getAttribute.
private Attribute getAttribute(int index) {
if (!event.isStartElement()) {
throw new IllegalStateException();
}
int count = 0;
Iterator attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = (Attribute) attributes.next();
if (count == index) {
return attribute;
} else {
count++;
}
}
throw new IllegalArgumentException();
}
use of javax.xml.stream.events.Attribute in project uPortal by Jasig.
the class PortletDefinitionAttributeSource 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 Collection<Attribute> attributes = new LinkedList<Attribute>();
// Add the portlet's portlet name and either the webapp URL or framework flag to the list of
// attributes.
final Attribute fnameAttribute = event.getAttributeByName(PORTLET_FNAME_ATTR_NAME);
if (fnameAttribute != null) {
final String fname = fnameAttribute.getValue();
IPortletDefinition def = portletDefinitionDao.getPortletDefinitionByFname(fname);
if (def == null) {
this.logger.warn("Cannot get portlet definition attributes. No portlet definition found for fname: '" + fname + "'.");
} else {
IPortletDescriptorKey descriptorKey = def.getPortletDescriptorKey();
attributes.add(xmlEventFactory.createAttribute(PORTLET_NAME_ATTRIBUTE, descriptorKey.getPortletName()));
attributes.add(xmlEventFactory.createAttribute(PORTLET_LIFECYCLE_ATTRIBUTE, def.getLifecycleState().toString()));
if (descriptorKey.isFrameworkPortlet()) {
attributes.add(xmlEventFactory.createAttribute(FRAMEWORK_PORTLET_ATTRIBUTE, "true"));
} else {
attributes.add(xmlEventFactory.createAttribute(WEBAPP_NAME_ATTRIBUTE, descriptorKey.getWebAppName()));
}
}
}
return attributes.iterator();
}
Aggregations