private static final void checkIterators(
      NamespaceStack stack, List<Namespace> lscope, List<Namespace> lintro) {

    Namespace[] scope = lscope.toArray(new Namespace[0]);
    checkIterable(stack, scope);
    Namespace[] intro = lintro.toArray(new Namespace[0]);
    checkIterable(stack.addedForward(), intro);
    reverse(intro);
    checkIterable(stack.addedReverse(), intro);
  }
 @Test
 public void testSeededConstructor() {
   Namespace x = Namespace.getNamespace("X");
   Namespace y = Namespace.getNamespace("y", "Y");
   Namespace[] nsa = new Namespace[] {x, Namespace.XML_NAMESPACE};
   NamespaceStack nstack = new NamespaceStack(nsa);
   checkIterable(nstack, nsa);
   checkIterable(nstack.addedForward(), nsa);
   Element emt = new Element("root", y);
   emt.addNamespaceDeclaration(Namespace.NO_NAMESPACE);
   nstack.push(emt);
   checkIterable(nstack, y, Namespace.NO_NAMESPACE, Namespace.XML_NAMESPACE);
   checkIterable(nstack.addedForward(), y, Namespace.NO_NAMESPACE);
 }
Exemple #3
0
 public JAttribute find(final org.jdom2.Attribute att) {
   final JNamespaceAware me = mapped.get(att);
   if (me != null) {
     return (JAttribute) me;
   }
   final org.jdom2.Element jp = att.getParent();
   final JParent pnt = jp == null ? this : find(jp);
   final NamespaceStack ns =
       jp == null ? new NamespaceStack() : new NamespaceStack(find(jp).scope);
   ns.push(att);
   final JAttribute ret = new JAttribute(this, pnt, att, ns.getScope());
   mapped.put(att, ret);
   return ret;
 }
  @Test
  public void testEmptyStack() {
    Namespace[] scopea = new Namespace[] {Namespace.NO_NAMESPACE, Namespace.XML_NAMESPACE};
    List<Namespace> scopel = Arrays.asList(scopea);

    NamespaceStack stack = new NamespaceStack();

    checkIterators(stack, scopel, scopel);

    try {
      stack.pop();
      fail("Should not be able to over-pop the stack.");
    } catch (IllegalStateException ise) {
      // good.
    } catch (Exception e) {
      e.printStackTrace();
      fail("Expected IllegalStateException but got " + e.getClass());
    }
  }
  private void exercise(Element emt, NamespaceStack stack) {
    List<Namespace> scope = emt.getNamespacesInScope();
    List<Namespace> intro = emt.getNamespacesIntroduced();

    for (Namespace ns : intro) {
      assertFalse(stack.isInScope(ns));
    }

    stack.push(emt);

    for (Namespace ns : intro) {
      assertTrue(stack.isInScope(ns));
    }

    checkIterators(stack, scope, intro);

    for (Element e : emt.getChildren()) {
      exercise(e, stack);
    }

    checkIterators(stack, scope, intro);
    stack.pop();
  }
Exemple #6
0
 public JElement find(final org.jdom2.Element emt) {
   final JNamespaceAware me = mapped.get(emt);
   if (me != null) {
     return (JElement) me;
   }
   final org.jdom2.Element jp = emt.getParentElement();
   if (jp == null) {
     // root level element (or detached).
     final org.jdom2.Document jd = emt.getDocument();
     // both may be null....
     if (jd != shadow) {
       // we are from different documents...
       throw new DOMException(
           DOMException.WRONG_DOCUMENT_ERR, "Element is not part of our document");
     }
     // OK, we are a root level Element... let's map ourselves.
     final NamespaceStack ns = new NamespaceStack(scope);
     ns.push(emt);
     final ArrayList<Namespace> added = new ArrayList<Namespace>();
     for (final Namespace ans : ns.addedForward()) {
       added.add(ans);
     }
     final JElement je =
         new JElement(this, this, emt, ns.getScope(), added.toArray(new Namespace[added.size()]));
     mapped.put(emt, je);
     checkID(je);
     return je;
   }
   final JElement pnt = find(jp);
   final NamespaceStack ns = new NamespaceStack(pnt.scope);
   ns.push(emt);
   final ArrayList<Namespace> added = new ArrayList<Namespace>();
   for (final Namespace ans : ns.addedForward()) {
     added.add(ans);
   }
   final JElement ret =
       new JElement(this, pnt, emt, ns.getScope(), added.toArray(new Namespace[added.size()]));
   mapped.put(emt, ret);
   checkID(ret);
   return ret;
 }