List of usage examples for javax.xml.stream XMLStreamConstants END_ELEMENT
int END_ELEMENT
To view the source code for javax.xml.stream XMLStreamConstants END_ELEMENT.
Click Source Link
From source file:fr.inria.oak.paxquery.pact.io.XmlNavTreePatternInputFormat.java
@Override public Record nextRecord(Record record) throws IOException { if (this.pactRecordsIterator != null) { if (this.pactRecordsIterator.hasNext()) { if (this.attachDocumentID) { record.addField(new StringValue(this.documentID)); RecordOperations.concatenate(record, this.pactRecordsIterator.next()); } else this.pactRecordsIterator.next().copyTo(record); //return true; return record; }/*ww w.j a v a2s. co m*/ this.pactRecordsIterator = null; this.extractor.getRecords().clear(); } try { while (this.streamReader.hasNext()) { this.streamReader.next(); if (this.streamReader.getEventType() == XMLStreamConstants.START_ELEMENT) { this.extractor.startElement(); } else if (this.streamReader.getEventType() == XMLStreamConstants.END_ELEMENT) { this.extractor.endElement(); } else if (this.streamReader.getEventType() == XMLStreamConstants.CHARACTERS) { this.extractor.characters(); } else if (this.streamReader.getEventType() == XMLStreamConstants.END_DOCUMENT) { this.reachedEnd = true; } if (this.extractor.getRecords().size() != 0) { this.pactRecordsIterator = this.extractor.getRecords().iterator(); if (this.attachDocumentID) { record.addField(new StringValue(this.documentID)); RecordOperations.concatenate(record, this.pactRecordsIterator.next()); } else this.pactRecordsIterator.next().copyTo(record); //return true; return record; } } //return false; return null; } catch (XMLStreamException e) { logger.error("XMLStreamException", e); //return false; return null; } }
From source file:de.ii.xtraplatform.ogc.api.gml.parser.GMLParser.java
private void parseFeature(SMInputCursor cursor) throws XMLStreamException { analyzer.analyzeFeatureStart(null, cursor.getNsUri(), cursor.getLocalName()); featureDepth = cursor.getParentCount(); for (int i = 0; i < cursor.getAttrCount(); i++) { analyzer.analyzeAttribute(cursor.getAttrNsUri(i), cursor.getAttrLocalName(i), cursor.getAttrValue(i)); }/*from w w w . j a v a2 s. com*/ SMFlatteningCursor feature; StringBuilder text = null; if (parseText) { feature = (SMFlatteningCursor) cursor.descendantCursor().advance(); text = new StringBuilder(); } else { feature = (SMFlatteningCursor) cursor.descendantElementCursor().advance(); } while (feature.readerAccessible()) { if (feature.getCurrEventCode() == XMLStreamConstants.START_ELEMENT) { boolean nil = false; for (int i = 0; i < feature.getAttrCount(); i++) { if (feature.getAttrNsUri(i).equals(XSI.getNS(XSI.VERSION.DEFAULT)) && feature.getAttrLocalName(i).equals(XSI.getWord(XSI.VOCABULARY.NIL)) && feature.getAttrValue(i).equals(XSI.getWord(XSI.VOCABULARY.NIL_TRUE))) { nil = true; } analyzer.analyzeAttribute(feature.getAttrNsUri(i), feature.getAttrLocalName(i), feature.getAttrValue(i)); } analyzer.analyzePropertyStart(feature.getNsUri(), feature.getLocalName(), feature.getParentCount() - featureDepth, feature, nil); } else if (feature.getCurrEventCode() == XMLStreamConstants.END_ELEMENT) { if (parseText && text.length() > 0) { analyzer.analyzePropertyText(feature.getNsUri(), feature.getLocalName(), feature.getParentCount() - featureDepth, text.toString()); text = new StringBuilder(); } analyzer.analyzePropertyEnd(feature.getNsUri(), feature.getLocalName(), feature.getParentCount() - featureDepth); } else if (parseText && (feature.getCurrEventCode() == XMLStreamConstants.CHARACTERS)) { text.append(feature.getText().trim()); } feature = (SMFlatteningCursor) feature.advance(); } analyzer.analyzeFeatureEnd(); }
From source file:com.norconex.collector.http.sitemap.impl.StandardSitemapResolver.java
private void parseLocation(InputStream is, HttpClient httpClient, SitemapURLAdder sitemapURLAdder, Set<String> resolvedLocations, String location) throws XMLStreamException { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is); ParseState parseState = new ParseState(); String locationDir = StringUtils.substringBeforeLast(location, "/"); int event = xmlReader.getEventType(); while (true) { switch (event) { case XMLStreamConstants.START_ELEMENT: String tag = xmlReader.getLocalName(); parseStartElement(parseState, tag); break; case XMLStreamConstants.CHARACTERS: String value = xmlReader.getText(); if (parseState.sitemapIndex && parseState.loc) { resolveLocation(value, httpClient, sitemapURLAdder, resolvedLocations); parseState.loc = false;// w ww . j av a 2 s. c o m } else if (parseState.baseURL != null) { parseCharacters(parseState, value); } break; case XMLStreamConstants.END_ELEMENT: tag = xmlReader.getLocalName(); parseEndElement(sitemapURLAdder, parseState, locationDir, tag); break; } if (!xmlReader.hasNext()) { break; } event = xmlReader.next(); } }
From source file:com.evolveum.polygon.connector.hcm.DocumentProcessing.java
public Map<String, Object> parseXMLData(HcmConnectorConfiguration conf, ResultsHandler handler, Map<String, Object> schemaAttributeMap, Filter query) { XMLInputFactory factory = XMLInputFactory.newInstance(); try {/*from w ww.j ava 2 s. com*/ String uidAttributeName = conf.getUidAttribute(); String primariId = conf.getPrimaryId(); String startName = ""; String value = null; StringBuilder assignmentXMLBuilder = null; List<String> builderList = new ArrayList<String>(); Integer nOfIterations = 0; Boolean isSubjectToQuery = false; Boolean isAssigment = false; Boolean evaluateAttr = true; Boolean specificAttributeQuery = false; XMLEventReader eventReader = factory.createXMLEventReader(new FileReader(conf.getFilePath())); List<String> dictionary = populateDictionary(FIRSTFLAG); if (!attrsToGet.isEmpty()) { attrsToGet.add(uidAttributeName); attrsToGet.add(primariId); specificAttributeQuery = true; evaluateAttr = false; LOGGER.ok("The uid and primary id were added to the queried attribute list"); schemaAttributeMap = modifySchemaAttributeMap(schemaAttributeMap); } while (eventReader.hasNext()) { XMLEvent event = eventReader.nextEvent(); Integer code = event.getEventType(); if (code == XMLStreamConstants.START_ELEMENT) { StartElement startElement = event.asStartElement(); startName = startElement.getName().getLocalPart(); if (!evaluateAttr && attrsToGet.contains(startName)) { evaluateAttr = true; } if (!elementIsEmployeeData) { if (startName.equals(EMPLOYEES)) { if (dictionary.contains(nOfIterations.toString())) { LOGGER.ok("The defined number of iterations has been hit: {0}", nOfIterations.toString()); break; } else { startName = ""; elementIsEmployeeData = true; nOfIterations++; } } } else if (evaluateAttr) { if (!isAssigment) { if (!ASSIGNMENTTAG.equals(startName)) { } else { assignmentXMLBuilder = new StringBuilder(); isAssigment = true; } } else { builderList = processAssignment(startName, null, START, builderList); } if (multiValuedAttributesList.contains(startName)) { elementIsMultiValued = true; } } } else if (elementIsEmployeeData) { if (code == XMLStreamConstants.CHARACTERS && evaluateAttr) { Characters characters = event.asCharacters(); if (!characters.isWhiteSpace()) { StringBuilder valueBuilder; if (value != null) { valueBuilder = new StringBuilder(value).append("") .append(characters.getData().toString()); } else { valueBuilder = new StringBuilder(characters.getData().toString()); } value = valueBuilder.toString(); // value = StringEscapeUtils.escapeXml10(value); // LOGGER.info("The attribute value for: {0} is // {1}", startName, value); } } else if (code == XMLStreamConstants.END_ELEMENT) { EndElement endElement = event.asEndElement(); String endName = endElement.getName().getLocalPart(); isSubjectToQuery = checkFilter(endName, value, query, uidAttributeName); if (!isSubjectToQuery) { attributeMap.clear(); elementIsEmployeeData = false; value = null; endName = EMPLOYEES; } if (endName.equals(EMPLOYEES)) { attributeMap = handleEmployeeData(attributeMap, schemaAttributeMap, handler, uidAttributeName, primariId); elementIsEmployeeData = false; } else if (evaluateAttr) { if (endName.equals(startName)) { if (value != null) { if (!isAssigment) { if (!elementIsMultiValued) { attributeMap.put(startName, value); } else { multiValuedAttributeBuffer.put(startName, value); } } else { value = StringEscapeUtils.escapeXml10(value); builderList = processAssignment(endName, value, VALUE, builderList); builderList = processAssignment(endName, null, END, builderList); } // LOGGER.info("Attribute name: {0} and the // Attribute value: {1}", endName, value); value = null; } } else { if (endName.equals(ASSIGNMENTTAG)) { builderList = processAssignment(endName, null, CLOSE, builderList); // if (assigmentIsActive) { for (String records : builderList) { assignmentXMLBuilder.append(records); } attributeMap.put(ASSIGNMENTTAG, assignmentXMLBuilder.toString()); // } else { // } builderList = new ArrayList<String>(); // assigmentIsActive = false; isAssigment = false; } else if (multiValuedAttributesList.contains(endName)) { processMultiValuedAttributes(multiValuedAttributeBuffer); } } } if (specificAttributeQuery && evaluateAttr) { evaluateAttr = false; } } } else if (code == XMLStreamConstants.END_DOCUMENT) { handleBufferedData(uidAttributeName, primariId, handler); } } } catch (FileNotFoundException e) { StringBuilder errorBuilder = new StringBuilder("File not found at the specified path.") .append(e.getLocalizedMessage()); LOGGER.error("File not found at the specified path: {0}", e); throw new ConnectorIOException(errorBuilder.toString()); } catch (XMLStreamException e) { LOGGER.error("Unexpected processing error while parsing the .xml document : {0}", e); StringBuilder errorBuilder = new StringBuilder( "Unexpected processing error while parsing the .xml document. ") .append(e.getLocalizedMessage()); throw new ConnectorIOException(errorBuilder.toString()); } return attributeMap; }
From source file:org.javelin.sws.ext.bind.internal.model.ElementPattern.java
@Override public T consume(XMLEventReader eventReader, UnmarshallingContext context) throws XMLStreamException { // just skip element's START_ELEMENT event StartElement startElement = eventReader.nextEvent().asStartElement(); // StartElement may contain attributes - these are NOT available as separate events in eventReader.nextEvent()! Iterator<?> attributes = startElement.getAttributes(); List<Attribute> attrList = new LinkedList<Attribute>(); while (attributes.hasNext()) { Attribute a = (Attribute) attributes.next(); attrList.add(a);//from www . ja v a 2 s . c om } T value = this.nestedPattern.consumeValue(new AttributesAwareXMLEventReader(eventReader, attrList), context); // skip element's END_ELEMENT event while (eventReader.peek() != null) { XMLEvent ev = eventReader.nextEvent(); if (ev.getEventType() == XMLStreamConstants.END_ELEMENT) break; } return value; }
From source file:lux.search.highlight.XmlHighlighter.java
@Override public void handleEvent(XMLStreamReader reader, int eventType) throws XMLStreamException { switch (eventType) { case XMLStreamConstants.START_DOCUMENT: xmlStreamReader = reader; // cache the reader so we can pull events super.handleEvent(reader, eventType); break;//from w ww. java2 s .co m case XMLStreamConstants.START_ELEMENT: super.handleEvent(reader, eventType); xmlStreamTokens .pushElement(new QName(reader.getNamespaceURI(), reader.getLocalName(), reader.getPrefix())); break; case XMLStreamConstants.END_ELEMENT: super.handleEvent(reader, eventType); xmlStreamTokens.popElement(); break; case XMLStreamConstants.COMMENT: case XMLStreamConstants.PROCESSING_INSTRUCTION: super.handleEvent(reader, eventType); break; case XMLStreamConstants.CDATA: throw new XMLStreamException("unexpected CDATA event"); case XMLStreamConstants.SPACE: super.handleEvent(reader, eventType); break; case XMLStreamConstants.CHARACTERS: textReader.text(); try { highlightTextNode(); } catch (IOException e) { throw new XMLStreamException(e); } break; case XMLStreamConstants.ENTITY_REFERENCE: throw new XMLStreamException("unexpected entity reference event"); default: super.handleEvent(reader, eventType); } }
From source file:com.microsoft.tfs.core.ws.runtime.types.StaxAnyContentType.java
@Override public void readFromElement(final XMLStreamReader reader) throws XMLStreamException { FastTempOutputStream ftos = null;//from w w w. ja v a 2s .co m XMLStreamWriter writer = null; /* * When this method is called, the writer is positioned at the element * that contains the "any" content. Process the child elements until the * container is done. */ /* * Advance one event to get the first child. */ int event = reader.next(); do { if (event == XMLStreamConstants.START_ELEMENT) { /* * Parse the child element into its own temp file. The copier * will read the child's end element. */ try { /* * Get a new fast temp output stream. */ ftos = new FastTempOutputStream(heapStorageLimitBytes, initialHeapStorageSizeBytes); tempOutputStreams.add(ftos); /* * Create a writer. */ writer = StaxFactoryProvider.getXMLOutputFactory().createXMLStreamWriter(ftos, SOAPRequestEntity.SOAP_ENCODING); writer.writeStartDocument(); StaxUtils.copyCurrentElement(reader, writer); /* * Make sure to finish off the document. */ writer.writeEndDocument(); } finally { if (writer != null) { writer.close(); } /* * Closing writers does not close the underlying stream, so * close that manually. This is required so the temp stream * can be read from. */ if (ftos != null) { try { ftos.close(); } catch (final IOException e) { log.error(e); } } } } } while ((event = reader.next()) != XMLStreamConstants.END_ELEMENT); }
From source file:davmail.exchange.dav.ExchangeDavMethod.java
protected String getTagContent(XMLStreamReader reader) throws XMLStreamException { String value = null;/*from w w w .ja v a 2s.c om*/ String tagLocalName = reader.getLocalName(); while (reader.hasNext() && !((reader.getEventType() == XMLStreamConstants.END_ELEMENT) && tagLocalName.equals(reader.getLocalName()))) { reader.next(); if (reader.getEventType() == XMLStreamConstants.CHARACTERS) { value = reader.getText(); } } // empty tag if (!reader.hasNext()) { throw new XMLStreamException("End element for " + tagLocalName + " not found"); } return value; }
From source file:com.norconex.collector.http.sitemap.impl.DefaultSitemapResolver.java
private void parseLocation(InputStream is, DefaultHttpClient httpClient, SitemapURLStore sitemapURLStore, Set<String> resolvedLocations, String location) throws XMLStreamException { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); inputFactory.setProperty(XMLInputFactory.IS_COALESCING, true); XMLStreamReader xmlReader = inputFactory.createXMLStreamReader(is); ParseState parseState = new ParseState(); String locationDir = StringUtils.substringBeforeLast(location, "/"); int event = xmlReader.getEventType(); while (true) { switch (event) { case XMLStreamConstants.START_ELEMENT: String tag = xmlReader.getLocalName(); parseStartElement(parseState, tag); break; case XMLStreamConstants.CHARACTERS: String value = xmlReader.getText(); if (parseState.sitemapIndex && parseState.loc) { resolveLocation(value, httpClient, sitemapURLStore, resolvedLocations); parseState.loc = false;//from www . j av a2 s. c om } else if (parseState.baseURL != null) { parseCharacters(parseState, value); } break; case XMLStreamConstants.END_ELEMENT: tag = xmlReader.getLocalName(); parseEndElement(sitemapURLStore, parseState, locationDir, tag); break; } if (!xmlReader.hasNext()) { break; } event = xmlReader.next(); } }
From source file:ca.efendi.datafeeds.messaging.FtpSubscriptionMessageListener.java
private void parse(FtpSubscription ftpSubscription, final InputStream is) throws XMLStreamException { final XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true); factory.setProperty(XMLInputFactory.IS_COALESCING, true); final XMLStreamReader reader = factory.createXMLStreamReader(is, "UTF-8"); CJProduct product = null;//from ww w . j ava 2s. c om String tagContent = null; //final ServiceContext serviceContext = new ServiceContext(); //ServiceContext serviceContext = ServiceContextFactory.getInstance( // BlogsEntry.class.getName(), actionRequest); //serviceContext.setScopeGroupId(20159); while (reader.hasNext()) { final int event = reader.next(); switch (event) { case XMLStreamConstants.START_ELEMENT: //tagContent = ""; if ("product".equals(reader.getLocalName())) { product = _cjProductLocalService.createCJProduct(0); } break; case XMLStreamConstants.CHARACTERS: //tagContent += reader.getText().trim(); tagContent = reader.getText().trim(); break; case XMLStreamConstants.END_ELEMENT: switch (reader.getLocalName()) { case "product": try { _log.warn("refreshing document..."); _cjProductLocalService.refresh(ftpSubscription, product); } catch (final SystemException e) { _log.error(e); } catch (final PortalException e) { _log.error(e); } break; case "programname": product.setProgramName(tagContent); break; case "programurl": product.setProgramUrl(tagContent); break; case "catalogname": product.setCatalogName(tagContent); break; case "lastupdated": product.setLastUpdated(tagContent); break; case "name": product.setName(tagContent); break; case "keywords": product.setKeywords(tagContent); break; case "description": product.setDescription(tagContent); break; case "sku": product.setSku(tagContent); break; case "manufacturer": product.setManufacturer(tagContent); break; case "manufacturerid": product.setManufacturerId(tagContent); break; case "currency": product.setCurrency(tagContent); break; case "price": product.setPrice(tagContent); break; case "buyurl": product.setBuyUrl(tagContent); break; case "impressionurl": product.setImpressionUrl(tagContent); break; case "imageurl": product.setImageUrl(tagContent); break; case "instock": product.setInStock(tagContent); break; } break; case XMLStreamConstants.START_DOCUMENT: break; } } }