public boolean editGroup(LanguageGroup group, Language language) {
   Element languageElement = this.getLanguageElement(language);
   Element element = factory.getGroupElement(languageElement, group);
   if (element != null) {
     factory.groupToElement(group, element);
     writeDocument();
     return true;
   }
   return false;
 }
  public List<Language> readLangauges() {
    List<Language> list = new ArrayList<Language>();
    Element element;
    Language lang;

    NodeList languages = factory.getListLanguages(this.getLanguagesElement());
    for (int i = 0; i < languages.getLength(); i++) {
      element = (Element) languages.item(i);
      lang = factory.elementToLanguage(element);
      list.add(lang);
    }
    return list;
  }
 private Element getLanguageElement(Language lang) {
   Element languageElement = factory.getLanguageElement(this.getLanguagesElement(), lang);
   if (languageElement == null) {
     languageElement = this.createLanguage(lang);
   }
   return languageElement;
 }
 /**
  * Edits/alters a template in a xml file.
  *
  * @param template template that should be edited
  * @return true if the template was succesfuly edited
  */
 public boolean editTemplate(ConstraintTemplate template, LanguageGroup parent) {
   /* Element languageElement = this.getLanguageElement(template.getLanguage());
   Element element = factory.getTemplateElement(template, languageElement);
   if (element != null) {
     factory.templateToElement(template, element);
     writeDocument();
     return true;
   }
   return false;*/
   Element parentElement = getParentElement(parent, template.getLanguage());
   Element element = factory.getTemplateElement(template, parentElement);
   if (element != null) {
     factory.templateToElement(template, element);
     writeDocument();
     return true;
   }
   return false;
 }
 public void deleteGroup(LanguageGroup group, LanguageGroup parent, Language language) {
   Element languageElement = this.getLanguageElement(language);
   Element parentElement = getParentElement(parent, language);
   Element groupElement = factory.getGroupElement(languageElement, group);
   if (parentElement != null && groupElement != null) {
     parentElement.removeChild(groupElement);
     writeDocument();
   }
 }
  private Element getParentElement(LanguageGroup parent, Language language) {
    Element languageElement = this.getLanguageElement(language);
    Element parentElement = null;
    if (parent == language) {
      parentElement = languageElement;
    } else {
      parentElement = factory.getGroupElement(languageElement, parent);
    }

    return parentElement;
  }
  /**
   * Deletes a template from a xml file.
   *
   * @param template template that should be deleted
   * @return true if the template was succesfuly deleted
   */
  public boolean deleteTemplate(ConstraintTemplate template, LanguageGroup parent) {
    Element parentElement = getParentElement(parent, template.getLanguage());

    Element element = factory.getTemplateElement(template, parentElement);
    if (element != null) {
      this.deleteElement(element, parentElement);
      // factory.deleteElement(element, parentElement);
      writeDocument();
      return true;
    }
    return false;
  }