| Line | |
|---|
| 1 | package de.ugoe.cs.util;
|
|---|
| 2 |
|
|---|
| 3 | final public class StringTools {
|
|---|
| 4 |
|
|---|
| 5 | public final static String ENDLINE = System.getProperty("line.separator");
|
|---|
| 6 |
|
|---|
| 7 | /**
|
|---|
| 8 | * <p>
|
|---|
| 9 | * Replaces all occurences of {@literal &, <, >, ', and "} with their
|
|---|
| 10 | * respective XML entites {@literal &, <, >, ', and "}
|
|---|
| 11 | * without destroying already existing entities.
|
|---|
| 12 | * </p>
|
|---|
| 13 | *
|
|---|
| 14 | * @param str
|
|---|
| 15 | * String where the XML entites are to be replaced
|
|---|
| 16 | * @return new String, where the XML entites are used instead of the
|
|---|
| 17 | * literals
|
|---|
| 18 | */
|
|---|
| 19 | public static String xmlEntityReplacement(String str) {
|
|---|
| 20 | String result = str;
|
|---|
| 21 | result = result.replaceAll("&(?!(?:lt|gt|apos|quot|amp);)", "&");
|
|---|
| 22 | result = result.replaceAll("<", "<");
|
|---|
| 23 | result = result.replaceAll(">", ">");
|
|---|
| 24 | result = result.replaceAll("'", "'");
|
|---|
| 25 | result = result.replaceAll("\"", """);
|
|---|
| 26 | return result;
|
|---|
| 27 | }
|
|---|
| 28 | }
|
|---|
Note: See
TracBrowser
for help on using the repository browser.