Package org.jdom.xpath

Examples of org.jdom.xpath.XPath


      List<Page> list) throws APIException {
    try {
      Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);

      // Retrieve embedding pages
      XPath xpa = XPath.newInstance("/api/query/embeddedin/ei");
      List results = xpa.selectNodes(root);
      Iterator iter = results.iterator();
      XPath xpaPageId = XPath.newInstance("./@pageid");
      XPath xpaNs = XPath.newInstance("./@ns");
      XPath xpaTitle = XPath.newInstance("./@title");
      while (iter.hasNext()) {
        Element currentNode = (Element) iter.next();
        Page page = DataManager.getPage(
            getWiki(), xpaTitle.valueOf(currentNode), null, null, null);
        page.setNamespace(xpaNs.valueOf(currentNode));
        page.setPageId(xpaPageId.valueOf(currentNode));
        list.add(page);
      }
View Full Code Here


    String nextStart = null;
    try {
      Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);

      // Get recent changes list
      XPath xpa = XPath.newInstance("/api/query/recentchanges/rc");
      List results = xpa.selectNodes(root);
      Iterator iter = results.iterator();
      while (iter.hasNext()) {
        Element currentNode = (Element) iter.next();
        boolean isAnonymous = currentNode.getAttribute("anon") != null;
        boolean isBot = currentNode.getAttribute("bot") != null;
View Full Code Here

      List<Page> list) throws APIException {
    try {
      Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);

      // Retrieve category members
      XPath xpa = XPath.newInstance("/api/query/abuselog/item");
      List results = xpa.selectNodes(root);
      Iterator iter = results.iterator();
      while (iter.hasNext()) {
        Element currentNode = (Element) iter.next();
        String title = currentNode.getAttributeValue("title");
        Page page = DataManager.getPage(getWiki(), title, null, null, null);
View Full Code Here

      // Manage redirects and missing pages
      updateRedirect(root, pages);

      // Set disambiguation status
      XPath xpa = XPath.newInstance("/api/query/pages/page");
      List results = xpa.selectNodes(root);
      Iterator iter = results.iterator();
      XPath xpaTitle = XPath.newInstance("./@title");
      XPath xpaCategory = createXPath("categories/cl", "ns", "" + Namespace.CATEGORY);
      List<Page> tmpPages = new ArrayList<Page>();
      while (iter.hasNext()) {
        Element currentNode = (Element) iter.next();
        String title = xpaTitle.valueOf(currentNode);
        for (Page p : pages) {
          tmpPages.clear();
          Iterator<Page> it = p.getRedirectIteratorWithPage();
          while (it.hasNext()) {
            Page p2 = it.next();
            tmpPages.add(p2);
            if ((p2.getTitle() != null) &&
                (Page.areSameTitle(p2.getTitle(), title))) {
              List listCategories = xpaCategory.selectNodes(currentNode);
              if (listCategories.size() > 0) {
                for (Page p3 : tmpPages) {
                  p3.setDisambiguationPage(Boolean.TRUE);
                }
              }
View Full Code Here

   */
  public String executeParse(
      Map<String, String> properties)
          throws APIException {
    try {
      XPath xpaContents = XPath.newInstance("/api/parse/text/.");
      Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);
      return xpaContents.valueOf(root);
    } catch (JDOMException e) {
      log.error("Error expanding templates", e);
      throw new APIException("Error parsing XML", e);
    }
  }
View Full Code Here

        }
        throw e;
      }

      // Retrieve sections
      XPath xpaSections = XPath.newInstance("/api/parse/sections/s");
      List listSections = xpaSections.selectNodes(root);
      List<Section> result = new ArrayList<Section>(listSections.size());
      Iterator itSection = listSections.iterator();
      while (itSection.hasNext()) {
        Element sectionNode = (Element) itSection.next();
        try {
          Section section = new Section(
              Integer.valueOf(sectionNode.getAttributeValue("toclevel")),
              Integer.valueOf(sectionNode.getAttributeValue("level")),
              sectionNode.getAttributeValue("line"),
              sectionNode.getAttributeValue("number"),
              Integer.valueOf(sectionNode.getAttributeValue("index")));
          result.add(section);
        } catch (NumberFormatException e) {
          //
        }
      }

      // Retrieve revision id
      XPath xpaPage = XPath.newInstance("/api/parse");
      Element parseNode = (Element) xpaPage.selectSingleNode(root);
      if ((parseNode != null) && (parseNode.getAttributeValue("revid") != null)) {
        page.setRevisionId(parseNode.getAttributeValue("revid"));
      }

      return result;
View Full Code Here

          throws APIException {
    try {
      Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);

      // Retrieve search results
      XPath xpa = XPath.newInstance("/api/query/search/p");
      List results = xpa.selectNodes(root);
      Iterator iter = results.iterator();
      XPath xpaNs = XPath.newInstance("./@ns");
      XPath xpaTitle = XPath.newInstance("./@title");
      while (iter.hasNext()) {
        Element currentNode = (Element) iter.next();
        Page similarPage = DataManager.getPage(
            getWiki(), xpaTitle.valueOf(currentNode), null, null, null);
        similarPage.setNamespace(xpaNs.valueOf(currentNode));
        list.add(similarPage);
      }

      // Retrieve continue
View Full Code Here

      // Manage redirects and missing pages
      updateRedirect(root, pages);

      // Retrieve pages
      XPath xpa = XPath.newInstance("/api/query/pages/page");
      List results = xpa.selectNodes(root);
      Iterator iter = results.iterator();
      while (iter.hasNext()) {
        Element pageNode = (Element) iter.next();
        String title = pageNode.getAttributeValue("title");
        Integer pageId = null;
        try {
          String pageIdValue = pageNode.getAttributeValue("pageid");
          if (pageIdValue != null) {
            pageId = Integer.valueOf(pageIdValue);
          }
        } catch (NumberFormatException e) {
          System.err.println("Incorrect page id");
        }
        String namespace = pageNode.getAttributeValue("ns");
        for (Page tmpPage : pages) {
          Iterator<Page> itPage = tmpPage.getRedirectIteratorWithPage();
          while (itPage.hasNext()) {
            Page page = itPage.next();
            boolean samePage = false;
            if ((pageId != null) && (page.getPageId() != null)) {
              samePage = pageId.equals(page.getPageId());
            } else {
              samePage = Page.areSameTitle(page.getTitle(), title);
            }
            if (samePage) {
              page.setNamespace(namespace);
              updatePageInformation(pageNode, page);
 
              // Retrieve revisions
              if (!Boolean.FALSE.equals(page.isExisting())) {
                XPath xpaRevisions = XPath.newInstance("revisions/rev");
                Element revNode = (Element) xpaRevisions.selectSingleNode(pageNode);
                if (revNode != null) {
                  page.setContents(revNode.getText());
                  page.setExisting(Boolean.TRUE);
                  page.setRevisionId(revNode.getAttributeValue("revid"));
                  page.setContentsTimestamp(revNode.getAttributeValue("timestamp"));
View Full Code Here

     */
    public List getTaglibs() throws JDOMException, IOException
    {
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(new File(getPluginScript()));
        XPath xpath = XPath.newInstance("/project/define:taglib");
        xpath.addNamespace( "define", "jelly:define" );
        List taglibElements = xpath.selectNodes(doc);
        List taglibs = new LinkedList();
        for (Iterator iter = taglibElements.iterator(); iter.hasNext();)
        {
            Element element = (Element) iter.next();
            Map taglib = new HashMap();
            taglib.put("uri", element.getAttributeValue("uri"));
            taglib.put("tagNames", new LinkedList());
            XPath tagsXp = XPath.newInstance("define:tag|define:jellybean");
            List tagsElements = tagsXp.selectNodes(element);
            for (Iterator tagsIter = tagsElements.iterator(); tagsIter.hasNext();)
            {
                Element tagsElement = (Element) tagsIter.next();
                ((List) taglib.get("tagNames")).add(tagsElement.getAttributeValue("name"));
            }
View Full Code Here

        return bestCandidate;
    }

    private Element getMatch(Object doc, String xpath) {
        try {
            XPath path = XPath.newInstance(xpath);
            return (Element)path.selectSingleNode(doc);
        } catch (JDOMException e) {
            throw new DatabindingException("Error evaluating xpath " + xpath, e);
        }
    }
View Full Code Here

TOP

Related Classes of org.jdom.xpath.XPath

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.