Example usage for org.jdom2.output Format getRawFormat

List of usage examples for org.jdom2.output Format getRawFormat

Introduction

In this page you can find the example usage for org.jdom2.output Format getRawFormat.

Prototype

public static Format getRawFormat() 

Source Link

Document

Returns a new Format object that performs no whitespace changes, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy.

Usage

From source file:org.apache.wiki.plugin.IndexPlugin.java

License:Apache License

/**
 * {@inheritDoc}//  ww w. j a v a2 s. c om
 */
public String execute(WikiContext context, Map<String, String> params) throws PluginException {
    String include = params.get(PARAM_INCLUDE);
    String exclude = params.get(PARAM_EXCLUDE);

    Element masterDiv = getElement("div", "index");
    Element indexDiv = getElement("div", "header");
    masterDiv.addContent(indexDiv);
    try {
        List<String> pages = listPages(context, include, exclude);
        context.getEngine().getPageSorter().sort(pages);
        char initialChar = ' ';
        Element currentDiv = new Element("div", xmlns_XHTML);
        for (String name : pages) {
            if (name.charAt(0) != initialChar) {
                if (initialChar != ' ') {
                    indexDiv.addContent(" - ");
                }
                initialChar = name.charAt(0);
                masterDiv.addContent(makeHeader(String.valueOf(initialChar)));
                currentDiv = getElement("div", "body");
                masterDiv.addContent(currentDiv);
                indexDiv.addContent(getLink("#" + initialChar, String.valueOf(initialChar)));
            } else {
                currentDiv.addContent(", ");
            }
            currentDiv.addContent(getLink(context.getURL(WikiContext.VIEW, name), name));
        }

    } catch (ProviderException e) {
        log.warn("could not load page index", e);
        throw new PluginException(e.getMessage());
    }
    // serialize to raw format string (no changes to whitespace)
    XMLOutputter out = new XMLOutputter(Format.getRawFormat());
    return out.outputString(masterDiv);
}

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  ww w .  java  2  s .c o 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.jumpmind.metl.core.runtime.component.XmlFormatter.java

License:Open Source License

private void createXml(ISendMessageCallback callback) {

    Document generatedXml = new Document();
    Stack<DocElement> parentStack = new Stack<DocElement>();
    ArrayList<String> outboundPayload = new ArrayList<String>();

    for (Message msg : messagesToProcess) {
        processMsgEntities(parentStack, msg, generatedXml);
    }//  w ww .j  a v  a  2 s.c  o  m
    XMLOutputter xmlOutputter = new XMLOutputter();
    Format format = null;
    if (xmlFormat.equals(COMPACT_FORMAT)) {
        format = Format.getCompactFormat();
    } else if (xmlFormat.equals(RAW_FORMAT)) {
        format = Format.getRawFormat();
    } else {
        format = Format.getPrettyFormat();
    }
    xmlOutputter.setFormat(format);
    outboundPayload.add(xmlOutputter.outputString(generatedXml));
    callback.sendTextMessage(null, outboundPayload);
}

From source file:org.jumpmind.metl.core.runtime.component.XsltProcessor.java

License:Open Source License

public static String getTransformedXml(String inputXml, String stylesheetXml, String xmlFormat,
        boolean omitXmlDeclaration) {
    StringWriter writer = new StringWriter();
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    try {//from   w  w  w  .  ja  v  a  2s.c  om
        Document inputDoc = builder.build(new StringReader(inputXml));
        StringReader reader = new StringReader(stylesheetXml);
        XSLTransformer transformer = new XSLTransformer(reader);
        Document outputDoc = transformer.transform(inputDoc);
        XMLOutputter xmlOutput = new XMLOutputter();
        Format format = null;
        if (xmlFormat.equals(COMPACT_FORMAT)) {
            format = Format.getCompactFormat();
        } else if (xmlFormat.equals(RAW_FORMAT)) {
            format = Format.getRawFormat();
        } else {
            format = Format.getPrettyFormat();
        }

        format.setOmitDeclaration(omitXmlDeclaration);
        xmlOutput.setFormat(format);
        xmlOutput.output(outputDoc, writer);
        writer.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}

From source file:org.mycore.common.MCRUtils.java

License:Open Source License

/**
 * This method convert a JDOM tree to a byte array.
 * //www .ja v  a2 s  .com
 * @param jdom
 *            the JDOM tree
 * @return a byte array of the JDOM tree
 * @deprecated uses {@link MCRJDOMContent#asByteArray()}
 */
@Deprecated
public static byte[] getByteArray(org.jdom2.Document jdom) throws MCRPersistenceException {
    return getByteArray(jdom, Format.getRawFormat());
}

From source file:org.mycore.frontend.servlets.MCRStaticXMLFileServlet.java

License:Open Source License

/** For defined document types like static webpages, replace editor elements with complete editor definition */
protected MCRContent expandEditorElements(HttpServletRequest request, HttpServletResponse response,
        URL resource) throws IOException, JDOMException, SAXException, MalformedURLException {
    MCRContent content = new MCRURLContent(resource);
    if (mayContainEditorForm(content)) {
        Document xml = content.asXML();
        MCREditorServlet.replaceEditorElements(request, resource.toString(), xml);
        MCRJDOMContent jdomContent = new MCRJDOMContent(xml);
        jdomContent.setFormat(Format.getRawFormat());
        return jdomContent;
    }/*from  w ww.  j  a v a2 s.c o m*/
    return content;
}

From source file:org.rascalmpl.library.lang.xml.DOM.java

License:Open Source License

public IString xmlRaw(IConstructor node) throws IOException {
    return xmlToString(node, Format.getRawFormat());
}