Package org.dom4j

Examples of org.dom4j.Namespace


    protected void marshalElement(Element element)
        throws JiBXException, IOException {
       
        // accumulate all needed namespace declarations
        int size = element.nodeCount();
        Namespace ns = element.getNamespace();
        int nsi = findNamespaceIndex(ns);
        ArrayList nss = null;
        boolean hascontent = false;
        int defind = -1;
        String defuri = null;
        for (int i = 0; i < size; i++) {
            Node node = element.node(i);
            if (node instanceof Namespace) {
                Namespace dns = (Namespace)node;
                if (findNamespaceIndex(dns) < 0) {
                    if (nss == null) {
                        nss = new ArrayList();
                    }
                    nss.add(dns);
                    String prefix = dns.getPrefix();
                    if (prefix == null || prefix.length() == 0) {
                        defind = nss.size() - 1;
                        defuri = dns.getURI();
                    }
                }
            } else {
                hascontent = true;
            }
        }
       
        // check for namespace declarations required
        String[] uris = null;
        if (nss == null) {
            m_xmlWriter.startTagOpen(nsi, element.getName());
        } else {
            int base = getNextNamespaceIndex();
            if (defind >= 0) {
                m_defaultNamespaceIndex = base + defind;
                m_defaultNamespaceURI = defuri;
            }
            uris = new String[nss.size()];
            int[] nums = new int[nss.size()];
            String[] prefs = new String[nss.size()];
            for (int i = 0; i < uris.length; i++) {
                Namespace addns = (Namespace)nss.get(i);
                uris[i] = addns.getURI();
                nums[i] = base + i;
                prefs[i] = addns.getPrefix();
                if (nsi < 0 && ns.equals(addns)) {
                    nsi = base + i;
                }
            }
            m_xmlWriter.pushExtensionNamespaces(uris);
View Full Code Here


   * @return the namespace for the given prefix and uri
   */
  public Namespace get(String prefix, String uri) {
    Map uriCache = getURICache(uri);
    WeakReference ref = (WeakReference) uriCache.get(prefix);
    Namespace answer = null;

    if (ref != null) {
      answer = (Namespace) ref.get();
    }

View Full Code Here

   * @param uri DOCUMENT ME!
   * @return the name model for the given name and namepsace
   */
  public Namespace get(String uri) {
    WeakReference ref = (WeakReference) noPrefixCache.get(uri);
    Namespace answer = null;

    if (ref != null) {
      answer = (Namespace) ref.get();
    }

View Full Code Here

   * @param prefix DOCUMENT ME!
   * @param uri    DOCUMENT ME!
   * @return a newly created {@link Namespace}instance.
   */
  protected Namespace createNamespace(String prefix, String uri) {
    return new Namespace(prefix, uri);
  }
View Full Code Here

    if (prefix == null) {
      prefix = "";
    }

    for (int i = namespaceStack.size() - 1; i >= 0; i--) {
      Namespace namespace = (Namespace) namespaceStack.get(i);

      if (prefix.equals(namespace.getPrefix())) {
        return namespace;
      }
    }

    return null;
View Full Code Here

   *
   * @param prefix DOCUMENT ME!
   * @return the URI for the given prefix or null if it could not be found.
   */
  public String getURI(String prefix) {
    Namespace namespace = getNamespaceForPrefix(prefix);

    return (namespace != null) ? namespace.getURI() : null;
  }
View Full Code Here

   * @param namespace DOCUMENT ME!
   * @return true if the given prefix is in the stack.
   */
  public boolean contains(Namespace namespace) {
    String prefix = namespace.getPrefix();
    Namespace current = null;

    if ((prefix == null) || (prefix.length() == 0)) {
      current = getDefaultNamespace();
    } else {
      current = getNamespaceForPrefix(prefix);
    }

    if (current == null) {
      return false;
    }

    if (current == namespace) {
      return true;
    }

    return namespace.getURI().equals(current.getURI());
  }
View Full Code Here

      }
    } else if (localName.trim().length() == 0) {
      localName = qualifiedName;
    }

    Namespace namespace = createNamespace(prefix, namespaceURI);

    return pushQName(localName, qualifiedName, namespace, prefix);
  }
View Full Code Here

    if (namespaceURI == null) {
      namespaceURI = "";
    }

    Namespace namespace = null;
    String prefix = "";
    int index = qualifiedName.indexOf(":");

    if (index > 0) {
      prefix = qualifiedName.substring(0, index);
View Full Code Here

  public void push(String prefix, String uri) {
    if (uri == null) {
      uri = "";
    }

    Namespace namespace = createNamespace(prefix, uri);
    push(namespace);
  }
View Full Code Here

TOP

Related Classes of org.dom4j.Namespace

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.