Пример #1
0
    public Map<String, String> run(Map<String, String> params, IProgressMonitor monitor)
        throws ConverterException {
      monitor = Progress.getMonitor(monitor);
      IProgressMonitor subMonitor = null;
      // 把转换过程分为两大部分共 10 个任务,其中加载 xliff 文件占 4,替换过程占 6。
      monitor.beginTask("Converting...", 10);
      Map<String, String> result = new HashMap<String, String>();
      String sklFile = params.get(Converter.ATTR_SKELETON_FILE);
      String xliffFile = params.get(Converter.ATTR_XLIFF_FILE);
      encoding = params.get(Converter.ATTR_SOURCE_ENCODING);
      outputFile = params.get(Converter.ATTR_TARGET_FILE);

      try {
        // 先将骨架文件的内容拷贝到目标文件,再解析目标文件
        copyFile(sklFile, outputFile);
        parseOutputFile(outputFile, xliffFile);
        parseXlfFile(xliffFile);
        if (monitor.isCanceled()) {
          throw new OperationCanceledException();
        }
        monitor.worked(1);

        subMonitor = new SubProgressMonitor(monitor, 9);
        ananysisXlfTU(subMonitor);
        subMonitor.done();
        // 生成批注节点
        createComments();

        outputXM.output(outputFile);
      } catch (Exception e) {
        e.printStackTrace();
        String errorTip = "XLIFF 转换成 trados 2009 双语文件失败!" + "\n" + e.getMessage();
        ConverterUtils.throwConverterException(Activator.PLUGIN_ID, errorTip, e);
      } finally {
        if (subMonitor != null) {
          subMonitor.done();
        }
        monitor.done();
      }
      return result;
    }
Пример #2
0
    /**
     * Run.
     *
     * @param args the args
     * @param monitor the monitor
     * @return the map< string, string>
     * @throws ConverterException the converter exception
     */
    public Map<String, String> run(Map<String, String> args, IProgressMonitor monitor)
        throws ConverterException {
      monitor = Progress.getMonitor(monitor);
      ReverseConversionInfoLogRecord infoLogger =
          ConverterUtils.getReverseConversionInfoLogRecord();
      infoLogger.startConversion();
      Map<String, String> result = new HashMap<String, String>();
      String backfile = args.get(Converter.ATTR_TARGET_FILE);
      String middleBackfile = MSOffice2Xliff.getOutputFilePath(backfile);
      // 先转换成ODT,ODS,ODP等文件,然后在转换成DOC,XLS,PPT
      args.put(Converter.ATTR_TARGET_FILE, middleBackfile);
      try {
        // 把转换过程分为三部分共 10 个任,其中委派其它转换的操作占 4,检测 Open Office Service 是否可用占 2,调用 Open Office Service
        // 进行的操作占 4。
        monitor.beginTask(Messages.getString("msoffice2003.Xliff2MSOffice.task1"), 10);
        long startTime = 0;
        if (isInfoEnabled) {
          startTime = System.currentTimeMillis();
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger1"), startTime);
        }
        result = dependantConverter.convert(args, Progress.getSubMonitor(monitor, 4));
        long endTime = System.currentTimeMillis();
        if (isInfoEnabled) {
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger2"), endTime);
          LOGGER.info(
              Messages.getString("msoffice2003.Xliff2MSOffice.logger3"), endTime - startTime);
        }

        // 是否取消操作
        if (monitor.isCanceled()) {
          throw new OperationCanceledException(Messages.getString("msoffice2003.cancel"));
        }
        monitor.subTask(Messages.getString("msoffice2003.Xliff2MSOffice.task2"));
        if (isInfoEnabled) {
          startTime = System.currentTimeMillis();
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger4"), startTime);
        }
        File backup = new File(backfile);
        File middleFile = new File(middleBackfile);
        boolean openbyuser = DetectOORunning.isRunning(); // 判断是否手动启动
        boolean configration = false;
        Hashtable<String, String> ooParams = new Hashtable<String, String>();
        ooParams.put("ooPath", args.get("ooPath"));
        ooParams.put("port", args.get("ooPort"));
        StartupOO startupoo = new StartupOO(ooParams);
        configration = startupoo.detectConfOO();
        if (!configration) {
          ConverterUtils.throwConverterException(
              Activator.PLUGIN_ID, Messages.getString("msoffice2003.Xliff2MSOffice.msg1"));
        }
        if (isInfoEnabled) {
          endTime = System.currentTimeMillis();
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger5"), endTime);
          LOGGER.info(
              Messages.getString("msoffice2003.Xliff2MSOffice.logger6"), endTime - startTime);
        }
        monitor.worked(2);

        // 是否取消操作
        monitor.subTask(Messages.getString("msoffice2003.Xliff2MSOffice.task3"));
        if (isInfoEnabled) {
          startTime = System.currentTimeMillis();
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger7"), startTime);
        }
        MS2OOConverter ms2ooConverter = new MS2OOConverter(ooParams);
        try {
          ms2ooConverter.startconvert(middleFile, backup, openbyuser);
        } catch (Exception e) {
          if (Converter.DEBUG_MODE) {
            e.printStackTrace();
          }
          try {
            openbyuser = false;
            ms2ooConverter.startconvert(middleFile, backup, openbyuser);
          } catch (Exception e1) {
            if (Converter.DEBUG_MODE) {
              e1.printStackTrace();
            }
            if (!openbyuser) {
              CloseOOconnection.closeService(ms2ooConverter.getPort());
            }
            ConverterUtils.throwConverterException(
                Activator.PLUGIN_ID, Messages.getString("msoffice2003.Xliff2MSOffice.msg2"), e);
          }
        }
        middleFile.delete();
        if (isInfoEnabled) {
          endTime = System.currentTimeMillis();
          LOGGER.info(Messages.getString("msoffice2003.Xliff2MSOffice.logger8"), endTime);
          LOGGER.info(
              Messages.getString("msoffice2003.Xliff2MSOffice.logger9"), endTime - startTime);
        }
        monitor.worked(4);
      } catch (OperationCanceledException e) {
        throw e;
      } catch (ConverterException e) {
        throw e;
      } catch (Exception e) {
        ConverterUtils.throwConverterException(
            Activator.PLUGIN_ID, Messages.getString("msoffice2003.Xliff2MSOffice.msg2"), e);
      } finally {
        monitor.done();
      }
      result.put(Converter.ATTR_TARGET_FILE, backfile);
      infoLogger.endConversion();
      return result;
    }