| Rev | Line | |
|---|
| [1] | 1 | package de.ugoe.cs.util;
|
|---|
| 2 |
|
|---|
| [175] | 3 | /**
|
|---|
| 4 | * <p>
|
|---|
| 5 | * Helper class that provides methods to simplify working with {@link String}s.
|
|---|
| 6 | * </p>
|
|---|
| 7 | *
|
|---|
| 8 | * @author Steffen Herbold
|
|---|
| 9 | * @version 1.0
|
|---|
| 10 | */
|
|---|
| [1] | 11 | final public class StringTools {
|
|---|
| 12 |
|
|---|
| [175] | 13 | /**
|
|---|
| 14 | * <p>
|
|---|
| [330] | 15 | * Private constructor to prevent initializing of the class.
|
|---|
| 16 | * </p>
|
|---|
| 17 | */
|
|---|
| 18 | private StringTools() {
|
|---|
| 19 |
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | /**
|
|---|
| 23 | * <p>
|
|---|
| [175] | 24 | * Simplifies use of operation system specific line separators.
|
|---|
| 25 | * </p>
|
|---|
| 26 | */
|
|---|
| [1] | 27 | public final static String ENDLINE = System.getProperty("line.separator");
|
|---|
| [175] | 28 |
|
|---|
| [1] | 29 | /**
|
|---|
| 30 | * <p>
|
|---|
| [175] | 31 | * Replaces all occurrences of {@literal &, <, >, ', and "} with their
|
|---|
| 32 | * respective XML entities {@literal &, <, >, ', and "}
|
|---|
| [1] | 33 | * without destroying already existing entities.
|
|---|
| 34 | * </p>
|
|---|
| 35 | *
|
|---|
| 36 | * @param str
|
|---|
| [175] | 37 | * String where the XML entities are to be replaced
|
|---|
| 38 | * @return new String, where the XML entities are used instead of the
|
|---|
| [1] | 39 | * literals
|
|---|
| 40 | */
|
|---|
| 41 | public static String xmlEntityReplacement(String str) {
|
|---|
| 42 | String result = str;
|
|---|
| [350] | 43 | if (result != null && !"".equals(result)) {
|
|---|
| 44 | result = result
|
|---|
| 45 | .replaceAll("&(?!(?:lt|gt|apos|quot|amp);)", "&");
|
|---|
| 46 | result = result.replaceAll("<", "<");
|
|---|
| 47 | result = result.replaceAll(">", ">");
|
|---|
| 48 | result = result.replaceAll("'", "'");
|
|---|
| 49 | result = result.replaceAll("\"", """);
|
|---|
| 50 | }
|
|---|
| [1] | 51 | return result;
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
Note: See
TracBrowser
for help on using the repository browser.