public List<String> getStructures(File input) throws JDOMException, IOException {
    List<String> result = new LinkedList<String>();
    SAXBuilder saxBuilder = new SAXBuilder();
    for (File file : input.listFiles()) {
      Document document = null;
      try {
        document = saxBuilder.build(file);
      } catch (JDOMParseException parseException) {
        // file not a valid xml file (e.g. config.txt)
        continue;
      }

      XPathFactory xpf = XPathFactory.instance();
      XPathExpression<Element> xpath =
          xpf.compile("/treatment/description/statement/structure", Filters.element());
      List<Element> elements = xpath.evaluate(document);
      for (Element element : elements) {
        String name = element.getAttributeValue("name");
        String constraint = element.getAttributeValue("constraint");
        if (constraint != null) name = constraint + " " + name;
        result.add(name);
      }
    }
    return result;
  }
  /**
   * Execute abuse log request.
   *
   * @param properties Properties defining request.
   * @param list List to be filled with abuse logs.
   * @return True if request should be continued.
   * @throws APIException
   */
  @Override
  public boolean executeAbuseLog(Map<String, String> properties, List<Page> list)
      throws APIException {
    try {
      Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);

      // Retrieve category members
      XPathExpression<Element> xpa =
          XPathFactory.instance().compile("/api/query/abuselog/item", Filters.element());
      List<Element> results = xpa.evaluate(root);
      Iterator<Element> iter = results.iterator();
      while (iter.hasNext()) {
        Element currentNode = iter.next();
        String title = currentNode.getAttributeValue("title");
        Page page = DataManager.getPage(getWiki(), title, null, null, null);
        list.add(page);
      }

      // Retrieve continue
      return false; // Not continuing
      /*return shouldContinue(
      root, "/api/query-continue/abuselog",
      properties);*/
    } catch (JDOMException e) {
      log.error("Error loading abuse filters list", e);
      throw new APIException("Error parsing XML", e);
    }
  }
  public List<Character> getCharacters(File input) throws JDOMException, IOException {
    List<Character> result = new LinkedList<Character>();
    SAXBuilder saxBuilder = new SAXBuilder();
    for (File file : input.listFiles()) {
      Document document = null;
      try {
        document = saxBuilder.build(file);
      } catch (JDOMParseException parseException) {
        // file not a valid xml file (e.g. config.txt)
        continue;
      }

      XPathFactory xpf = XPathFactory.instance();
      XPathExpression<Element> xpath =
          xpf.compile("/treatment/description/statement/structure/character", Filters.element());
      List<Element> elements = xpath.evaluate(document);
      for (Element element : elements) {
        String charType = element.getAttributeValue("char_type");
        if (charType != null && charType.equals("range_value")) {
          String toValue = element.getAttributeValue("to");
          String fromValue = element.getAttributeValue("from");
          String category = element.getAttributeValue("name");
          result.add(new Character(toValue, category));
          result.add(new Character(fromValue, category));
        } else {
          String value = element.getAttributeValue("value");
          String category = element.getAttributeValue("name");
          result.add(new Character(value, category));
        }
      }
    }
    return result;
  }
  public static Document GetTasksByQuery(InputStream stream, String query)
      throws JDOMException, IOException {
    SAXBuilder builder = new SAXBuilder();

    // String query = "//task[contains(attendant/@ids,'" + userId + "')]";

    Document doc = null;
    try {

      doc = builder.build(stream);
    } catch (IOException ex) {
      Logger.getLogger(TasksJDOMParser.class.getName()).log(Level.SEVERE, null, ex);

      throw ex;
    }

    XPathFactory xpfac = XPathFactory.instance();

    XPathExpression xp = xpfac.compile(query);

    List<Element> tasks = (List<Element>) xp.evaluate(doc);

    Document xmlDoc = new Document();

    Element root = new Element("tasks");

    for (int index = 0; index < tasks.size(); index++) {
      root.addContent(tasks.get(index).clone());
    }

    xmlDoc.addContent(root);
    return xmlDoc;
  }
Example #5
0
  public static void xpathAttVal(Document doc, String ruta, String val) {

    XPathExpression<Element> xpath = XPathFactory.instance().compile(ruta, Filters.element());
    List<Element> elemento = xpath.evaluate(doc);
    Iterator it = elemento.iterator();

    while (it.hasNext()) {
      Element at = (Element) it.next();
      System.out.println(at.getName() + ": " + at.getAttributeValue(val));
    }
  }
  @Override
  @PayloadRoot(namespace = NAMESPACE_URI, localPart = HOLIDAY_REQUEST_LOCALPART)
  public void handleHolidayRequest(@RequestPayload Element holidayRequest) throws Exception {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Date startDate = sdf.parse(startDateExpression.evaluate(holidayRequest).get(0).getValue());
    Date endDate = sdf.parse(endDateExpression.evaluate(holidayRequest).get(0).getValue());
    String name =
        nameExpression.evaluate(holidayRequest).get(0).getValue()
            + " "
            + surnameExpression.evaluate(holidayRequest).get(0).getValue();

    humanResourceService.bookHoliday(startDate, endDate, name);
  }
Example #7
0
  public void parseDoc(File file) throws Exception {
    adjustFile(file);
    start = -1;
    end = -1;
    prevValue = -1;
    ocrAl = new ArrayList<>(1000);
    outFileName =
        file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 4) + "ngt.xml";
    builder = new SAXBuilder();
    doc = builder.build(file);
    root = doc.getRootElement();
    xmlns = root.getNamespace();
    xpath =
        XPathFactory.instance()
            .compile(
                "//ns:span[@class='ocr_word']",
                Filters.element(),
                null,
                Namespace.getNamespace("ns", "http://www.w3.org/1999/xhtml"));
    List<Element> elements = xpath.evaluate(root);
    for (Element element : elements) {
      parseOcrWord(element);
    }

    ocrAl.add("%%%");
    ocrAl.add("%%%");
    findAnchors();
    writeFragment(start, end);
  }
  @Test
  public final void testCleanupUnsetValues() {
    try {
      request = new SoapRequest("getAdMedium");
    } catch (Exception e) {
      Assert.fail(e.getMessage());
    }

    Assert.assertNotNull(request);
    Assert.assertNotNull(request.getDocument());

    request.setValue("//ns:admediumId", "3096");

    Document document = request.getDocument();

    Namespace namespace =
        Namespace.getNamespace("ns", "http://api.zanox.com/namespace/2011-03-01/");
    document.getRootElement().addNamespaceDeclaration(namespace);

    XPathFactory xpfac = XPathFactory.instance();

    XPathExpression xp =
        xpfac.compile(
            "//ns:adspaceId",
            Filters.element(),
            null,
            document.getRootElement().getNamespacesInScope());

    List<Element> elements = xp.evaluate(document);

    Assert.assertNotNull("Result is null.", elements);
    Assert.assertTrue(
        "There should be at least the ns:adspaceId node in elements.", elements.size() == 1);
    Assert.assertTrue(
        "The text of the element should be '?'", elements.get(0).getText().toString().equals("?"));

    request.cleanupUnsetValues();

    elements = xp.evaluate(document);

    Assert.assertNotNull("Result is null.", elements);
    Assert.assertTrue(
        "There should be at least the ns:adspaceId node in elements.", elements.size() == 0);
  }
 private Date parseDate(XPathExpression<Element> expression, Element element)
     throws ParseException {
   Element result = expression.evaluateFirst(element);
   if (result != null) {
     SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
     return dateFormat.parse(result.getText());
   } else {
     throw new IllegalArgumentException(
         "Could not evaluate [" + expression + "] on [" + element + "]");
   }
 }
  public List<Character> getRangeValueCharacters(File input) throws JDOMException, IOException {
    List<Character> result = new LinkedList<Character>();
    SAXBuilder saxBuilder = new SAXBuilder();

    for (File file : input.listFiles()) {
      Document document = null;
      try {
        document = saxBuilder.build(file);
      } catch (JDOMParseException parseException) {
        // file not a valid xml file (e.g. config.txt)
        continue;
      }

      XPathFactory xpf = XPathFactory.instance();
      XPathExpression<Element> xpath =
          xpf.compile(
              "/treatment/description/statement/structure/character",
              Filters.element()); /*, null,
			              Namespace.getNamespace("xpns", "http://www.w3.org/2002/xforms")); */
      List<Element> elements = xpath.evaluate(document);
      for (Element element : elements) {
        String charType = element.getAttributeValue("char_type");
        if (charType != null && charType.equals("range_value")) {
          String toValue = element.getAttributeValue("to");
          String fromValue = element.getAttributeValue("from");

          String name = element.getAttributeValue("name");
          if (toValue != null && !numericalsPattern.matcher(toValue).matches()) {
            result.add(new Character(toValue, name));
          }

          if (fromValue != null && !numericalsPattern.matcher(fromValue).matches()) {
            result.add(new Character(fromValue, name));
          }
        }
      }
    }
    return result;
  }
 /** ************************************************************************* */
 public static Element selectElement(Document doc, String path) {
   XPathExpression<Element> expression =
       XPathFactory.instance().compile(path, new ElementFilter());
   return expression.evaluateFirst(doc);
 }