protected XmlNamespaceContext(ResourceBundle bundle) { this(); Enumeration<String> en = bundle.getKeys(); while (en.hasMoreElements()) { String prefix = en.nextElement(); String namespace = bundle.getString(prefix); addNamespace(prefix, namespace); } }
private void writeNamespaceDeclarations(XmlNamespaceContext context) throws SAXException { Set<String> keys = new TreeSet<>(context.getNamespaces().keySet()); if (root != null && !keys.contains(root.getPrefix())) { contentHandler.startPrefixMapping(root.getPrefix(), root.getNamespaceURI()); } for (String prefix : keys) { contentHandler.startPrefixMapping(prefix, context.getNamespaceURI(prefix)); } }
public static XmlNamespaceContext newDefaultInstance() { return newInstance(DEFAULT_RESOURCE); }
public XmlXParams(QName root, XmlNamespaceContext namespaceContext, XmlFactory xmlFactory) { this.namespaceContext = namespaceContext == null ? XmlNamespaceContext.newInstance() : namespaceContext; this.xmlFactory = xmlFactory == null ? createXmlFactory(createXMLInputFactory(), createXMLOutputFactory()) : xmlFactory; this.root = root == null ? new QName("root") : root; String prefix = this.root.getPrefix(); if (prefix != null && !prefix.isEmpty()) { this.namespaceContext.addNamespace(prefix, this.root.getNamespaceURI()); } }
ns = context.getNamespaceURI(""); } else { sb.append(ch); ns = context.getNamespaceURI(sb.toString()); if (ns == null) { throw new IOException(baseIRI + ": namespace not found: " + sb.toString());
/** * Empty namespace context. * * @return an XML namespace context */ public static XmlNamespaceContext newInstance() { return new XmlNamespaceContext(); }
@Override public String getPrefix(String namespaceURI) { Iterator<String> it = getPrefixes(namespaceURI); return it != null && it.hasNext() ? it.next() : null; }
public JsonXmlStreamer() { context = XmlNamespaceContext.newDefaultInstance(); root = new QName("root"); eventFactory = XMLEventFactory.newInstance(); outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty("javax.xml.stream.isNamespaceAware", Boolean.TRUE); jsonFactory = new JsonFactory(); elements = new ArrayDeque<>(); }
public static XmlNamespaceContext newInstance(String bundleName, Locale locale, ClassLoader classLoader) { try { return new XmlNamespaceContext(ResourceBundle.getBundle(bundleName, locale, classLoader)); } catch (MissingResourceException e) { logger.log(Level.WARNING, e.getMessage(), e); return new XmlNamespaceContext(); } }
@Override public void addNamespace(String prefix, String namespace) { super.addNamespace(prefix, namespace); synchronized (lock) { sortedNamespacesByPrefixLength = new ArrayList<>(getNamespaces().values()); // sort from longest to shortest prefix for successful matching sortedNamespacesByPrefixLength.sort((s1, s2) -> { Integer l1 = s1.length(); Integer l2 = s2.length(); return l2.compareTo(l1); }); } }
@Override public void writeStartObject() throws IOException { if (!rootUsed) { generator.setNextName(params.getRoot()); } generator.writeStartObject(); if (!rootUsed) { try { for (String prefix : params.getNamespaceContext().getNamespaces().keySet()) { String uri = params.getNamespaceContext().getNamespaceURI(prefix); if (uri == null || uri.isEmpty()) { continue; } generator.getStaxWriter().writeNamespace(prefix, uri); } } catch (XMLStreamException e) { logger.log(Level.SEVERE, e.getMessage(), e); } rootUsed = true; } }
/** * Use thread context class laoder to instantiate a namespace context. * @param bundleName the resource bundle name * @return XML namespace context */ public static XmlNamespaceContext newInstance(String bundleName) { return newInstance(bundleName, Locale.getDefault(), Thread.currentThread().getContextClassLoader()); }
public IRINamespaceContext add(Map<String, String> map) { for (Map.Entry<String, String> e : map.entrySet()) { super.addNamespace(e.getKey(), e.getValue()); } synchronized (lock) { sortedNamespacesByPrefixLength = new ArrayList<>(getNamespaces().values()); // sort from longest to shortest prefix for successful matching sortedNamespacesByPrefixLength.sort((s1, s2) -> { Integer l1 = s1.length(); Integer l2 = s2.length(); return l2.compareTo(l1); }); } return this; }
consumer.add(eventFactory.createStartElement(qname, null, null)); if (namespaceDecls) { if (!context.getNamespaces().containsKey(qname.getPrefix())) { consumer.add(eventFactory.createNamespace(qname.getPrefix(), qname.getNamespaceURI())); for (String prefix : context.getNamespaces().keySet()) { String namespaceURI = context.getNamespaceURI(prefix); consumer.add(eventFactory.createNamespace(prefix, namespaceURI));
this.baseIRI = nsURI; context.addNamespace(prefix, nsURI.toString()); } else if ("@base".equalsIgnoreCase(directive)) { this.baseIRI = parseURI();