Esempio n. 1
0
  /**
   * Gets the online data to see it obtained previously in RESTAPI.
   *
   * @param doc
   * @return
   */
  public Visual getDataToSee(Document doc) {
    try {
      NodeList movieList = doc.getElementsByTagName("movie");
      Node p = movieList.item(0);
      if (p == null) {
        nodecheck = false;
      }
      if (p.getNodeType() == Node.ELEMENT_NODE) {
        Element movie = (Element) p;

        visual.setTitle(movie.getAttribute("title"));
        visual.setType(movie.getAttribute("type"));
        visual.setDate(movie.getAttribute("year"));
        visual.setLenght(movie.getAttribute("runtime"));
        visual.setGenre(movie.getAttribute("genre"));
        visual.setSynopsis(movie.getAttribute("plot"));
        visual.setLanguage(movie.getAttribute("language"));
        visual.setDirector(movie.getAttribute("director"));
        visual.setActors(movie.getAttribute("actors"));
      }

    } catch (NullPointerException e) {
      System.out.println("Error 404. File Not Found.");
    }

    return visual;
  }
Esempio n. 2
0
  /**
   * Reads the written data from a specific database and a specific item.
   *
   * @param type
   * @param name
   * @throws IOException
   */
  public Visual readWrittenData(String type, String name) throws IOException {
    String id;
    Document doc = null;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
      DocumentBuilder builder = factory.newDocumentBuilder();

      // Decides from where you want to read.
      if (type.equals("series")) {
        doc = builder.parse("resources/series.xml");
      } else if (type.equals("movies")) {
        doc = builder.parse("resources/movies.xml");
      }

      NodeList personList = doc.getElementsByTagName(name);
      for (int i = 0; i < personList.getLength(); i++) {
        Node p = personList.item(i);
        if (p == null) {
          nodecheck = false;
        }
        if (p.getNodeType() == Node.ELEMENT_NODE) {
          Element movie = (Element) p;
          // Gets the attribute from the specified element.
          visual.setTitle(movie.getAttribute("title"));
          visual.setType(movie.getAttribute("type"));
          visual.setDate(movie.getAttribute("year"));
          visual.setLenght(movie.getAttribute("runtime"));
          visual.setGenre(movie.getAttribute("genre"));
          visual.setSynopsis(movie.getAttribute("plot"));
          visual.setLanguage(movie.getAttribute("language"));
          visual.setDirector(movie.getAttribute("director"));
          visual.setActors(movie.getAttribute("actors"));

          System.out.println("Archivo leido.");
        }
      }

    } catch (Exception ex) {
      System.out.println("Please, write a correct database name.");
      // If the database´s name isn´t correct, the method will launch again.
      readWrittenData(api.lookForType(), api.lookForName());
    }

    return visual;
  }