Example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml3

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeHtml3

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeHtml3.

Prototype

public static final String escapeHtml3(final String input) 

Source Link

Document

Escapes the characters in a String using HTML entities.

Supports only the HTML 3.0 entities.

Usage

From source file:org.apache.marmotta.splash.common.ui.MessageDialog.java

public static void show(String title, String message, String description) {
    final JDialog dialog = new JDialog((Frame) null, title);
    dialog.setModal(true);//from   www  .  j  a v  a2 s  . c  om
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    final JPanel root = new JPanel(new GridBagLayout());
    root.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    dialog.getRootPane().setContentPane(root);

    final JButton close = new JButton("OK");
    close.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.setVisible(false);
        }
    });
    GridBagConstraints cClose = new GridBagConstraints();
    cClose.gridx = 0;
    cClose.gridy = 2;
    cClose.gridwidth = 2;
    cClose.weightx = 1;
    cClose.weighty = 0;
    cClose.insets = new Insets(5, 5, 5, 5);

    root.add(close, cClose);
    dialog.getRootPane().setDefaultButton(close);

    Icon icon = loadIcon(MARMOTTA_ICON);
    if (icon != null) {
        JLabel lblIcn = new JLabel(icon);

        GridBagConstraints cIcon = new GridBagConstraints();
        cIcon.gridx = 1;
        cIcon.gridy = 0;
        cIcon.gridheight = 2;
        cIcon.fill = GridBagConstraints.NONE;
        cIcon.weightx = 0;
        cIcon.weighty = 1;
        cIcon.anchor = GridBagConstraints.NORTH;
        cIcon.insets = new Insets(10, 5, 5, 0);
        root.add(lblIcn, cIcon);
    }

    JLabel lblMsg = new JLabel("<html>" + StringEscapeUtils.escapeHtml3(message).replaceAll("\\n", "<br>"));
    lblMsg.setFont(lblMsg.getFont().deriveFont(Font.BOLD, 16f));
    GridBagConstraints cLabel = new GridBagConstraints();
    cLabel.gridx = 0;
    cLabel.gridy = 0;
    cLabel.fill = GridBagConstraints.BOTH;
    cLabel.weightx = 1;
    cLabel.weighty = 0.5;
    cLabel.insets = new Insets(5, 5, 5, 5);
    root.add(lblMsg, cLabel);

    JLabel lblDescr = new JLabel(
            "<html>" + StringEscapeUtils.escapeHtml3(description).replaceAll("\\n", "<br>"));
    cLabel.gridy++;
    cLabel.insets = new Insets(0, 5, 5, 5);
    root.add(lblDescr, cLabel);

    dialog.pack();
    dialog.setLocationRelativeTo(null);

    dialog.setVisible(true);
    dialog.dispose();
}

From source file:org.apache.marmotta.splash.common.ui.SelectionDialog.java

public static int select(String title, String message, String description, List<Option> options,
        int defaultOption) {
    final JDialog dialog = new JDialog((Frame) null, title);
    dialog.setModal(true);//  w  w w.  j  a  v a2s.  c  o m
    dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);

    final AtomicInteger result = new AtomicInteger(Math.max(defaultOption, -1));

    JButton defaultBtn = null;

    final JPanel root = new JPanel(new GridBagLayout());
    root.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    dialog.getRootPane().setContentPane(root);

    JLabel lblMsg = new JLabel("<html>" + StringEscapeUtils.escapeHtml3(message).replaceAll("\\n", "<br>"));
    lblMsg.setFont(lblMsg.getFont().deriveFont(Font.BOLD, 16f));
    GridBagConstraints cLabel = new GridBagConstraints();
    cLabel.gridx = 0;
    cLabel.gridy = 0;
    cLabel.fill = GridBagConstraints.BOTH;
    cLabel.weightx = 1;
    cLabel.weighty = 0.5;
    cLabel.insets = new Insets(5, 5, 5, 5);
    root.add(lblMsg, cLabel);

    JLabel lblDescr = new JLabel(
            "<html>" + StringEscapeUtils.escapeHtml3(description).replaceAll("\\n", "<br>"));
    cLabel.gridy++;
    cLabel.insets = new Insets(0, 5, 5, 5);
    root.add(lblDescr, cLabel);

    // All the options
    cLabel.ipadx = 10;
    cLabel.ipady = 10;
    cLabel.insets = new Insets(5, 15, 0, 15);
    for (int i = 0; i < options.size(); i++) {
        cLabel.gridy++;

        final Option o = options.get(i);
        final JButton btn = new JButton(
                "<html>" + StringEscapeUtils.escapeHtml3(o.label).replaceAll("\\n", "<br>"),
                MessageDialog.loadIcon(o.icon));
        if (StringUtils.isNotBlank(o.info)) {
            btn.setToolTipText("<html>" + StringEscapeUtils.escapeHtml3(o.info).replaceAll("\\n", "<br>"));
        }

        btn.setHorizontalAlignment(AbstractButton.LEADING);
        btn.setVerticalTextPosition(AbstractButton.CENTER);
        btn.setHorizontalTextPosition(AbstractButton.TRAILING);

        final int myAnswer = i;
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                result.set(myAnswer);
                dialog.setVisible(false);
            }
        });

        root.add(btn, cLabel);
        if (i == defaultOption) {
            dialog.getRootPane().setDefaultButton(btn);
            defaultBtn = btn;
        }
    }

    final Icon icon = MessageDialog.loadIcon();
    if (icon != null) {
        JLabel lblIcn = new JLabel(icon);

        GridBagConstraints cIcon = new GridBagConstraints();
        cIcon.gridx = 1;
        cIcon.gridy = 0;
        cIcon.gridheight = 2 + options.size();
        cIcon.fill = GridBagConstraints.NONE;
        cIcon.weightx = 0;
        cIcon.weighty = 1;
        cIcon.anchor = GridBagConstraints.NORTH;
        cIcon.insets = new Insets(10, 5, 5, 0);
        root.add(lblIcn, cIcon);
    }

    final JButton close = new JButton("Cancel");
    close.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            result.set(-1);
            dialog.setVisible(false);
        }
    });
    GridBagConstraints cClose = new GridBagConstraints();
    cClose.gridx = 0;
    cClose.gridy = 2 + options.size();
    cClose.gridwidth = 2;
    cClose.weightx = 1;
    cClose.weighty = 0;
    cClose.insets = new Insets(15, 5, 5, 5);

    root.add(close, cClose);
    if (defaultOption < 0) {
        dialog.getRootPane().setDefaultButton(close);
        defaultBtn = close;
    }

    dialog.pack();
    dialog.setLocationRelativeTo(null);
    defaultBtn.requestFocusInWindow();

    dialog.setVisible(true);
    dialog.dispose();

    return result.get();
}

From source file:org.bitbucket.mlopatkin.android.logviewer.TooltipGenerator.java

private static StringBuilder appendEnc(StringBuilder b, String text) {
    return b.append(StringEscapeUtils.escapeHtml3(text));
}

From source file:org.flowerplatform.web.git.history.remote.GitHistoryStatefulService.java

private String getCommitMessage(Repository repo, HistoryEntryDto entry, RevCommit commit) throws IOException {
    DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    int maxBranches = 20;

    StringBuilder d = new StringBuilder();
    d.append("<p>");
    d.append(GitPlugin.getInstance().getMessage("git.history.commitMessage.commit"));
    d.append(" ");
    d.append(commit.getId().name());//from  www  . j av  a  2s  . co  m
    d.append("<br>");

    PersonIdent author = commit.getAuthorIdent();
    if (author != null) {
        d.append(GitPlugin.getInstance().getMessage("git.history.commitMessage.author"));
        d.append(": ");
        d.append(author.getName());
        d.append(" &lt;");
        d.append(author.getEmailAddress());
        d.append("&gt; ");
        d.append(fmt.format(author.getWhen()));
        d.append("<br>");
    }

    PersonIdent committer = commit.getCommitterIdent();
    if (committer != null) {
        d.append(GitPlugin.getInstance().getMessage("git.history.commitMessage.committer"));
        d.append(": ");
        d.append(committer.getName());
        d.append(" &lt;");
        d.append(committer.getEmailAddress());
        d.append("&gt; ");
        d.append(fmt.format(committer.getWhen()));
        d.append("<br>");
    }

    for (CommitDto parent : entry.getCommitMessage().getParents()) {
        d.append(GitPlugin.getInstance().getMessage("git.history.commitMessage.parent"));
        d.append(": ");
        d.append(String.format("<u><a href=''>%s</a></u>", parent.getId()));
        d.append(" (");
        d.append(parent.getLabel());
        d.append(")");
        d.append("<br>");
    }

    for (CommitDto child : entry.getCommitMessage().getChildren()) {
        d.append(GitPlugin.getInstance().getMessage("git.history.commitMessage.child"));
        d.append(": ");
        d.append(String.format("<u><a href=''>%s</a></u>", child.getId()));
        d.append(" (");
        d.append(child.getLabel());
        d.append(")");
        d.append("<br>");
    }

    List<Ref> branches = getBranches(commit, getBranches(repo), repo);
    if (!branches.isEmpty()) {
        d.append(GitPlugin.getInstance().getMessage("git.history.commitMessage.branches"));
        d.append(": ");
        int count = 0;
        for (Iterator<Ref> i = branches.iterator(); i.hasNext();) {
            Ref head = i.next();
            d.append(formatHeadRef(head));
            if (i.hasNext()) {
                if (count++ <= maxBranches) {
                    d.append(", ");
                } else {
                    d.append(GitPlugin.getInstance().getMessage("git.history.commitMessage.author",
                            new Object[] { Integer.valueOf(branches.size() - maxBranches) }));
                    break;
                }
            }
        }
        d.append("<br>");
    }

    String tagsString = getTagsString(repo, commit);
    if (tagsString.length() > 0) {
        d.append(GitPlugin.getInstance().getMessage("git.history.commitMessage.tags"));
        d.append(": ");
        d.append(tagsString);
        d.append("<br>");
    }

    d.append("<br>");
    d.append(String.format("<b>%s</b>",
            StringEscapeUtils.escapeHtml3(commit.getFullMessage()).replaceAll("\n", "<br>")));
    d.append("</p>");

    return d.toString();
}

From source file:org.openecomp.sdnc.sli.SvcLogicNode.java

public void printAsGv(PrintStream pstr) {

    if (visited) {
        return;/* w ww.  ja  v  a 2  s  . co  m*/
    } else {
        visited = true;
    }

    StringBuffer sbuff = new StringBuffer();

    sbuff.append("node");
    sbuff.append(nodeId);
    sbuff.append(" [ shape=none, margin=0, label=<<table border=\"0\" cellborder=\"1\" align=\"left\">");
    sbuff.append("<tr><td colspan=\"2\"><b>");
    sbuff.append(nodeId);
    sbuff.append(" : ");
    sbuff.append(nodeType);
    sbuff.append("</b></td></tr><th><td><i>Attribute</i></td><td><i>Value</i></td></th>");

    if (nodeName.length() > 0) {
        sbuff.append("<tr><td>name</td><td>");
        sbuff.append(nodeName);
        sbuff.append("</td></tr>");
    }

    Set<Map.Entry<String, SvcLogicExpression>> attrSet = attributes.entrySet();
    for (Iterator<Map.Entry<String, SvcLogicExpression>> iter = attrSet.iterator(); iter.hasNext();) {
        Map.Entry<String, SvcLogicExpression> curAttr = iter.next();
        sbuff.append("<tr><td>");
        sbuff.append(curAttr.getKey());
        sbuff.append("</td><td>");
        sbuff.append(StringEscapeUtils.escapeHtml3(curAttr.getValue().toString()));
        sbuff.append("</td></tr>");
    }
    sbuff.append("</table>>];");

    pstr.println(sbuff.toString());

    if (outcomes != null) {
        TreeMap<String, SvcLogicNode> sortedOutcomes = new TreeMap<String, SvcLogicNode>(outcomes);
        Set<Map.Entry<String, SvcLogicNode>> outcomeSet = sortedOutcomes.entrySet();

        for (Iterator<Map.Entry<String, SvcLogicNode>> iter = outcomeSet.iterator(); iter.hasNext();) {
            Map.Entry<String, SvcLogicNode> curOutcome = iter.next();
            String outValue = curOutcome.getKey();
            SvcLogicNode outNode = curOutcome.getValue();
            pstr.println("node" + nodeId + " -> node" + outNode.getNodeId() + " [label=\"" + outValue + "\"];");
            outNode.printAsGv(pstr);
        }
    }
}