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

The following are Jave code examples for showing how to use getPrefix() 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: MdeNode.java   View Source Code Vote up 6 votes
/**
 *  Gets the qualifiedAttributeName attribute of the Renderer object.<p>
 *
 *  NOTE: i don't think this method is required at all. if the instance
 *  document is constructed correctly, the attributes are already qualified as
 *  needed and there is no need to mess with it any further ..
 *
 * @param  name     NOT YET DOCUMENTED
 * @param  typeDef  NOT YET DOCUMENTED
 * @param  element  NOT YET DOCUMENTED
 * @return          The qualifiedAttributeName value
 */
protected String getQualifiedAttributeName(String name, Element element, GlobalDef typeDef) {
	Namespace typeDefNamespace = typeDef.getNamespace();
	String typeDefNSPrefix = typeDefNamespace.getPrefix();
	String qualifiedName = name;

	// if the name is qualified, remove namespace prefix if it is the same as
	// the typeDef's prefix
	if (NamespaceRegistry.isQualified(name)) {

		// get the namespace corresponding to the name's prefix - in the context of provided typeDef
		qualifiedName = resolveQualifiedName(name, typeDef);

	}
	else { // no prefix supplied
		String schemaPath = SchemaHelper.toSchemaPath(xpath);
		SchemaNode parentNode = sh.getSchemaNode(schemaPath);

		// when there is no prefix, don't qualify the attribute
		qualifiedName = name;
	}

	// prtln(" ... returning " + qualifiedName);
	return qualifiedName;
}
 
Example 2
Project: dls-repository-stack   File: MdeNode.java   View Source Code Vote up 6 votes
/**
 *  Gets the qualifiedAttributeName attribute of the Renderer object.<p>
 *
 *  NOTE: i don't think this method is required at all. if the instance
 *  document is constructed correctly, the attributes are already qualified as
 *  needed and there is no need to mess with it any further ..
 *
 * @param  name     NOT YET DOCUMENTED
 * @param  typeDef  NOT YET DOCUMENTED
 * @param  element  NOT YET DOCUMENTED
 * @return          The qualifiedAttributeName value
 */
protected String getQualifiedAttributeName(String name, Element element, GlobalDef typeDef) {
	Namespace typeDefNamespace = typeDef.getNamespace();
	String typeDefNSPrefix = typeDefNamespace.getPrefix();
	String qualifiedName = name;

	// if the name is qualified, remove namespace prefix if it is the same as
	// the typeDef's prefix
	if (NamespaceRegistry.isQualified(name)) {

		// get the namespace corresponding to the name's prefix - in the context of provided typeDef
		qualifiedName = resolveQualifiedName(name, typeDef);

	}
	else { // no prefix supplied
		String schemaPath = SchemaHelper.toSchemaPath(xpath);
		SchemaNode parentNode = sh.getSchemaNode(schemaPath);

		// when there is no prefix, don't qualify the attribute
		qualifiedName = name;
	}

	// prtln(" ... returning " + qualifiedName);
	return qualifiedName;
}
 
Example 3
Project: ats-framework   File: XmlNode.java   View Source Code Vote up 5 votes
public XmlNode( XmlNode parent, Element node ) {

        this.node = node;

        Namespace nodeNamespace = node.getNamespace();
        if (nodeNamespace != null && !StringUtils.isNullOrEmpty(nodeNamespace.getPrefix())) {
            this.name = nodeNamespace.getPrefix() + ":" + node.getName();
        } else {
            this.name = node.getName();
        }

        this.attributes = new TreeMap<>();
        for (int i = 0; i < node.attributes().size(); i++) {
            Attribute att = node.attribute(i);
            this.attributes.put(att.getName(), att.getValue());
        }

        this.value = this.node.getTextTrim();

        this.parent = parent;

        this.children = new ArrayList<>();
        List<Element> childrenElements = this.node.elements();
        for (Element child : childrenElements) {
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                this.children.add(new XmlNode(this, child));
            }
        }
    }
 
Example 4
Project: joai-project   File: NamespaceRegistry.java   View Source Code Vote up 5 votes
/**
 *  Gets the prefix corresponding to the provided uri after finding that uri's
 *  namespace.
 *
 * @param  uri  NOT YET DOCUMENTED
 * @return      The prefixforUri value
 */
public String getPrefixforUri(String uri) {
	Namespace ns = getNSforUri(uri);
	if (ns == Namespace.NO_NAMESPACE) {
		// prtln ("WARNING: getPrefixforUri() did not find namespace not found for " + uri);
	}
	return ns.getPrefix();
}
 
Example 5
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 6
Project: dls-repository-stack   File: NamespaceRegistry.java   View Source Code Vote up 5 votes
/**
 *  Gets the prefix corresponding to the provided uri after finding that uri's
 *  namespace.
 *
 * @param  uri  NOT YET DOCUMENTED
 * @return      The prefixforUri value
 */
public String getPrefixforUri(String uri) {
	Namespace ns = getNSforUri(uri);
	if (ns == Namespace.NO_NAMESPACE) {
		// prtln ("WARNING: getPrefixforUri() did not find namespace not found for " + uri);
	}
	return ns.getPrefix();
}
 
Example 7
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 8
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 9
Project: jaxen   File: DocumentNavigator.java   View Source Code Vote up 5 votes
public Iterator getNamespaceAxisIterator(Object contextNode)
{
    if ( ! ( contextNode instanceof Element ) )
    {
        return JaxenConstants.EMPTY_ITERATOR;
    }

    Element element = (Element) contextNode;
    List nsList = new ArrayList();
    HashSet prefixes = new HashSet();
    for ( Element context = element; context != null; context = context.getParent() ) {
        List declaredNS = new ArrayList(context.declaredNamespaces());
        declaredNS.add(context.getNamespace());

        for ( Iterator iter = context.attributes().iterator(); iter.hasNext(); )
        {
            Attribute attr = (Attribute) iter.next();
            declaredNS.add(attr.getNamespace());
        }

        for ( Iterator iter = declaredNS.iterator(); iter.hasNext(); )
        {
            Namespace namespace = (Namespace) iter.next();
            if (namespace != Namespace.NO_NAMESPACE)
            {
                String prefix = namespace.getPrefix();
                if ( ! prefixes.contains( prefix ) ) {
                    prefixes.add( prefix );
                    nsList.add( namespace.asXPathResult( element ) );
                }
            }
        }
    }
    nsList.add( Namespace.XML_NAMESPACE.asXPathResult( element ) );
    return nsList.iterator();
}
 
Example 10
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 11
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 12
Project: incubator-taverna-workbench-common-activities   File: XPathActivityXMLTree.java   View Source Code Vote up 4 votes
private String addNamespaceToXPathMap(Namespace namespace) 
{
  // EMTPY PREFIX
  if (namespace.getPrefix().length() == 0) {
    if (namespace.getURI().length() == 0) {
      // DEFAULT NAMESPACE with no URI - nothing to worry about
      return "";
    }
    else {
      // DEFAULT NAMESPACE WITH NO PREFIX, BUT URI IS KNOWN
      return (addNamespaceToXPathMap(new Namespace("default", namespace.getURI())));
    }
  }
  
  // NEW NON-EMPTY PREFIX
  if (!this.currentXPathNamespaces.containsKey(namespace.getPrefix())) {
    this.currentXPathNamespaces.put(namespace.getPrefix(), namespace.getURI());
    return (namespace.getPrefix());
  }
  
  // EXISTING NON-EMPTY PREFIX AND THE SAME URI - NO NEED TO ADD AGAIN
  else if (this.currentXPathNamespaces.get(namespace.getPrefix()).equals(namespace.getURI())) {
    return (namespace.getPrefix());
  }
  
  // EXISTING NON-EMPTY PREFIX, BUT DIFFERENT URI
  else {
    String repeatedPrefix = namespace.getPrefix();
    
    int i = 0;
    while (this.currentXPathNamespaces.containsKey(repeatedPrefix + i)) {
      // check if current alternative prefix wasn't yet applied to current URI
      if (this.currentXPathNamespaces.get(repeatedPrefix + i).equals(namespace.getURI())) {
        return (repeatedPrefix + i);
      }
      else {
        // still another URI for the same prefix, keep trying to increase the ID in the prefix
        i++;
      }
    }
    
    String modifiedPrefix = repeatedPrefix + i;
    this.currentXPathNamespaces.put(modifiedPrefix, namespace.getURI());
    return (modifiedPrefix);
  }
}
 
Example 13
Project: jaxen   File: DocumentNavigator.java   View Source Code Vote up 4 votes
public String getNamespacePrefix(Object obj)
{
    Namespace ns = (Namespace) obj;

    return ns.getPrefix();
}
 
Example 14
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 15
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();
}