Search in sources :

Example 1 with AbstractWriter

use of net.heartsome.cat.tmx.converter.AbstractWriter in project translationstudio8 by heartsome.

the class Xlsx2Tmx method doCovnerter.

public void doCovnerter(File2TmxConvertBean file2TmxBean, IProgressMonitor monitor) throws Exception {
    Xlsx2TmxHelper tmxConver = new Xlsx2TmxHelper();
    attString = Model2String.getCustomArributeXML(file2TmxBean.customeAttr);
    AbstractWriter writer = getWriter(file2TmxBean);
    if (writer instanceof TmxWriter) {
        TmxWriter tmxWriter = (TmxWriter) writer;
        tmxWriter.setAttibuteString(attString);
    }
    // writer.writeHeader(file2TmxBean.srcLangCode);
    try {
        tmxConver.parseXlsxFileAndWriteTmxBody(file2TmxBean.sourceFilePath, writer, monitor);
    } catch (ParserConfigurationException e) {
        LOGGER.error("", e);
        throw new Exception(Messages.getString("converter.xlsx2tmx.parseExcle.error"));
    } catch (SAXException e) {
        LOGGER.error("", e);
        if ("LANG-CODE-ERORR".equals(e.getMessage())) {
            throw new Exception(Messages.getString("converter.common.vaild.langcode.error"));
        } else if ("DIFF--SRC-LANG-CODE".equals(e.getMessage())) {
            throw new Exception(Messages.getString("converter.common.appendtmx.diffsrcLang.error"));
        } else if ("EMPTY-LANG-CODE".equals(e.getMessage())) {
            throw new Exception(Messages.getString("converter.common.vaild.langcode.error"));
        } else if ("DUPLICATE-LANG-CODE-ERORR".equals(e.getMessage())) {
            throw new Exception(Messages.getString("converter.common.vaild.duplicatelangcode.error"));
        }
    } catch (IOException e) {
        LOGGER.error("", e);
        throw new Exception(Messages.getString("converter.xlsx2tmx.writeTmx.error"));
    } catch (OpenXML4JException e) {
        LOGGER.error("", e);
        throw new Exception(Messages.getString("converter.xlsx2tmx.parseExcle.error"));
    } finally {
        writer.writeEnd();
        writer.closeOutStream();
        monitor.done();
    }
}
Also used : OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) AbstractWriter(net.heartsome.cat.tmx.converter.AbstractWriter) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) OpenXML4JException(org.apache.poi.openxml4j.exceptions.OpenXML4JException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) TmxWriter(net.heartsome.cat.tmx.converter.TmxWriter) SAXException(org.xml.sax.SAXException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 AbstractWriter (net.heartsome.cat.tmx.converter.AbstractWriter)1 TmxWriter (net.heartsome.cat.tmx.converter.TmxWriter)1 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)1 SAXException (org.xml.sax.SAXException)1