Example usage for org.jdom2.output XMLOutputter XMLOutputter

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

Introduction

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

Prototype

public XMLOutputter(XMLOutputProcessor processor) 

Source Link

Document

This will create an XMLOutputter with the specified XMLOutputProcessor.

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);
            }//w w w . ja  v  a  2s. 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.artifactory.webapp.wicket.page.home.settings.ivy.IvySettingsPanel.java

License:Open Source License

@Override
public String generateSettings() {
    Document document = new Document();
    Element rootNode = new Element("ivy-settings");

    Element settingsElement = new Element("settings");
    settingsElement.setAttribute("defaultResolver", "main");
    rootNode.addContent(settingsElement);

    if (!authorizationService.isAnonymous() || !authorizationService.isAnonAccessEnabled()) {
        rootNode.addContent(/*from  w  ww .  j  ava  2  s. c o m*/
                new Comment("Authentication required for publishing (deployment). 'Artifactory Realm' is "
                        + "the realm used by Artifactory so don't change it."));

        Element credentialsElement = new Element("credentials");
        try {
            credentialsElement.setAttribute("host", new URL(servletContextUrl).getHost());
        } catch (MalformedURLException e) {
            String errorMessage = "An error occurred while decoding the servlet context URL for the credentials host attribute: ";
            error(errorMessage + e.getMessage());
            log.error(errorMessage, e);
        }
        credentialsElement.setAttribute("realm", "Artifactory Realm");

        FilteredResourcesWebAddon filteredResourcesWebAddon = addonsManager
                .addonByType(FilteredResourcesWebAddon.class);

        credentialsElement.setAttribute("username",
                filteredResourcesWebAddon.getGeneratedSettingsUsernameTemplate());

        credentialsElement.setAttribute("passwd", "@PASS_ATTR_PLACEHOLDER@");

        rootNode.addContent(credentialsElement);
    }

    Element resolversElement = new Element("resolvers");

    Element chainElement = new Element("chain");
    chainElement.setAttribute("name", "main");

    String resolverName = resolverPanel.getResolverName();
    resolverName = StringUtils.isNotBlank(resolverName) ? resolverName : "public";

    if (resolverPanel.useIbiblioResolver()) {

        Element ibiblioElement = new Element("ibiblio");
        ibiblioElement.setAttribute("name", resolverName);
        ibiblioElement.setAttribute("m2compatible", Boolean.TRUE.toString());
        ibiblioElement.setAttribute("root", resolverPanel.getFullRepositoryUrl());
        chainElement.addContent(ibiblioElement);
    } else {

        Element urlElement = new Element("url");
        urlElement.setAttribute("name", resolverName);

        urlElement.setAttribute("m2compatible", Boolean.toString(resolverPanel.isM2Compatible()));

        Element artifactPatternElement = new Element("artifact");
        artifactPatternElement.setAttribute("pattern", resolverPanel.getFullArtifactPattern());
        urlElement.addContent(artifactPatternElement);

        Element ivyPatternElement = new Element("ivy");
        ivyPatternElement.setAttribute("pattern", resolverPanel.getFullDescriptorPattern());
        urlElement.addContent(ivyPatternElement);

        chainElement.addContent(urlElement);
    }

    resolversElement.addContent(chainElement);

    rootNode.addContent(resolversElement);

    document.setRootElement(rootNode);

    String result = new XMLOutputter(Format.getPrettyFormat()).outputString(document);
    // after the xml is generated replace the password placeholder with the template placeholder (otherwise jdom
    // escapes this string)
    FilteredResourcesWebAddon filteredResourcesWebAddon = addonsManager
            .addonByType(FilteredResourcesWebAddon.class);
    return result.replace("@PASS_ATTR_PLACEHOLDER@",
            filteredResourcesWebAddon.getGeneratedSettingsUserCredentialsTemplate(false));
}

From source file:org.blip.workflowengine.configuration.XmlConfigWrite.java

License:Apache License

default void write(final Microservice microservice, final File file) throws IOException {
    Objects.requireNonNull(microservice, "microservice argument is null");
    Objects.requireNonNull(file, "file argument is null");

    if (!file.isFile()) {
        throw new IllegalArgumentException("Not a file");
    } else if (!file.canWrite()) {
        throw new IllegalArgumentException("Can't write to file");
    }//from  w w w. j a v a  2s  .c  om

    final XMLOutputter out = new XMLOutputter(Format.getPrettyFormat());
    final Document document = new Document(microserviceToXml().apply(microservice));
    out.output(document, new FileOutputStream(file));
}

From source file:org.blip.workflowengine.functions.PropertyNodeXmlFunctions.java

License:Apache License

default Function<Element, Value> xmlToValue() {
    return element -> {
        Objects.requireNonNull(element, "element is null");

        final String name = element.getName();

        if (name.contentEquals("null")) {
            return ImmutableValue.of(null);
        } else if (name.contentEquals("boolean")) {
            return ImmutableValue.of(Boolean.valueOf(element.getValue()));
        } else if (name.contentEquals("instant")) {
            return ImmutableValue.of(Instant.parse(element.getValue()));
        } else if (name.contentEquals(("byte-array"))) {
            final String base64Encoded = element.getValue();
            final byte[] binary = Base64.getDecoder().decode(base64Encoded.getBytes(Charset.forName("UTF-8")));
            return ImmutableValue.of(binary);
        } else if (name.contentEquals("string")) {
            return ImmutableValue.of(element.getValue());
        } else if (name.contentEquals("byte")) {
            return ImmutableValue.of(Byte.valueOf(element.getValue()));
        } else if (name.contentEquals("short")) {
            return ImmutableValue.of(Short.valueOf(element.getValue()));
        } else if (name.contentEquals("integer")) {
            return ImmutableValue.of(Integer.valueOf(element.getValue()));
        } else if (name.contentEquals("long")) {
            return ImmutableValue.of(Long.valueOf(element.getValue()));
        } else if (name.contentEquals("float")) {
            return ImmutableValue.of(Float.valueOf(element.getValue()));
        } else if (name.contentEquals("double")) {
            return ImmutableValue.of(Double.valueOf(element.getValue()));
        } else if (name.contentEquals("collection")) {
            final ImmutableList.Builder<Object> objectBuilder = ImmutableList.builder();
            for (final Element element1 : element.getChildren()) {
                if (element1.getName().contentEquals("entry")) {
                    final List<Element> children = element1.getChildren();
                    if (children.size() == 2) {
                        final Element keyElement = children.get(0);
                        final Element valueElement = children.get(1);

                        final Value key = xmlToValue().apply(keyElement);
                        final Value value = xmlToValue().apply(valueElement);
                        final Map.Entry entry = new AbstractMap.SimpleEntry(key.value(), value.value());
                        objectBuilder.add(entry);
                    }//  w  w w .  jav a2  s. c o  m
                } else {
                    final Object rawValue = xmlToValue().apply(element1).value();
                    if (Objects.nonNull(rawValue)) {
                        objectBuilder.add(rawValue);
                    }
                }
            }

            return ImmutableValue.of(objectBuilder.build());
        } else if (name.contentEquals("property-node")) {
            return ImmutableValue.of((xmlToPropertyNode().apply(element)));
        } else {
            throw new IllegalArgumentException(
                    new XMLOutputter(Format.getPrettyFormat()).outputString(element));
        }
    };
}

From source file:org.blip.workflowengine.functions.PropertyNodeXmlFunctions.java

License:Apache License

default Element xpath(final PropertyNode propertyNode, final String expression) throws XPathException {
    Objects.requireNonNull(propertyNode, "propertyNode is null");
    Objects.requireNonNull(expression, "XPath expression is null");
    if (expression.trim().isEmpty()) {
        throw new IllegalArgumentException("XPath expression is empty");
    }// w w  w .  j  a v  a 2 s.c om

    try {
        final Processor processor = new Processor(false);
        final DocumentBuilder builder = processor.newDocumentBuilder();
        final XPathCompiler xpc = processor.newXPathCompiler();

        final XPathSelector selector = xpc.compile(expression).load();
        final Element element = propertyNodeToXml().apply(propertyNode);
        final XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat());

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        xmlOutputter.output(element, baos);
        final Reader reader = new InputStreamReader(new ByteArrayInputStream(baos.toByteArray()),
                String.valueOf(Charset.forName("UTF-8")));
        final InputSource inputSource = new InputSource(reader);
        inputSource.setEncoding(String.valueOf(Charset.forName("UTF-8")));

        selector.setContextItem(builder.build(new SAXSource(inputSource)));
        final XdmValue xdmValue = selector.evaluate();

        final String content = String.format("<%s>%s</%s>", "XPathResult", xdmValue.toString(), "XPathResult");
        final Document doc = new SAXBuilder().build(new StringReader(content));

        return doc.getRootElement();

    } catch (Exception exception) {
        throw new XPathException(exception);
    }

}

From source file:org.educautecisystems.core.Sistema.java

License:Open Source License

public static void guardarConfPrincipal() {
    File archivoConfPrincipal = new File(pathGeneralConf);

    if (archivoConfPrincipal.exists()) {
        archivoConfPrincipal.delete();// ww  w.j a  v a2  s  .  c o m
    }

    Document documento = new Document();

    Namespace baseNamespace = Namespace.getNamespace("eus", "http://educautecisystems.org/");
    Element root = new Element("config", baseNamespace);
    documento.setRootElement(root);

    Element eBaseDeDatos = new Element("database", baseNamespace);
    eBaseDeDatos.addContent(new Element("host").setText(confBaseDeDatos.getHost()));
    eBaseDeDatos.addContent(new Element("port").setText(confBaseDeDatos.getPort()));
    eBaseDeDatos.addContent(new Element("user").setText(confBaseDeDatos.getUser()));
    eBaseDeDatos.addContent(new Element("password").setText(confBaseDeDatos.getPassword()));
    eBaseDeDatos.addContent(new Element("esquema").setText(confBaseDeDatos.getEsquema()));
    root.addContent(eBaseDeDatos);

    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());

    try {
        FileOutputStream fis = new FileOutputStream(archivoConfPrincipal);
        outputter.output(documento, fis);
        fis.close();
    } catch (IOException ioe) {
        System.err.println("No se pudo escribor configuracin principal.");
    }
}

From source file:org.educautecisystems.core.Sistema.java

License:Open Source License

private static void generarChatConf(File archivoConfChatXML) {
    Document document = new Document();

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

    /* Datos servidor */
    Element eServidor = new Element("server", baseNamespace);
    eServidor.addContent(new Element("ip").setText(ip_defecto));
    eServidor.addContent(new Element("port").setText(port_defecto));
    root.addContent(eServidor);/*w w  w.  j  a  v  a2  s  .  c  o  m*/

    /* Datos sesin */
    Element eSession = new Element("session", baseNamespace);
    eSession.addContent(new Element("nickname").setText(nickname_defecto));
    eSession.addContent(new Element("real_name").setText(realName_defecto));
    root.addContent(eSession);

    /* Guardar archivo */
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    document.setRootElement(root);

    try {
        outputter.output(document, new FileOutputStream(archivoConfChatXML));
    } catch (IOException ioe) {
        System.err.println("No se puedo crear archivo de configuracin.");
    }

    /* Iniciar informacin */
    chatServerConf = new ChatServerConf(ip_defecto, port_defecto);
    chatSessionConf = new ChatSessionConf(nickname_defecto, realName_defecto);
}

From source file:org.educautecisystems.core.Sistema.java

License:Open Source License

public static void guardarChatConf() {
    File archivoConfChatXML = new File(pathChatConf);

    /* Borrar archivo, si existe. */
    if (archivoConfChatXML.exists()) {
        archivoConfChatXML.delete();/*  w ww  .java 2 s  .  c om*/
    }

    Document document = new Document();

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

    /* Datos servidor */
    Element eServidor = new Element("server", baseNamespace);
    eServidor.addContent(new Element("ip").setText(chatServerConf.getIp()));
    eServidor.addContent(new Element("port").setText(chatServerConf.getPort()));
    root.addContent(eServidor);

    /* Datos sesin */
    Element eSession = new Element("session", baseNamespace);
    eSession.addContent(new Element("nickname").setText(chatSessionConf.getNickname()));
    eSession.addContent(new Element("real_name").setText(chatSessionConf.getRealName()));
    root.addContent(eSession);

    /* Guardar archivo */
    XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    document.setRootElement(root);

    try {
        outputter.output(document, new FileOutputStream(archivoConfChatXML));
    } catch (IOException ioe) {
        System.err.println("No se puedo crear archivo de configuracin.");
    }
}

From source file:org.esa.beam.occci.ModisL1aScanner.java

License:Open Source License

private static void printElement(Element element) {
    XMLOutputter fmt = new XMLOutputter(Format.getPrettyFormat());
    try {/*from  w w w.j  a v a  2  s  .co m*/
        fmt.output(element, System.out);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.esa.snap.core.dataop.downloadable.XMLSupport.java

License:Open Source License

public static void SaveXML(final Document doc, final String filePath) throws IOException {

    final XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat());
    try (final FileWriter writer = new FileWriter(filePath)) {

        outputter.output(doc, writer);/*from www .j  a va  2 s .  c om*/
        writer.close();
    }
}