Example usage for org.jdom2 Namespace getNamespace

List of usage examples for org.jdom2 Namespace getNamespace

Introduction

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

Prototype

public static Namespace getNamespace(final String prefix, final String uri) 

Source Link

Document

This will retrieve (if in existence) or create (if not) a Namespace for the supplied prefix and uri.

Usage

From source file:org.yawlfoundation.yawl.resourcing.util.DataSchemaBuilder.java

License:Open Source License

/**
 * Creates and stores the default XSD namespace
 * @return the default XSD namespace//from ww w  . j a va 2  s. c o  m
 */
private Namespace getDefaultNamespace() {
    Namespace ns = Namespace.getNamespace("xsd", XMLConstants.W3C_XML_SCHEMA_NS_URI);
    _nsList.put(XMLConstants.W3C_XML_SCHEMA_NS_URI, ns);
    return ns;
}

From source file:org.yawlfoundation.yawl.resourcing.util.DataSchemaBuilder.java

License:Open Source License

/**
 * Adds a new namespace to the list of namespaces ussed by this schema
 * @param URI the namespace's URI/*from w w  w . j ava 2  s .c  om*/
 * @param prefix the namespace's prefix
 * @return the namespace
 */
private Namespace addNamespace(String URI, String prefix) {
    if ((prefix == null) || prefix.length() == 0)
        return null;
    if (!_nsList.containsKey(URI)) {
        _nsList.put(URI, Namespace.getNamespace(prefix, URI));
    }
    return _nsList.get(URI);
}

From source file:projetxml.model.XMLManagement.java

private void ajouterDonnees(String nomFichier, Map<String, String> infos, Map<String, String> infosOmdb) {
    Element racine = documentOutput.getRootElement();
    Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    racine.addNamespaceDeclaration(xsi);
    racine.setAttribute("noNamespaceSchemaLocation", "input.xsd", xsi);

    Element episode = new Element("episode");
    racine.addContent(episode);//from www  .  j  a v a2  s .  c o  m

    Element titre = new Element("titre");
    titre.setText(nomFichier);
    episode.addContent(titre);

    Element titreComplet = new Element("titreComplet");
    titreComplet.setText(infos.get("title"));
    episode.addContent(titreComplet);

    Element numero = new Element("numero");
    numero.setText(infos.get("episode"));
    episode.addContent(numero);

    Element saison = new Element("saison");
    saison.setText(infos.get("season"));
    episode.addContent(saison);

    Element qualite = new Element("qualite");
    qualite.setText(infos.get("quality"));
    episode.addContent(qualite);

    Element lien = new Element("lien");
    lien.setText(infos.get("link"));
    episode.addContent(lien);

    Element note = new Element("note");
    note.setText(infosOmdb.get("rated"));
    episode.addContent(note);

    Element description = new Element("description");
    description.setText(infosOmdb.get("plot"));
    episode.addContent(description);

    Element image = new Element("image");
    image.setText(infosOmdb.get("poster"));
    episode.addContent(image);

    Element torrent = new Element("torrent");
    episode.addContent(torrent);

    Element infoHash = new Element("infoHash");
    infoHash.setText(infos.get("infoHash"));
    torrent.addContent(infoHash);

    Element magnetURI = new Element("magnetURI");
    magnetURI.setText(infos.get("magnetURI"));
    torrent.addContent(magnetURI);

    Element seeds = new Element("seeds");
    seeds.setText(infos.get("seeds"));
    torrent.addContent(seeds);

    Element peers = new Element("peers");
    peers.setText(infos.get("peers"));
    torrent.addContent(peers);

    Element verified = new Element("verified");
    verified.setText(infos.get("verified"));
    torrent.addContent(verified);

    Element filename = new Element("filename");
    filename.setText(infos.get("filename"));
    torrent.addContent(filename);

    Element enclosure = new Element("enclosure");
    enclosure.setText(infos.get("enclosure"));
    torrent.addContent(enclosure);

}

From source file:pt.ist.socialsoftware.edition.export.ExpertEditionTEIExport.java

License:Creative Commons License

private Element generateCorpus() {
    this.jdomDoc = new Document();
    Element rootElement = new Element("teiCorpus");

    rootElement.setNamespace(this.xmlns);

    rootElement.addNamespaceDeclaration(Namespace.getNamespace("svg", "http://www.w3.org/2000/svg"));

    rootElement.addNamespaceDeclaration(Namespace.getNamespace("xi", "http://www.w3.org/2001/XInclude"));

    this.jdomDoc.setRootElement(rootElement);
    return rootElement;
}

From source file:pt.ist.socialsoftware.edition.visitors.TEIGenerator.java

License:Creative Commons License

private Element generateCorpus() {
    jdomDoc = new Document();
    Element rootElement = new Element("teiCorpus");

    rootElement.setNamespace(xmlns);// w w  w  .j  a v a2 s  .c o  m

    rootElement.addNamespaceDeclaration(Namespace.getNamespace("svg", "http://www.w3.org/2000/svg"));

    rootElement.addNamespaceDeclaration(Namespace.getNamespace("xi", "http://www.w3.org/2001/XInclude"));

    jdomDoc.setRootElement(rootElement);
    return rootElement;
}

From source file:sample.webservices.endpoint.HolidayEndpoint.java

License:Apache License

public HolidayEndpoint(HumanResourceService humanResourceService)
        throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException {
    this.humanResourceService = humanResourceService;
    Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);
    XPathFactory xPathFactory = XPathFactory.instance();
    this.startDateExpression = xPathFactory.compile("//hr:StartDate", Filters.element(), null, namespace);
    this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null, namespace);
    this.nameExpression = xPathFactory.compile("concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(),
            null, namespace);//from  w  ww.  ja  va 2  s  .  c o  m
}

From source file:sample.ws.endpoint.HolidayEndpoint.java

License:Apache License

@Autowired
public HolidayEndpoint(HumanResourceService humanResourceService)
        throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException {
    this.humanResourceService = humanResourceService;

    Namespace namespace = Namespace.getNamespace("hr", NAMESPACE_URI);

    XPathFactory xPathFactory = XPathFactory.instance();

    this.startDateExpression = xPathFactory.compile("//hr:StartDate", Filters.element(), null, namespace);
    this.endDateExpression = xPathFactory.compile("//hr:EndDate", Filters.element(), null, namespace);
    this.nameExpression = xPathFactory.compile("concat(//hr:FirstName,' ',//hr:LastName)", Filters.fstring(),
            null, namespace);//w w w.jav  a2s.  co m
}

From source file:test.sql.XPathModifier.java

License:Apache License

public void addNamespace(String prefix, String uri) {
    if ((prefix == null) || (uri == null))
        return;/*from   w w w.j ava  2s .  c om*/

    if (debugFlag)
        System.out.println("adding namespace:  " + prefix + ", " + uri);

    Namespace namespace = Namespace.getNamespace(prefix, uri);
    if (namespace != null) {
        if (namespaces == null) {
            namespaces = new ArrayList<Namespace>();
        }
        namespaces.add(namespace);
    } else {
        System.out.println("namespace came back null");
    }
}

From source file:us.xwhite.dvd.endpoint.RentalEndpoint.java

License:Apache License

public RentalEndpoint(RentalService rentalService)
        throws JDOMException, XPathFactoryConfigurationException, XPathExpressionException {
    this.rentalService = rentalService;
    Namespace namespace = Namespace.getNamespace("sakila", NAMESPACE_URI);
    XPathFactory xPathFactory = XPathFactory.instance();
    this.storeId = xPathFactory.compile("//@storeId", Filters.attribute(), null, namespace);
    this.filmTitles = xPathFactory.compile("//@title", Filters.attribute(), null, namespace);
}

From source file:utils.RandomTopo.java

License:Open Source License

/** Generates an XCSP representation of a graph coloring problem
 * @param publicInteragentConstraints    whether inter-agent constraints should be public
 * @param soft                      whether the output should be a Max-DisCSP
 * @param intensional                whether the output should be intensional
 * @return An XCSP-formatted Document// w  w  w. j  av a  2s . c  o m
 */
public Document toXCSP(final boolean publicInteragentConstraints, final boolean soft,
        final boolean intensional) {

    // Create the root element
    Element probElement = new Element("instance");
    probElement.setAttribute("noNamespaceSchemaLocation",
            "src/frodo2/algorithms/XCSPschema" + (soft || !intensional ? "" : "JaCoP") + ".xsd",
            Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"));

    // Create the "presentation" element
    Element presElmt = new Element("presentation");
    probElement.addContent(presElmt);
    presElmt.setAttribute("name", this.instanceName);
    presElmt.setAttribute("maxConstraintArity", "2");
    presElmt.setAttribute("maximize", "false");
    presElmt.setAttribute("format", "XCSP 2.1_FRODO");

    // Create the "agents" element
    Element elmt = new Element("agents");
    probElement.addContent(elmt);
    final int nbrNodes = graph.nodes.size();
    elmt.setAttribute("nbAgents", Integer.toString(nbrNodes - this.stochNodes.size()));
    for (String varID : this.graph.nodes) {

        // Skip the stoch nodes
        if (this.stochNodes.contains(varID))
            continue;

        Element subElmt = new Element("agent");
        elmt.addContent(subElmt);
        subElmt.setAttribute("name", "a" + varID);
    }

    // Create the "domains" element
    elmt = new Element("domains");
    probElement.addContent(elmt);
    elmt.setAttribute("nbDomains", "1");
    Element subElmt = new Element("domain");
    elmt.addContent(subElmt);
    subElmt.setAttribute("name", "colors");
    subElmt.setAttribute("nbValues", Integer.toString(nbrColors));
    subElmt.addContent("1.." + Integer.toString(nbrColors));

    // Create the "variables" element
    elmt = new Element("variables");
    probElement.addContent(elmt);
    elmt.setAttribute("nbVariables", Integer.toString(graph.nodes.size()));
    for (String varID : this.graph.nodes) {
        subElmt = new Element("variable");
        elmt.addContent(subElmt);
        subElmt.setAttribute("name", "n" + varID);
        subElmt.setAttribute("domain", "colors");
        if (this.stochNodes.contains(varID))
            subElmt.setAttribute("type", "random");
        else
            subElmt.setAttribute("agent", "a" + varID);
    }

    // Create the "relations" element
    Element relElmt = new Element("relations");
    if (soft || !intensional || !this.unaryCons.isEmpty()) {
        probElement.addContent(relElmt);
    }

    if (soft || !intensional) { // extensional

        subElmt = new Element("relation");
        relElmt.addContent(subElmt);
        subElmt.setAttribute("name", "neq");
        subElmt.setAttribute("semantics", "soft");
        subElmt.setAttribute("arity", "2");
        subElmt.setAttribute("defaultCost", "0");
        subElmt.setAttribute("nbTuples", Integer.toString(nbrColors));

        StringBuilder builder = new StringBuilder(soft ? "1: " : "infinity: ");
        for (int i = 1; i < nbrColors; i++)
            builder.append(Integer.toString(i) + " " + i + " | ");
        builder.append(Integer.toString(nbrColors) + " " + nbrColors);
        subElmt.setText(builder.toString());

    } else { // pure satisfaction, intensional

        // Create the "predicates" element
        elmt = new Element("predicates");
        probElement.addContent(elmt);
        elmt.setAttribute("nbPredicates", "1");

        subElmt = new Element("predicate");
        elmt.addContent(subElmt);
        subElmt.setAttribute("name", "neq");

        elmt = new Element("parameters");
        subElmt.addContent(elmt);
        elmt.setText("int X int Y");

        elmt = new Element("expression");
        subElmt.addContent(elmt);

        subElmt = new Element("functional");
        elmt.addContent(subElmt);
        subElmt.setText("ne(X, Y)");
    }

    if (!this.stochNodes.isEmpty()) {

        // Create the "probabilities" element
        elmt = new Element("probabilities");
        probElement.addContent(elmt);
        elmt.setAttribute("nbProbabilities", Integer.toString(this.stochNodes.size()));

        for (String varID : this.stochNodes) {

            subElmt = new Element("probability");
            elmt.addContent(subElmt);
            subElmt.setAttribute("name", "n" + varID + "proba");
            subElmt.setAttribute("semantics", "soft");
            subElmt.setAttribute("arity", "1");
            subElmt.setAttribute("nbTuples", Integer.toString(nbrColors));

            // Choose a random probability distribution
            StringBuilder builder = new StringBuilder();
            double[] probas = new double[nbrColors];
            double sum = 0.0;
            for (int i = 0; i < nbrColors; i++) {
                probas[i] = Math.random();
                sum += probas[i];
            }
            for (int i = 0; i < nbrColors - 1; i++)
                builder.append(Double.toString(probas[i] / sum) + ": " + (i + 1) + " | ");
            builder.append(Double.toString(probas[nbrColors - 1] / sum) + ": " + nbrColors);
            subElmt.setText(builder.toString());
        }
    }

    // Create the "constraints" element
    Element conElmt = new Element("constraints");
    probElement.addContent(conElmt);

    // Create the unary constraints
    double tightness = 0.0;
    final double weight = 1.0 / (this.nbrColors * (this.graph.nodes.size() - this.stochNodes.size()));
    for (Map.Entry<String, ArrayList<Integer>> entry : this.unaryCons.entrySet()) {
        String n = entry.getKey();
        ArrayList<Integer> colors = entry.getValue();
        tightness += colors.size() * weight;

        // Create the relation
        subElmt = new Element("relation");
        relElmt.addContent(subElmt);
        subElmt.setAttribute("name", "unaryRel_" + n);
        subElmt.setAttribute("semantics", soft || !intensional ? "soft" : "conflicts");
        subElmt.setAttribute("arity", "1");
        if (soft || !intensional)
            subElmt.setAttribute("defaultCost", "0");
        subElmt.setAttribute("nbTuples", Integer.toString(colors.size()));

        StringBuilder builder = new StringBuilder(soft ? "1: " : !intensional ? "infinity: " : "");
        for (int i = colors.size() - 1; i > 0; i--)
            builder.append(colors.get(i)).append("|");
        builder.append(colors.get(0));
        subElmt.setText(builder.toString());

        // Create the constraint
        elmt = new Element("constraint");
        conElmt.addContent(elmt);
        elmt.setAttribute("name", "unaryCons_" + n);
        elmt.setAttribute("scope", "n" + n);
        elmt.setAttribute("arity", "1");
        elmt.setAttribute("reference", "unaryRel_" + n);
        elmt.setAttribute("agent", "a" + n);
        //random volatility
        int vol;
        do {
            vol = (int) Math.round(gaussian ? ((new Random().nextGaussian() + 50)) : ((Math.random() * 100)));
        } while (vol < 0 || vol > 100);
        elmt.setAttribute("volatility", String.valueOf(vol));
    }

    // Go through all edges in the graph
    for (Edge edge : graph.edges) {

        // Skip this constraint if it involves two random variables
        if (this.stochNodes.contains(edge.source) && this.stochNodes.contains(edge.dest))
            continue;

        elmt = new Element("constraint");
        conElmt.addContent(elmt);

        final String n1 = "n" + edge.source;
        final String n2 = "n" + edge.dest;

        elmt.setAttribute("name", n1 + "_neq_" + n2);
        elmt.setAttribute("scope", n1 + " " + n2);
        elmt.setAttribute("arity", "2");
        elmt.setAttribute("reference", "neq");
        if (publicInteragentConstraints)
            elmt.setAttribute("agent", "PUBLIC");

        if (!soft && intensional) {
            subElmt = new Element("parameters");
            elmt.addContent(subElmt);
            subElmt.setText(n1 + " " + n2);
        }
        //random volatility
        int vol;
        do {
            vol = (int) Math
                    .round(gaussian ? ((new Random().nextGaussian() * 100 + 50)) : ((Math.random() * 100)));
        } while (vol < 0 || vol > 100);
        elmt.setAttribute("volatility", String.valueOf(vol));
    }

    // Add the probability distributions
    for (String varID : this.stochNodes) {
        final String varName = "n" + varID;

        elmt = new Element("constraint");
        conElmt.addContent(elmt);
        elmt.setAttribute("name", varName + "dist");
        elmt.setAttribute("scope", varName);
        elmt.setAttribute("arity", "1");
        elmt.setAttribute("reference", varName + "proba");
    }

    relElmt.setAttribute("nbRelations", Integer.toString(relElmt.getContentSize()));
    conElmt.setAttribute("nbConstraints", Integer.toString(conElmt.getContentSize()));

    // Write the stats
    presElmt.addContent(createStats("number of nodes", Integer.toString(this.graph.nodes.size())));
    presElmt.addContent(createStats("target density", Double.toString(this.targetDensity)));
    presElmt.addContent(createStats("true average density", Double.toString(this.graph.computeDensity())));
    presElmt.addContent(createStats("target unary tightness", Double.toString(this.targetTightness)));
    presElmt.addContent(createStats("true average unary tightness", Double.toString(tightness)));
    presElmt.addContent(createStats("number of colors", Integer.toString(this.nbrColors)));
    presElmt.addContent(
            createStats("number of uncontrollable nodes", Integer.toString(this.stochNodes.size())));
    presElmt.addContent(
            createStats("number of disconnected components", Integer.toString(graph.components.size())));
    presElmt.addContent(createStats("max degree", Integer.toString(graph.computeMaxDeg())));

    return new Document(probElement);
}