package de.ugoe.cs.util; final public class StringTools { public final static String ENDLINE = System.getProperty("line.separator"); /** *

* Replaces all occurences of {@literal &, <, >, ', and "} with their * respective XML entites {@literal &, <, >, ', and "} * without destroying already existing entities. *

* * @param str * String where the XML entites are to be replaced * @return new String, where the XML entites are used instead of the * literals */ public static String xmlEntityReplacement(String str) { String result = str; result = result.replaceAll("&(?!(?:lt|gt|apos|quot|amp);)", "&"); result = result.replaceAll("<", "<"); result = result.replaceAll(">", ">"); result = result.replaceAll("'", "'"); result = result.replaceAll("\"", """); return result; } }