Example #1
0
 @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);
 }
Example #2
0
  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);
  }
Example #3
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;
 }