Esempio n. 1
0
 private void readTuPropElement(TmxTU tu) throws VTDException {
   VTDNav vn = vu.getVTDNav();
   vn.push();
   AutoPilot ap = new AutoPilot(vn);
   ap.selectXPath("./prop");
   while (ap.evalXPath() != -1) {
     String content = vu.getElementContent();
     if (content == null) {
       continue;
     }
     int inx = vn.getAttrVal("type");
     String typeValue = inx != -1 ? vn.toString(inx) : null;
     if (typeValue == null) {
       continue;
     }
     if (typeValue.equals(TmxContexts.PRE_CONTEXT_NAME)) {
       tu.appendContext(TmxContexts.PRE_CONTEXT_NAME, content.trim());
     } else if (typeValue.equals(TmxContexts.NEXT_CONTEXT_NAME)) {
       tu.appendContext(TmxContexts.NEXT_CONTEXT_NAME, content.trim());
     } else if (typeValue.equals("x-Context")) {
       // Trados TMX file
       String[] contexts = content.split(",");
       if (contexts.length == 2) {
         tu.appendContext(TmxContexts.PRE_CONTEXT_NAME, contexts[0].trim());
         tu.appendContext(TmxContexts.NEXT_CONTEXT_NAME, contexts[1].trim());
       }
     } else {
       TmxProp p = new TmxProp(typeValue, content);
       tu.appendProp(p);
     }
   }
   vn.pop();
 }
Esempio n. 2
0
  private void readTuElementAttribute(TmxTU tu) throws VTDException {
    VTDNav vn = vu.getVTDNav();

    vn.push();
    AutoPilot apAttributes = new AutoPilot(vu.getVTDNav());
    apAttributes.selectXPath("@*");
    int inx = -1;
    while ((inx = apAttributes.evalXPath()) != -1) {
      String name = vn.toString(inx);
      inx = vn.getAttrVal(name);
      String value = inx != -1 ? vn.toString(inx) : "";
      // tuid, o-encoding, datatype, usagecount, lastusagedate, creationtool, creationtoolversion,
      // creationdate,
      // creationid, changedate, segtype, changeid, o-tmf, srclang.
      if (name.equals("tuid")) {
        tu.setTuId(value);
      } else if (name.equals("creationtool")) {
        tu.setCreationTool(value);
      } else if (name.equals("creationtoolversion")) {
        tu.setCreationToolVersion(value);
      } else if (name.equals("creationdate")) {
        tu.setCreationDate(value);
      } else if (name.equals("creationid")) {
        tu.setCreationUser(value);
      } else if (name.equals("changedate")) {
        tu.setChangeDate(value);
      } else if (name.equals("changeid")) {
        tu.setChangeUser(value);
      } else {
        tu.appendAttribute(name, value);
      }
    }
    vn.pop();
  }
Esempio n. 3
0
  private void readTuTuvElement(TmxTU tu) throws VTDException {
    VTDNav vn = vu.getVTDNav();
    vn.push();
    AutoPilot ap = new AutoPilot(vn);
    ap.selectXPath("./tuv");
    // TUV 节点下的Note,Prop节点暂时不处理,所以此处暂时不解析
    while (ap.evalXPath() != -1) {
      int inx = vn.getAttrVal("xml:lang");
      inx = inx == -1 ? vn.getAttrVal("lang") : inx;
      String lang = inx != -1 ? vn.toString(inx) : null;
      if (lang == null) {
        continue;
      }

      vn.push();
      if (vu.pilot("./seg") != -1) {
        String fullText = vu.getElementContent().trim();
        String pureText = DocUtils.getTmxTbxPureText(vu).trim();
        if (fullText == null || pureText == null || fullText.equals("") || pureText.equals("")) {
          // fix Bug #2928 by Jason SQLite--导入TMX异常, 导入程序正常退出,但是未完全导入所有内容,此处在continue时应该先调用vn.pop()
          vn.pop();
          continue;
        }
        TmxSegement segment = new TmxSegement();
        segment.setLangCode(Utils.convertLangCode(lang));
        if (tmxFilter == null) segment.setFullText(fullText);
        else {
          String text = tmxFilter.clearString(fullText);
          segment.setFullText(text);
        }
        segment.setPureText(pureText);
        if (lang.equalsIgnoreCase(header.getSrclang())) {
          tu.setSource(segment);
        } else {
          tu.appendSegement(segment);
        }
      }
      vn.pop();
    }
    vn.pop();
  }
Esempio n. 4
0
  private void readTuNoteElement(TmxTU tu) throws VTDException {
    VTDNav vn = vu.getVTDNav();

    vn.push();
    AutoPilot ap = new AutoPilot(vn);
    ap.selectXPath("./note");
    while (ap.evalXPath() != -1) {
      String fragment = vu.getElementFragment();
      TmxNote note = new TmxNote();
      note.setContent(fragment);
      int inx = vn.getAttrVal("xml:lang");
      String value = inx != -1 ? vn.toString(inx) : null;
      if (value != null) {
        note.setXmlLang(value);
      }
      inx = vn.getAttrVal("o-encoding");
      value = inx != -1 ? vn.toString(inx) : null;
      if (value != null) {
        note.setXmlLang(value);
      }
      tu.appendNote(note);
    }
    vn.pop();
  }