Example usage for org.dom4j QName QName

List of usage examples for org.dom4j QName QName

Introduction

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

Prototype

public QName(String name, Namespace namespace) 

Source Link

Usage

From source file:org.codehaus.cargo.container.weblogic.WebLogic9xConfigXmlInstalledLocalDeployer.java

License:Apache License

/**
 * create the config.xml element representing the Deployable. In WebLogic 9x, this is the
 * element app-deployment./*ww w.j  a  v  a 2 s.c om*/
 * 
 * @param deployable to configure
 * @param domain root element of the config.xml file
 * @return app-deployment element
 */
protected Element createElementForDeployableInDomain(Deployable deployable, Element domain) {
    QName appDeploymentQName = new QName("app-deployment",
            new Namespace("", "http://www.bea.com/ns/weblogic/920/domain"));
    Element appDeployment = domain.addElement(appDeploymentQName);
    String id = createIdForDeployable(deployable);
    // the name element is a unique identifier in the config.xml file. that's why this is being
    // named id as opposed to name
    Element appId = appDeployment.addElement("name");
    appId.setText(id);
    Element target = appDeployment.addElement("target");
    target.setText(getServerName());
    Element sourcePath = appDeployment.addElement("source-path");
    sourcePath.setText(getAbsolutePath(deployable));
    return appDeployment;
}

From source file:org.codehaus.cargo.util.Dom4JXmlFileBuilder.java

License:Apache License

/**
 * @param element to traverse and change namespace of
 * @param parent - who to match namespaces with.
 *//* w  ww . ja va2 s .  com*/
private void setNamespaceOfElementToTheSameAsParent(Element element, Element parent) {
    final Namespace namespaceOfParent = parent.getNamespace();
    element.accept(new VisitorSupport() {
        @Override
        public void visit(Element node) {
            QName nameOfElementWithCorrectNamespace = new QName(node.getName(), namespaceOfParent);
            node.setQName(nameOfElementWithCorrectNamespace);
        }
    });
}

From source file:org.collectionspace.chain.csp.persistence.services.XmlJsonConversion.java

License:Educational Community License

public static Document getXMLRelationship(Element[] listItems) {
    Document doc = DocumentFactory.getInstance().createDocument();
    Element root = doc.addElement(new QName("relations-common-list",
            new Namespace("ns3", "http://collectionspace.org/services/relation")));
    root.addNamespace("ns2", "http://collectionspace.org/services/jaxb");
    //<ns3:relations-common-list xmlns:ns3="http://collectionspace.org/services/relation" xmlns:ns2="http://collectionspace.org/services/jaxb">

    if (listItems != null) {
        for (Element bitdoc : listItems) {
            root.add(bitdoc);/*from   w  w  w. java 2  s  .  c om*/
        }
    }

    return doc;

}

From source file:org.collectionspace.chain.csp.persistence.services.XmlJsonConversion.java

License:Educational Community License

public static Document convertToXml(Record r, JSONObject in, String section, String permtype,
        Boolean useInstance) throws JSONException, UnderlyingStorageException {
    if (!useInstance) {
        return convertToXml(r, in, section, permtype);
    }/* w w  w.j  a va2s . c o  m*/

    Document doc = DocumentFactory.getInstance().createDocument();
    String[] parts = r.getServicesRecordPath(section).split(":", 2);
    if (useInstance) {
        parts = r.getServicesInstancesPath(section).split(":", 2);
    }
    String[] rootel = parts[1].split(",");
    Element root = doc.addElement(new QName(rootel[1], new Namespace("ns2", rootel[0])));

    Element element = root.addElement("displayName");
    element.addText(in.getString("displayName"));
    Element element2 = root.addElement("shortIdentifier");
    element2.addText(in.getString("shortIdentifier"));
    if (in.has("vocabType")) {
        Element element3 = root.addElement("vocabType");
        element3.addText(in.getString("vocabType"));
    }

    return doc;
    //yes I know hardcode is bad - but I need this out of the door today
    /*
    <ns2:personauthorities_common xmlns:ns2="http://collectionspace.org/services/person">
    <displayName>PAHMA Person Authority</displayName>
    <vocabType>PersonAuthority</vocabType>
    <shortIdentifier>pamha</shortIdentifier>
    </ns2:personauthorities_common>
     */

}

From source file:org.collectionspace.chain.csp.persistence.services.XmlJsonConversion.java

License:Educational Community License

public static Document convertToXml(Record r, JSONObject in, String section, String operation)
        throws JSONException, UnderlyingStorageException {
    Document doc = DocumentFactory.getInstance().createDocument();
    try {/*from w w  w. jav a 2  s . co m*/
        String path = r.getServicesRecordPath(section);
        if (path != null) {
            String[] parts = path.split(":", 2);
            String[] rootel = parts[1].split(",");
            Element root = doc.addElement(new QName(rootel[1], new Namespace("ns2", rootel[0])));
            if (r.getAllServiceFieldTopLevel(operation, section).length > 0) {
                for (FieldSet f : r.getAllServiceFieldTopLevel(operation, section)) {
                    addFieldSetToXml(root, f, in, section, operation);
                }
                return doc;
            }
        } else {
            // Revert to DEBUG after v4.0 testing
            log.warn(String.format("Record %s lacks expected section %s", r.getRecordName(), section));
        }
    } catch (Exception ex) {
        log.debug("Error in XmlJsonConversion.convertToXml", ex);
        throw ex;
    }
    return null;
}

From source file:org.collectionspace.chain.csp.webui.nuispec.ServicesXsd.java

License:Educational Community License

private void generateRepeat(Repeat r, Element root, Namespace ns, String listName) {

    if (r.hasServicesParent()) {
        Element sequenced = null;
        for (String path : r.getServicesParent()) {
            if (path != null) {
                if (null != sequenced) {
                    Element dele = sequenced.addElement(new QName("element", ns));
                    dele.addAttribute("name", path);
                    dele.addAttribute("type", path);
                    dele.addAttribute("minOccurs", "0");
                    dele.addAttribute("maxOccurs", "unbounded");
                }//  w  w w .j a  v a2s  .  c o  m
                Element ele = root.addElement(new QName("complexType", ns));
                ele.addAttribute("name", path);
                sequenced = ele.addElement(new QName("sequence", ns));
            }
        }
        if (sequenced != null) {
            Element dele = sequenced.addElement(new QName("element", ns));
            dele.addAttribute("name", r.getServicesTag());
            dele.addAttribute("type", r.getServicesTag());
            dele.addAttribute("minOccurs", "0");
            dele.addAttribute("maxOccurs", "unbounded");
        }
    }

    Element ele = root.addElement(new QName("complexType", ns));
    ele.addAttribute("name", listName);
    Element sele = ele.addElement(new QName("sequence", ns));
    for (FieldSet fs : r.getChildren("")) {
        generateDataEntry(sele, fs, ns, root, true);
    }

}

From source file:org.collectionspace.chain.csp.webui.nuispec.ServicesXsd.java

License:Educational Community License

private void generateDataEntry(Element ele, FieldSet fs, Namespace ns, Element root, Boolean isRepeat) {
    if (fs instanceof Field) {
        // <xs:element name="csid" type="xs:string"/>
        Element field = ele.addElement(new QName("element", ns));
        field.addAttribute("name", fs.getServicesTag());
        field.addAttribute("type", "xs:string");
        if (isRepeat) {
            field.addAttribute("minOccurs", "0");
            field.addAttribute("maxOccurs", "unbounded");
        }/* w w w .jav a  2s  .  c o m*/
    }
    if (fs instanceof Repeat) {
        Repeat rfs = (Repeat) fs;
        String listName = rfs.getServicesTag();
        if (rfs.hasServicesParent()) {
            // group repeatable
            // <xs:element name="objectNameList" type="ns:objectNameList"/>
            Element field = ele.addElement(new QName("element", ns));
            field.addAttribute("name", rfs.getServicesParent()[0]);
            Namespace groupns = new Namespace("ns", "");
            field.addAttribute("type", "ns:" + rfs.getServicesParent()[0]);
        } else {
            // single repeatable
            // <xs:element name="responsibleDepartments"
            // type="responsibleDepartmentList"/>
            Element field = ele.addElement(new QName("element", ns));
            field.addAttribute("name", rfs.getServicesTag());

            listName = rfs.getChildren("")[0].getServicesTag() + "List";
            field.addAttribute("type", listName);

        }
        generateRepeat(rfs, root, ns, listName);
    }

}

From source file:org.collectionspace.chain.csp.webui.nuispec.ServicesXsd.java

License:Educational Community License

@SuppressWarnings("null")
private void generateSearchList(Element root, Namespace ns) {

    Element ele = root.addElement(new QName("complexType", ns));
    ele.addAttribute("name", "abstractCommonList");
    Element aele = ele.addElement(new QName("annotation", ns));
    Element appele = aele.addElement(new QName("appinfo", ns));
    Element jxb = appele.addElement(new QName("class", new Namespace("jaxb", "")));
    jxb.addAttribute("ref", "org.collectionspace.services.jaxb.AbstractCommonList");

    String[] listpath = record.getServicesListPath().split("/");

    Element lele = root.addElement(new QName("element", ns));
    lele.addAttribute("name", listpath[0]);
    Element clele = lele.addElement(new QName("complexType", ns));
    Element cplele = clele.addElement(new QName("complexContent", ns));
    Element exlele = cplele.addElement(new QName("extension", ns));
    exlele.addAttribute("base", "abstractCommmonList");
    Element sexlele = exlele.addElement(new QName("sequence", ns));
    Element slele = sexlele.addElement(new QName("element", ns));
    slele.addAttribute("name", listpath[1]);
    slele.addAttribute("maxOccurs", "unbounded");
    Element cslele = slele.addElement(new QName("complexType", ns));
    Element scslele = cslele.addElement(new QName("sequence", ns));

    Set<String> searchflds = new HashSet();
    for (String minis : record.getAllMiniDataSets()) {
        if (minis != null && !minis.equals("")) {
            for (FieldSet flds : record.getMiniDataSetByName(minis)) {
                searchflds.add(flds.getServicesTag());
                log.info(flds.getServicesTag());
            }//from w  w w.j a  va2 s.  c o m
        }
    }
    Iterator iter = searchflds.iterator();
    while (iter.hasNext()) {
        Element sfld = scslele.addElement(new QName("element", ns));
        sfld.addAttribute("name", (String) iter.next());
        sfld.addAttribute("type", "xs:string");
        sfld.addAttribute("minOccurs", "1");

    }

    /*standard fields */

    Element stfld1 = scslele.addElement(new QName("element", ns));
    stfld1.addAttribute("name", "uri");
    stfld1.addAttribute("type", "xs:string");
    stfld1.addAttribute("minOccurs", "1");

    Element stfld2 = scslele.addElement(new QName("element", ns));
    stfld2.addAttribute("name", "csid");
    stfld2.addAttribute("type", "xs:string");
    stfld2.addAttribute("minOccurs", "1");
}

From source file:org.collectionspace.chain.csp.webui.nuispec.ServicesXsd.java

License:Educational Community License

private String serviceschema(Storage s, String path) throws UIException {
    if (path != null) {
        section = path;/*from  w w w  . j  ava  2 s  . co  m*/
    }

    Document doc = DocumentFactory.getInstance().createDocument();
    Namespace ns = new Namespace("xs", "http://www.w3.org/2001/XMLSchema");
    String[] parts = record.getServicesRecordPath(section).split(":", 2);
    String[] rootel = parts[1].split(",");
    Element root = doc.addElement(new QName("schema", new Namespace("xs", "http://www.w3.org/2001/XMLSchema")));
    root.addAttribute("xmlns:ns", rootel[0]);
    root.addAttribute("xmlns", rootel[0]);
    root.addAttribute("targetNamespace", rootel[0]);
    root.addAttribute("version", "0.1");

    //      Element ele = root.addElement(new QName("element", ns));
    //      ele.addAttribute("name", rootel[1]);
    //      Element cele = ele.addElement(new QName("complexType", ns));

    // add toplevel items

    for (FieldSet fs : record.getAllFieldTopLevel("")) {
        generateDataEntry(root, fs, ns, root, false);
    }

    generateSearchList(root, ns);
    // log.info(doc.asXML());
    // return doc.asXML();

    return doc.asXML();

}

From source file:org.collectionspace.chain.util.xtmpl.XTmplTmpl.java

License:Educational Community License

@SuppressWarnings("unchecked")
private void compileTemplate(Document template) throws InvalidXTmplException {
    try {//w  ww . j ava  2 s .c o m
        Map<String, String> map = new HashMap<String, String>();
        map.put("xtmpl", XTMPL_URI);
        Dom4jXPath xpath = new Dom4jXPath("//.[@xtmpl:point]");
        xpath.setNamespaceContext(new SimpleNamespaceContext(map));
        List<Node> paths = xpath.selectNodes(template);
        QName attr_qname = new QName("point", new Namespace("xtmpl", XTMPL_URI));
        for (Node n : paths) {
            if (!(n instanceof Element))
                continue;
            Element e = (Element) n;
            Attribute attr = e.attribute(attr_qname);
            String key = attr.getText();
            String path = e.getPath();
            e.remove(attr);
            attach.put(key, path);
        }
        removeNamespaces(template.getDocument().getRootElement());
        document = template;
    } catch (JaxenException e) {
        throw new InvalidXTmplException("Cannot parse template file", e);
    }
}