Ejemplo n.º 1
0
  @Test
  public void getParents() throws XPathException, SAXException, PermissionDeniedException {
    Sequence largeSet =
        executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'love')]/ancestor::SPEECH", 187, null);

    NodeSet result = ((AbstractNodeSet) largeSet).getParents(-1);
    assertEquals(51, result.getLength());
  }
Ejemplo n.º 2
0
  @Test
  public void selectAncestorDescendant_2()
      throws XPathException, SAXException, PermissionDeniedException {
    Sequence outerSet =
        executeQuery(broker, "//SCENE/TITLE[fn:contains(., 'closet')]/ancestor::SCENE", 1, null);

    NodeSet result =
        ((AbstractNodeSet) outerSet)
            .selectAncestorDescendant(outerSet.toNodeSet(), NodeSet.DESCENDANT, true, -1, true);
    assertEquals(1, result.getLength());
  }
Ejemplo n.º 3
0
  @Test
  public void childSelector() throws XPathException {
    NodeSelector selector = new ChildSelector(seqSpeech.toNodeSet(), -1);
    NameTest test = new NameTest(Type.ELEMENT, new QName("LINE", ""));
    NodeSet set =
        broker
            .getStructuralIndex()
            .findElementsByTagName(
                ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector);

    assertEquals(9492, set.getLength());
  }
Ejemplo n.º 4
0
  @Test
  public void nodeProxy_getParents()
      throws XPathException, SAXException, PermissionDeniedException {
    Sequence smallSet =
        executeQuery(
            broker, "//SPEECH/LINE[fn:contains(., 'perturbed spirit')]/ancestor::SPEECH", 1, null);

    NodeProxy proxy = (NodeProxy) smallSet.itemAt(0);

    NodeSet result = proxy.getParents(-1);
    assertEquals(1, result.getLength());

    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
    NodeSet speakers =
        broker
            .getStructuralIndex()
            .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);

    result = speakers.selectParentChild(proxy, NodeSet.DESCENDANT, -1);
    assertEquals(1, result.getLength());
  }
Ejemplo n.º 5
0
  @Test
  public void ancestorSelector() throws XPathException {
    NodeSelector selector = new AncestorSelector(seqSpeech.toNodeSet(), -1, false, true);
    NameTest test = new NameTest(Type.ELEMENT, new QName("ACT", ""));
    NodeSet set =
        broker
            .getStructuralIndex()
            .findElementsByTagName(
                ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector);

    assertEquals(15, set.getLength());
  }
Ejemplo n.º 6
0
  @Test
  public void descendantOrSelfSelector() throws XPathException {
    NodeSelector selector = new DescendantOrSelfSelector(seqSpeech.toNodeSet(), -1);
    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEECH", ""));
    NodeSet set =
        broker
            .getStructuralIndex()
            .findElementsByTagName(
                ElementValue.ELEMENT, seqSpeech.getDocumentSet(), test.getName(), selector);

    assertEquals(2628, set.getLength());
  }
Ejemplo n.º 7
0
  @Test
  public void extArrayNodeSet_selectParentChild_3()
      throws XPathException, SAXException, PermissionDeniedException {
    Sequence nestedSet = executeQuery(broker, "//section[@n = ('1.1', '1.1.1', '1.2')]", 3, null);
    NameTest test = new NameTest(Type.ELEMENT, new QName("para", ""));
    NodeSet children =
        broker
            .getStructuralIndex()
            .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);

    NodeSet result = children.selectParentChild(nestedSet.toNodeSet(), NodeSet.DESCENDANT);
    assertEquals(4, result.getLength());
  }
Ejemplo n.º 8
0
  @Test
  public void selectAncestors() throws XPathException, SAXException, PermissionDeniedException {
    NameTest test = new NameTest(Type.ELEMENT, new QName("SCENE", ""));
    NodeSet scenes =
        broker
            .getStructuralIndex()
            .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
    Sequence largeSet =
        executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'love')]/ancestor::SPEECH", 187, null);

    NodeSet result = ((AbstractNodeSet) scenes).selectAncestors(largeSet.toNodeSet(), false, -1);
    assertEquals(49, result.getLength());
  }
Ejemplo n.º 9
0
  @Test
  public void descendantSelector() throws XPathException, SAXException, PermissionDeniedException {
    Sequence seq = executeQuery(broker, "//SCENE", 72, null);
    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
    NodeSelector selector = new DescendantSelector(seq.toNodeSet(), -1);
    NodeSet set =
        broker
            .getStructuralIndex()
            .findElementsByTagName(
                ElementValue.ELEMENT, seq.getDocumentSet(), test.getName(), selector);

    assertEquals(2639, set.getLength());
  }
Ejemplo n.º 10
0
  @Test
  public void selectParentChild_2() throws XPathException, SAXException, PermissionDeniedException {
    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
    NodeSet speakers =
        broker
            .getStructuralIndex()
            .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
    Sequence largeSet =
        executeQuery(broker, "//SPEECH/LINE[fn:contains(., 'love')]/ancestor::SPEECH", 187, null);

    NodeSet result =
        NodeSetHelper.selectParentChild(speakers, largeSet.toNodeSet(), NodeSet.DESCENDANT, -1);
    assertEquals(187, result.getLength());
  }
Ejemplo n.º 11
0
  @Test
  public void selectAncestorDescendant()
      throws XPathException, SAXException, PermissionDeniedException {
    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
    NodeSet speakers =
        broker
            .getStructuralIndex()
            .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
    Sequence outerSet =
        executeQuery(broker, "//SCENE/TITLE[fn:contains(., 'closet')]/ancestor::SCENE", 1, null);

    NodeSet result =
        speakers.selectAncestorDescendant(
            outerSet.toNodeSet(), NodeSet.DESCENDANT, false, -1, true);
    assertEquals(56, result.getLength());
  }
Ejemplo n.º 12
0
  @Test
  public void selectParentChild() throws XPathException, SAXException, PermissionDeniedException {

    NameTest test = new NameTest(Type.ELEMENT, new QName("SPEAKER", ""));
    NodeSet speakers =
        broker
            .getStructuralIndex()
            .findElementsByTagName(ElementValue.ELEMENT, docs, test.getName(), null);
    Sequence smallSet =
        executeQuery(
            broker, "//SPEECH/LINE[fn:contains(., 'perturbed spirit')]/ancestor::SPEECH", 1, null);

    NodeSet result =
        NodeSetHelper.selectParentChild(speakers, smallSet.toNodeSet(), NodeSet.DESCENDANT, -1);
    assertEquals(1, result.getLength());
    String value = serialize(broker, result.itemAt(0));
    assertEquals(value, "<SPEAKER>HAMLET</SPEAKER>");
  }
Ejemplo n.º 13
0
  @Test
  public void testOptimizations() throws XPathException, SAXException, PermissionDeniedException {

    Serializer serializer = broker.getSerializer();
    serializer.reset();
    DocumentSet docs = root.allDocs(broker, new DefaultDocumentSet(), true);

    System.out.println("------------ Testing NativeElementIndex.findChildNodesByTagName ---------");
    // parent set: 1.1.1; child set: 1.1.1.1, 1.1.1.2, 1.1.1.3, 1.1.2.1, 1.2.1
    ExtNodeSet nestedSet = (ExtNodeSet) executeQuery(broker, "//section[@n = '1.1.1']", 1, null);
    NodeSet children =
        broker
            .getStructuralIndex()
            .findDescendantsByTagName(
                ElementValue.ELEMENT,
                new QName("para", ""),
                Constants.CHILD_AXIS,
                docs,
                nestedSet,
                -1);
    assertEquals(3, children.getLength());

    // parent set: 1.1; child set: 1.1.1, 1.1.2
    nestedSet = (ExtNodeSet) executeQuery(broker, "//section[@n = '1.1']", 1, null);
    children =
        broker
            .getStructuralIndex()
            .findDescendantsByTagName(
                ElementValue.ELEMENT,
                new QName("section", ""),
                Constants.CHILD_AXIS,
                docs,
                nestedSet,
                -1);
    assertEquals(2, children.getLength());

    // parent set: 1, 1.1, 1.1.1, 1.1.2 ; child set: 1.1.1.1, 1.1.1.2, 1.1.1.3, 1.1.2.1, 1.2.1
    // problem: ancestor set contains nested nodes
    nestedSet =
        (ExtNodeSet) executeQuery(broker, "//section[@n = ('1.1', '1.1.1', '1.1.2')]", 3, null);
    children =
        broker
            .getStructuralIndex()
            .findDescendantsByTagName(
                ElementValue.ELEMENT,
                new QName("para", ""),
                Constants.CHILD_AXIS,
                docs,
                nestedSet,
                -1);
    assertEquals(4, children.getLength());

    // parent set: 1.1, 1.1.2, 1.2 ; child set: 1.1.1.1, 1.1.1.2, 1.1.1.3, 1.1.2.1, 1.2.1
    // problem: ancestor set contains nested nodes
    nestedSet =
        (ExtNodeSet) executeQuery(broker, "//section[@n = ('1.1', '1.1.2', '1.2')]", 3, null);
    children =
        broker
            .getStructuralIndex()
            .findDescendantsByTagName(
                ElementValue.ELEMENT,
                new QName("para", ""),
                Constants.CHILD_AXIS,
                docs,
                nestedSet,
                -1);
    assertEquals(2, children.getLength());

    nestedSet = (ExtNodeSet) executeQuery(broker, "//section[@n = '1.1']", 1, null);
    children =
        broker
            .getStructuralIndex()
            .findDescendantsByTagName(
                ElementValue.ELEMENT,
                new QName("para", ""),
                Constants.DESCENDANT_AXIS,
                docs,
                nestedSet,
                -1);
    assertEquals(4, children.getLength());

    nestedSet = (ExtNodeSet) executeQuery(broker, "//section[@n = '1']", 1, null);
    children =
        broker
            .getStructuralIndex()
            .findDescendantsByTagName(
                ElementValue.ELEMENT,
                new QName("para", ""),
                Constants.DESCENDANT_AXIS,
                docs,
                nestedSet,
                -1);
    assertEquals(5, children.getLength());

    nestedSet = (ExtNodeSet) executeQuery(broker, "//section[@n = '1.1.2']", 1, null);
    children =
        broker
            .getStructuralIndex()
            .findDescendantsByTagName(
                ElementValue.ELEMENT,
                new QName("section", ""),
                Constants.DESCENDANT_SELF_AXIS,
                docs,
                nestedSet,
                -1);
    assertEquals(1, children.getLength());

    nestedSet = (ExtNodeSet) executeQuery(broker, "//section[@n = '1.1.2']", 1, null);
    children =
        broker
            .getStructuralIndex()
            .findDescendantsByTagName(
                ElementValue.ATTRIBUTE,
                new QName("n", ""),
                Constants.ATTRIBUTE_AXIS,
                docs,
                nestedSet,
                -1);
    assertEquals(1, children.getLength());

    nestedSet = (ExtNodeSet) executeQuery(broker, "//section[@n = '1.1']", 1, null);
    children =
        broker
            .getStructuralIndex()
            .findDescendantsByTagName(
                ElementValue.ATTRIBUTE,
                new QName("n", ""),
                Constants.DESCENDANT_ATTRIBUTE_AXIS,
                docs,
                nestedSet,
                -1);
    assertEquals(7, children.getLength());

    System.out.println("------------ PASSED: NativeElementIndex.findChildNodesByTagName ---------");
  }