Package javax.xml.stream.events

Examples of javax.xml.stream.events.Namespace


  public org.dom4j.Namespace readNamespace(XMLEventReader reader)
      throws XMLStreamException {
    XMLEvent event = reader.peek();

    if (event.isNamespace()) {
      Namespace ns = (Namespace) reader.nextEvent();

      return createNamespace(ns);
    } else {
      throw new XMLStreamException("Expected Namespace event, found: "
          + event);
View Full Code Here


      elem.addAttribute(createQName(attr.getName()), attr.getValue());
    }

    // create namespaces
    for (Iterator i = startEvent.getNamespaces(); i.hasNext();) {
      Namespace ns = (Namespace) i.next();
      elem.addNamespace(ns.getPrefix(), ns.getNamespaceURI());
    }

    return elem;
  }
View Full Code Here

    }
   
    private static void printNamespaces(Iterator ni){
        while(ni.hasNext()){
            System.out.print(" ");
            Namespace n = (Namespace) ni.next();
            printNamespace(n);
        }
    }
View Full Code Here

        QName name = elem.getName();
        @SuppressWarnings("unchecked")
        Iterator<Namespace> it = elem.getNamespaces();
       
        while (it.hasNext()) {
            Namespace ns = 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:
        @SuppressWarnings("unchecked")
        Iterator<Namespace> it2 = elem.getNamespaces();
        while (it2.hasNext()) {
            Namespace ns = it2.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:
        @SuppressWarnings("unchecked")
View Full Code Here

    {
        // Note: base class checks for 'known' problems and prefixes:
        if (mNsByPrefix == null) {
            mNsByPrefix = buildByPrefixMap();
        }
        Namespace ns = mNsByPrefix.get(prefix);
        if (ns == null && mParentCtxt != null) {
            return mParentCtxt.getNamespaceURI(prefix);
        }
        return (ns == null) ? null : ns.getNamespaceURI();
    }
View Full Code Here

    {
        // Note: base class checks for 'known' problems and prefixes:
        if (mNsByURI == null) {
            mNsByURI = buildByNsURIMap();
        }
        Namespace ns = mNsByURI.get(nsURI);
        if (ns == null && mParentCtxt != null) {
            return mParentCtxt.getPrefix(nsURI);
        }
        return (ns == null) ? null : ns.getPrefix();
    }
View Full Code Here

    {
        // Note: base class checks for 'known' problems and prefixes:
        ArrayList<String> l = null;

        for (int i = 0, len = mNamespaces.size(); i < len; ++i) {
            Namespace ns = mNamespaces.get(i);
            String uri = ns.getNamespaceURI();
            if (uri == null) {
                uri = "";
            }
            if (uri.equals(nsURI)) {
                if (l == null) {
                    l = new ArrayList<String>();
                }
                String prefix = ns.getPrefix();
                l.add((prefix == null) ? "" : prefix);
            }
        }

        if (mParentCtxt != null) {
View Full Code Here

    }

    public void outputNamespaceDeclarations(Writer w) throws IOException
    {
        for (int i = 0, len = mNamespaces.size(); i < len; ++i) {
            Namespace ns = mNamespaces.get(i);
            w.write(' ');
            w.write(XMLConstants.XMLNS_ATTRIBUTE);
            if (!ns.isDefaultNamespaceDeclaration()) {
                w.write(':');
                w.write(ns.getPrefix());
            }
            w.write("=\"");
            w.write(ns.getNamespaceURI());
            w.write('"');
        }
    }
View Full Code Here

     * scope, if any.
     */
    public void outputNamespaceDeclarations(XMLStreamWriter w) throws XMLStreamException
    {
        for (int i = 0, len = mNamespaces.size(); i < len; ++i) {
            Namespace ns = mNamespaces.get(i);
            if (ns.isDefaultNamespaceDeclaration()) {
                w.writeDefaultNamespace(ns.getNamespaceURI());
            } else {
                w.writeNamespace(ns.getPrefix(), ns.getNamespaceURI());
            }
        }
    }
View Full Code Here

            return Collections.emptyMap();
        }

        LinkedHashMap<String,Namespace> m = new LinkedHashMap<String,Namespace>(1 + len + (len>>1));
        for (int i = 0; i < len; ++i) {
            Namespace ns = mNamespaces.get(i);
            String prefix = ns.getPrefix();
            if (prefix == null) { // shouldn't happen but...
                prefix = "";
            }
            m.put(prefix, ns);
        }
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.