protected void parseHeader(StartElement element, final Language sourceLanguage) { isParagraphSegtype = SEG_PARAGRAPH.equals(getAttributeValue(element, "segtype")); isOmegaT = CT_OMEGAT.equals(getAttributeValue(element, "creationtool")); // log some details Log.logRB("TMXR_INFO_CREATION_TOOL", new Object[] {getAttributeValue(element, "creationtool")}); Log.logRB( "TMXR_INFO_CREATION_TOOL_VERSION", new Object[] {getAttributeValue(element, "creationtoolversion")}); Log.logRB("TMXR_INFO_SEG_TYPE", new Object[] {getAttributeValue(element, "segtype")}); Log.logRB("TMXR_INFO_SOURCE_LANG", new Object[] {getAttributeValue(element, "srclang")}); // give a warning if the TMX source language is // different from the project source language String tmxSourceLanguage = getAttributeValue(element, "srclang"); if (!tmxSourceLanguage.equalsIgnoreCase(sourceLanguage.getLanguage())) { Log.logWarningRB( "TMXR_WARNING_INCORRECT_SOURCE_LANG", new Object[] {tmxSourceLanguage, sourceLanguage}); } // give a warning that TMX file will be upgraded to sentence segmentation if (isSegmentingEnabled && isParagraphSegtype) { Log.logWarningRB("TMXR_WARNING_UPGRADE_SENTSEG"); } }
/** Read TMX file. */ public void readTMX( File file, final Language sourceLanguage, final Language targetLanguage, boolean isSegmentingEnabled, final boolean forceOmegaTMX, final boolean extTmxLevel2, final boolean useSlash, final LoadCallback callback) throws Exception { this.extTmxLevel2 = extTmxLevel2; this.useSlash = useSlash; this.isSegmentingEnabled = isSegmentingEnabled; // log the parsing attempt Log.logRB("TMXR_INFO_READING_FILE", new Object[] {file.getAbsolutePath()}); boolean allFound = true; InputStream in; if (file.getName().endsWith(".gz")) { in = new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))); } else { in = new BufferedInputStream(new FileInputStream(file)); } xml = factory.createXMLEventReader(in); try { while (xml.hasNext()) { XMLEvent e = xml.nextEvent(); switch (e.getEventType()) { case XMLEvent.START_ELEMENT: StartElement eStart = (StartElement) e; if ("tu".equals(eStart.getName().getLocalPart())) { parseTu(eStart); ParsedTuv origTuv = getTuvByLang(sourceLanguage); ParsedTuv targetTuv = getTuvByLang(targetLanguage); allFound &= callback.onEntry(currentTu, origTuv, targetTuv, isParagraphSegtype); } else if ("header".equals(eStart.getName().getLocalPart())) { parseHeader(eStart, sourceLanguage); } break; } } } finally { xml.close(); in.close(); } if (!allFound) { Log.logWarningRB("TMXR_WARNING_SOURCE_NOT_FOUND"); warningsCount++; } Log.logRB("TMXR_INFO_READING_COMPLETE"); Log.log(""); }