Example usage for org.dom4j DocumentFactory getInstance

List of usage examples for org.dom4j DocumentFactory getInstance

Introduction

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

Prototype

public static synchronized DocumentFactory getInstance() 

Source Link

Document

Access to singleton implementation of DocumentFactory which is used if no DocumentFactory is specified when building using the standard builders.

Usage

From source file:VersionRelease.java

License:Open Source License

public void run() {
    processDir(jbossHome);/*from  ww w .  j  a v a  2 s. c  o m*/
    try {
        DocumentFactory df = DocumentFactory.getInstance();
        Document doc = df.createDocument();
        Element root = doc.addElement("jar-versions");
        Iterator iter = jars.iterator();
        while (iter.hasNext()) {
            JarInfo info = (JarInfo) iter.next();
            info.writeXML(root);
        }

        File versionsXml = new File(jbossHome, "jar-versions.xml");
        FileWriter versionInfo = new FileWriter(versionsXml);
        OutputFormat outformat = OutputFormat.createPrettyPrint();
        XMLWriter writer = new XMLWriter(versionInfo, outformat);
        writer.setEscapeText(true);
        writer.write(doc);
        writer.flush();
        versionInfo.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:architecture.common.license.License.java

License:Apache License

public String toXML() {
    DocumentFactory factory = DocumentFactory.getInstance();
    Document document = factory.createDocument();
    Element root = document.addElement("license");

    root.addAttribute("id", String.valueOf(getLicenseId()));
    root.addAttribute("name", getName());
    if (edition != null)
        root.addAttribute("edition", getEdition());
    root.addAttribute("creationDate", formatDate(getCreationDate()));
    root.addAttribute("version", getVersion().getVersionString());
    root.addAttribute("type", getType().name());
    if (getClient() != null) {
        Element client = root.addElement("client");
        if (getClient().getName() != null)
            client.addAttribute("name", getClient().getName());
        if (getClient().getCompany() != null)
            client.addAttribute("company", getClient().getCompany());
    }/*from   w w  w  . ja  v a 2  s . c  o m*/

    for (Module m : getModules()) {
        Element me = root.addElement("module");
        me.addAttribute("name", m.getName());
    }

    for (java.util.Map.Entry<String, String> entry : getProperties().entrySet()) {
        Element prop = root.addElement("property");
        prop.addAttribute("name", (String) entry.getKey());
        prop.setText((String) entry.getValue());
    }
    return document.asXML();
}

From source file:at.jabberwocky.impl.core.io.PacketReader.java

public PacketReader(XmlPullParser p, Reader r, PacketQueue q) {
    parser = p;
    reader = r;
    queue = q;
    docFactory = DocumentFactory.getInstance();
    stop = new AtomicBoolean(false);
}

From source file:au.edu.usq.fascinator.harvester.fedora.FedoraItem.java

License:Open Source License

public FedoraItem(FedoraRestClient client, String pid) {
    this.client = client;
    this.pid = pid;
    nsMap = new HashMap<String, String>();
    nsMap.put("dc", "http://purl.org/dc/elements/1.1/");
    nsMap.put("oai_dc", "http://www.openarchives.org/OAI/2.0/oai_dc/");
    nsMap.put("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
    DocumentFactory.getInstance().setXPathNamespaceURIs(nsMap);
}

From source file:bio.pih.genoogle.io.Output.java

/**
 * @param searchResults//from   w ww  .  j a  va2 s  .  c om
 * 
 * @return {@link Document} containing the {@link SearchResults} in XML form.
 */
public static Document genoogleOutputToXML(List<SearchResults> searchResults) {
    assert searchResults != null;
    DocumentFactory factory = DocumentFactory.getInstance();

    Document doc = factory.createDocument();
    doc.setName("genoogle");

    Element output = doc.addElement(Genoogle.SOFTWARE_NAME);
    output.addAttribute("version", Genoogle.VERSION.toString());
    output.addAttribute("copyright", Genoogle.COPYRIGHT);

    Element iterationsElement = output.addElement("iterations");
    for (int i = 0; i < searchResults.size(); i++) {
        SearchResults searchResult = searchResults.get(i);

        Element iterationElement = iterationsElement.addElement("iteration");
        iterationElement.addAttribute("number", String.valueOf(i));

        SymbolList query = searchResult.getParams().getQuery();
        if (query instanceof RichSequence) {
            iterationElement.addAttribute("query", ((RichSequence) query).getHeader());
        }

        iterationElement.add(searchResultToXML(searchResult));
    }

    return doc;
}

From source file:bio.pih.genoogle.io.Output.java

public static Element genoogleXmlHeader() {
    DocumentFactory factory = DocumentFactory.getInstance();

    Document doc = factory.createDocument();
    doc.setName("genoogle");

    Map<String, String> xslProcessing = Maps.newHashMap();
    xslProcessing.put("type", "text/xsl");
    xslProcessing.put("href", "results.xsl");
    ProcessingInstruction xsltInstruction = DocumentHelper.createProcessingInstruction("xml-stylesheet",
            xslProcessing);/*from   w  ww . ja  v a 2s . c  o m*/
    doc.add(xsltInstruction);

    Element output = doc.addElement("genoogle");
    output.addElement("references").addAttribute("program", Genoogle.SOFTWARE_NAME)
            .addAttribute("version", Double.toString(Genoogle.VERSION))
            .addAttribute("copyright", Genoogle.COPYRIGHT);
    return output;
}

From source file:bio.pih.genoogle.io.Output.java

/**
 * @param searchResult//ww  w  . java  2 s  .c o  m
 * @return {@link Element} containing the {@link SearchResults} at XML form.
 */
public static Element searchResultToXML(SearchResults searchResult) {
    assert searchResult != null;
    // TODO: Revise this behavor to throws the exception before.
    if (searchResult.hasFail()) {
        for (Throwable e : searchResult.getFails()) {
            e.printStackTrace(System.err);
        }
    }
    DocumentFactory factory = DocumentFactory.getInstance();
    Element resultsElement = factory.createElement("results");
    resultsElement.add(paramsToXML(searchResult.getParams()));
    resultsElement.add(hitsToXML(searchResult.getHits()));

    return resultsElement;
}

From source file:bio.pih.genoogle.io.Output.java

/**
 * @param params/*from   w  ww  . j av  a  2s.  com*/
 * @return {@link Element} containing the {@link SearchParams} at XML form.
 */
public static Element paramsToXML(SearchParams params) {
    assert params != null;
    DocumentFactory factory = DocumentFactory.getInstance();

    Element paramsElement = factory.createElement("params");

    paramsElement.addAttribute("databank", params.getDatabank());
    paramsElement.addAttribute("maxSubSequencesDistance",
            Integer.toString(params.getMaxSubSequencesDistance()));
    paramsElement.addAttribute("minHspLength", Integer.toString(params.getMinHspLength()));
    paramsElement.addAttribute("maxHitsResults", Integer.toString(params.getMaxHitsResults()));
    paramsElement.addAttribute("sequencesExtendDropoff", Integer.toString(params.getSequencesExtendDropoff()));
    paramsElement.addAttribute("matchScore", Integer.toString(params.getMatchScore()));
    paramsElement.addAttribute("mismatchScore", Integer.toString(params.getMismatchScore()));

    return paramsElement;
}

From source file:bio.pih.genoogle.io.Output.java

/**
 * @param hits/*from   ww  w  . ja  v a 2  s.  co  m*/
 * @return {@link Element} containing the {@link List} of {@link Hit} at XML form.
 */
public static Element hitsToXML(List<Hit> hits) {
    assert hits != null;
    DocumentFactory factory = DocumentFactory.getInstance();

    Element hitsElement = factory.createElement("hits");
    for (Hit hit : hits) {
        hitsElement.add(hitToXML(hit));
    }

    return hitsElement;
}

From source file:bio.pih.genoogle.io.Output.java

/**
 * @param hit// w w w .  ja va  2 s.  c o  m
 * @return {@link Element} containing the {@link Hit} at XML form.
 */
public static Element hitToXML(Hit hit) {
    assert hit != null;
    DocumentFactory factory = DocumentFactory.getInstance();

    Element hitElement = factory.createElement("hit");
    hitElement.addAttribute("id", hit.getId());
    hitElement.addAttribute("gi", hit.getGi());
    hitElement.addAttribute("description", hit.getDescription());
    hitElement.addAttribute("accession", hit.getAccession());
    hitElement.addAttribute("length", Integer.toString(hit.getLength()));
    hitElement.addAttribute("databank", hit.getDatabankName());
    hitElement.add(hspsToXML(hit.getHSPs()));

    return hitElement;
}