コード例 #1
0
ファイル: YouViewUpdater.java プロジェクト: Reedyuk/atlas
  // TODO report status effectively
  @Override
  protected void runTask() {
    try {
      LocalDate today = LocalDate.now(DateTimeZone.UTC);
      LocalDate start = today.minusDays(minusDays);
      LocalDate finish = today.plusDays(plusDays);

      List<Channel> youViewChannels = channelResolver.getAllChannels();

      UpdateProgress progress = UpdateProgress.START;

      while (!start.isAfter(finish)) {
        LocalDate end = start.plusDays(1);
        for (Channel channel : youViewChannels) {
          Interval interval =
              new Interval(start.toDateTimeAtStartOfDay(), end.toDateTimeAtStartOfDay());
          Document xml =
              fetcher.getSchedule(interval.getStart(), interval.getEnd(), getYouViewId(channel));
          Element root = xml.getRootElement();
          Elements entries = root.getChildElements(ENTRY_KEY, root.getNamespaceURI(ATOM_PREFIX));

          progress = progress.reduce(processor.process(channel, entries, interval));
          reportStatus(progress.toString());
        }
        start = end;
      }
    } catch (Exception e) {
      log.error("Exception when processing YouView schedule", e);
      Throwables.propagate(e);
    }
  }
コード例 #2
0
 /**
  * Retrieve the nearest ancestor element that has the given name, or null if no such ancestor
  * exists.
  */
 public Element getAncestor(Element element, String localName, String namespaceURI) {
   ParentNode parent = element.getParent();
   if (parent != null && parent instanceof Element) {
     Element eparent = (Element) parent;
     if (eparent.getLocalName().equals(localName)
         && eparent.getNamespaceURI().equals(namespaceURI)) {
       return eparent;
     }
     return getAncestor(eparent, localName, namespaceURI);
   }
   return null;
 }