Java Code Examples for org.dom4j.Namespace.getURI()

The following are Jave code examples for showing how to use getURI() of the org.dom4j.Namespace class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: joai-project   File: NamespaceRegistry.java   View Source Code Vote up 6 votes
/**
 *  Register a namespace by placing itto the uriMap (mapping uri to its
 *  namespace) and resets default namespaces so they will be recomputed using
 *  updated uriMap.
 *
 * @param  ns  namespace to be registered
 */
public void register(Namespace ns) {
	// prtln ("registering namespace (" + ns.getPrefix() + ") " + ns.getURI());
	prefixMap.put(ns.getPrefix(), ns);
	/*
		NOTE: this implementation of uriMap assumes that there will be only one namespace per uri,
		which is probably not safe. In particular, if we define a "namedDefaultNamespace" then we
		have two namespaces with the same uri. HOWEVER, this implementation allows us to assume that
		the namespace returned for a given uri is the last-registered namespace, and that is a nice
		property, e.g., when we register a namedDefaultNamespace, then we get this when we ask for
		the namespace assigned to it's uri, and this is what we count on in schema processing when we
		call "getSchemaNamespace()".
	*/
	String uri = ns.getURI();
	Namespace existing = getNSforUri(uri);
	if (existing != NO_NAMESPACE) {
		// prtln ("\t NOTE: overwriting existing namespace with prefix: \"" + existing.getPrefix() + "\"");
	}

	uriMap.put(ns.getURI(), ns);

	// reset these namespaces, which will get recomputed when needed
	namedDefaultNamespace = null;
	defaultNamespace = null;

}
 
Example 2
Project: dls-repository-stack   File: NamespaceRegistry.java   View Source Code Vote up 6 votes
/**
 *  Register a namespace by placing itto the uriMap (mapping uri to its
 *  namespace) and resets default namespaces so they will be recomputed using
 *  updated uriMap.
 *
 * @param  ns  namespace to be registered
 */
public void register(Namespace ns) {
	// prtln ("registering namespace (" + ns.getPrefix() + ") " + ns.getURI());
	prefixMap.put(ns.getPrefix(), ns);
	/*
		NOTE: this implementation of uriMap assumes that there will be only one namespace per uri,
		which is probably not safe. In particular, if we define a "namedDefaultNamespace" then we
		have two namespaces with the same uri. HOWEVER, this implementation allows us to assume that
		the namespace returned for a given uri is the last-registered namespace, and that is a nice
		property, e.g., when we register a namedDefaultNamespace, then we get this when we ask for
		the namespace assigned to it's uri, and this is what we count on in schema processing when we
		call "getSchemaNamespace()".
	*/
	String uri = ns.getURI();
	Namespace existing = getNSforUri(uri);
	if (existing != NO_NAMESPACE) {
		// prtln ("\t NOTE: overwriting existing namespace with prefix: \"" + existing.getPrefix() + "\"");
	}

	uriMap.put(ns.getURI(), ns);

	// reset these namespaces, which will get recomputed when needed
	namedDefaultNamespace = null;
	defaultNamespace = null;

}
 
Example 3
Project: jaxen   File: DocumentNavigator.java   View Source Code Vote up 6 votes
public String translateNamespacePrefixToUri(String prefix, Object context)
{
    Element element = null;
    if ( context instanceof Element ) 
    {
        element = (Element) context;
    }
    else if ( context instanceof Node )
    {
        Node node = (Node) context;
        element = node.getParent();
    }
    if ( element != null )
    {
        Namespace namespace = element.getNamespaceForPrefix( prefix );

        if ( namespace != null ) 
        {
            return namespace.getURI();
        }
    }
    return null;
}
 
Example 4
Project: bio2rdf-rest   File: DocumentHelper.java   View Source Code Vote up 6 votes
/**
 * for the xml append and check whether the root element is the same
 * @param root
 * @param prefixToUri
 * @return
 */
public static boolean isMatchAtRoot(Element root,Map<String,String> prefixToUri) {
	if(root == null) {
		return false;
	}
	Namespace namespace = root.getNamespace();
	String uri = namespace.getURI();
	if("".equals(namespace.getPrefix()) && !"".equals(uri)) {
		for(Map.Entry<String, String> entry : prefixToUri.entrySet()) {
			if(uri.equals(entry.getValue()) && entry.getKey()!=null && entry.getKey().startsWith("TPrefix")) {//TPrefix mean that default namespace in UI tree
				return true;
			}
		}
		return false;
	}
	return true;
}
 
Example 5
Project: bio2rdf-rest   File: DocumentHelper.java   View Source Code Vote up 6 votes
/**
 * for the xml append and check whether the root element is the same
 * @param root
 * @param prefixToUri
 * @return
 */
public static boolean isMatchAtRoot(Element root,Map<String,String> prefixToUri) {
	if(root == null) {
		return false;
	}
	Namespace namespace = root.getNamespace();
	String uri = namespace.getURI();
	if("".equals(namespace.getPrefix()) && !"".equals(uri)) {
		for(Map.Entry<String, String> entry : prefixToUri.entrySet()) {
			if(uri.equals(entry.getValue()) && entry.getKey()!=null && entry.getKey().startsWith("TPrefix")) {//TPrefix mean that default namespace in UI tree
				return true;
			}
		}
		return false;
	}
	return true;
}
 
Example 6
Project: bio2rdf-rest   File: DocumentHelper.java   View Source Code Vote up 6 votes
/**
 * for the xml append and check whether the root element is the same
 * @param root
 * @param prefixToUri
 * @return
 */
public static boolean isMatchAtRoot(Element root,Map<String,String> prefixToUri) {
	if(root == null) {
		return false;
	}
	Namespace namespace = root.getNamespace();
	String uri = namespace.getURI();
	if("".equals(namespace.getPrefix()) && !"".equals(uri)) {
		for(Map.Entry<String, String> entry : prefixToUri.entrySet()) {
			if(uri.equals(entry.getValue()) && entry.getKey()!=null && entry.getKey().startsWith("TPrefix")) {//TPrefix mean that default namespace in UI tree
				return true;
			}
		}
		return false;
	}
	return true;
}
 
Example 7
Project: joai-project   File: NamespaceRegistry.java   View Source Code Vote up 5 votes
/**
 *  Returns true if there is a namespace defined in addition to the default ns
 *  and the schemaNamespace. Multinamespace documents require that we ensure
 *  there is a named default namespace so all xPath references are qualified.
 *
 * @return    The multiNamespace value
 */
public boolean isMultiNamespace() {
	// prtln ("isMultiNamespace()");
	List uris = new ArrayList();
	for (Iterator i = prefixMap.values().iterator(); i.hasNext(); ) {
		Namespace ns = (Namespace) i.next();
		String uri = ns.getURI();
		if (uri != this.schemaNamespaceUri &&
			uri != this.xmlNamespaceUri) {
			uris.add(uri);
			// prtln ("\tadded " + uri);
		}
	}
	return (uris.size() > 1);
}
 
Example 8
Project: joai-project   File: NamespaceRegistry.java   View Source Code Vote up 5 votes
/**
 *  NOT YET DOCUMENTED
 *
 * @param  ns  NOT YET DOCUMENTED
 * @return     NOT YET DOCUMENTED
 */
public static String nsToString(Namespace ns) {
	if (ns == null) {
		return "NULL NAMESPACE";
	}

	return "\"" + ns.getPrefix() + "\" : \"" + ns.getURI() + "\"";
}
 
Example 9
Project: sistra   File: WSInvokerConector.java   View Source Code Vote up 5 votes
private void procesarNamespaceNode(Element element, Properties nmprops) {
    Namespace namespace = element.getNamespace();
    if (!Namespace.NO_NAMESPACE.equals(namespace)) {
        String uri = namespace.getURI();
        String prefix = nmprops.getProperty(uri);
        if (prefix != null) {
            element.add(new Namespace(prefix, uri));
        }
    }

    for (int i = 0; i < element.elements().size(); i++) {
        Element child = (Element) element.elements().get(i);
        procesarNamespaceNode(child, nmprops);
    }
}
 
Example 10
Project: Gargoyle   File: XMLAttibuteFormatWriter.java   View Source Code Vote up 5 votes
protected boolean isNamespaceDeclaration(Namespace ns) {
	if ((ns != null) && (ns != Namespace.XML_NAMESPACE)) {
		String uri = ns.getURI();

		if (uri != null) {
			if (!namespaceStack.contains(ns)) {
				return true;
			}
		}
	}

	return false;
}
 
Example 11
Project: dls-repository-stack   File: NamespaceRegistry.java   View Source Code Vote up 5 votes
/**
 *  Returns true if there is a namespace defined in addition to the default ns
 *  and the schemaNamespace. Multinamespace documents require that we ensure
 *  there is a named default namespace so all xPath references are qualified.
 *
 * @return    The multiNamespace value
 */
public boolean isMultiNamespace() {
	// prtln ("isMultiNamespace()");
	List uris = new ArrayList();
	for (Iterator i = prefixMap.values().iterator(); i.hasNext(); ) {
		Namespace ns = (Namespace) i.next();
		String uri = ns.getURI();
		if (uri != this.schemaNamespaceUri &&
			uri != this.xmlNamespaceUri) {
			uris.add(uri);
			// prtln ("\tadded " + uri);
		}
	}
	return (uris.size() > 1);
}
 
Example 12
Project: dls-repository-stack   File: NamespaceRegistry.java   View Source Code Vote up 5 votes
/**
 *  NOT YET DOCUMENTED
 *
 * @param  ns  NOT YET DOCUMENTED
 * @return     NOT YET DOCUMENTED
 */
public static String nsToString(Namespace ns) {
	if (ns == null) {
		return "NULL NAMESPACE";
	}

	return "\"" + ns.getPrefix() + "\" : \"" + ns.getURI() + "\"";
}
 
Example 13
Project: bygle-ldp   File: JenaEndPointManager.java   View Source Code Vote up 5 votes
public String buildRDF(String xmlBase, List<Namespace> list, String rdf) {
	String result = "<rdf:RDF ";
	for (int i = 0; i < list.size(); i++) {
		Namespace namespace = list.get(i);
		result += namespace.getPrefix().isEmpty() ? "xmlns=\"" + namespace.getURI() + "\" " : "xmlns:" + namespace.getPrefix() + "=\"" + namespace.getURI() + "\" ";
	}
	result += !xmlBase.isEmpty() ? "xml:base=\"" + xmlBase + "\"" : "";
	result += ">\n" + rdf;
	result += "\n</rdf:RDF>";
	return result;
}
 
Example 14
Project: xpath-to-xml   File: Dom4jAttribute.java   View Source Code Vote up 4 votes
@Override
public QName getName() {
    final Namespace namespace = attribute.getNamespace();
    return new QName(namespace.getURI(), attribute.getName(), namespace.getPrefix());
}
 
Example 15
Project: xpath-to-xml   File: Dom4jElement.java   View Source Code Vote up 4 votes
@Override
public QName getName() {
    final Namespace namespace = element.getNamespace();
    return new QName(namespace.getURI(), element.getName(), namespace.getPrefix());
}
 
Example 16
Project: apache-archiva   File: XMLReader.java   View Source Code Vote up 4 votes
public String getDefaultNamespaceURI()
{
    Namespace namespace = this.document.getRootElement().getNamespace();
    return namespace.getURI();
}
 
Example 17
Project: jaxen   File: DocumentNavigator.java   View Source Code Vote up 4 votes
public String getNamespaceStringValue(Object obj)
{
    Namespace ns = (Namespace) obj;

    return ns.getURI();
}
 
Example 18
Project: joai-project   File: NamespaceRegistry.java   View Source Code Vote up 3 votes
/**
 *  Gets the prefix for given namespace object, but uses the LOCAL namespace
 *  (obtained by the provided namespace's uri) so that the prefix returned is
 *  correct within the local context. <p>
 *
 *
 *
 * @param  ns  NOT YET DOCUMENTED
 * @return     The prefixforNS value
 */
public String getPrefixforNS(Namespace ns) {
	// the given namespace may come from a different context, and therefore we
	// use the ns.Uri to find the local namespace before determining prefix
	String nsUri = ns.getURI();
	Namespace localNs = getNSforUri(nsUri);
	return localNs.getPrefix();
}
 
Example 19
Project: dls-repository-stack   File: NamespaceRegistry.java   View Source Code Vote up 3 votes
/**
 *  Gets the prefix for given namespace object, but uses the LOCAL namespace
 *  (obtained by the provided namespace's uri) so that the prefix returned is
 *  correct within the local context. <p>
 *
 *
 *
 * @param  ns  NOT YET DOCUMENTED
 * @return     The prefixforNS value
 */
public String getPrefixforNS(Namespace ns) {
	// the given namespace may come from a different context, and therefore we
	// use the ns.Uri to find the local namespace before determining prefix
	String nsUri = ns.getURI();
	Namespace localNs = getNSforUri(nsUri);
	return localNs.getPrefix();
}