Exemplo 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;
  }
Exemplo n.º 2
0
  /**
   * tuToMultiLingualObject converts a given tu element into a MultiLingualObject
   *
   * @param tu the tu Element
   * @return the MultiLingualObject for the given tu
   */
  public MultiLingualObject tuToMultiLingualObject(Element tu) {
    LinguisticProperties linguisticProperties = createLinguisticProperties(tu);

    MultiLingualObject multi = new MultiLingualObject(linguisticProperties, LinguisticTypes.TMX);
    LinguisticProperty tuProp = new LinguisticProperty("tu", tu);
    multi.addLinguisticProperty(tuProp);

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

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

    List<Element> tuvs = this.getTuvList(tu);
    for (int i = 0; i < tuvs.size(); i++) {
      MonoLingualObject mono = tuvToMonoLingualObject(tuvs.get(i));
      if (mono != null) multi.addMonoLingualObject(mono);
    }
    return multi;
  }
Exemplo n.º 3
0
  /**
   * saveModifiedLinguisticProperties
   *
   * @param multiLingualObject
   */
  @SuppressWarnings("unchecked")
  public Element saveModifiedLinguisticProperties(MultiLingualObject multiLingualObject) {
    LinguisticProperty lingtu = multiLingualObject.getObjectLinguisticProperty("tu");
    Element tu = (Element) lingtu.getValue();
    if (tu == null) return tu;

    LinguisticProperties linguisticProperties = multiLingualObject.getLinguisticProperties();
    if (linguisticProperties == null) return tu;
    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, tu, 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, tu, data);
        }
      }
    }

    return tu;
  }
Exemplo n.º 4
0
  /**
   * create LinguisticProperties Method returns the attributes of the element as
   * LinguisticProperties
   *
   * @param element the element to retrieve the attributes from
   * @return the LinguisticProperties for the element
   */
  @SuppressWarnings("unchecked")
  public LinguisticProperties createLinguisticProperties(Element element) {
    LinguisticProperties linguisticProperties = new LinguisticProperties();

    List<Attribute> attributes = element.getAttributes();
    for (int i = 0; i < attributes.size(); i++) {
      Attribute att = attributes.get(i);
      if (att.getName().equals("lang")) // ignore language
      continue;
      TmxProp tmxProp =
          new TmxProp(att.getValue(), "", "", TmxProp.PropType.CORE, att.getName(), idVal++);
      LinguisticProperty lingProp = new LinguisticProperty(tmxProp.toString(), tmxProp);
      lingProp.setData(att);
      lingProp.setPropStatus(LinguisticProperty.PropStatus.NEW);
      linguisticProperties.add(lingProp);
    }

    List<Element> props = element.getChildren("prop");
    for (int i = 0; i < props.size(); i++) {
      TmxProp tmxProp = new TmxProp(props.get(i), idVal++);
      LinguisticProperty lingProp = new LinguisticProperty(tmxProp.toString(), tmxProp);
      lingProp.setData(props.get(i));
      lingProp.setPropStatus(LinguisticProperty.PropStatus.NEW);
      linguisticProperties.add(lingProp);
    }

    List<Element> notes = element.getChildren("note");
    for (int i = 0; i < notes.size(); i++) {
      TmxProp tmxProp = new TmxProp(notes.get(i), idVal++);
      LinguisticProperty lingProp = new LinguisticProperty(tmxProp.toString(), tmxProp);
      lingProp.setData(notes.get(i));
      lingProp.setPropStatus(LinguisticProperty.PropStatus.NEW);
      linguisticProperties.add(lingProp);
    }

    return linguisticProperties;
  }