]> git.basschouten.com Git - openhab-addons.git/blob
7833a4a4f337abc75a794c13df39fd665e680897
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.sonos.internal.util;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16
17 /**
18  * The {@link StringUtils} class defines some static string utility methods
19  *
20  * @author Leo Siepel - Initial contribution
21  */
22 @NonNullByDefault
23 public class StringUtils {
24
25     /**
26      * Simple method to escape XML special characters in String.
27      * There are five XML Special characters which needs to be escaped :
28      * & - &
29      * < - &lt;
30      * > - &gt;
31      * " - &quot;
32      * ' - &apos;
33      */
34     public static String escapeXml(String xml) {
35         xml = xml.replace("&", "&amp;");
36         xml = xml.replace("<", "&lt;");
37         xml = xml.replace(">", "&gt;");
38         xml = xml.replace("\"", "&quot;");
39         xml = xml.replace("'", "&apos;");
40         return xml;
41     }
42
43     /**
44      * Simple method to un escape XML special characters in String.
45      * There are five XML Special characters which needs to be escaped :
46      * & - &amp;
47      * < - &lt;
48      * > - &gt;
49      * " - &quot;
50      * ' - &apos;
51      */
52     public static String unEscapeXml(String xml) {
53         xml = xml.replace("&amp;", "&");
54         xml = xml.replace("&lt;", "<");
55         xml = xml.replace("&gt;", ">");
56         xml = xml.replace("&quot;", "\"");
57         xml = xml.replace("&apos;", "'");
58         return xml;
59     }
60 }