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:org.frogx.service.games.hearts.Match.java

License:Open Source License

public void processLastTurn() throws InvalidTurnException, ComponentException {
    log.info("Prima di controllare moveID==57, stampo moveID --> " + moveID);
    if (moveID == 57) {
        log.info(//from w w w.  ja  v  a  2s .  c om
                "\tMano finita! Calcolo il vincitore, assegno i punteggi e mando il messaggio di fine partita.");
        ArrayList winData = new ArrayList();
        int standings[];
        Role checkWinRole = null;
        Collection<Element> standingsData = new ArrayList<Element>();
        log.info("\tMi calcolo winData tramite cardsController.matchEnding()");
        winData = cardsController.matchEnding();
        if (winData != null) {
            checkWinRole = (Role) winData.get(0);
            standings = (int[]) winData.get(1);
            log.info("\tWinner: " + checkWinRole.toString());
            log.info("\tStandings: N " + standings[0] + " - E " + standings[1] + " - S " + standings[2]
                    + " - W " + standings[3]);
            Element stats = DocumentFactory.getInstance().createDocument().addElement("matchend", NAMESPACE);
            stats.addAttribute("scoreN", Integer.toString(standings[0]));
            stats.addAttribute("scoreE", Integer.toString(standings[1]));
            stats.addAttribute("scoreS", Integer.toString(standings[2]));
            stats.addAttribute("scoreW", Integer.toString(standings[3]));
            log.info("\tIl messaggio in xml con i punteggi che mando a tutti e' :" + stats.asXML().toString());
            standingsData.add(stats);
            room.broadcastTurn(standingsData, this.player);
            status = Status.inactive;
        }
    }
}

From source file:org.frogx.service.games.hearts.Match.java

License:Open Source License

/**
 * Calculate the xml representation of the present match state.
 *///from   w  w w  .j  av  a 2 s .  c  o m
private void calculateStateElement() {
    log.info("calculateStatElement: init");
    stateElement = DocumentFactory.getInstance().createDocument().addElement("state", NAMESPACE);
    stateElement.addElement("bots").addText(Integer.toString(botUsers));
    if (turn == Role.north)
        stateElement.addElement("turn").addText(Role.north.name());
    if (turn == Role.east)
        stateElement.addElement("turn").addText(Role.east.name());
    if (turn == Role.south)
        stateElement.addElement("turn").addText(Role.south.name());
    if (turn == Role.west)
        stateElement.addElement("turn").addText(Role.west.name());

    Element table = stateElement.addElement("table");
    if (status == Status.active) {
        log.info("Room status: ACTIVE");

        if (!gameStarted) {
            gameHands = cardsController.cardsDealer();
            this.onTable[0] = 0;
            this.onTable[1] = 0;
            this.onTable[2] = 0;
            this.onTable[3] = 0;
            gameStarted = true;
        }
        Element field = table.addElement("playerN");
        for (int i = 1; i <= gameHands.get(0).size(); i++) {
            int cardToAdd = gameHands.get(0).get(i - 1);
            field.addAttribute("Card" + i, Integer.toString(cardToAdd));
        }
        if (gameHands.get(0).size() < 13) {
            for (int i = gameHands.get(0).size() + 1; i <= 13; i++) {
                int cardToAdd = 0;
                log.severe("Card " + i + " " + Integer.toString(cardToAdd));
                field.addAttribute("Card" + i, Integer.toString(cardToAdd));
            }
        }
        field.addAttribute("ontable", Integer.toString(onTable[0]));

        Element field2 = table.addElement("playerE");

        for (int i = 1; i <= gameHands.get(1).size(); i++) {
            int cardToAdd = gameHands.get(1).get(i - 1);

            field2.addAttribute("Card" + i, Integer.toString(cardToAdd));
        }
        if (gameHands.get(1).size() < 13) {
            for (int i = gameHands.get(1).size() + 1; i <= 13; i++) {
                int cardToAdd = 0;

                field2.addAttribute("Card" + i, Integer.toString(cardToAdd));
            }
        }
        field2.addAttribute("ontable", Integer.toString(onTable[1]));

        Element field3 = table.addElement("playerS");
        for (int i = 1; i <= gameHands.get(2).size(); i++) {
            int cardToAdd = gameHands.get(2).get(i - 1);

            field3.addAttribute("Card" + i, Integer.toString(cardToAdd));
        }
        if (gameHands.get(2).size() < 13) {
            for (int i = gameHands.get(2).size() + 1; i <= 13; i++) {
                int cardToAdd = 0;

                field3.addAttribute("Card" + i, Integer.toString(cardToAdd));
            }
        }
        field3.addAttribute("ontable", Integer.toString(onTable[2]));

        Element field4 = table.addElement("playerW");
        for (int i = 1; i <= gameHands.get(3).size(); i++) {
            int cardToAdd = gameHands.get(3).get(i - 1);
            //   log.severe("Card "+i+ " " + Integer.toString(cardToAdd));   
            field4.addAttribute("Card" + i, Integer.toString(cardToAdd));
        }
        if (gameHands.get(3).size() < 13) {
            for (int i = gameHands.get(3).size() + 1; i <= 13; i++) {
                int cardToAdd = 0;
                //   log.severe("Card "+ i + " " + Integer.toString(cardToAdd));   
                field4.addAttribute("Card" + i, Integer.toString(cardToAdd));
            }
        }
        field4.addAttribute("ontable", Integer.toString(onTable[3]));
    }
    log.info(stateElement.asXML());
}

From source file:org.frogx.service.maven.plugin.games.GenerateFrogxResourcesMojo.java

License:Open Source License

public boolean generatePluginDescriptor() {
    // Check requirements
    if (match == null || namespace == null) {
        return false;
    }//  ww w  .  j a v a  2 s. c  o m

    // Create XML data
    getLog().info("Generating a game descriptor (" + frogxPluginDescriptor + ").");
    DocumentFactory documentFactory = DocumentFactory.getInstance();
    Element gameEl = documentFactory.createElement("plugin", pluginDescriptorNS);

    Element element = gameEl.addElement("type");
    element.setText("match");

    element = gameEl.addElement("match");
    element.setText(match);

    element = gameEl.addElement("namespace");
    element.setText(namespace);

    if (description != null) {
        element = gameEl.addElement("description");
        element.setText(description);
    }

    if (category != null) {
        element = gameEl.addElement("category");
        element.setText(category);
    }

    Document doc = documentFactory.createDocument(gameEl);
    doc.setXMLEncoding("UTF-8");

    // Check and create the necessary folder
    File genResourceDir = getGeneratedFrogxResourcesDirectory();
    if (!genResourceDir.exists()) {
        genResourceDir.mkdirs();
    }

    // Write the game descriptor
    try {
        writeDocument(doc, new File(getGeneratedFrogxResourcesDirectory(), frogxPluginDescriptor));
    } catch (IOException e) {
        getLog().warn("An Error occured while writing the generated " + "game descriptor. ", e);
        return false;
    }
    return true;
}

From source file:org.gbif.portal.util.mhf.message.impl.xml.XMLMessageFactory.java

License:Open Source License

/**
 * Creates a new Message based on the node that is passed in
 *
 * @param node   To copy or detach/*w w  w.j ava2  s. c o m*/
 * @param detach If the node may be detached from the parent document
 * @return A new message
 */
public XMLMessage build(Node node, boolean detach) {
    Document document = DocumentFactory.getInstance().createDocument();
    if (detach) {
        document.add(node.detach());
    } else {
        Node cloned = (Node) node.clone();
        document.add(cloned);
    }
    return new XMLMessage(document);
}

From source file:org.gradle.api.tasks.ide.eclipse.EclipseClasspath.java

License:Apache License

private Document createXmlDocument() {
    Document document = DocumentFactory.getInstance().createDocument();
    Element root = document.addElement(CLASSPATH);

    addSrcDirs(root);//from   w w  w.j av  a  2  s  .  c o m
    addTestSrcDirs(root);
    classpathEntry(root, CON, DEFAULT_JRE_CONTAINER);
    addDependsOnProjects(root);
    addLibs(root);

    return document;
}

From source file:org.gradle.api.tasks.ide.eclipse.EclipseProject.java

License:Apache License

private Document createXmlDocument() {
    Document document = DocumentFactory.getInstance().createDocument();
    Element root = document.addElement("projectDescription");
    root.addElement("name").setText(projectName);
    root.addElement("comment");
    root.addElement("projects");
    addBuildSpec(root);/*from  w  w  w. j  a  v  a2 s.c om*/
    addNatures(root);
    return document;
}

From source file:org.gradle.api.tasks.ide.eclipse.EclipseWtp.java

License:Apache License

private void createFacets(Project project) {
    Document document = DocumentFactory.getInstance().createDocument();

    EclipseUtil.addFacet(document, "fixed", new DefaultAttribute("facet", "jst.java"));
    EclipseUtil.addFacet(document, "fixed", new DefaultAttribute("facet", "jst.web"));

    EclipseUtil.addFacet(document, "installed", new DefaultAttribute("facet", "jst.java"),
            new DefaultAttribute("version", "5.0"));
    EclipseUtil.addFacet(document, "installed", new DefaultAttribute("facet", "jst.web"),
            new DefaultAttribute("version", "2.4"));

    try {/*w w w  . j a va2  s .com*/
        File facetFile = project.file(".settings/org.eclipse.wst.common.project.facet.core.xml");
        if (facetFile.exists()) {
            facetFile.delete();
        }
        if (!facetFile.getParentFile().exists()) {
            facetFile.getParentFile().mkdirs();
        }
        XMLWriter writer = new XMLWriter(new FileWriter(facetFile), OutputFormat.createPrettyPrint());
        writer.write(document);
        writer.close();
    } catch (IOException e) {
        throw new GradleException("Problem when writing Eclipse project file.", e);
    }
}

From source file:org.gradle.api.tasks.ide.eclipse.EclipseWtp.java

License:Apache License

private Document createXmlDocument() {
    Document document = DocumentFactory.getInstance().createDocument();
    Element root = document.addElement("project-modules").addAttribute("id", "moduleCoreId")
            .addAttribute("project-version", "1.5.0");
    Element wbModule = root.addElement("wb-module").addAttribute("deploy-name", getDeployName().toString());
    wbModule.addElement("property").addAttribute("name", "context-root").addAttribute("value",
            getDeployName().toString());
    addResourceMappings(wbModule);/*from w ww .  ja v a2 s. c  o  m*/
    wbModule.addElement("property").addAttribute("name", "java-output-path").addAttribute("value",
            relativePath(getOutputDirectory()));
    addLibs(wbModule);
    addDependsOnProjects(wbModule);
    return document;
}

From source file:org.gradle.api.tasks.ide.eclipse.EclipseWtpModule.java

License:Apache License

private void createFacets(Project project) {
    Document document = DocumentFactory.getInstance().createDocument();

    EclipseUtil.addFacet(document, "fixed", new DefaultAttribute("facet", "jst.java"));
    EclipseUtil.addFacet(document, "fixed", new DefaultAttribute("facet", "jst.utility"));

    EclipseUtil.addFacet(document, "installed", new DefaultAttribute("facet", "jst.java"),
            new DefaultAttribute("version", "5.0"));
    EclipseUtil.addFacet(document, "installed", new DefaultAttribute("facet", "jst.utility"),
            new DefaultAttribute("version", "1.0"));

    try {//from   w w  w .  j  a  va 2s  .  c  o  m
        File facetFile = project.file(".settings/org.eclipse.wst.common.project.facet.core.xml");
        if (facetFile.exists()) {
            facetFile.delete();
        }
        if (!facetFile.getParentFile().exists()) {
            facetFile.getParentFile().mkdirs();
        }
        XMLWriter writer = new XMLWriter(new FileWriter(facetFile), OutputFormat.createPrettyPrint());
        writer.write(document);
        writer.close();
    } catch (IOException e) {
        throw new GradleException("Problem when writing Eclipse project file.", e);
    }
}

From source file:org.gradle.api.tasks.ide.eclipse.EclipseWtpModule.java

License:Apache License

private Document createXmlDocument() {
    Document document = DocumentFactory.getInstance().createDocument();
    Element root = document.addElement("project-modules").addAttribute("id", "moduleCoreId")
            .addAttribute("project-version", "1.5.0");
    Element wbModule = root.addElement("wb-module").addAttribute("deploy-name", getProject().getName());
    addResourceMappings(wbModule);//  w  ww  .j a  va  2s.c  o  m
    return document;
}