@Test public void testGetDeclaredNamespaces() { try { rootNode.getDeclaredNamespaces( new NamespaceBinding[] {new NamespaceBinding("prefix", "uri")}); fail("Exception is excepted"); } catch (UnsupportedOperationException ex) { assertEquals( "Invalid exception message", "Operation is not supported", ex.getMessage()); } }
/** * Test if this namespace binding is the same as another * * @param obj the comparand * @return true if the comparand is a Namespace binding of the same prefix to the same URI */ @Override public boolean equals(Object obj) { return obj instanceof NamespaceBinding && prefix.equals(((NamespaceBinding) obj).getPrefix()) && uri.equals(((NamespaceBinding) obj).getURI()); }
if (nsBinding.isXmlNamespace()) { String prefix = nsBinding.getPrefix(); if (pendingUndeclarations != null) { for (int p = 0; p < pendingUndeclarations.length; p++) { NamespaceBinding nb = pendingUndeclarations[p]; if (nb != null && prefix.equals(nb.getPrefix())) { pendingUndeclarations[p] = null; if (namespaces[i].equals(nsBinding)) { if (namespaces[i].getPrefix().equals(nsBinding.getPrefix())) { return !nsBinding.isDefaultUndeclaration();
distinctNamespaces.put(nb.getPrefix(), nb.getURI()); bindings.add(new NamespaceBinding(entry.getKey(), entry.getValue()));
/** * Get the local part of the name of this node. This is the name after the ":" if any. * * @return the local part of the name. For an unnamed node, returns "". Unlike the DOM * interface, this returns the full name in the case of a non-namespaced name. */ public String getLocalPart() { return nsBinding.getPrefix(); }
/** * startContent: Add any namespace undeclarations needed to stop * namespaces being inherited from parent elements */ public void startContent() throws XPathException { if (pendingUndeclarations != null) { for (NamespaceBinding ns : pendingUndeclarations) { if (ns != null) { namespace(new NamespaceBinding(ns.getPrefix(), ""), 0); // relies on the namespace() method to prevent duplicate undeclarations } } } pendingUndeclarations = null; nextReceiver.startContent(); }
private void addNamespaceInternal(/*@NotNull*/ NamespaceBinding nscode, boolean externalCall) { if (namespaceList == null) { namespaceList = new NamespaceBinding[]{nscode}; } else { NamespaceBinding[] nsList = namespaceList; for (int i = 0; i < nsList.length; i++) { if (nsList[i].equals(nscode)) { return; } if (nsList[i].getPrefix().equals(nscode.getPrefix())) { if (nsList[i].getURI().isEmpty()) { // this is an undeclaration; replace it with the new declaration nsList[i] = nscode; return; } else if (externalCall) { throw new IllegalArgumentException("New namespace conflicts with existing namespace binding"); } else { return; } } } int len = nsList.length; NamespaceBinding[] ns2 = new NamespaceBinding[len + 1]; System.arraycopy(nsList, 0, ns2, 0, len); ns2[len] = nscode; namespaceList = ns2; } }
throw NoOpenStartTagException.makeNoOpenStartTagException( Type.NAMESPACE, ns.getPrefix(), hostLanguage, currentLevelIsDocument[level], if (ns.getPrefix().equals(pendingNSList[i].getPrefix())) { if (ns.getURI().equals(pendingNSList[i].getURI())) { return; // duplicate namespace, no action needed if (pendingNSList[i].isDefaultUndeclaration() || ns.isDefaultUndeclaration()) { String prefix = ns.getPrefix(); String uri1 = ns.getURI(); String uri2 = pendingNSList[i].getURI(); XPathException err = new XPathException("Cannot create two namespace nodes with the same prefix mapped to different URIs (prefix=" + (prefix.isEmpty() ? "\"\"" : prefix) + ", URI=" + if (ns.getPrefix().isEmpty() && !ns.getURI().isEmpty()) { declaresDefaultNamespace = true; if (elementIsInNullNamespace == null) {
/** * Return the string value of the node. The interpretation of this depends on the type * of node. For a namespace node, it is the namespace URI. * * @return the string value of the node */ public String getStringValue() { return nsBinding.getURI(); }
public void namespace(NamespaceBindingSet namespaceBindings, int properties) throws XPathException { for (NamespaceBinding ns : namespaceBindings) { if (!acceptAttributes) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.NAMESPACE, ns.getPrefix(), getPipelineConfiguration().getHostLanguage(), inDocument, ExplicitLocation.UNKNOWN_LOCATION); } // avoid duplicates for (int n = 0; n < countStack[depth - 1]; n++) { if (namespaces[namespacesSize - 1 - n].equals(namespaceBindings)) { return; } } addToStack(ns); countStack[depth - 1]++; } }
/** * Get a {@link net.sf.saxon.om.NamespaceBinding} whose (prefix, uri) pair are the prefix and URI of this * node name * * @return the corresponding NamespaceBinding */ public NamespaceBinding getNamespaceBinding() { return NamespaceBinding.makeNamespaceBinding(getPrefix(), getURI()); }
/** * Determine whether this is the same node as another node. * Note: a.equals(b) if and only if generateId(a)==generateId(b). * This method has the same semantics as isSameNode() in DOM Level 3, but * works on Saxon NodeInfo objects rather than DOM Node objects. * * @param other the node to be compared with this node * @return true if this NodeInfo object and the supplied NodeInfo object represent * the same node in the tree. */ public boolean equals(Object other) { return other instanceof NamespaceNode && element.equals(((NamespaceNode) other).element) && nsBinding.equals(((NamespaceNode) other).nsBinding); }
/** * Add a namespace node to the current element * * @param parent the node number of the element * @param binding namespace identifying the prefix and uri */ void addNamespace(int parent, /*@NotNull*/ NamespaceBinding binding) { ensureNamespaceCapacity(1); namespaceParent[numberOfNamespaces] = parent; namespaceBinding[numberOfNamespaces] = binding; if (beta[parent] == -1) { beta[parent] = numberOfNamespaces; } numberOfNamespaces++; if (!binding.isXmlNamespace()) { usesNamespaces = true; } }
distinctNamespaces.put(nb.getPrefix(), nb.getURI()); bindings.add(new NamespaceBinding(entry.getKey(), entry.getValue()));
/** * Get the local part of the name of this node. This is the name after the ":" if any. * * @return the local part of the name. For an unnamed node, returns "". Unlike the DOM * interface, this returns the full name in the case of a non-namespaced name. */ public String getLocalPart() { return nsBinding.getPrefix(); }
/** * startContent: Add any namespace undeclarations needed to stop * namespaces being inherited from parent elements */ public void startContent() throws XPathException { if (pendingUndeclarations != null) { for (NamespaceBinding ns : pendingUndeclarations) { if (ns != null) { namespace(new NamespaceBinding(ns.getPrefix(), ""), 0); // relies on the namespace() method to prevent duplicate undeclarations } } } pendingUndeclarations = null; nextReceiver.startContent(); }
private void addNamespaceInternal(/*@NotNull*/ NamespaceBinding nscode, boolean externalCall) { if (namespaceList == null) { namespaceList = new NamespaceBinding[]{nscode}; } else { NamespaceBinding[] nsList = namespaceList; for (int i = 0; i < nsList.length; i++) { if (nsList[i].equals(nscode)) { return; } if (nsList[i].getPrefix().equals(nscode.getPrefix())) { if (nsList[i].getURI().isEmpty()) { // this is an undeclaration; replace it with the new declaration nsList[i] = nscode; return; } else if (externalCall) { throw new IllegalArgumentException("New namespace conflicts with existing namespace binding"); } else { return; } } } int len = nsList.length; NamespaceBinding[] ns2 = new NamespaceBinding[len + 1]; System.arraycopy(nsList, 0, ns2, 0, len); ns2[len] = nscode; namespaceList = ns2; } }
throw NoOpenStartTagException.makeNoOpenStartTagException( Type.NAMESPACE, ns.getPrefix(), hostLanguage, currentLevelIsDocument[level], if (ns.getPrefix().equals(pendingNSList[i].getPrefix())) { if (pendingNSList[i].isDefaultUndeclaration() || ns.isDefaultUndeclaration()) { String prefix = ns.getPrefix(); String uri1 = ns.getURI(); String uri2 = pendingNSList[i].getURI(); XPathException err = new XPathException("Cannot create two namespace nodes with the same prefix mapped to different URIs (prefix=" + (prefix.isEmpty() ? "\"\"" : prefix) + ", URI=" + if (ns.getPrefix().isEmpty() && !ns.getURI().isEmpty()) { declaresDefaultNamespace = true; if (elementIsInNullNamespace == null) {
/** * Return the string value of the node. The interpretation of this depends on the type * of node. For a namespace node, it is the namespace URI. * * @return the string value of the node */ public String getStringValue() { return nsBinding.getURI(); }
public void namespace(NamespaceBindingSet namespaceBindings, int properties) throws XPathException { for (NamespaceBinding ns : namespaceBindings) { if (!acceptAttributes) { throw NoOpenStartTagException.makeNoOpenStartTagException( Type.NAMESPACE, ns.getPrefix(), getPipelineConfiguration().getHostLanguage(), inDocument, ExplicitLocation.UNKNOWN_LOCATION); } // avoid duplicates for (int n = 0; n < countStack[depth - 1]; n++) { if (namespaces[namespacesSize - 1 - n].equals(namespaceBindings)) { return; } } addToStack(ns); countStack[depth - 1]++; } }