Ejemplo n.º 1
0
  private static void scrieInFisierXML(File fisier, LinkedHashMap<String, Produs> toateProdusele) {
    Document doc = new Document();
    Element theRoot = new Element("toate_produsele");

    doc.setRootElement(theRoot);

    int size = toateProdusele.size();
    theRoot.setAttribute("nr_produse", Integer.toString(size));

    Set<String> Keys = toateProdusele.keySet();

    for (String i : Keys) {
      Element produs = new Element("produs");

      Element produs_id = new Element("produs_id");
      produs_id.addContent(new Text(Integer.toString(toateProdusele.get(i).getId())));

      Element nume = new Element("nume_produs");
      nume.addContent(new Text(toateProdusele.get(i).getNume()));

      Element pret = new Element("pret_produs");
      pret.addContent(new Text(Double.toString(toateProdusele.get(i).getPret())));

      Element cantiate = new Element("cantitate_produs");
      cantiate.addContent(new Text(Integer.toString(toateProdusele.get(i).getnrBucatiInStoc())));

      Element id_categorie = new Element("categorie_id");
      id_categorie.addContent(new Text(Integer.toString(toateProdusele.get(i).getIdCategorie())));

      Element link_img = new Element("link_img");
      link_img.addContent(new Text(toateProdusele.get(i).getLinkImg()));

      produs.addContent(produs_id);
      produs.addContent(nume);
      produs.addContent(pret);
      produs.addContent(cantiate);
      produs.addContent(id_categorie);
      produs.addContent(link_img);

      theRoot.addContent(produs);
      System.out.println("S-a adaugat elem \t" + i);
    }

    XMLOutputter xmlOutput = new XMLOutputter(Format.getPrettyFormat());

    try {
      xmlOutput.output(doc, new FileOutputStream(fisier));
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  private static void saveChannel(Channel channel, OutputStream out) throws Exception {
    Element root = new Element("channel");
    root.setAttribute("version", "1.0");
    root.setAttribute("type", channel.getClass().getName());

    Element elSettings = new Element("settings");
    SimpleBeanToXML.objectToXml(elSettings, channel);
    root.addContent(elSettings);
    Document doc = new Document();
    doc.setRootElement(root);
    XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
    xout.output(doc, out);
  }
Ejemplo n.º 3
0
  public void newBatchProcess(String id, LocalDateTime requestDateTime, List<String> records) {
    Element recordsElement = new Element(RECORDS);
    addErrorsToDocument(records, recordsElement);

    Element requestDateTimeElement =
        new Element(REQUEST_DATE_TIME).setText(requestDateTime.toString());
    Element idElement = new Element(ID).setText(id);
    Element errorsElement = new Element(ERRORS);

    Element batchProcessElement = new Element(BATCH_PROCESS);
    batchProcessElement.addContent(idElement);
    batchProcessElement.addContent(requestDateTimeElement);
    batchProcessElement.addContent(recordsElement);
    batchProcessElement.addContent(errorsElement);

    document.setRootElement(batchProcessElement);
  }