Exemplo n.º 1
0
 private Show parseShowInfo(Matcher matcher) {
   Show show = new Show();
   show.setName(matcher.group(2));
   show.setShowLink(matcher.group(1));
   show.setDate(matcher.group(3).trim());
   show.setTvDotComRating(matcher.group(4));
   return show;
 }
Exemplo n.º 2
0
  /**
   * Creates a list of shows by reading the given XML file.
   *
   * @param fileName
   * @return
   * @throws JDOMException
   * @throws IOException
   */
  public static List<Show> createShowsFromXml(String fileName) throws JDOMException, IOException {
    List<Show> allShows = new ArrayList<Show>();
    Show show;
    SAXBuilder builder = new SAXBuilder();
    Document d = builder.build(new File(fileName));
    Element root = d.getRootElement();
    Element newElement;
    String value;

    // percorre todos os shows
    List<Element> children = (List<Element>) root.getChildren();
    for (Iterator<Element> i = children.iterator(); i.hasNext(); ) {
      newElement = (Element) i.next();
      show = new Show();

      // name
      value = newElement.getChildText("name");
      if (value != null) show.setName(value);
      // show link
      value = newElement.getChildText("showLink");
      if (value != null) show.setShowLink(value);
      // start date
      value = newElement.getChildText("startDate");
      if (value != null) show.setDate(value);
      // tv.com rating
      value = newElement.getChildText("tvDotComRating");
      if (value != null) show.setTvDotComRating(value);
      // tv.com votes
      value = newElement.getChildText("tvDotComVotes");
      if (value != null) show.setTvDotComVotes(Integer.parseInt(value));

      System.out.println(newElement.getChildText("name"));
      //			System.out.println(newElement.getChildText("showLink"));
      //			System.out.println(newElement.getChildText("startDate"));
      System.out.println(newElement.getChildText("tvDotComRating"));
      System.out.println(newElement.getChildText("tvDotComVotes"));

      allShows.add(show);
    }
    return allShows;
  }