Package org.jdom.xpath

Examples of org.jdom.xpath.XPath


   * @param ranges Current list of ranges.
   * @param xpath XPath selector.
   * @throws JDOMException
   */
  private static void analyzeRanges(Element root, List<Range> ranges, String xpath) throws JDOMException {
    XPath xpa = XPath.newInstance(xpath);
    List results = xpa.selectNodes(root);
    Iterator iter = results.iterator();
    while (iter.hasNext()) {
      Element node = (Element) iter.next();
      Element prefixNode = node.getChild("Prefix");
      String prefix = (prefixNode != null) ? prefixNode.getValue() : null;
View Full Code Here


   * @param node Current node.
   * @param rangeElement Range element.
   * @throws JDOMException
   */
  private static void analyzeRules(Element node, Range rangeElement) throws JDOMException {
    XPath xpa = XPath.newInstance("./Rules/Rule");
    List results = xpa.selectNodes(node);
    Iterator iter = results.iterator();
    while (iter.hasNext()) {
      Element ruleNode = (Element) iter.next();
      Element rangeNode = ruleNode.getChild("Range");
      String range = (rangeNode != null) ? rangeNode.getValue() : null;
View Full Code Here

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

      // Retrieve back links
      XPath xpa = XPath.newInstance("/api/query/pages/page");
      List listTemplates = xpa.selectNodes(root);
      Iterator itTemplate = listTemplates.iterator();
      while (itTemplate.hasNext()) {
        Element currentTemplate = (Element) itTemplate.next();
        String pageId = currentTemplate.getAttributeValue("pageid");
        String ns = currentTemplate.getAttributeValue("ns");
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 xpaTemplate = createXPath("templates/tl", "ns", "" + Namespace.TEMPLATE);
      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 listTemplates = xpaTemplate.selectNodes(currentNode);
              if (listTemplates.size() > 0) {
                for (Page p3 : tmpPages) {
                  p3.setDisambiguationPage(Boolean.TRUE);
                }
              }
View Full Code Here

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

      // Retrieve embedding pages
      XPath xpa = XPath.newInstance("/api/query/pageswithprop/page");
      List results = xpa.selectNodes(root);
      Iterator iter = results.iterator();
      while (iter.hasNext()) {
        Element currentNode = (Element) iter.next();
        Integer pageId = null;
        try {
View Full Code Here

      Map<Page, Integer> categories, int depth) throws APIException {
    try {
      Element root = getRoot(properties, ApiRequest.MAX_ATTEMPTS);

      // Retrieve category members
      XPath xpa = XPath.newInstance("/api/query/categorymembers/cm");
      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));
        if ((page.getNamespace() != null) &&
            (page.getNamespace().intValue() == Namespace.CATEGORY)) {
          categories.put(page, depth + 1);
View Full Code Here

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

      // Get random list
      XPath xpa = XPath.newInstance("/api/query/random/page");
      List results = xpa.selectNodes(root);
      Iterator iter = results.iterator();
      XPath xpaPageId = XPath.newInstance("./@id");
      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);
      }
    } catch (JDOMException e) {
View Full Code Here

   * @throws APIException
   */
  private LoginResult constructLogin(Element root)
      throws APIException {
    try {
      XPath xpa = XPath.newInstance("/api/login");
      Element node = (Element) xpa.selectSingleNode(root);
      if (node != null) {
        XPath xpaResult = XPath.newInstance("./@result");
        String result = xpaResult.valueOf(node);
        if ("Success".equalsIgnoreCase(result)) {
          XPath xpaUserid = XPath.newInstance("./@lguserid");
          XPath xpaUsername = XPath.newInstance("./@lgusername");
          XPath xpaToken = XPath.newInstance("./@lgtoken");
          getWiki().getConnection().setLgInformation(
              xpaToken.valueOf(node),
              xpaUsername.valueOf(node),
              xpaUserid.valueOf(node));
          return LoginResult.createCorrectLogin();
        } else if (EnumLoginResult.NEED_TOKEN.getCode().equalsIgnoreCase(result)) {
          XPath xpaToken = XPath.newInstance("./@token");
          return LoginResult.createNeedTokenLogin(xpaToken.valueOf(node));
        }
        XPath xpaWait = XPath.newInstance("./@wait");
        XPath xpaDetails = XPath.newInstance("./@details");
        return LoginResult.createErrorLogin(result, xpaDetails.valueOf(node), xpaWait.valueOf(node));
      }
    } catch (JDOMException e) {
      log.error("Error login", e);
      throw new APIException("Error parsing XML result", e);
    }
View Full Code Here

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

      // Retrieve embedding pages
      XPath xpa = XPath.newInstance("/api/query/protectedtitles/pt");
      List results = xpa.selectNodes(root);
      Iterator iter = results.iterator();
      while (iter.hasNext()) {
        Element currentNode = (Element) iter.next();
        if ("infinity".equals(currentNode.getAttributeValue("expiry"))) {
          Page page = DataManager.getPage(
View Full Code Here

   */
  public String executeExpandTemplates(
      Map<String, String> properties)
          throws APIException {
    try {
      XPath xpaContents = XPath.newInstance("/api/expandtemplates/.");
      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

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.