private void buildEndDocument () { Ending ed = new Ending(docId); events.add(new Event(EventType.END_DOCUMENT, ed)); done = true; }
public Event next () { try { // Check for cancellation first if ( canceled ) { queue.clear(); queue.add(new Event(EventType.CANCELED)); hasNext = false; } // Parse next if nothing in the queue if ( queue.isEmpty() ) { if ( !read() ) { Ending ending = new Ending(otherId.createId()); ending.setSkeleton(skel); queue.add(new Event(EventType.END_DOCUMENT, ending)); } } // Return the head of the queue if ( queue.peek().getEventType() == EventType.END_DOCUMENT ) { hasNext = false; } return queue.poll(); } catch ( XMLStreamException e ) { throw new OkapiIOException(e); } }
@Override public String processEndDocument (Ending resource) { XMLSkeleton skel = (XMLSkeleton)resource.getSkeleton(); if ( skel == null ) return ""; return skel.toString(); }
/** * Add the END_SUBDOCUMENT {@link Event} to the event queue. */ public void endSubDocument() { if (!subFilter) { Ending endDocument = new Ending(subDocumentId.createId(IdGenerator.END_SUBDOCUMENT)); Event event = new Event(EventType.END_SUBDOCUMENT, endDocument); filterEvents.add(event); LOGGER.debug("End Sub-Document for " + endDocument.getId()); } }
@Override protected Event handleEndBatch (Event event) { Ending res = event.getEnding(); if (res == null) { res = new Ending(""); event.setResource(res); } MetricsAnnotation sma = res.getAnnotation(MetricsAnnotation.class); if (sma == null) { sma = new MetricsAnnotation(); res.setAnnotation(sma); } Metrics m = sma.getMetrics(); m.setMetric(GMX.TotalWordCount, srcBatchWordCount); return super.handleEndBatch(event); }
@Override protected Event handleEndBatchItem (Event event) { Ending res = event.getEnding(); if (res == null) { res = new Ending(""); event.setResource(res); } MetricsAnnotation sma = res.getAnnotation(MetricsAnnotation.class); if ( sma == null ) { sma = new MetricsAnnotation(); res.setAnnotation(sma); } Metrics m = sma.getMetrics(); m.setMetric(GMX.TotalWordCount, srcBatchItemWordCount); srcBatchWordCount += srcBatchItemWordCount; return super.handleEndBatchItem(event); }
/** * create a END_DOCUMENT {@link Event} * @return the newly created {@link Ending} event. */ protected Event createEndFilterEvent() { Ending endDocument = new Ending(documentId.getLastId()); LOGGER.debug("End Document for " + endDocument.getId()); //$NON-NLS-1$ return new Event(EventType.END_DOCUMENT, endDocument); }
private void closeGroups () { if ( groupStack.size() > 0 ) { Ending ending = new Ending(otherId.createId()); queue.add(new Event(EventType.END_GROUP, ending)); groupStack.pop(); } }
public Event next() { try { // Check for cancellation first if (canceled) { queue.clear(); queue.add(new Event(EventType.CANCELED)); hasNext = false; } // Parse next if nothing in the queue if (queue.isEmpty()) { if (!read()) { Ending ending = new Ending(ts.otherId.createId()); ending.setSkeleton(skel); queue.add(new Event(EventType.END_DOCUMENT, ending)); } } // Return the head of the queue if (queue.peek().getEventType() == EventType.END_DOCUMENT) { hasNext = false; } return queue.poll(); } catch (XMLStreamException e) { throw new OkapiIOException(e); } }
@Override public String processEndGroup (Ending resource) { XMLSkeleton skel = (XMLSkeleton)resource.getSkeleton(); if ( skel == null ) return ""; return skel.toString(); }
public void parseNext () { ITextUnit textUnit = new TextUnit(String.valueOf(++tuId)); if ( !getSegment(textUnit) ) { // Send the end-document event queue.add(new Event(EventType.END_DOCUMENT, new Ending(String.valueOf("ed")))); } else { queue.add(new Event(EventType.TEXT_UNIT, textUnit)); } }
Ending ending = new Ending(String.valueOf(++otherId)); ending.setSkeleton(new GenericSkeleton( inputText.substring(current).replace("\n", lineBreak))); queue.add(new Event(EventType.END_DOCUMENT, ending));
@Override public String processEndSubDocument (Ending resource) { XMLSkeleton skel = (XMLSkeleton)resource.getSkeleton(); if ( skel == null ) return ""; return skel.toString(); }
@Override public Event next () { if ( queue == null ) return null; if ( queue.size() > 0 ) { return queue.poll(); } // Get the next event read(); // End process if needed if ( queue.size() == 0 ) { queue = null; // No more Ending ending = new Ending("ed"); return new Event(EventType.END_DOCUMENT, ending); } // Else, return the next event that was read return queue.poll(); }
Ending ending = new Ending("ed"); ending.setSkeleton(skel); parseState = 0; return new Event(EventType.END_DOCUMENT, ending);
protected String _processEndGroup(Ending resource) { if ( storageStack.size() > 0 ) { storageStack.peek().add(resource); storageStack.pop(); return ""; } return getString((GenericSkeleton)resource.getSkeleton(), EncoderContext.SKELETON); }
private Event completeDocument() { close(); Ending ending = new Ending("ed"); return new Event(EventType.END_DOCUMENT, ending); }
Ending ending = new Ending(String.valueOf(++otherId)); ending.setSkeleton(new GenericSkeleton(content.substring(last).replace("\n", lineBreak))); queue.add(new Event(EventType.END_SUBDOCUMENT, ending)); return true;
@Override public String processEndSubDocument (Ending resource) { if (isSubfilterActive()) { return sfWriter.processEndSubDocument(resource); } if ( storageStack.size() > 0 ) { storageStack.peek().add(resource); return ""; } return getString((GenericSkeleton)resource.getSkeleton(), EncoderContext.SKELETON); }
private void handlePart() throws XMLStreamException { while(xmlEventReader.hasNext()) { XMLEvent e = xmlEventReader.nextEvent(); if (!e.isStartElement() || !e.asStartElement().getName().equals(RELATIONSHIP_TAG_NAME)) { filterEvents.add(new Event(EventType.DOCUMENT_PART, createDocumentPart(e))); continue; } Attribute type = e.asStartElement().getAttributeByName(RELATIONSHIP_TYPE); Attribute targetMode = e.asStartElement().getAttributeByName(RELATIONSHIP_TARGET_MODE); Attribute target = e.asStartElement().getAttributeByName(RELATIONSHIP_TARGET); if (null == type || targetMode == null || target == null || !HYPERLINK_TYPE.equals(type.getValue()) || !TARGET_MODE_EXTERNAL.equals(targetMode.getValue()) || target.getValue().isEmpty()) { filterEvents.add(new Event(EventType.DOCUMENT_PART, createDocumentPart(e))); continue; } TextUnit textUnit = createTextUnit(e); filterEvents.add(new Event(EventType.TEXT_UNIT, textUnit)); } filterEvents.add(new Event(EventType.END_DOCUMENT, new Ending(subDocumentId))); filterEventIterator = filterEvents.iterator(); }