while (reader.hasNext()
&& reader.next() != XMLStreamConstants.START_ELEMENT) {
}
if (!reader.hasNext())
throw new TMXParseException("No root element");
if (!reader.getName().equals(tmx))
throw new TMXParseException("Wrong root element: expected tmx");
// At this point, event = START_ELEMENT and name = tmx
while (reader.hasNext()) {
int eventType = reader.next();
if (eventType == XMLStreamConstants.START_ELEMENT) {
if (handledTUs > 0 && handledTUs % BATCH_SIZE == 0) {
commitBatch(handledTUs);
}
QName elemName = reader.getName();
if (elemName.equals(tu)) {
Element tuElem = ElementBuilder.buildElement(reader);
transMemoryAdapter
.processTransUnit(transMemory, tuElem);
handledTUs++;
} else if (elemName.equals(header)) {
Element headerElem =
ElementBuilder.buildElement(reader);
transMemoryAdapter.processHeader(transMemory,
headerElem);
}
}
}
commitBatch(handledTUs); // A new transaction is needed for Seam to
// commit it
} catch (EntityExistsException e) {
String msg =
"Possible duplicate TU (duplicate tuid or duplicate"
+ "src content without tuid)";
throw new TMXParseException(msg, e);
} catch (XMLStreamException e) {
throw new TMXParseException(e);
} finally {
log.info("parsing stopped for: {}, TU count={}",
transMemory.getSlug(), handledTUs);
}
}