Example usage for org.dom4j Namespace clone

List of usage examples for org.dom4j Namespace clone

Introduction

In this page you can find the example usage for org.dom4j Namespace clone.

Prototype

public Object clone() 

Source Link

Usage

From source file:com.cladonia.xngreditor.actions.ToolsChangeNSPrefixAction.java

License:Open Source License

/**
 * /*from   w  w  w  . j a va2  s  . c  o  m*/
 * Renames a namespace at the root element
 * @param element the root element
 * @param allNamespaces the full vector of namespaces
 * @param newNamespaces the vector of new namespaces
 * @throws Exception
 */
private void renameNamespacesAtRoot(XElement element, Vector allNamespaces, Vector newNamespaces)
        throws Exception {

    //need to handle if the root has a namespace associated
    try {
        Namespace used = element.getNamespace();
        int match = -1;
        if (used != null) {
            for (int cnt = 0; cnt < allNamespaces.size(); ++cnt) {
                if (used == (Namespace) allNamespaces.get(cnt)) {
                    match = cnt;
                }
            }
            if (match > -1) {
                //replace the elements prefix with the corresponding one in the
                //other vector
                Namespace tempNs = (Namespace) newNamespaces.get(match);

                Namespace old = (Namespace) used.clone();

                QName qname = new QName(element.getName(), tempNs);
                element.setQName(qname);
                element.add(old);
            }
        }
        try {
            element.setAttributes(this.setPrefixOnAttributes(element, allNamespaces, newNamespaces));
        } catch (Exception e1) {
            MessageHandler.showError(parent, "Error reading the document",
                    "Tools Rename a Namespace Prefix Error");
        }
    } catch (NullPointerException e) {
        //no namespaces in the root            
        MessageHandler.showError(parent, "No namespace declared", "Tools Rename a Namespace Prefix Error");
    }
}