Example usage for org.jdom2.output XMLOutputter outputString

List of usage examples for org.jdom2.output XMLOutputter outputString

Introduction

In this page you can find the example usage for org.jdom2.output XMLOutputter outputString.

Prototype

public final String outputString(EntityRef entity) 

Source Link

Document

Return a string representing an EntityRef .

Usage

From source file:org.arcanist.client.ArcanistCCGFrame.java

License:Open Source License

@Override
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source == fileOpenDeckMenuItem) {
        ExtensionFileFilter filter = new ExtensionFileFilter("Text Files (*.txt)", new String[] { ".txt" });
        File file = fileChooser(JFileChooser.OPEN_DIALOG, Prefs.homePath + "decks", filter);
        if (file != null) {
            Rectangle tableView = getTableView();

            String deckString = DeckParser.readDeckStringFromFile(pronoun, file);
            if (deckString != null) {
                ArcanistCCG.NetManager.deckAdd(tableView.x, tableView.y, deckString);
            }/*from  www  .ja  va2  s.  co  m*/
            // //DeckParser newDeckParser = new DeckParser(pronoun, true, file, tableView.x, tableView.y);
            // //newDeckParser.startThread();
        }
    } else if (source == fileDeckBuilderMenuItem) {
        new DeckBuilder(this);
    } else if (source == fileClearMenuItem) {
        if (JOptionPane.showInternalConfirmDialog(desktop, "Are you SURE you want to remove EVERYTHING?",
                "Remove?", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
            return;

        ArcanistCCG.NetManager.tableClear();
    } else if (source == fileConnectMenuItem) {
        new NetPlayFrame(this);
    } else if (source == fileLobbyMenuItem) {
        ServerThread st = ArcanistCCG.getServerThread();
        if (st == null) {
            return;
        }
        new LobbyFrame(this, st);
    } else if (source == fileDisconnectMenuItem) {
        if (JOptionPane.showInternalConfirmDialog(desktop, "Are you SURE you want to disconnect?",
                "Disconnect?", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION)
            return;
        ArcanistCCG.NetManager.setClientThread(null);
    } else if (source == fileSendStateMenuItem) {
        String state = XmlUtils.saveState(pronoun);
        ArcanistCCG.NetManager.tableStateLoad(state, true);
    } else if (source == fileLoadStateMenuItem) {
        ExtensionFileFilter filter = new ExtensionFileFilter("XML Files (*.xml)", new String[] { ".xml" });
        File file = fileChooser(JFileChooser.OPEN_DIALOG, Prefs.homePath + "states", filter);
        if (file != null) {
            Document doc = XmlUtils.readXML(file);
            if (doc == null) {
                ArcanistCCG.NetManager.notify(ChatPanel.STYLE_ERROR,
                        "--Error loading state. Check the log for details.--");
            } else {
                boolean neutralView = false;
                int userinput = JOptionPane.showInternalConfirmDialog(desktop,
                        "Should locally-visible things (cards, hands, etc) in this saved state be hidden?\nOtherwise everyone will see whatever was visible at the time it was saved.",
                        "Neutral View?", JOptionPane.YES_NO_OPTION);
                if (userinput == JOptionPane.YES_OPTION)
                    neutralView = true;

                XMLOutputter outputter = new XMLOutputter(Format.getRawFormat());
                String stateString = outputter.outputString(doc);

                ArcanistCCG.NetManager.tableStateLoad(stateString, neutralView);
            }
        }
    } else if (source == fileSaveStateMenuItem) {
        ExtensionFileFilter filter = new ExtensionFileFilter("XML Files (*.xml)", new String[] { ".xml" });
        File file = fileChooser(JFileChooser.SAVE_DIALOG, Prefs.homePath + "states", filter);
        if (file != null) {
            XmlUtils.saveState(pronoun, file.getAbsolutePath());
        }
    } else if (source == fileExitMenuItem) {
        System.exit(0);
    } else if (source == settingsAppearanceMenuItem) {
        new PrefsAppearanceFrame(this);
    } else if (source == settingsKeyboardMenuItem) {
        new PrefsKeyboardFrame(this);
    } else if (source == settingsPathsMenuItem) {
        new PrefsPathsFrame(this);
    } else if (source == settingsTextOnImagesMenuItem) {
        Prefs.textOnImages = ((JCheckBoxMenuItem) settingsTextOnImagesMenuItem).getState();
        if (Prefs.textOnImages == true)
            updateOverlayText();
        tablePane.repaint();
    } else if (source == settingsTableSizeMenuItem) {
        Dimension prevSize = tablePane.getPreferredSize();
        int userinput;
        int tableWidth = prevSize.width, tableHeight = prevSize.height;

        JPanel sizePanel = new JPanel();
        JTextField widthField = new JTextField(new NumberDocument(), tableWidth + "", 3);
        //widthField.setPreferredSize(new Dimension(40,20));
        sizePanel.add(widthField);
        sizePanel.add(new JLabel("x"));
        JTextField heightField = new JTextField(new NumberDocument(), tableHeight + "", 3);
        //heightField.setPreferredSize(new Dimension(40,20));
        sizePanel.add(heightField);
        Object[] options = { "OK", "Cancel" };
        do {
            userinput = JOptionPane.showInternalOptionDialog(desktop, sizePanel,
                    "Table Size (" + tableWidth + "x" + tableHeight + ")", JOptionPane.DEFAULT_OPTION,
                    JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
            if (userinput == 1)
                return; //User hit 'cancel'
            else {
                try {
                    tableWidth = Integer.parseInt(widthField.getText());
                    tableHeight = Integer.parseInt(heightField.getText());
                } catch (NumberFormatException exception) {
                    return;
                }
            }
        } while (tableWidth <= 0 || tableHeight <= 0);

        ArcanistCCG.NetManager.tableResize(tableWidth, tableHeight);
        // //resizeTable(tableWidth, tableHeight);
    } else if (source == addCounterMenuItem) {
        new CounterFrame(pronoun);
    } else if (source == addRollerMenuItem) {
        new DieRollerFrame(pronoun);
    } else if (source == addTimerMenuItem) {
        new TimerFrame(pronoun);
    } else if (source == addTokenMenuItem) {
        new TokensFrame(pronoun);
    } else if (source == addNoteMenuItem) {
        Rectangle tableView = getTableView();
        ArcanistCCG.NetManager.noteAdd(tableView.x, tableView.y, " Note ");
    } else if (source == addDiscardMenuItem) {
        Rectangle tableView = getTableView();
        ArcanistCCG.NetManager.deckAdd(tableView.x, tableView.y, false, true, true, false, 'D', "");
    } else if (source == addHandMenuItem) {
        Rectangle tableView = getTableView();
        ArcanistCCG.NetManager.handAdd(tableView.x, tableView.y, "Hand", Hand.DEFAULT_WIDTH,
                Hand.DEFAULT_HEIGHT);
    } else if (source == addJumboMenuItem) {
        if (addJumboMenuItem.isEnabled()) { //It's still clickable when disabled!
            createJumboFrame();
        }
    } else if (source == helpHelpMenuItem) {
        new HelpWindow(this);
    } else if (source == helpAboutMenuItem) {
        String message = "ArcanistCCG " + ArcanistCCG.VERSION + "\n";
        message += "Copyright (C) 2011 David Millis\n";
        message += ArcanistCCG.WEBSITE + "\n\n";
        message += "ArcanistCCG comes with ABSOLUTELY NO WARRANTY.\n";
        message += "Distributed under the terms of the GNU General Public License.";
        message += "\n\nIncludes rotation code based on Image Processing Filters\n";
        message += "Copyright (C) Jerry Huxtable 1998\n";
        message += "http://www.lhlabs.com";
        JTextArea aboutTxt = new JTextArea(message);
        aboutTxt.setEditable(false);
        JScrollPane aboutScrollPane = new JScrollPane(aboutTxt);
        aboutScrollPane.setPreferredSize(new Dimension(350, 175));
        JOptionPane.showInternalMessageDialog(desktop, aboutScrollPane, "About", JOptionPane.PLAIN_MESSAGE);
    }
}

From source file:org.codice.ddf.opensearch.source.OpenSearchSource.java

License:Open Source License

private List<Metacard> processAdditionalForeignMarkups(Element element, String id)
        throws UnsupportedQueryException {
    List<Metacard> metacards = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(markUpSet) && markUpSet.contains(element.getName())) {
        XMLOutputter xmlOutputter = new XMLOutputter();
        Metacard metacard = parseContent(xmlOutputter.outputString(element), id);
        if (metacard != null) {
            metacards.add(metacard);//from   w  ww. j a  v  a 2  s . c o  m
        }
    }
    return metacards;
}

From source file:org.educautecisystems.core.chat.elements.UserChat.java

License:Open Source License

public static String generateXMLFromList(ArrayList<UserChat> users) {
    Document xmlDocument = new Document();

    Namespace baseNamespace = Namespace.getNamespace("chat", "http://free.chat.com/");
    Element root = new Element("users", baseNamespace);

    for (UserChat user : users) {
        Element userXml = new Element("user", baseNamespace);

        userXml.addContent(new Element("id").setText("" + user.getId()));
        userXml.addContent(new Element("real_name").setText(user.getRealName()));
        userXml.addContent(new Element("nickname").setText(user.getNickName()));

        root.addContent(userXml);/*  w  w w. j a v  a2s .com*/
    }

    xmlDocument.setRootElement(root);
    XMLOutputter xmlOutputter = new XMLOutputter();

    return xmlOutputter.outputString(xmlDocument);
}

From source file:org.fiware.cybercaptor.server.rest.RestAPIAttackPaths.java

License:Open Source License

@GET
@Path("list")
@Produces(MediaType.TEXT_XML)/*w  ww  . j  av  a  2 s. c  o m*/
public Response getList(@Context HttpServletRequest request) {
    Monitoring monitoring = ((Monitoring) request.getSession(true).getAttribute("monitoring"));

    if (monitoring == null)
        return Response.status(Status.NO_CONTENT).build();

    Element attackPathsXML = org.fiware.cybercaptor.server.api.AttackPathManagement
            .getAttackPathsXML(monitoring);
    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());
    return Response.ok(output.outputString(attackPathsXML)).build();
}

From source file:org.fiware.cybercaptor.server.rest.RestAPIAttackPaths.java

License:Open Source License

@GET
@Path("{id}")
@Produces(MediaType.TEXT_XML)//from  ww w. ja v  a2  s . c o  m
public Response getAttackPath(@Context HttpServletRequest request, @PathParam("id") int id) {
    Monitoring monitoring = ((Monitoring) request.getSession(true).getAttribute("monitoring"));

    if (monitoring == null)
        return Response.status(Status.NO_CONTENT).build();

    Element attackPathXML = org.fiware.cybercaptor.server.api.AttackPathManagement.getAttackPathXML(monitoring,
            id);
    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());

    return Response.ok(output.outputString(attackPathXML)).build();
}

From source file:org.fiware.cybercaptor.server.rest.RestAPIAttackPaths.java

License:Open Source License

@GET
@Path("{id}/remediations")
@Produces(MediaType.TEXT_XML)/*from w w  w  . j  av a2 s  . co m*/
public Response getAttackPathRemediations(@Context HttpServletRequest request, @PathParam("id") int id) {
    Monitoring monitoring = ((Monitoring) request.getSession(true).getAttribute("monitoring"));
    Database db = ((Database) request.getSession(true).getAttribute("database"));

    if (monitoring == null || db == null)
        return Response.status(Status.NO_CONTENT).build();

    Element remediationXML = org.fiware.cybercaptor.server.api.AttackPathManagement
            .getRemediationXML(monitoring, id, db);
    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());

    if (remediationXML == null)
        return Response.status(Status.PRECONDITION_FAILED).build();
    return Response.ok(output.outputString(remediationXML)).build();
}

From source file:org.fiware.cybercaptor.server.rest.RestAPIAttackPaths.java

License:Open Source License

@GET
@Path("attack_graph")
@Produces(MediaType.TEXT_XML)/*from w  w w  . j  a va  2 s.c  o m*/
public Response getAttackGraph(@Context HttpServletRequest request) {
    Monitoring monitoring = ((Monitoring) request.getSession(true).getAttribute("monitoring"));

    if (monitoring == null)
        return Response.status(Status.NO_CONTENT).build();

    Element attackGraphXML = monitoring.getAttackGraph().toDomElement();
    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());
    return Response.ok(output.outputString(attackGraphXML)).build();
}

From source file:org.fiware.cybercaptor.server.rest.RestJsonAPI.java

License:Open Source License

/**
 * Get the attack paths list/*from  ww  w .  j ava 2 s. c o m*/
 *
 * @param request the HTTP Request
 * @return the HTTP Response
 */
@GET
@Path("attack_path/list")
@Produces(MediaType.APPLICATION_JSON)
public Response getList(@Context HttpServletRequest request) {
    Monitoring monitoring = ((Monitoring) request.getSession(true).getAttribute("monitoring"));

    if (monitoring == null) {
        return RestApplication.returnErrorMessage(request,
                "The monitoring object is empty. Did you forget to " + "initialize it ?");
    }

    Element attackPathsXML = AttackPathManagement.getAttackPathsXML(monitoring);
    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());
    return RestApplication.returnJsonObject(request, XML.toJSONObject(output.outputString(attackPathsXML)));

}

From source file:org.fiware.cybercaptor.server.rest.RestJsonAPI.java

License:Open Source License

/**
 * Get one attack path (id starting from 0)
 *
 * @param request the HTTP Request// www .  j a v  a2s .  c  om
 * @param id      the id of the attack path to get
 * @return the HTTP Response
 */
@GET
@Path("attack_path/{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getAttackPath(@Context HttpServletRequest request, @PathParam("id") int id) {
    Monitoring monitoring = ((Monitoring) request.getSession(true).getAttribute("monitoring"));

    if (monitoring == null) {
        return RestApplication.returnErrorMessage(request,
                "The monitoring object is empty. Did you forget to " + "initialize it ?");
    }

    int numberAttackPaths = monitoring.getAttackPathList().size();

    if (id >= numberAttackPaths) {
        return RestApplication.returnErrorMessage(request,
                "The attack path " + id + " does not exist. There are only" + numberAttackPaths
                        + " attack paths (0 to " + (numberAttackPaths - 1) + ")");
    }

    Element attackPathXML = AttackPathManagement.getAttackPathXML(monitoring, id);
    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());

    return RestApplication.returnJsonObject(request, XML.toJSONObject(output.outputString(attackPathXML)));
}

From source file:org.fiware.cybercaptor.server.rest.RestJsonAPI.java

License:Open Source License

/**
 * Compute and return the remediations for an attack path
 *
 * @param request the HTTP Request//from   www  . ja  v  a 2s .  c o m
 * @param id      the identifier of the attack path for which the remediations will be computed
 * @return the HTTP Response
 */
@GET
@Path("attack_path/{id}/remediations")
@Produces(MediaType.APPLICATION_JSON)
public Response getAttackPathRemediations(@Context HttpServletRequest request, @PathParam("id") int id) {
    Monitoring monitoring = ((Monitoring) request.getSession(true).getAttribute("monitoring"));
    Database db = ((Database) request.getSession(true).getAttribute("database"));

    if (monitoring == null) {
        return RestApplication.returnErrorMessage(request,
                "The monitoring object is empty. Did you forget to " + "initialize it ?");
    }

    if (db == null) {
        return RestApplication.returnErrorMessage(request,
                "The database object is empty. Did you forget to " + "initialize it ?");
    }

    int numberAttackPaths = monitoring.getAttackPathList().size();

    if (id >= numberAttackPaths) {
        return RestApplication.returnErrorMessage(request,
                "The attack path " + id + " does not exist. There are only" + numberAttackPaths
                        + " attack paths (0 to " + (numberAttackPaths - 1) + ")");
    }

    Element remediationXML = AttackPathManagement.getRemediationXML(monitoring, id, db);
    XMLOutputter output = new XMLOutputter(Format.getPrettyFormat());

    return RestApplication.returnJsonObject(request, XML.toJSONObject(output.outputString(remediationXML)));
}