Ejemplo n.º 1
0
  void removeNamespace(Namespace namespace) {
    Namespace current = getNodeNamespace();

    //    Do not remove in-use namespace
    if (namespace.is(current)) return;
    NamedNodeMap attrs = this.dom.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
      XmlNode attr = XmlNode.createImpl(attrs.item(i));
      if (namespace.is(attr.getNodeNamespace())) return;
    }

    //    TODO    I must confess I am not sure I understand the spec fully.  See ECMA357 13.4.4.31
    String existingPrefix = getExistingPrefixFor(namespace);
    if (existingPrefix != null) {
      if (namespace.isUnspecifiedPrefix()) {
        //    we should remove any namespace with this URI from scope; we do this by declaring a
        // namespace with the same
        //    prefix as the existing prefix and setting its URI to the default namespace
        declareNamespace(existingPrefix, getDefaultNamespace().getUri());
      } else {
        if (existingPrefix.equals(namespace.getPrefix())) {
          declareNamespace(existingPrefix, getDefaultNamespace().getUri());
        }
      }
    } else {
      //    the argument namespace is not declared in this scope, so do nothing.
    }
  }
Ejemplo n.º 2
0
 private static XmlNode createImpl(Node node) {
   if (node instanceof Document) throw new IllegalArgumentException();
   XmlNode rv = null;
   if (getUserData(node) == null) {
     rv = new XmlNode();
     rv.dom = node;
     setUserData(node, rv);
   } else {
     rv = getUserData(node);
   }
   return rv;
 }
Ejemplo n.º 3
0
  /**
   * Constructor that defines name and connects to specified parent element.
   *
   * @param name
   * @param parent
   */
  protected XmlNode(String name, XmlNode parent) {
    super();

    this.name = adaptName(name);
    this.parent = parent;

    if (parent != null) {
      parent.addElement(this);
    }
  }
Ejemplo n.º 4
0
 void addMatchingChildren(XMLList result, XmlNode.Filter filter) {
   Node node = this.dom;
   NodeList children = node.getChildNodes();
   for (int i = 0; i < children.getLength(); i++) {
     Node childnode = children.item(i);
     XmlNode child = XmlNode.createImpl(childnode);
     if (filter.accept(childnode)) {
       result.addToList(child);
     }
   }
 }
Ejemplo n.º 5
0
  private void print(int level) {
    for (int i = 0; i < level; i++) {
      System.out.print("     ");
    }
    System.out.print(name + ": " + attributes + ": TEXT = [" + textBuff + "]\n");

    Iterator it = elementList.iterator();
    while (it.hasNext()) {
      Object element = it.next();
      if (element instanceof XmlNode) {
        XmlNode childNode = (XmlNode) element;
        childNode.print(level + 1);
      } else {
        for (int i = 0; i <= level; i++) {
          System.out.print("     ");
        }
        System.out.println((String) element);
      }
    }
  }
Ejemplo n.º 6
0
  /**
   * Adds new subelement.
   *
   * @param elementNode
   */
  public void addElement(XmlNode elementNode) {
    flushText();

    String elementName = elementNode.getName();

    if (!this.containsKey(elementName)) {
      this.put(elementName, new ArrayList());
    }

    ArrayList elementsForName = (ArrayList) this.get(elementName);
    elementsForName.add(elementNode);

    elementList.add(elementNode);
  }
Ejemplo n.º 7
0
 static XmlNode newElementWithText(
     XmlProcessor processor, XmlNode reference, XmlNode.QName qname, String value) {
   if (reference instanceof org.w3c.dom.Document)
     throw new IllegalArgumentException("Cannot use Document node as reference");
   Document document = null;
   if (reference != null) {
     document = reference.dom.getOwnerDocument();
   } else {
     document = processor.newDocument();
   }
   Node referenceDom = (reference != null) ? reference.dom : null;
   Element e = document.createElementNS(qname.getUri(), qname.qualify(referenceDom));
   if (value != null) {
     e.appendChild(document.createTextNode(value));
   }
   return XmlNode.createImpl(e);
 }