Example usage for org.dom4j Namespace Namespace

List of usage examples for org.dom4j Namespace Namespace

Introduction

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

Prototype

public Namespace(String prefix, String uri) 

Source Link

Document

DOCUMENT ME!

Usage

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");
        }/*from w w w . j  av a  2s. com*/
    }
    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());
            }/*ww w . j av  a 2 s.  co  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 .  ja va 2s. 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 {//from ww w .  j a  v  a 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);
    }
}

From source file:org.collectionspace.services.id.IDResource.java

License:Educational Community License

/**
 * Returns a representation of a single ID generator instance resource.
 *
 * @param    csid  An identifier for an ID generator instance.
 *
 * @return  A representation of an ID generator instance resource.
 *//*from  w  w w  .  j a  va  2 s.c  o m*/
@GET
@Path("/{csid}")
@Produces(MediaType.APPLICATION_XML)
public Response readIDGenerator(@PathParam("csid") String csid) {

    ResponseBuilder builder = Response.ok();
    Response response = builder.build();

    String resourceRepresentation = "";
    try {
        ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext();
        IDGeneratorInstance instance = service.readIDGenerator(ctx, csid);

        Document doc = DocumentHelper.createDocument();
        Element root = doc.addElement(ID_GENERATOR_NAME);
        Namespace namespace = new Namespace(ID_SERVICE_NAMESPACE_PREFIX, ID_SERVICE_NAMESPACE);
        doc.getRootElement().add(namespace);

        // Make new elements for each of the components of this ID generator
        // instance, and attach them to the root element.

        // Append display name information for this ID generator instance.
        String displayname = instance.getDisplayName();
        root = appendDisplayNameIDGeneratorInformation(root, displayname);
        // Append detailed information for this ID generator instance.
        root = appendDetailedIDGeneratorInformation(root, instance);

        resourceRepresentation = XmlTools.prettyPrintXML(doc);
        response = Response.status(Response.Status.OK).entity(resourceRepresentation)
                .type(MediaType.APPLICATION_XML).build();

        // @TODO Return an XML-based error results format with the
        // responses below.

    } catch (DocumentNotFoundException dnfe) {
        response = Response.status(Response.Status.NOT_FOUND).entity(dnfe.getMessage())
                .type(MediaType.TEXT_PLAIN).build();

    } catch (IllegalStateException ise) {
        response = Response.status(Response.Status.BAD_REQUEST).entity(ise.getMessage())
                .type(MediaType.TEXT_PLAIN).build();

        // This is guard code that should never be reached.
    } catch (Exception e) {
        response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage())
                .type(MediaType.TEXT_PLAIN).build();
    }

    return response;
}

From source file:org.collectionspace.services.id.IDResource.java

License:Educational Community License

/**
 * Returns a base XML document representing a list of
 * ID generator instances./*from   w w  w  . j a  v a2 s  . c om*/
 *
 * @return  A base XML document representing a list
 *          of ID generator instances.
 */
private Document baseListDocument() {

    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement(ID_GENERATOR_LIST_NAME);
    Namespace namespace = new Namespace(ID_SERVICE_NAMESPACE_PREFIX, ID_SERVICE_NAMESPACE);
    doc.getRootElement().add(namespace);

    return doc;
}

From source file:org.etudes.component.app.melete.MeleteAbstractExportServiceImpl.java

License:Apache License

/**
 * creates document root element "manifest" and adds the namespaces
 *
 * @return returns the manifest element/*from   ww w  .  ja  v a 2s.  com*/
 * @throws  Exception
 */
public Element createManifest() throws Exception {
    Element root = DocumentHelper.createElement("manifest");
    //Set up the necessary namespaces
    root.setQName(new QName("manifest", new Namespace(null, DEFAULT_NAMESPACE_URI)));
    root.add(new Namespace("imsmd", getMetaDataNameSpace()));
    root.add(new Namespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"));

    /*root.addAttribute("xsi:schemaLocation",
    "http://www.imsglobal.org/xsd/imscp_v1p1 "
          + "http://www.imsglobal.org/xsd/imscp_v1p1.xsd "
          + "http://www.imsglobal.org/xsd/imsmd_v1p2 "
          + "http://www.imsglobal.org/xsd/imsmd_v1p2.xsd ");
    */

    root.addAttribute("identifier", "Manifest-" + getUUID());
    root.addAttribute("version", "IMS CP 1.1.4");
    return root;
}

From source file:org.etudes.component.app.melete.MeleteAbstractExportServiceImpl.java

License:Apache License

/**
 * creates the default namespace element
 * @param elename - element name//  w  w  w  . ja v  a  2s . co m
 * @param qname - qualified name
 * @return - returns the default namespace element
 */
public Element createDefaultNSElement(String elename, String qname) {
    Element metadata = DocumentHelper.createElement(elename);
    metadata.setQName(new QName(qname, new Namespace(null, DEFAULT_NAMESPACE_URI)));
    return metadata;
}

From source file:org.etudes.component.app.melete.MeleteAbstractExportServiceImpl.java

License:Apache License

/**
 * creates the LOM metadata element//from   w w  w . j av  a2s. co  m
 * @param elename - element name
 * @param qname - qualified name
 * @return - returns the metadata element
 */
public Element createLOMElement(String elename, String qname) {

    Element imsmdlom = DocumentHelper.createElement(elename);
    imsmdlom.setQName(new QName(qname, new Namespace("imsmd", getMetaDataNameSpace())));

    return imsmdlom;
}

From source file:org.etudes.jforum.view.admin.ImportExportAction.java

License:Apache License

/**
 * creates the default namespace element
 * // w  w  w.  jav  a2  s  . c o  m
 * @param elename
 *            - element name
 * @param qname
 *            - qualified name
 * @return - returns the default namespace element
 */
private Element createDefaultNSElement(String elename, String qname) {
    Element metadata = DocumentHelper.createElement(elename);
    metadata.setQName(new QName(qname, new Namespace(null, DEFAULT_NAMESPACE_URI)));
    return metadata;
}