Exemplo n.º 1
0
  @Override
  public void saveAllTasks(Collection<Task> tasks) {

    try {
      doc = new Document(new Element("tasks"), new DocType("tasks", "XmlDTD.dtd"));

      Iterator it = tasks.iterator();
      while (it.hasNext()) {
        Task task = (Task) it.next();
        doc.getRootElement()
            .addContent(
                new Element("task")
                    .setAttribute("id", task.getId())
                    .addContent(new Element("name").addContent(task.getName()))
                    .addContent(new Element("description").addContent(task.getDescription()))
                    .addContent(new Element("date").addContent(sdf.format(task.getDate()))));
      }

      XMLOutputter outPutter =
          new XMLOutputter(Format.getRawFormat().setIndent(" ").setLineSeparator("\n"));

      outPutter.output(doc, new FileWriter(config.getFileName()));

    } catch (IOException ex) {
      log.error(null, ex);
      throw new WritingFileException("Didn't write xml", ex.getCause());
    }
  }
Exemplo n.º 2
0
 @Override
 public Object clone() {
   Task t = null;
   try {
     t = new Task((Date) this.date.clone());
     if (this.name != null) {
       t.name = this.name;
     }
     if (this.description != null) {
       t.description = this.description;
     }
     if (this.contacts != null) {
       t.contacts = this.contacts;
     }
   } catch (Exception e) {
     log.error("Something wrong in cloning.", e);
   }
   return t;
 }