Пример #1
0
  // 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);
    }
  }
 private List<String> getNamespaceDeclaredPrefixes(Element e) {
   final List<String> prefixes = new ArrayList<String>();
   for (int i = 0; i < e.getNamespaceDeclarationCount(); i += 1) {
     prefixes.add(e.getNamespacePrefix(i));
   }
   return prefixes;
 }
Пример #3
0
  /**
   * This method is used to parse an Assertion in the RuleML Document.
   *
   * @param ass Element The XOM Element object that represents the assertion.
   * @return A term object that represents the assertion in a way that can be used by the reasoning
   *     engine.
   * @throws ParseException Thrown if there is a serious error parsing the assertion.
   */
  private Term parseAssert(Element ass) throws ParseException {
    Elements children = ass.getChildElements();

    Element firstChild = skipRoleTag(children.get(0));

    if (firstChild.getLocalName().equals(tagNames.ATOM)) {
      DefiniteClause dc = parseFact(firstChild);
      Vector<Term> v = new Vector<Term>();
      for (int i = 0; i < dc.atoms.length; i++) {
        v.add(dc.atoms[i]);
      }
      Term t = new Term(SymbolTable.IASSERT, SymbolTable.INOROLE, Types.IOBJECT, v);
      t.setAtom(true);
      return t;
    } else if (firstChild.getLocalName().equals(tagNames.IMPLIES)) {
      Vector<DefiniteClause> v2 = parseImplies(firstChild);
      DefiniteClause dc = (DefiniteClause) v2.get(0);
      Vector<Term> v = new Vector<Term>();
      for (int i = 0; i < dc.atoms.length; i++) {
        v.add(dc.atoms[i]);
      }
      Term t = new Term(SymbolTable.IASSERT, SymbolTable.INOROLE, Types.IOBJECT, v);
      t.setAtom(true);
      return t;
    } else {
      throw new ParseException("Assert element can only contain Atom (fact) or Implies elements.");
    }
  }
 protected Element createElement(String name, XMLNamespace ns) {
   Element elem = new Element(name, ns.getUri());
   if (!LAKEVIEW.equals(ns)) {
     elem.setNamespacePrefix(ns.getPrefix());
   }
   return elem;
 }
Пример #5
0
 @Override
 protected IStructureRecord query(String value) throws AmbitException {
   OpsinResult result = request.name2structure(value);
   if (result.getStatus().equals(OPSIN_RESULT_STATUS.SUCCESS)) {
     record.clear();
     /*
     String str = NameToInchi.convertResultToInChI(result);
     if (str!=null) {
     	record.setContent(str);
     	record.setFormat(IStructureRecord.MOL_TYPE.INC.toString());
     	return record;
     }
     */
     /*
     String str = result.getSmiles();
     if (str!=null) {
     	record.setContent(null);
     	record.setSmiles(str);
     	return record;
     }
     */
     Element cml = result.getCml();
     if (cml != null) {
       record.setContent(cml.toXML());
       record.setFormat(IStructureRecord.MOL_TYPE.CML.toString());
       return record;
     }
     return null; // success reported,but no meaningful result
   } else return null;
 }
  private ComponentSet addComponents(
      Map<String, Connectable> connectables, int rows, int cols, Elements componentElements) {
    ComponentSet set;
    set = new ComponentSet(cols, rows);
    for (int i = 0; i < componentElements.size(); i++) {
      Element componentElement = componentElements.get(i);
      String type = componentElement.getAttributeValue("type");
      String name = componentElement.getAttributeValue("name");

      Connectable connectable = factory.make(type, name);
      if (connectable != null) {
        connectables.put(name, connectable);
        if (connectable instanceof Component) {
          Component component = (Component) connectable;
          component.setxLoc(Integer.parseInt(componentElement.getAttributeValue("col")));
          component.setyLoc(Integer.parseInt(componentElement.getAttributeValue("row")));
          component.setInverted(Boolean.parseBoolean(componentElement.getAttributeValue("inv")));
          set.addComponent(component);
        } else if (connectable instanceof Endpoint) {
          set.addEndpoint((Endpoint) connectable);
        }
      }
    }
    return set;
  }
  public List<ICTomorrowItemMetadata> getMetadataFile(int jobId) throws ICTomorrowApiException {
    try {
      Element resultElement = getResultElement(client.get(getMetadataFileUrl(jobId)));

      String jobStatus = resultElement.getFirstChildElement("job_status").getValue().trim();

      if ("COMPLETE".equals(jobStatus)) {
        Element downloadElement = resultElement.getFirstChildElement("Download");

        List<ICTomorrowItemMetadata> items = Lists.newArrayList();
        Elements itemElements =
            downloadElement.getFirstChildElement("Items").getChildElements("Item");
        for (int i = 0; i < itemElements.size(); i++) {
          items.add(getItem(itemElements.get(i)));
        }

        return items;
      } else if ("FAILED".equals(jobStatus)) {
        throw new ICTomorrowApiException("Metadata file creation failed");
      }

      return null;
    } catch (HttpException e) {
      throw new ICTomorrowApiException("Exception while recording consumer activity", e);
    }
  }
  private Collection<ConnectableDefinition> loadConnectableDefs(File connectableDefs) {
    Collection<ConnectableDefinition> defs = new HashSet<ConnectableDefinition>();
    try {
      Builder parser = new Builder();
      Document doc = parser.build(connectableDefs);
      Element root = doc.getRootElement();

      Elements definitions = root.getChildElements();
      for (int i = 0; i < definitions.size(); i++) {
        Element definition = definitions.get(i);
        String id = definition.getAttributeValue("id");
        String pinCount = definition.getAttributeValue("pins");
        String type = definition.getAttributeValue("type");

        ConnectableDefinition d = new ConnectableDefinition(id, type, Integer.parseInt(pinCount));

        Elements pins = definition.getChildElements();
        for (int j = 0; j < pins.size(); j++) {
          Element pinElement = pins.get(j);
          String pinNumber = pinElement.getAttributeValue("number");
          String pinName = pinElement.getAttributeValue("name");
          d.addPin(Integer.parseInt(pinNumber), pinName);
        }

        defs.add(d);
      }
    } catch (ParsingException ex) {
      System.err.println("malformed XML file : " + ex.getMessage());
    } catch (IOException ex) {
      System.err.println("io error : " + ex.getMessage());
    }
    return defs;
  }
Пример #9
0
  private static boolean isLive(String aServer) {
    try {
      URL url = new URL(aServer + "health");
      HttpURLConnection uc = (HttpURLConnection) url.openConnection();

      if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(BUNDLE.get("TC_STATUS_CHECK"), url);
      }

      if (uc.getResponseCode() == 200) {
        Document xml = new Builder().build(uc.getInputStream());
        Element response = (Element) xml.getRootElement();
        Element health = response.getFirstChildElement("health");
        String status = health.getValue();

        if (status.equals("dying") || status.equals("sick")) {
          if (LOGGER.isWarnEnabled()) {
            LOGGER.warn(BUNDLE.get("TC_SERVER_STATUS"), status);
          }

          return true;
        } else if (status.equals("ok")) {
          return true;
        } else {
          LOGGER.error(BUNDLE.get("TC_UNEXPECTED_STATUS"), status);
        }
      }
    } catch (UnknownHostException details) {
      LOGGER.error(BUNDLE.get("TC_UNKNOWN_HOST"), details.getMessage());
    } catch (Exception details) {
      LOGGER.error(details.getMessage());
    }

    return false;
  }
Пример #10
0
 /**
  * Converts a Sem Im into xml.
  *
  * @param semIm the instantiated structural equation model to convert
  * @return xml representation
  */
 public static Element getElement(SemIm semIm) {
   Element semElement = new Element(SemXmlConstants.SEM);
   semElement.appendChild(makeVariables(semIm));
   semElement.appendChild(makeEdges(semIm));
   semElement.appendChild(makeMarginalErrorDistribution(semIm));
   semElement.appendChild(makeJointErrorDistribution(semIm));
   return semElement;
 }
 public static void removeMimeType(String mimeId) {
   Elements els = _root.getChildElements("mime-type");
   for (int i = 0; i < els.size(); i++)
     if (els.get(i).getAttribute("id").getValue().equals(mimeId)) {
       _root.removeChild(els.get(i));
       return;
     }
 }
Пример #12
0
 private boolean contains(List<Element> usedGlossEntries, Element entry) {
   String id = entry.getAttributeValue("id", xmlns);
   for (Element used : usedGlossEntries) {
     String usid = used.getAttributeValue("id", xmlns);
     if (id.equals(usid)) return true;
   }
   return false;
 }
 public static void runCommentExamples(String templateResourceName, String baseUri) {
   Element templateElement = getTemplate(templateResourceName, baseUri);
   Nodes templatesWithExamples =
       templateElement.query(".//template[comment[@class='" + EXAMPLE_INPUT + "' and @id]]");
   for (int i = 0; i < templatesWithExamples.size(); i++) {
     runCommentExamples((Element) templatesWithExamples.get(i));
   }
 }
Пример #14
0
 public String getType(PseudoPath path) {
   Element element = getElement(path);
   if (element != null) {
     return element.getLocalName();
   } else {
     return null;
   }
 }
 @Override
 public void finishMakingDocument(Document document) {
   final Element e = document.getRootElement();
   for (String namespace : namespacePrefixes.keySet()) {
     e.addNamespaceDeclaration(namespacePrefixes.get(namespace), namespace);
   }
   super.finishMakingDocument(document);
 }
Пример #16
0
  private Element getParent(TextMapElement item) {
    Element parent = (Element) item.n.getParent();
    while (sm.getSemanticsTable().getSemanticTypeFromAttribute(parent) == null
        || sm.getSemanticsTable().getSemanticTypeFromAttribute(parent).equals("action")) {
      parent = (Element) parent.getParent();
    }

    return parent;
  }
 /**
  * @param data
  * @param predecessors
  */
 private void appendPropabilities(TemporalProbabilityFeature data, Element predecessors) {
   for (DataType dtp : data.getPredecessors()) {
     Element probability = new Element("ts:element", Constants.URI);
     probability.addAttribute(new Attribute("type", "probability"));
     probability.addAttribute(new Attribute("eventType", String.valueOf(dtp.getEventType())));
     probability.addAttribute(new Attribute("value", String.valueOf(data.getProbabilityFor(dtp))));
     predecessors.appendChild(probability);
   }
 }
 public static MimeType getMimeTypeByExt(String ext) {
   Elements els = _root.getChildElements("mime-type");
   for (int i = 0; i < els.size(); i++) {
     Element el = els.get(i);
     Elements exts = el.getChildElements("ext");
     for (int j = 0; j < exts.size(); j++)
       if (exts.get(j).getValue().toLowerCase().equals(ext.toLowerCase())) return new MimeType(el);
   }
   return new MimeType();
 }
Пример #19
0
 public static void xom() {
   // XOM dynamically enforces presence, non-nullness & non-emptyness of URI if prefix is given
   nu.xom.Element root = new nu.xom.Element("todo");
   try {
     root.setNamespacePrefix("todo");
   } catch (nu.xom.NamespaceConflictException e) {
     System.out.println("XOM:");
     System.out.println(e.getMessage());
   }
 }
Пример #20
0
  /**
   * Get the first element which is not labeled with OID
   *
   * @param elements Elements to search for child
   * @param startIndex Start index to start search at
   * @return Index of the first element which is not labeled with OID. If not exist, returns -1.
   */
  private int getFirstChildElementIndex(Elements elements, int startIndex) {
    for (int i = startIndex; i < elements.size(); i++) {
      Element child = skipRoleTag(elements.get(i));

      if (!child.getLocalName().equals(tagNames.OID)) {
        return i;
      }
    }
    return -1;
  }
Пример #21
0
 /**
  * Get the first element with the given name
  *
  * @param elements Element to search for the child
  * @param childName Name of the element to look for
  * @return The first Element which is labeled with childName
  */
 private Element getFirstChildElement(Element element, String childName) {
   Elements children = element.getChildElements();
   for (int i = 0; i < children.size(); i++) {
     Element child = children.get(i);
     if (child.getLocalName().equals(childName)) {
       return child;
     }
   }
   return null;
 }
Пример #22
0
 private Element getGlossEntryByID(String id, Elements allGlossentries) {
   for (int i = 0; i < allGlossentries.size(); i++) {
     Element entry = (Element) allGlossentries.get(i);
     String eid = entry.getAttributeValue("id", xmlns);
     if (id.equals(eid)) {
       return entry;
     }
   }
   return null;
 }
 private String getCharacteristic(Element itemElement, String characteristicName) {
   Elements characteristics = itemElement.getChildElements("Characteristic");
   for (int i = 0; i < characteristics.size(); i++) {
     Element currentElement = characteristics.get(i);
     String nameAttribute = currentElement.getAttributeValue("Name");
     if (characteristicName.equals(nameAttribute)) {
       return currentElement.getAttributeValue("Value");
     }
   }
   return null;
 }
Пример #24
0
  public synchronized void deletePath(PseudoPath path) {
    if (path.getNameCount() == 0) {
      throw new IllegalArgumentException("Empty path can not be deleted.");
    }

    Element toBeDeleted = getElement(path);
    if (toBeDeleted != null) {
      ParentNode parent = toBeDeleted.getParent();
      parent.removeChild(toBeDeleted);
    }
  }
Пример #25
0
  public static void xomWithURI() {
    nu.xom.Element root = new nu.xom.Element("todo");

    // Setting URI and prefix has the consequence that the namespace declaration is added
    root.setNamespaceURI("http://www.example.com");
    root.setNamespacePrefix("todo");
    //		System.out.println(root.getAttributeCount()); // prints 0 xmlns etc. are no attributes.
    nu.xom.Document doc = new nu.xom.Document(root);
    System.out.println("XOM:");
    System.out.println(doc.toXML());
  }
  public ICTomorrowMeter getMeter(int consumerId, int offerId) throws ICTomorrowApiException {
    try {
      HttpResponse res = client.get(meterUrl(consumerId, offerId));

      Element resultElement = getResultElement(res);

      return parseMeter(resultElement.getFirstChildElement("meter"));
    } catch (HttpException e) {
      throw new ICTomorrowApiException("Exception while getting meter", e);
    }
  }
Пример #27
0
 /**
  * Removes <Reify> elements recursively from a given element
  *
  * @param element Element to skip <Reify> elements in
  */
 private void removeReifyElements(Element element) {
   Elements children = element.getChildElements();
   for (int i = 0; i < children.size(); i++) {
     Element child = children.get(i);
     if (child.getLocalName().equals(tagNames.REIFY)) {
       element.removeChild(child);
     } else {
       removeReifyElements(child);
     }
   }
 }
  /**
   * Marshall the data in this object to an Element object.
   *
   * @return The data expressed in an Element.
   */
  public Element marshall() {
    Element element = new Element(getQualifiedName(), Namespaces.NS_ATOM);
    if (type != null) {
      Attribute typeAttribute = new Attribute(ATTRIBUTE_TYPE, type.toString());
      element.addAttribute(typeAttribute);
    }

    if (content != null) {
      element.appendChild(content);
    }
    return element;
  }
Пример #29
0
 Element getChildByName(Element element, String name) {
   Elements children = element.getChildElements();
   Element child;
   for (int i = 0; i < children.size(); i++) {
     child = children.get(i);
     String childName = child.getAttributeValue("name");
     if (childName.equals(name)) {
       return child;
     }
   }
   return null;
 }
Пример #30
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;
 }