javax.xml.stream.events.XMLEvent Java Examples

The following examples show how to use javax.xml.stream.events.XMLEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VespaRecordWriter.java    From vespa with Apache License 2.0 6 votes vote down vote up
private String findDocIdFromXml(String xml) {
    try {
        XMLEventReader eventReader = XMLInputFactory.newInstance().createXMLEventReader(new StringReader(xml));
        while (eventReader.hasNext()) {
            XMLEvent event = eventReader.nextEvent();
            if (event.getEventType() == XMLEvent.START_ELEMENT) {
                StartElement element = event.asStartElement();
                String elementName = element.getName().getLocalPart();
                if (VespaDocumentOperation.Operation.valid(elementName)) {
                    return element.getAttributeByName(QName.valueOf("documentid")).getValue();
                }
            }
        }
    } catch (XMLStreamException | FactoryConfigurationError e) {
        // as json dude does
        return null;
    }
    return null;
}
 
Example #2
Source File: StAXEvent2SAX.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private void handleStartDocument(final XMLEvent event) throws SAXException {
    _sax.setDocumentLocator(new Locator2() {
        public int getColumnNumber() {
            return event.getLocation().getColumnNumber();
        }
        public int getLineNumber() {
            return event.getLocation().getLineNumber();
        }
        public String getPublicId() {
            return event.getLocation().getPublicId();
        }
        public String getSystemId() {
            return event.getLocation().getSystemId();
        }
        public String getXMLVersion(){
            return version;
        }
        public String getEncoding(){
            return encoding;
        }

    });
    _sax.startDocument();
}
 
Example #3
Source File: Jaxb2XmlDecoder.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public Flux<Object> decode(Publisher<DataBuffer> inputStream, ResolvableType elementType,
		@Nullable MimeType mimeType, @Nullable Map<String, Object> hints) {

	Flux<XMLEvent> xmlEventFlux = this.xmlEventDecoder.decode(
			inputStream, ResolvableType.forClass(XMLEvent.class), mimeType, hints);

	Class<?> outputClass = elementType.toClass();
	QName typeName = toQName(outputClass);
	Flux<List<XMLEvent>> splitEvents = split(xmlEventFlux, typeName);

	return splitEvents.map(events -> {
		Object value = unmarshal(events, outputClass);
		LogFormatUtils.traceDebug(logger, traceOn -> {
			String formatted = LogFormatUtils.formatValue(value, !traceOn);
			return Hints.getLogPrefix(hints) + "Decoded [" + formatted + "]";
		});
		return value;
	});
}
 
Example #4
Source File: StAXFilteredEvent.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public String getElementText() throws XMLStreamException
{
    StringBuffer buffer = new StringBuffer();
    XMLEvent e = nextEvent();
    if (!e.isStartElement())
        throw new XMLStreamException(
        CommonResourceBundle.getInstance().getString("message.mustBeOnSTART_ELEMENT"));

    while(hasNext()) {
        e = nextEvent();
        if(e.isStartElement())
            throw new XMLStreamException(
            CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly"));
        if(e.isCharacters())
            buffer.append(((Characters) e).getData());
        if(e.isEndElement())
            return buffer.toString();
    }
    throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.END_ELEMENTnotFound"));
}
 
Example #5
Source File: EmployeeRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #6
Source File: EventFilterSupport.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public XMLEvent nextEvent()throws XMLStreamException{
    if(super.hasNext()){
        //get the next event by calling XMLEventReader
        XMLEvent event = super.nextEvent();

        //if this filter accepts this event then return this event
        if(fEventFilter.accept(event)){
            return event;
        }
        else{
            return nextEvent();
        }
    }else{
        throw new NoSuchElementException();
    }
}
 
Example #7
Source File: EntityRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param eventWriter
 *            .
 * @param name
 *            The name.
 * @param value
 *            The value.
 * @throws XMLStreamException
 *             .
 */
public static void createNode(final XMLEventWriter eventWriter, final String name, final String value)
		throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #8
Source File: AttrXmlResourceValue.java    From bazel with Apache License 2.0 6 votes vote down vote up
private static Map<String, String> readSubValues(XMLEventReader reader, QName subTagType)
    throws XMLStreamException {
  ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
  while (reader.hasNext()
      && XmlResourceValues.isTag(XmlResourceValues.peekNextTag(reader), subTagType)) {
    StartElement element = reader.nextEvent().asStartElement();
    builder.put(
        XmlResourceValues.getElementName(element), XmlResourceValues.getElementValue(element));
    XMLEvent endTag = reader.nextEvent();
    if (!XmlResourceValues.isEndTag(endTag, subTagType)) {
      throw new XMLStreamException(
          String.format("Unexpected [%s]; Expected %s", endTag, "</enum>"), endTag.getLocation());
    }
  }
  return builder.build();
}
 
Example #9
Source File: XMLDocumentScannerImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void reset(PropertyManager propertyManager) {
    super.reset(propertyManager);
    // other settings
    fDoctypeName = null;
    fDoctypePublicId = null;
    fDoctypeSystemId = null;
    fSeenDoctypeDecl = false;
    fNamespaceContext.reset();
    fSupportDTD = ((Boolean)propertyManager.getProperty(XMLInputFactory.SUPPORT_DTD)).booleanValue();

    // xerces features
    fLoadExternalDTD = !((Boolean)propertyManager.getProperty(Constants.ZEPHYR_PROPERTY_PREFIX + Constants.IGNORE_EXTERNAL_DTD)).booleanValue();
    setScannerState(XMLEvent.START_DOCUMENT);
    setDriver(fXMLDeclDriver);
    fSeenInternalSubset = false;
    if(fDTDScanner != null){
        ((XMLDTDScannerImpl)fDTDScanner).reset(propertyManager);
    }
    fEndPos = 0;
    fStartPos = 0;
    if(fDTDDecl != null){
        fDTDDecl.clear();
    }

}
 
Example #10
Source File: UploadActionListener.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
public static Boolean reportIsEmpty(File reportFile) throws IOException, XMLStreamException {
	BufferedReader br = Files.newBufferedReader(reportFile.toPath());
	try {
		XMLEventReader reader = xmlInputFactory.createXMLEventReader(br);

		while(reader.hasNext()) {
			XMLEvent event = reader.nextEvent();
			if(event.isStartElement() && !event.asStartElement().getName().getLocalPart().equals("OWASPZAPReport")) {
				return false;
			}
		}
	} finally {
		br.close();
	}
	return true;
}
 
Example #11
Source File: StaxXmlUtil.java    From maven-framework-project with MIT License 6 votes vote down vote up
/**
 * 基于迭代模型的方式解析XML
 */
@Test
public void iteratorParseXML() throws Exception {
	XMLInputFactory factory = XMLInputFactory.newInstance();
	InputStream is = ClassLoader.getSystemResourceAsStream("books.xml");
	XMLEventReader reader = factory.createXMLEventReader(is);
	int iteratorNum = 0; //统计遍历的次数
	while(reader.hasNext()) {
		XMLEvent event = reader.nextEvent();
		if(event.isStartElement()) {                                   //通过XMLEvent判断节点类型
			String name = event.asStartElement().getName().toString(); //通过event.asxxx转换节点
			if(name.equals("title")) {
				System.out.print("书籍[" + reader.getElementText() + "]");
			}
			if(name.equals("price")) {
				System.out.println("的价格为[" + reader.getElementText() + "]");
			}
		}
		iteratorNum++;
	}
	is.close();
	System.out.println("本次操作遍历XML的次数合计为[" + iteratorNum + "]次");
}
 
Example #12
Source File: AnimalRepository.java    From JavaMainRepo with Apache License 2.0 6 votes vote down vote up
public static void createNode(XMLEventWriter eventWriter, String name, String value) throws XMLStreamException {
	XMLEventFactory eventFactory = XMLEventFactory.newInstance();
	XMLEvent end = eventFactory.createDTD("\n");
	XMLEvent tab = eventFactory.createDTD("\t");
	// Create Start node
	StartElement sElement = eventFactory.createStartElement("", "", name);
	eventWriter.add(tab);
	eventWriter.add(sElement);
	// Create Content
	Characters characters = eventFactory.createCharacters(value);
	eventWriter.add(characters);
	// Create End node
	EndElement eElement = eventFactory.createEndElement("", "", name);
	eventWriter.add(eElement);
	eventWriter.add(end);
}
 
Example #13
Source File: FileSourceGEXF.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * <pre>
 * name 		: THICKNESS
 * attributes 	: THICKNESSAttribute { VALUE!, START, STARTOPEN, END, ENDOPEN }
 * structure 	: SPELLS ?
 * </pre>
 */
private void __thickness(final String edgeId) throws IOException, XMLStreamException {
	XMLEvent e;
	EnumMap<THICKNESSAttribute, String> attributes;

	e = getNextEvent();
	checkValid(e, XMLEvent.START_ELEMENT, "thickness");

	attributes = getAttributes(THICKNESSAttribute.class, e.asStartElement());

	checkRequiredAttributes(e, attributes, THICKNESSAttribute.VALUE);

	e = getNextEvent();

	if (isEvent(e, XMLEvent.START_ELEMENT, "spells")) {
		pushback(e);

		__spells();
		e = getNextEvent();
	}

	checkValid(e, XMLEvent.END_ELEMENT, "thickness");
}
 
Example #14
Source File: XMLStreamFilterImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private int findNextEvent() throws XMLStreamException {
    fStreamAdvancedByHasNext = false;
    while(fStreamReader.hasNext()){
        fCurrentEvent = fStreamReader.next();
        if(fStreamFilter.accept(fStreamReader)){
            fEventAccepted = true;
            return fCurrentEvent;
        }
    }
    //although it seems that IllegalStateException should be thrown when next() is called
    //on a stream that has no more items, we have to assume END_DOCUMENT is always accepted
    //in order to pass the TCK
    if (fCurrentEvent == XMLEvent.END_DOCUMENT)
        return fCurrentEvent;
    else
        return -1;
}
 
Example #15
Source File: EventFilterSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public XMLEvent nextTag() throws XMLStreamException{
    while (super.hasNext()) {
        XMLEvent event = super.nextTag();
        //if the filter accepts this event return this event.
        if(fEventFilter.accept(event)){
           return event;
        }
    }
    throw new NoSuchElementException();
}
 
Example #16
Source File: XMLStreamReaderImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Get the target of a processing instruction
 * @return the target or null
 */
public String getPITarget() {
    if( fEventType == XMLEvent.PROCESSING_INSTRUCTION){
        return fScanner.getPITarget();
    }
    else throw new java.lang.IllegalStateException("Current state of the parser is " + getEventTypeString(fEventType) +
    " But Expected state is " + XMLEvent.PROCESSING_INSTRUCTION  ) ;

}
 
Example #17
Source File: XmlFilterReader.java    From knox with Apache License 2.0 5 votes vote down vote up
private void processEvent( XMLEvent event ) throws ParserConfigurationException, XPathExpressionException, IOException, XMLStreamException {
  int type = event.getEventType();
  switch( type ) {
    case XMLStreamConstants.START_DOCUMENT:
      processStartDocument( (StartDocument)event );
      break;
    case XMLStreamConstants.END_DOCUMENT:
      processEndDocument();
      break;
    case XMLStreamConstants.START_ELEMENT:
      if( parser.peek().getEventType() == XMLStreamConstants.END_ELEMENT ) {
        isEmptyElement = true;
      }
      processStartElement( event.asStartElement());
      break;
    case XMLStreamConstants.END_ELEMENT:
      processEndElement( event.asEndElement() );
      isEmptyElement = false;
      break;
    case XMLStreamConstants.CHARACTERS:
    case XMLStreamConstants.CDATA:
    case XMLStreamConstants.SPACE:
      processCharacters( event.asCharacters() );
      break;
    case XMLStreamConstants.COMMENT:
      processComment( (Comment)event );
      break;
    case XMLStreamConstants.DTD:
    case XMLStreamConstants.NAMESPACE:
    case XMLStreamConstants.ATTRIBUTE:
    case XMLStreamConstants.ENTITY_REFERENCE:
    case XMLStreamConstants.ENTITY_DECLARATION:
    case XMLStreamConstants.NOTATION_DECLARATION:
    case XMLStreamConstants.PROCESSING_INSTRUCTION:
    default:
      // Fail if we run into any of these for now.
      throw new IllegalStateException( Integer.toString( type ) );
  }
}
 
Example #18
Source File: ExternalAttachmentsUnmarshaller.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private Map<URI, Policy> unmarshal(final XMLEventReader reader, final StartElement parentElement) throws PolicyException {
    XMLEvent event = null;
    while (reader.hasNext()) {
        try {
            event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.CHARACTERS:
                    processCharacters(event.asCharacters(), parentElement, map);
                    reader.nextEvent();
                    break;

                case XMLStreamConstants.END_ELEMENT:
                    processEndTag(event.asEndElement(), parentElement);
                    reader.nextEvent();
                    return map;

                case XMLStreamConstants.START_ELEMENT:
                    final StartElement element = event.asStartElement();
                    processStartTag(element, parentElement, reader, map);
                    break;

                case XMLStreamConstants.END_DOCUMENT:
                    return map;

                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0087_UNKNOWN_EVENT(event)));
            }
        } catch (XMLStreamException e) {
            final Location location = event == null ? null : event.getLocation();
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0088_FAILED_PARSE(location)), e);
        }
    }
    return map;
}
 
Example #19
Source File: XMLStreamReaderImpl.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
* @return the prefix of the current event, or null if the event does
* not have a prefix. For START_ELEMENT and END_ELEMENT, return
* XMLConstants.DEFAULT_NS_PREFIX when no prefix is available.
*/
public String getPrefix() {
    if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT){
        String prefix = fScanner.getElementQName().prefix;
        return prefix == null ? XMLConstants.DEFAULT_NS_PREFIX : prefix;
    }
    return null ;
}
 
Example #20
Source File: XPathMatchingEventReader.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Override
public XMLEvent nextEvent() throws XMLStreamException {
  final XMLEvent event = super.nextEvent();
  MatchStatus result = eventTracker.isMatch(event);
  if (!result.equals(MatchStatus.UNDETERMINED)) {
    // it is a definitive element match result, one way or the other
    lastElementMatchResult = result;
    if (result.equals(MatchStatus.ELEMENT_MATCH)) {
      lastMatchingEvent = event;
    }
  }
  return event;
}
 
Example #21
Source File: XMLStreamReaderImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** Returns the namespace of the attribute at the provided
 * index
 * @param index the position of the attribute
 * @return the namespace URI (can be null)
 * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
 */
public String getAttributeNamespace(int index) {
    //State should be either START_ELEMENT or ATTRIBUTE
    if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
        return fScanner.getAttributeIterator().getURI(index);
    } else{
        throw new java.lang.IllegalStateException("Current state is not among the states "
                 + getEventTypeString(XMLEvent.START_ELEMENT) + " , "
                 + getEventTypeString(XMLEvent.ATTRIBUTE)
                 + "valid for getAttributeNamespace()") ;
    }

}
 
Example #22
Source File: DefParser.java    From OpenRTS with MIT License 5 votes vote down vote up
private Definition parseEvent(XMLEvent event, Definition def) {
	StartElement se = event.asStartElement();
	String elementName = se.getName().getLocalPart();
	if (elementName.equals("catalog")) {
		return null;
	}

	Iterator<Attribute> attributes = se.getAttributes();

	if (def == null) {
		Attribute id = attributes.next();
		if (id.getName().toString() != ID) {
			throw new RuntimeException("At line " + event.getLocation().getLineNumber() + ", problem with definition '" + elementName
					+ "'. The first attribute of a definition must be called '" + ID + "'.");
		}
		def = new Definition(elementName, id.getValue());
		// LogUtil.logger.info("def cree "+def.type+" - "+def.id);
	} else {
		DefElement de = new DefElement(elementName);
		while (attributes.hasNext()) {
			Attribute a = attributes.next();
			de.addVal(a.getName().toString(), a.getValue());
		}
		def.getElements().add(de);
		// LogUtil.logger.info("    element ajouté : "+de.name+" - "+de.getVal());
	}
	return def;
}
 
Example #23
Source File: XMLStreamReaderImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @return
 */
public int getTextStart() {
    if( fEventType == XMLEvent.CHARACTERS || fEventType == XMLEvent.COMMENT || fEventType == XMLEvent.CDATA || fEventType == XMLEvent.SPACE){
         return  fScanner.getCharacterData().offset;
     } else{
         throw new IllegalStateException("Current state = " + getEventTypeString(fEventType)
         + " is not among the states " + getEventTypeString(XMLEvent.CHARACTERS) + " , "
                 + getEventTypeString(XMLEvent.COMMENT) + " , " + getEventTypeString(XMLEvent.CDATA)
                 + " , " + getEventTypeString(XMLEvent.SPACE) +" valid for getTextStart() " ) ;
     }
}
 
Example #24
Source File: XMLStreamFilterImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private int findNextTag() throws XMLStreamException {
    fStreamAdvancedByHasNext = false;
    while(fStreamReader.hasNext()){
        fCurrentEvent = fStreamReader.nextTag();
        if(fStreamFilter.accept(fStreamReader)){
            fEventAccepted = true;
            return fCurrentEvent;
        }
    }
    if (fCurrentEvent == XMLEvent.END_DOCUMENT)
        return fCurrentEvent;
    else
        return -1;
}
 
Example #25
Source File: StaxEventXMLReader.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a new instance of the {@code StaxEventXmlReader} that reads from the given
 * {@code XMLEventReader}. The supplied event reader must be in {@code XMLStreamConstants.START_DOCUMENT} or
 * {@code XMLStreamConstants.START_ELEMENT} state.
 * @param reader the {@code XMLEventReader} to read from
 * @throws IllegalStateException if the reader is not at the start of a document or element
 */
StaxEventXMLReader(XMLEventReader reader) {
	Assert.notNull(reader, "'reader' must not be null");
	try {
		XMLEvent event = reader.peek();
		if (event != null && !(event.isStartDocument() || event.isStartElement())) {
			throw new IllegalStateException("XMLEventReader not at start of document or element");
		}
	}
	catch (XMLStreamException ex) {
		throw new IllegalStateException("Could not read first element: " + ex.getMessage());
	}
	this.reader = reader;
}
 
Example #26
Source File: XMLEventReaderImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/** Skips any insignificant space events until a START_ELEMENT or
 * END_ELEMENT is reached. If anything other than space characters are
 * encountered, an exception is thrown. This method should
 * be used when processing element-only content because
 * the parser is not able to recognize ignorable whitespace if
 * the DTD is missing or not interpreted.
 * @throws XMLStreamException if anything other than space characters are encountered
 */
public XMLEvent nextTag() throws XMLStreamException {
    //its really a pain if there is peeked event before calling nextTag()
    if(fPeekedEvent != null){
        //check the peeked event first.
        XMLEvent event = fPeekedEvent;
        fPeekedEvent = null ;
        int eventType = event.getEventType();
        //if peeked event is whitespace move to the next event
        //if peeked event is PI or COMMENT move to the next event
        if( (event.isCharacters() && event.asCharacters().isWhiteSpace())
        || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
        || eventType == XMLStreamConstants.COMMENT
        || eventType == XMLStreamConstants.START_DOCUMENT){
            event = nextEvent();
            eventType = event.getEventType();
        }

        //we have to have the while loop because there can be many PI or comment event in sucession
        while((event.isCharacters() && event.asCharacters().isWhiteSpace())
        || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
        || eventType == XMLStreamConstants.COMMENT){

            event = nextEvent();
            eventType = event.getEventType();
        }

        if (eventType != XMLStreamConstants.START_ELEMENT && eventType != XMLStreamConstants.END_ELEMENT) {
            throw new XMLStreamException("expected start or end tag", event.getLocation());
        }
        return event;
    }

    //if there is no peeked event -- delegate the work of getting next event to fXMLReader
    fXMLReader.nextTag();
    return (fLastEvent = fXMLEventAllocator.allocate(fXMLReader));
}
 
Example #27
Source File: ParseWikipedia.java    From WikipediaEntities with GNU Affero General Public License v3.0 5 votes vote down vote up
private void parsePage(XMLEventReader eventReader) throws XMLStreamException, InterruptedException {
  String title = null, text = null, redirect = null;
  boolean skip = false;
  while(eventReader.hasNext()) {
    XMLEvent event = eventReader.nextEvent();
    if(event.isEndElement() && event.asEndElement().getName().getLocalPart() == "page") {
      break;
    }
    if(!skip && event.isStartElement()) {
      StartElement startElement = event.asStartElement();
      // Ignore non-main pages
      if(startElement.getName().getLocalPart() == "ns")
        skip |= !"0".equals(parseTextContents(eventReader));

      if(startElement.getName().getLocalPart() == "title")
        title = parseTextContents(eventReader);

      if(startElement.getName().getLocalPart() == "text")
        text = parseTextContents(eventReader);

      if(startElement.getName().getLocalPart() == "redirect")
        redirect = startElement.getAttributeByName(TITLEQNAME).getValue();
    }
  }
  // Post-process page.
  if(!skip && redirect == null && text == null && title != null)
    System.err.println("No redirect or text, but title: " + title);
  // Ignore non-main pages
  if(skip || title == null || text == null)
    return;
  queue.put(new Article(prefix, title, redirect, text));
  readprog.incrementAndLog();
}
 
Example #28
Source File: XMLParser.java    From cloud-espm-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Check if node has text and return it else return null.
 * 
 * @param event
 * @return text of the node
 */
public String getEvent(XMLEvent event) {
	if (event.isCharacters()) {
		return event.asCharacters().getData();
	} else {
		return null;
	}
}
 
Example #29
Source File: XMLStreamReaderImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public String getLocalName() {
    if(fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.END_ELEMENT){
        //xxx check whats the value of fCurrentElement
        return fScanner.getElementQName().localpart ;
    }
    else if(fEventType == XMLEvent.ENTITY_REFERENCE){
        return fScanner.getEntityName();
    }
    throw new IllegalStateException("Method getLocalName() cannot be called for " +
        getEventTypeString(fEventType) + " event.");
}
 
Example #30
Source File: XMLStreamReaderImpl.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/** Returns the prefix of this attribute at the
 * provided index
 * @param index the position of the attribute
 * @return the prefix of the attribute
 * @throws IllegalStateException if this is not a START_ELEMENT or ATTRIBUTE
 */
public String getAttributePrefix(int index) {
    //State should be either START_ELEMENT or ATTRIBUTE
    if( fEventType == XMLEvent.START_ELEMENT || fEventType == XMLEvent.ATTRIBUTE) {
        return fScanner.getAttributeIterator().getPrefix(index);
    } else{
        throw new java.lang.IllegalStateException("Current state is not among the states "
                 + getEventTypeString(XMLEvent.START_ELEMENT) + " , "
                 + getEventTypeString(XMLEvent.ATTRIBUTE)
                 + "valid for getAttributePrefix()") ;
    }
}