Esempio n. 1
0
  /**
   * tuvToMonoLingualObject converts a given tuv element into a MoonLingualObject
   *
   * @param tuv the tuv Element
   * @return the MonoLingualObject for the given tuv
   */
  public MonoLingualObject tuvToMonoLingualObject(Element tuv) {
    // get the attributes, props and notes
    LinguisticProperties linguisticProperties = createLinguisticProperties(tuv);
    LinguisticProperty tuProp = new LinguisticProperty("tuv", tuv);
    String segment = this.elementContentToString(this.getSeg(tuv));
    String plainTextSegment = MonoLingualObject.simpleComputePlainText(segment);
    MonoLingualObject mono =
        new MonoLingualObject(
            linguisticProperties,
            LinguisticTypes.TMX,
            segment,
            plainTextSegment,
            this.getTuvLang(tuv));

    String uniquidvalue = (String) linguisticProperties.search("unique-id");
    if ((uniquidvalue != null) && !uniquidvalue.equals("")) {
      mono.setStUniqueID(uniquidvalue);
    }

    String stlastAccessTime = (String) linguisticProperties.search("lastAccessTime");
    if ((stlastAccessTime != null) && !stlastAccessTime.equals("")) {
      try {
        long lastAccessTime = Long.parseLong(stlastAccessTime);
        mono.setLastAccessTime(lastAccessTime);
      } catch (NumberFormatException e) {
      }
    }

    mono.addLinguisticProperty(tuProp);
    return mono;
  }
Esempio n. 2
0
  /**
   * saveModifiedLinguisticProperties save the properties back to the tuv of the MonoLingualObject.
   * It is assumed that the tuv Element is stored as a LinguisticProperty
   * (monoLingualObject.getObjectLinguisticProperty("tuv")).
   *
   * @param monoLingualObject the MonoLingualObject which contains the changed or new Properties
   * @return the possible changed tuv Element
   */
  @SuppressWarnings("unchecked")
  public Element saveModifiedLinguisticProperties(MonoLingualObject monoLingualObject) {
    LinguisticProperty lingtuv = monoLingualObject.getObjectLinguisticProperty("tuv");
    Element tuv = (Element) lingtuv.getValue();
    if (tuv == null) return tuv;

    LinguisticProperties linguisticProperties = monoLingualObject.getLinguisticProperties();
    if (linguisticProperties == null) return tuv;
    Set<String> enumprop = linguisticProperties.keySet();
    Iterator<String> it = enumprop.iterator();
    while (it.hasNext()) {
      String key = (String) it.next();
      Object value = (Object) linguisticProperties.get(key);
      Object data = null;
      TmxProp tmxProp = null;
      LinguisticProperty ling = null;
      if (value.getClass().getName().equals("java.util.Vector")) {
        for (int i = 0; i < ((Vector<LinguisticProperty>) value).size(); i++) {
          ling = ((Vector<LinguisticProperty>) value).get(i);
          if (ling.getPropStatus().equals(LinguisticProperty.PropStatus.NEW)) continue;
          Object lingValue = ling.getValue();
          String classname = lingValue.getClass().getName();
          if (classname.equals("de.folt.models.documentmodel.tmx.TmxProp")) {
            tmxProp = (TmxProp) lingValue;
            data = ling.getData();
            handleTmxProp(tmxProp, ling, tuv, data);
          }
        }
      } else {
        ling = (LinguisticProperty) linguisticProperties.get(key);
        Object lingValue = ling.getValue();
        String classname = lingValue.getClass().getName();
        if (classname.equals("de.folt.models.documentmodel.tmx.TmxProp")) {
          if (ling.getPropStatus().equals(LinguisticProperty.PropStatus.OLD)) continue;
          tmxProp = (TmxProp) lingValue;
          data = ling.getData();
          handleTmxProp(tmxProp, ling, tuv, data);
        }
      }
    }

    return tuv;
  }