Package javax.xml.stream.events

Examples of javax.xml.stream.events.Namespace


        }

        // Add namspace declarations if required
        if (this.filter.getNamespacePrefixes()) {
            for (Iterator i = event.getNamespaces(); i.hasNext();) {
                Namespace staxNamespace = (javax.xml.stream.events.Namespace) i.next();
                String uri = staxNamespace.getNamespaceURI();
                if (uri == null) {
                    uri = "";
                }

                String prefix = staxNamespace.getPrefix();
                if (prefix == null) {
                    prefix = "";
                }

                String qName = "xmlns";
View Full Code Here


            Iterator prefixes = this.namespaces.getDeclaredPrefixes();
            while (prefixes.hasNext()) {
                String prefix = (String) prefixes.next();
                String uri = this.namespaces.getNamespaceURI(prefix);

                Namespace ns = this.createNamespace(prefix, uri);
                if (nsMap == null) {
                    nsMap = new HashMap();
                }
                nsMap.put(prefix, ns);
            }
        }

        // create attributes
        String[] qname = { null, null };
        for (int i = 0, s = attributes.getLength(); i < s; i++) {

            this.parseQName(attributes.getQName(i), qname);

            String attrPrefix = qname[0];
            String attrLocal = qname[1];

            String attrQName = attributes.getQName(i);
            String attrValue = attributes.getValue(i);
            String attrURI = attributes.getURI(i);

            if ("xmlns".equals(attrQName) || "xmlns".equals(attrPrefix)) {

                // namespace declaration disguised as an attribute. If the
                // namespace has already been declared, skip it, otherwise
                // write it as an namespace

                if (!nsMap.containsKey(attrPrefix)) {
                    Namespace ns = this.createNamespace(attrPrefix, attrValue);
                    if (nsMap == null) {
                        nsMap = new HashMap();
                    }
                    nsMap.put(attrPrefix, ns);
                }
View Full Code Here

  @SuppressWarnings("unchecked")
  public String getNamespacePrefix(int index) {
    Iterator<Namespace> itr = current.asStartElement().getNamespaces();
    int level = 0;
    Namespace ns = null;
    while (itr.hasNext()) {
      ns = itr.next();
      if (level == index) {
        return ns.getPrefix();
      }
      level++;
    }
    return null;
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  public String getNamespaceURI(int index) {
    Iterator<Namespace> itr = current.asStartElement().getNamespaces();
    int level = 0;
    Namespace ns = null;
    while (itr.hasNext()) {
      ns = itr.next();
      if (level == index) {
        return ns.getNamespaceURI();
      }
      level++;
    }
    return null;
  }
View Full Code Here

        }
       
        // Add namspace declarations if required
        if (filter.getNamespacePrefixes()) {
            for (Iterator i = event.getNamespaces(); i.hasNext();) {
                Namespace staxNamespace = (javax.xml.stream.events.Namespace)i.next();
                String uri = staxNamespace.getNamespaceURI();
                if (uri==null) uri="";
               
                String prefix = staxNamespace.getPrefix();
                if (prefix==null) prefix="";
               
                String qName = "xmlns";
                if (prefix.length() == 0) {
                    prefix = qName;
View Full Code Here

    {
        QName name = elem.getName();
        Iterator it = elem.getNamespaces();
       
        while (it.hasNext()) {
            Namespace ns = (Namespace) it.next();
            // First need to 'declare' namespace:
            String prefix = ns.getPrefix();
            if (prefix == null || prefix.length() == 0) {
                setDefaultNamespace(ns.getNamespaceURI());
            } else {
                setPrefix(prefix, ns.getNamespaceURI());
            }
        }

        /* Outputting element itself is fairly easy. The main question
         * is whether namespaces match. Let's use simple heuristics:
         * if writer is to do automatic prefix matching, let's only
         * pass explicit prefix (not default one); otherwise we'll
         * pass all parameters as is.
         */
        /* Quick check first though: if URI part of QName is null, it's
         * assumed element will just use whatever is current default
         * namespace....
         */
        String nsURI = name.getNamespaceURI();
        if (nsURI == null) {
            writeStartElement(name.getLocalPart());
        } else {
            String prefix = name.getPrefix();
            writeStartElement(prefix, name.getLocalPart(), nsURI);
        }

        // And now we need to output namespaces (including default), if any:
        it = elem.getNamespaces();
        while (it.hasNext()) {
            Namespace ns = (Namespace) it.next();
            String prefix = ns.getPrefix();
            if (prefix == null || prefix.length() == 0) {
                writeDefaultNamespace(ns.getNamespaceURI());
            } else {
                writeNamespace(prefix, ns.getNamespaceURI());
            }
        }
   

        // And finally, need to output attributes as well:
View Full Code Here

            }
        }
       
        if(_namespaces != null){
            Iterator it = _namespaces.iterator();
            Namespace attr = null;
            while(it.hasNext()){
                attr = (Namespace)it.next();
                s = s + " " + attr.toString();
            }
        }
        s = s + ">";
        return s;
    }
View Full Code Here

    }
   
    public void addNamespaces(Iterator namespaces){
        if(namespaces != null) {
            while(namespaces.hasNext()){
                Namespace namespace = (Namespace)namespaces.next();
                _namespaces.add(namespace);
            }           
        }
    }
View Full Code Here

    }

    private void handleStartElement(StartElement event) throws SAXException {
        // start namespace bindings
        for (Iterator i = event.getNamespaces(); i.hasNext();) {
            Namespace ns = (Namespace)i.next();
            visitor.startPrefixMapping(
                fixNull(ns.getPrefix()),
                fixNull(ns.getNamespaceURI()));
        }

        // fire startElement
        QName qName = event.getName();
        tagName.uri = fixNull(qName.getNamespaceURI());
View Full Code Here

   private void registerNamespaces(StartElement event)
   {
      Iterator<Namespace> iter = event.getNamespaces();
      while (iter.hasNext())
      {
         Namespace namespace = iter.next();
         importer.registerNamespace(namespace.getPrefix(), namespace.getNamespaceURI());
      }
   }
View Full Code Here

TOP

Related Classes of javax.xml.stream.events.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.