Java 类org.dom4j.Namespace 实例源码

项目:directory-ldap-api    文件:ExtendedRequestDsml.java   
/**
 * {@inheritDoc}
 */
@Override
public Element toDsml( Element root )
{
    Element element = super.toDsml( root );

    // Request Name
    if ( getDecorated().getRequestName() != null )
    {
        element.addElement( "requestName" ).setText(
            getDecorated().getRequestName() );
    }

    // Request Value        
    Namespace xsdNamespace = new Namespace( "xsd", ParserUtils.XML_SCHEMA_URI );
    Namespace xsiNamespace = new Namespace( "xsi", ParserUtils.XML_SCHEMA_INSTANCE_URI );
    element.getDocument().getRootElement().add( xsdNamespace );
    element.getDocument().getRootElement().add( xsiNamespace );

    Element valueElement = element.addElement( "requestValue" ).addText(
        ParserUtils.base64Encode( getRequestValue() ) );
    valueElement.addAttribute( new QName( "type", xsiNamespace ),
        "xsd:" + ParserUtils.BASE64BINARY );

    return element;
}
项目:joai-project    文件:ComplexType.java   
/**
 *  String representation of the ComplexType object
 *
 * @return    a String representation of the ComplexType object
 */
public String toString() {
    String s = "ComplexType: " + getName();
    String nl = "\n\t";
    s += nl + "type: " + getType();
    s += nl + "location: " + getLocation();
    s += nl + "contentmodel: " + getContentModel();
    if (getNamespace() != Namespace.NO_NAMESPACE)
        s += nl + "namespace: " + getNamespace().getPrefix() + ": " + getNamespace().getURI();
    else
        s += nl + "namespace: null";
    //      s += nl + "modelGroup: " + modelGroup;
    //      s += nl + "there are " + getChildren().size() + " content elements";
    /*
         *  if (modelGroup == null)
         *  s += "\n" + element.asXML();
         */
    s += nl + "schemaNamespace: " + this.getSchemaReader().getNamespaces().getSchemaNamespace().getPrefix();
    s += Dom4jUtils.prettyPrint(getElement());
    return s;
}
项目:joai-project    文件:SimpleType.java   
/**
 *  Description of the Method
 *
 *@return    Description of the Return Value
 */
public String toString() {
    String s = "SimpleType: " + getName();
    s += "\n\t location: " + getLocation();
    if (isEnumeration()) {
        s += "\n\tEnumeration";
        for (Iterator i = getSimpleEnumerationValues().iterator(); i.hasNext(); ) {
            s += "\n\t\t" + (String) i.next();
        }
    }
    else if (isUnion()) {
        s += "\n\tUnion (" + getUnionMemberTypesAsString() + ")";
    }
    else {
        s += getElement().asXML();
    }
    if (getNamespace() != Namespace.NO_NAMESPACE)
        s += "\n\tnamespace: " + getNamespace().getPrefix() + ": " + getNamespace().getURI();
    else
        s += "\n\tnamespace: null";
    return s;
}
项目:joai-project    文件:ReaderStack.java   
/**
* Search the stack (moving from local to more global SchemaReaders) for the namespace
* belonging to the given prefix.
*/
public Namespace getNamespaceForPrefix (String prefix) {
    Namespace ns = Namespace.NO_NAMESPACE;
    prtln ("\n\tReaderStack.getNamespace() looking for prefix: " + prefix);
    for (int i=0; i < size(); i++) {
        SchemaReader sr = getItemAt(i);
        prtln ("\t\t " + sr.getLocation());
        NamespaceRegistry namespaceContext = sr.getNamespaces();
        ns = namespaceContext.getNSforPrefix(prefix);
        if (!ns.getPrefix().equals("")) {
            prtln ("\t\t\t ... found namespace -- " + ns.getPrefix() + ": " + ns.getURI());
            break;
        }
    }
    return ns;
}
项目:joai-project    文件:StructureWalker.java   
/**
 *  Tries to resolve give QName into a "top-level" namespace and prefix. If the
 *  there is no prefix and the namespace is the default namespace, assign the
 *  NAMED defaultNamespace.
 *
 * @param  qName          Description of the Parameter
 * @return                Description of the Return Value
 * @exception  Exception  Description of the Exception
 */
private QName resolveQName(QName qName) throws Exception {
    String prefix = qName.getNamespacePrefix();
    String name = qName.getName();
    String uri = qName.getNamespaceURI();
    prtln("\n\t resolveQName: ", 1);
    prtln("\t\t name: " + name, 1);
    prtln("\t\t prefix: " + prefix, 1);
    prtln("\t\t uri: " + uri, 1);
    Namespace topLevelNS = namespaces.getNSforUri(uri);
    if (topLevelNS == null) {
        prtlnErr("ERROR: resolveQName could not find top-level namespace for " + uri);
        return null;
    }
    else if (topLevelNS == namespaces.getDefaultNamespace()) {
        topLevelNS = namespaces.getNamedDefaultNamespace();
    }

    return df.createQName(name, topLevelNS);
}
项目:joai-project    文件:StructureWalker.java   
/**
 *  Resolve qualified name against top-level namespace registry
 *
 * @param  name  NOT YET DOCUMENTED
 * @return       NOT YET DOCUMENTED
 */
private Element createChildElement(String name) {
    prtln("\n createChildElement() name: " + name, 1);
    Namespace ns = getCurrentNamespace();
    prtln("\t currentNamespace -- " + ns.getPrefix() + ": " + ns.getURI(), 1);
    Element child = null;
    if (ns == null || !namespaceEnabled) {
        child = df.createElement(name);
    }
    else {
        QName baseQName = df.createQName(name, ns);
        try {
            child = df.createElement(resolveQName(baseQName));
        } catch (Exception e) {
            prtlnErr("createChildElement error: " + e.getMessage());
            e.printStackTrace();
            return null;
        }
    }
    prtln("   ... child: " + child.asXML(), 1);
    return child;
}
项目:joai-project    文件:StructureWalker.java   
/**
 *  this method will indeed insert the right elements, but we do we want them
 *  in the instance document?? i'm thinking that we DO want them in the
 *  schemaNodeMap, but not in the instanceDocument ... so we can remove them
 *  from the instance document
 *
 * @param  globalElementDef  the GlobalElement type definition containing the sub group element
 * @param  e              current schema Element to process
 * @param  parent         instanceDoc Element to which we attach new instanceElement
 * @exception  Exception  if this element cannot be processed
 */
private void processSubstitutionGroup(GlobalElement globalElementDef, Element e, Element parent) throws Exception {
    prtln("\nprocessSubstitutionGroup()", 1);

    if (globalElementDef.isAbstract()) {
        prtln("\n\t ABSTRACT GLOBAL ELEMENT!\n", 1);
    }

    Iterator subGroup = globalElementDef.getSubstitutionGroup().iterator();
    prtln("\t substitution group", 1);
    while (subGroup.hasNext()) {
        GlobalElement member = (GlobalElement) subGroup.next();
        prtln("\n Substitution Member: " + member.getQualifiedInstanceName(), 1);
        Namespace memberNS = member.getNamespace();

        prtln("\t namespace obtained from globalDef: " + NamespaceRegistry.nsToString(memberNS), 1);

        pushNS(memberNS);
        readerStack.push(member.getSchemaReader());
        processSchemaElement(member.getElement(), parent);
        this.popNS();
        readerStack.pop();
    }
}
项目:joai-project    文件:NamespaceRegistry.java   
/**
 *  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;

}
项目:joai-project    文件:SchemaReader.java   
/**
* Return globalDef from the globalDefMap after resolving the given typeName into a baseName and namespace. 
Returns null if namespace cannot be determined.

NOTE: this can be refactored to use getInstanceQualifiedName (returned prefix must be resolved into a namespace
before the call to globalDefMap.getValue (baseName, namespace)
*/
public GlobalDef getGlobalDef (String typeName) {
    // prtln ("getGlobalDef with " + typeName);
    Namespace namespace = targetNamespace;
    String prefix = null;
    String baseName = typeName;
    if (NamespaceRegistry.isQualified(typeName)) {
        baseName = NamespaceRegistry.stripNamespacePrefix(typeName);
        prefix = NamespaceRegistry.getNamespacePrefix(typeName);
        namespace = getNamespaces().getNSforPrefix(prefix);
        if (namespace == Namespace.NO_NAMESPACE) {
            prtln ("\nWARNING: getGlobalDef can't find namespace for \"" + prefix + "\"");
            prtln (this.namespaces.toString());
            return null;
        }
    }
    return globalDefMap.getValue (baseName, namespace.getURI());
}
项目:joai-project    文件:GlobalDefMap.java   
/**
 *  Accessor method for retrieving a specific named GlobalDef. Namespace prefixes for the
 default name space (or the targetNameSpace if there is no defaultNamespace defined), are stripped.
 *
 *@param  name  Description of the Parameter
 *@return       The value value
 */
public GlobalDef getValue(String name) {

    GlobalDef ret = null;
    if (NamespaceRegistry.isQualified(name)) {
        String prefix = NamespaceRegistry.getNamespacePrefix(name);
        String unqualifiedName = NamespaceRegistry.stripNamespacePrefix(name);
        Namespace ns = this.getNamespaces().getNSforPrefix(prefix);
        ret = this.getValue(unqualifiedName, ns);           
    }
    else {
        ret = getValue(name, namespaces.getDefaultNamespace());
        try {
            if (ret == null) {
                prtln ("GlobalDefMap failed to find " + name + " in the default namespace");
                throw new Exception ();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return ret;
}
项目:joai-project    文件:ModelGroup.java   
/**
 *  String representation of the ModelGroup object
 *
 * @return    a String representation of the ModelGroup object
 */
public String toString() {
    String s = "ModelGroup: " + getName();
    String nl = "\n\t";
    s += nl + "type: " + getType();
    s += nl + "location: " + getLocation();
    s += nl + "contentmodel: " + getContentModel();
    if (getNamespace() != Namespace.NO_NAMESPACE)
        s += nl + "namespace: " + getNamespace().getPrefix() + ": " + getNamespace().getURI();
    else
        s += nl + "namespace: null";
    //      s += nl + "modelGroup: " + modelGroup;
    //      s += nl + "there are " + getChildren().size() + " content elements";
    /*
         *  if (modelGroup == null)
         *  s += "\n" + element.asXML();
         */
    // s += Dom4jUtils.prettyPrint (getElement());
    return s;
}
项目:joai-project    文件:MdeNode.java   
/**
 *  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;
}
项目:apache-archiva    文件:XMLReader.java   
/**
 * Remove namespaces from element recursively.
 */
@SuppressWarnings("unchecked")
public void removeNamespaces( Element elem )
{
    elem.setQName( QName.get( elem.getName(), Namespace.NO_NAMESPACE, elem.getQualifiedName() ) );

    Node n;

    Iterator<Node> it = elem.elementIterator();
    while ( it.hasNext() )
    {
        n = it.next();

        switch ( n.getNodeType() )
        {
            case Node.ATTRIBUTE_NODE:
                ( (Attribute) n ).setNamespace( Namespace.NO_NAMESPACE );
                break;
            case Node.ELEMENT_NODE:
                removeNamespaces( (Element) n );
                break;
        }
    }
}
项目:dls-repository-stack    文件:ComplexType.java   
/**
 *  String representation of the ComplexType object
 *
 * @return    a String representation of the ComplexType object
 */
public String toString() {
    String s = "ComplexType: " + getName();
    String nl = "\n\t";
    s += nl + "type: " + getType();
    s += nl + "location: " + getLocation();
    s += nl + "contentmodel: " + getContentModel();
    if (getNamespace() != Namespace.NO_NAMESPACE)
        s += nl + "namespace: " + getNamespace().getPrefix() + ": " + getNamespace().getURI();
    else
        s += nl + "namespace: null";
    //      s += nl + "modelGroup: " + modelGroup;
    //      s += nl + "there are " + getChildren().size() + " content elements";
    /*
         *  if (modelGroup == null)
         *  s += "\n" + element.asXML();
         */
    s += nl + "schemaNamespace: " + this.getSchemaReader().getNamespaces().getSchemaNamespace().getPrefix();
    s += Dom4jUtils.prettyPrint(getElement());
    return s;
}
项目:dls-repository-stack    文件:SimpleType.java   
/**
 *  Description of the Method
 *
 *@return    Description of the Return Value
 */
public String toString() {
    String s = "SimpleType: " + getName();
    s += "\n\t location: " + getLocation();
    if (isEnumeration()) {
        s += "\n\tEnumeration";
        for (Iterator i = getSimpleEnumerationValues().iterator(); i.hasNext(); ) {
            s += "\n\t\t" + (String) i.next();
        }
    }
    else if (isUnion()) {
        s += "\n\tUnion (" + getUnionMemberTypesAsString() + ")";
    }
    else {
        s += getElement().asXML();
    }
    if (getNamespace() != Namespace.NO_NAMESPACE)
        s += "\n\tnamespace: " + getNamespace().getPrefix() + ": " + getNamespace().getURI();
    else
        s += "\n\tnamespace: null";
    return s;
}
项目:dls-repository-stack    文件:ReaderStack.java   
/**
* Search the stack (moving from local to more global SchemaReaders) for the namespace
* belonging to the given prefix.
*/
public Namespace getNamespaceForPrefix (String prefix) {
    Namespace ns = Namespace.NO_NAMESPACE;
    prtln ("\n\tReaderStack.getNamespace() looking for prefix: " + prefix);
    for (int i=0; i < size(); i++) {
        SchemaReader sr = getItemAt(i);
        prtln ("\t\t " + sr.getLocation());
        NamespaceRegistry namespaceContext = sr.getNamespaces();
        ns = namespaceContext.getNSforPrefix(prefix);
        if (!ns.getPrefix().equals("")) {
            prtln ("\t\t\t ... found namespace -- " + ns.getPrefix() + ": " + ns.getURI());
            break;
        }
    }
    return ns;
}
项目:dls-repository-stack    文件:StructureWalker.java   
/**
 *  Tries to resolve give QName into a "top-level" namespace and prefix. If the
 *  there is no prefix and the namespace is the default namespace, assign the
 *  NAMED defaultNamespace.
 *
 * @param  qName          Description of the Parameter
 * @return                Description of the Return Value
 * @exception  Exception  Description of the Exception
 */
private QName resolveQName(QName qName) throws Exception {
    String prefix = qName.getNamespacePrefix();
    String name = qName.getName();
    String uri = qName.getNamespaceURI();
    prtln("\n\t resolveQName: ", 1);
    prtln("\t\t name: " + name, 1);
    prtln("\t\t prefix: " + prefix, 1);
    prtln("\t\t uri: " + uri, 1);
    Namespace topLevelNS = namespaces.getNSforUri(uri);
    if (topLevelNS == null) {
        prtlnErr("ERROR: resolveQName could not find top-level namespace for " + uri);
        return null;
    }
    else if (topLevelNS == namespaces.getDefaultNamespace()) {
        topLevelNS = namespaces.getNamedDefaultNamespace();
    }

    return DocumentHelper.createQName(name, topLevelNS);
}
项目:dls-repository-stack    文件:StructureWalker.java   
/**
 *  Resolve qualified name against top-level namespace registry
 *
 * @param  name  NOT YET DOCUMENTED
 * @return       NOT YET DOCUMENTED
 */
private Element createChildElement(String name) {
    prtln("\n createChildElement() name: " + name, 1);
    Namespace ns = getCurrentNamespace();
    prtln("\t currentNamespace -- " + ns.getPrefix() + ": " + ns.getURI(), 1);
    Element child = null;
    if (ns == null || !namespaceEnabled) {
        child = DocumentHelper.createElement(name);
    }
    else {
        QName baseQName = DocumentHelper.createQName(name, ns);
        try {
            child = DocumentHelper.createElement(resolveQName(baseQName));
        } catch (Exception e) {
            prtlnErr("createChildElement error: " + e.getMessage());
            e.printStackTrace();
            return null;
        }
    }
    prtln("   ... child: " + child.asXML(), 1);
    return child;
}
项目:dls-repository-stack    文件:StructureWalker.java   
/**
 *  this method will indeed insert the right elements, but we do we want them
 *  in the instance document?? i'm thinking that we DO want them in the
 *  schemaNodeMap, but not in the instanceDocument ... so we can remove them
 *  from the instance document
 *
 * @param  globalElementDef  the GlobalElement type definition containing the sub group element
 * @param  e              current schema Element to process
 * @param  parent         instanceDoc Element to which we attach new instanceElement
 * @exception  Exception  if this element cannot be processed
 */
private void processSubstitutionGroup(GlobalElement globalElementDef, Element e, Element parent) throws Exception {
    prtln("\nprocessSubstitutionGroup()", 1);

    if (globalElementDef.isAbstract()) {
        prtln("\n\t ABSTRACT GLOBAL ELEMENT!\n", 1);
    }

    Iterator subGroup = globalElementDef.getSubstitutionGroup().iterator();
    prtln("\t substitution group", 1);
    while (subGroup.hasNext()) {
        GlobalElement member = (GlobalElement) subGroup.next();
        prtln("\n Substitution Member: " + member.getQualifiedInstanceName(), 1);
        Namespace memberNS = member.getNamespace();

        prtln("\t namespace obtained from globalDef: " + NamespaceRegistry.nsToString(memberNS), 1);

        pushNS(memberNS);
        readerStack.push(member.getSchemaReader());
        processSchemaElement(member.getElement(), parent);
        this.popNS();
        readerStack.pop();
    }
}
项目:dls-repository-stack    文件:NamespaceRegistry.java   
/**
 *  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;

}
项目:dls-repository-stack    文件:NamespaceRegistry.java   
/**
 *  Register all the namespaces defined in the docuement's rootElement.
 *
 * @param  doc  NOT YET DOCUMENTED
 */
public void registerNamespaces(Document doc) throws Exception {
    prtln ("\nregisterNamespaces()");
    try {
        Element root = doc.getRootElement();
        setTargetNamespaceUri(root.attributeValue("targetNamespace"));
        register(getNamespace(doc));
        List otherNamespaces = root.additionalNamespaces();
        if (otherNamespaces != null) {
            for (Iterator i = otherNamespaces.iterator(); i.hasNext(); ) {
                register((Namespace) i.next());
            }
        }
    } catch (Throwable t) {
        throw new Exception ("registerNamespaces ERROR: " + t);
    }
}
项目:dls-repository-stack    文件:SchemaReader.java   
/**
 *  Return globalDef from the globalDefMap after resolving the given typeName
 *  into a baseName and namespace. Returns null if namespace cannot be
 *  determined. NOTE: this can be refactored to use getInstanceQualifiedName
 *  (returned prefix must be resolved into a namespace before the call to
 *  globalDefMap.getValue (baseName, namespace)
 *
 * @param  typeName  typeName identifying the globalDef to find
 * @return           The globalDef value
 */
public GlobalDef getGlobalDef(String typeName) {
    // prtln ("getGlobalDef with " + typeName);
    Namespace namespace = targetNamespace;
    String prefix = null;
    String baseName = typeName;
    if (NamespaceRegistry.isQualified(typeName)) {
        baseName = NamespaceRegistry.stripNamespacePrefix(typeName);
        prefix = NamespaceRegistry.getNamespacePrefix(typeName);
        namespace = getNamespaces().getNSforPrefix(prefix);
        if (namespace == Namespace.NO_NAMESPACE) {
            prtln("\nWARNING: getGlobalDef can't find namespace for \"" + prefix + "\"");
            prtln(this.namespaces.toString());
            return null;
        }
    }
    return globalDefMap.getValue(baseName, namespace.getURI());
}
项目:dls-repository-stack    文件:GlobalDefMap.java   
/**
 *  Accessor method for retrieving a specific named GlobalDef. Namespace prefixes for the
 default name space (or the targetNameSpace if there is no defaultNamespace defined), are stripped.
 *
 *@param  name  Description of the Parameter
 *@return       The value value
 */
public GlobalDef getValue(String name) {

    GlobalDef ret = null;
    if (NamespaceRegistry.isQualified(name)) {
        String prefix = NamespaceRegistry.getNamespacePrefix(name);
        String unqualifiedName = NamespaceRegistry.stripNamespacePrefix(name);
        Namespace ns = this.getNamespaces().getNSforPrefix(prefix);
        ret = this.getValue(unqualifiedName, ns);           
    }
    else {
        ret = getValue(name, namespaces.getDefaultNamespace());
        try {
            if (ret == null) {
                prtln ("GlobalDefMap failed to find " + name + " in the default namespace");
                throw new Exception ();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return ret;
}
项目:dls-repository-stack    文件:ModelGroup.java   
/**
 *  String representation of the ModelGroup object
 *
 * @return    a String representation of the ModelGroup object
 */
public String toString() {
    String s = "ModelGroup: " + getName();
    String nl = "\n\t";
    s += nl + "type: " + getType();
    s += nl + "location: " + getLocation();
    s += nl + "contentmodel: " + getContentModel();
    if (getNamespace() != Namespace.NO_NAMESPACE)
        s += nl + "namespace: " + getNamespace().getPrefix() + ": " + getNamespace().getURI();
    else
        s += nl + "namespace: null";
    //      s += nl + "modelGroup: " + modelGroup;
    //      s += nl + "there are " + getChildren().size() + " content elements";
    /*
         *  if (modelGroup == null)
         *  s += "\n" + element.asXML();
         */
    // s += Dom4jUtils.prettyPrint (getElement());
    return s;
}
项目:dls-repository-stack    文件:MdeNode.java   
/**
 *  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;
}
项目:bygle-ldp    文件:XMLBuilder.java   
public XMLBuilder(String rootNode,Map<String, String> uris) throws XMLException {
    try {
        DocumentFactory factory = new DocumentFactory();
        factory.setXPathNamespaceURIs(uris);
        dom4JDocument = factory.createDocument();
        root = dom4JDocument.addElement( rootNode );
        Iterator<?> iterator = uris.entrySet().iterator();
         while (iterator.hasNext()) {
                @SuppressWarnings("rawtypes")
                Map.Entry pairs = (Map.Entry)iterator.next();
                root.add(Namespace.get((String)pairs.getKey(), (String) pairs.getValue()));
         }
    } catch (Exception e) {
        throw new XMLException(e.getMessage());
    }
}
项目:bygle-ldp    文件:XMLBuilder.java   
public XMLBuilder(String rootNode,Map<String, String> uris,String encoding) throws XMLException {
    try {
        DocumentFactory factory = new DocumentFactory();
        factory.setXPathNamespaceURIs(uris);
        dom4JDocument = factory.createDocument();
        if(encoding!=null)
            dom4JDocument.setXMLEncoding(encoding);
        root = dom4JDocument.addElement( rootNode );
        Iterator<?> iterator = uris.entrySet().iterator();
         while (iterator.hasNext()) {
                @SuppressWarnings("rawtypes")
                Map.Entry pairs = (Map.Entry)iterator.next();
                root.add(Namespace.get((String)pairs.getKey(), (String) pairs.getValue()));
         }
    } catch (Exception e) {
        throw new XMLException(e.getMessage());
    }
}
项目:Intercloud    文件:Roster.java   
/**
 * Returns an unmodifiable copy of the {@link Item Items} in the roster packet.
 *
 * @return an unmodifable copy of the {@link Item Items} in the roster packet.
 */
@SuppressWarnings("unchecked")
public Collection<Item> getItems() {
    Collection<Item> items = new ArrayList<Item>();
    Element query = element.element(new QName("query", Namespace.get("jabber:iq:roster")));
    if (query != null) {
        for (Iterator<Element> i=query.elementIterator("item"); i.hasNext(); ) {
            Element item = i.next();
            String jid = item.attributeValue("jid");
            String name = item.attributeValue("name");
            String ask = item.attributeValue("ask");
            String subscription = item.attributeValue("subscription");
            Collection<String> groups = new ArrayList<String>();
            for (Iterator<Element> j=item.elementIterator("group"); j.hasNext(); ) {
                Element group = j.next();
                groups.add(group.getText().trim());
            }
            Ask askStatus = ask == null ? null : Ask.valueOf(ask);
            Subscription subStatus = subscription == null ?
                    null : Subscription.valueOf(subscription);
            items.add(new Item(new JID(jid), name, askStatus, subStatus, groups));
        }
    }
    return Collections.unmodifiableCollection(items);
}
项目:jaxen    文件:DocumentNavigator.java   
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;
}
项目:jaxen    文件:DOM4JXPathTest.java   
public void testNamespaceNodesAreInherited() throws JaxenException
{
        Namespace ns0 = Namespace.get("p0", "www.acme0.org");
        Namespace ns1 = Namespace.get("p1", "www.acme1.org");
        Namespace ns2 = Namespace.get("p2", "www.acme2.org");
        Element element = new DefaultElement("test", ns1);
        Attribute attribute = new DefaultAttribute("pre:foo", "bar", ns2);
        element.add(attribute);
        Element root = new DefaultElement("root", ns0);
        root.add(element);
        Document doc = new DefaultDocument(root);

        XPath xpath = new Dom4jXPath( "/*/*/namespace::node()" );

        List results = xpath.selectNodes( doc );

        assertEquals( 4,
                      results.size() );
}
项目:netarchivesuite-svngit-migration    文件:SimpleXml.java   
/** Get an XPath version of the given dotted path.  A dotted path
 * foo.bar.baz corresponds to the XML node &lt;foo&gt;&lt;bar&gt;&lt;baz&gt;
 *  &lt;/baz&gt;&lt;/bar&gt;&lt;/foo&gt;
 *
 * Implementation note: If needed, this could be optimized by keeping a
 * HashMap cache of the XPaths, since they don't change.
 *
 * @param path A dotted path
 * @return An XPath that matches the dotted path equivalent, using
 * "dk:" as namespace prefix for all but the first element.
 */
private XPath getXPath(String path) {
    String[] pathParts = path.split("\\.");
    StringBuilder result = new StringBuilder();
    result.append("/");
    result.append(pathParts[0]);
    for (int i = 1; i < pathParts.length; i++) {
        result.append("/dk:");
        result.append(pathParts[i]);
    }
    XPath xpath = xmlDoc.createXPath(result.toString());
    Namespace nameSpace = xmlDoc.getRootElement().getNamespace();
    Map<String, String> namespaceURIs = new HashMap<String, String>(1);
    namespaceURIs.put("dk", nameSpace.getURI());
    xpath.setNamespaceURIs(namespaceURIs);
    return xpath;
}
项目:OpenZAL    文件:InternalDocumentService.java   
@Override
public void registerHandlers(DocumentDispatcher dispatcher)
{
  mHandlerMapPublisher.receivedHandlerMap( dispatcher.getHandlers() );

  Map<QName, ? extends SoapHandler> services = mSoapService.getServices();
  for (Map.Entry<QName, ? extends SoapHandler> entry : services.entrySet())
  {
    QName qName = entry.getKey();
    org.dom4j.QName zimbraQName = new org.dom4j.QName(
      qName.getName(),
      Namespace.get(qName.getNamespace())
    );

    dispatcher.registerHandler(
      zimbraQName,
      wrapHandler(entry.getValue())
    );
  }
}
项目:OpenZAL    文件:InternalRestoreDocumentService.java   
@Override
public void registerHandlers(@NotNull DocumentDispatcher dispatcher)
{
  Map<QName, ? extends SoapHandler> services = mSoapService.getServices();
  for( QName qName : services.keySet() )
  {
    org.dom4j.QName zimbraQName = new org.dom4j.QName(
      qName.getName(),
      Namespace.get(qName.getNamespace())
    );

    dispatcher.unRegisterHandler(
      zimbraQName
    );

    if( mOriginalHandlersMap.containsKey(zimbraQName) )
    {
      dispatcher.registerHandler(
        zimbraQName,
        mOriginalHandlersMap.get(zimbraQName)
      );
    }
  }
}
项目:OpenZAL    文件:InternalUnregisterDocumentService.java   
@Override
public void registerHandlers(@NotNull DocumentDispatcher dispatcher)
{
  Map<QName, ? extends SoapHandler> services = mSoapService.getServices();
  for( QName qName : services.keySet() )
  {
    org.dom4j.QName zimbraQName = new org.dom4j.QName(
      qName.getName(),
      Namespace.get(qName.getNamespace())
    );

    dispatcher.unRegisterHandler(
      zimbraQName
    );
  }
}
项目:Openfire    文件:WebSocketConnection.java   
@Override
public void deliver(Packet packet) throws UnauthorizedException
{
    final String xml;
    if (Namespace.NO_NAMESPACE.equals(packet.getElement().getNamespace())) {
        // use string-based operation here to avoid cascading xmlns wonkery
        StringBuilder packetXml = new StringBuilder(packet.toXML());
        packetXml.insert(packetXml.indexOf(" "), " xmlns=\"jabber:client\"");
        xml = packetXml.toString();
    } else {
        xml = packet.toXML();
    }
    if (validate()) {
        deliverRawText(xml);
    } else {
        // use fallback delivery mechanism (offline)
        getPacketDeliverer().deliver(packet);
    }
}
项目:Openfire    文件:SASLAuthentication.java   
public static Element getSASLMechanismsElement( ClientSession session )
{
    final Element result = DocumentHelper.createElement( new QName( "mechanisms", new Namespace( "", SASL_NAMESPACE ) ) );
    for (String mech : getSupportedMechanisms()) {
        if (mech.equals("EXTERNAL")) {
            boolean trustedCert = false;
            if (session.isSecure()) {
                final Connection connection   = ( (LocalClientSession) session ).getConnection();
                final TrustStore trustStore   = connection.getConfiguration().getTrustStore();
                trustedCert = trustStore.isTrusted( connection.getPeerCertificates() );
            }
            if ( !trustedCert ) {
                continue; // Do not offer EXTERNAL.
            }
        }
        final Element mechanism = result.addElement("mechanism");
        mechanism.setText(mech);
    }
    return result;
}
项目:Openfire    文件:SASLAuthentication.java   
public static Element getSASLMechanismsElement( LocalIncomingServerSession session )
{
    final Element result = DocumentHelper.createElement( new QName( "mechanisms", new Namespace( "", SASL_NAMESPACE ) ) );
    if (session.isSecure()) {
        final Connection connection   = session.getConnection();
        final TrustStore trustStore   = connection.getConfiguration().getTrustStore();
        final X509Certificate trusted = trustStore.getEndEntityCertificate( session.getConnection().getPeerCertificates() );

        boolean haveTrustedCertificate = trusted != null;
        if (trusted != null && session.getDefaultIdentity() != null) {
            haveTrustedCertificate = verifyCertificate(trusted, session.getDefaultIdentity());
        }
        if (haveTrustedCertificate) {
            // Offer SASL EXTERNAL only if TLS has already been negotiated and the peer has a trusted cert.
            final Element mechanism = result.addElement("mechanism");
            mechanism.setText("EXTERNAL");
        }
    }
    return result;
}
项目:jamppa    文件:XMPPComponent.java   
private IQ handle(IQ iq, Map<String, QueryHandler> handlers) {
    Element queryElement = iq.getElement().element("query");
    if (queryElement == null) {
        return XMPPUtils.error(iq, "IQ does not contain query element.",
                LOGGER);
    }

    Namespace namespace = queryElement.getNamespace();

    QueryHandler queryHandler = handlers.get(namespace.getURI());
    if (queryHandler == null) {
        return XMPPUtils.error(iq, "QueryHandler not found for namespace: "
                + namespace, LOGGER);
    }

    return queryHandler.handle(iq);
}
项目:bio2rdf-rest    文件:DocumentHelper.java   
/**
 * 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;
}
项目:bio2rdf-rest    文件:DocumentHelper.java   
/**
 * 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;
}