use of javax.xml.stream.events.Attribute in project knox by apache.
the class XmlFilterReader method bufferAttributes.
private void bufferAttributes(StartElement event, Element element) {
Iterator attributes = event.getAttributes();
while (attributes.hasNext()) {
Attribute attribute = (Attribute) attributes.next();
bufferAttribute(element, attribute);
}
}
use of javax.xml.stream.events.Attribute in project knox by apache.
the class XmlFilterReader method streamAttributes.
private void streamAttributes(StartElement event, Element element) throws XPathExpressionException {
Iterator i = event.getAttributes();
while (i.hasNext()) {
Attribute attribute = (Attribute) i.next();
streamAttribute(element, attribute);
}
}
use of javax.xml.stream.events.Attribute in project data-prep by Talend.
the class StreamingSheetReader method handleEvent.
/**
* Handles a Stream event.
*
* @param event
* @throws SAXException
*/
private void handleEvent(XMLEvent event) throws SAXException {
if (event.getEventType() == XMLStreamConstants.CHARACTERS) {
Characters c = event.asCharacters();
lastContents += c.getData();
} else if (event.getEventType() == XMLStreamConstants.START_ELEMENT) {
StartElement startElement = event.asStartElement();
String tagLocalName = startElement.getName().getLocalPart();
if ("row".equals(tagLocalName)) {
Attribute rowIndex = startElement.getAttributeByName(new QName("r"));
if (firstRowIndex == -1) {
firstRowIndex = Integer.parseInt(rowIndex.getValue());
}
currentRow = new StreamingRow(Integer.parseInt(rowIndex.getValue()) - 1);
} else if ("cols".equals(tagLocalName)) {
parsingCols = true;
} else if ("col".equals(tagLocalName) && parsingCols) {
colNumber = colNumber + 1;
} else if ("c".equals(tagLocalName)) {
Attribute ref = startElement.getAttributeByName(new QName("r"));
String[] coord = ref.getValue().split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
currentCell = new StreamingCell(CellReference.convertColStringToIndex(coord[0]), Integer.parseInt(coord[1]) - 1);
setFormatString(startElement, currentCell);
Attribute type = startElement.getAttributeByName(new QName("t"));
if (type != null) {
currentCell.setType(type.getValue());
} else {
currentCell.setType("n");
}
Attribute style = startElement.getAttributeByName(new QName("s"));
if (style != null) {
String indexStr = style.getValue();
try {
int index = Integer.parseInt(indexStr);
currentCell.setCellStyle(stylesTable.getStyleAt(index));
} catch (NumberFormatException nfe) {
LOGGER.warn("Ignoring invalid style index {}", indexStr);
}
}
// we store the dimension as well to revert with this method when cols not found
// can happen see xlsx attached here https://jira.talendforge.org/browse/TDP-1957
// <dimension ref="A1:B60"/>
} else if ("dimension".equals(tagLocalName)) {
Attribute attribute = startElement.getAttributeByName(new QName("ref"));
if (attribute != null) {
this.dimension = attribute.getValue();
}
}
// Clear contents cache
lastContents = "";
} else if (event.getEventType() == XMLStreamConstants.END_ELEMENT) {
EndElement endElement = event.asEndElement();
String tagLocalName = endElement.getName().getLocalPart();
if ("v".equals(tagLocalName) || "t".equals(tagLocalName)) {
currentCell.setRawContents(unformattedContents());
currentCell.setContents(formattedContents());
} else if ("row".equals(tagLocalName) && currentRow != null) {
rowCache.add(currentRow);
} else if ("c".equals(tagLocalName)) {
currentRow.getCellMap().put(currentCell.getColumnIndex(), currentCell);
} else if ("cols".equals(tagLocalName)) {
parsingCols = false;
}
}
}
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(IScopeProvider scopeProvider, 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<Namespace> rootNamespaceAttributes = new ArrayList<Namespace>();
List<XMLEvent> imports = new ArrayList<XMLEvent>();
for (XSD xsd : xsds) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
XMLStreamWriter w = XmlUtils.REPAIR_NAMESPACES_OUTPUT_FACTORY.createXMLStreamWriter(byteArrayOutputStream, StreamUtil.DEFAULT_INPUT_STREAM_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, StreamUtil.DEFAULT_INPUT_STREAM_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.initFromXsds(namespace, scopeProvider, xsds);
resultXsds.add(resultXsd);
}
}
return resultXsds;
}
use of javax.xml.stream.events.Attribute in project S-argo by Expugn.
the class ScoutMasterParser method readConfig.
/**
* Reads the ScoutMaster file and saves the data found to variables.
*/
@SuppressWarnings("unchecked")
private void readConfig() {
InputStream in = null;
XMLEventReader eventReader = null;
try {
/* CREATE XMLInputFactory AND XMLEventReader */
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
in = new FileInputStream("data/mods/" + scoutMasterName + ".xml");
eventReader = inputFactory.createXMLEventReader(in);
/* READ XML FILE */
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
if (event.isStartElement()) {
if (event.asStartElement().getName().getLocalPart().equals("BotName")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("name")) {
botName = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("SAOSmile")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("imageURL")) {
image_sao_smile_URL = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("SAOGrin")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("imageURL")) {
image_sao_grin_URL = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("SAOSmug")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("imageURL")) {
image_sao_smug_URL = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("SAOFlowers")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("imageURL")) {
image_sao_flowers_URL = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("SAOStars")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("imageURL")) {
image_sao_stars_URL = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("ALOSmile")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("imageURL")) {
image_alo_smile_URL = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("ALOGrin")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("imageURL")) {
image_alo_grin_URL = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("ALOSmug")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("imageURL")) {
image_alo_smug_URL = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("ALOFlowers")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("imageURL")) {
image_alo_flowers_URL = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("ALOStars")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("imageURL")) {
image_alo_stars_URL = attribute.getValue();
}
}
continue;
}
if (event.asStartElement().getName().getLocalPart().equals("Quote")) {
Iterator<Attribute> attributes = event.asStartElement().getAttributes();
while (attributes.hasNext()) {
Attribute attribute = attributes.next();
if (attribute.getName().toString().equals("say")) {
quotes.add("*\"" + attribute.getValue() + "\"*");
}
}
}
}
}
} catch (FileNotFoundException | XMLStreamException e) {
useDefaults = true;
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
/* IGNORED */
}
try {
if (eventReader != null) {
eventReader.close();
}
} catch (XMLStreamException e) {
/* IGNORED */
}
}
}
Aggregations