1 | /* |
2 | * Tomdroid |
3 | * Tomboy on Android |
4 | * http://www.launchpad.net/tomdroid |
5 | * |
6 | * Copyright 2009, Benoit Garret <benoit.garret_launchpad@gadz.org> |
7 | * |
8 | * This file is part of Tomdroid. |
9 | * |
10 | * Tomdroid is free software: you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License as published by |
12 | * the Free Software Foundation, either version 3 of the License, or |
13 | * (at your option) any later version. |
14 | * |
15 | * Tomdroid is distributed in the hope that it will be useful, |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * GNU General Public License for more details. |
19 | * |
20 | * You should have received a copy of the GNU General Public License |
21 | * along with Tomdroid. If not, see <http://www.gnu.org/licenses/>. |
22 | */ |
23 | package org.tomdroid.util; |
24 | |
25 | public class XmlUtils { |
26 | |
27 | /** |
28 | * Useful to replace the characters forbidden in xml by their escaped counterparts |
29 | * Ex: & -> &amp; |
30 | * |
31 | * @param input the string to escape |
32 | * @return the escaped string |
33 | */ |
34 | public static String escape(String input) { |
35 | return input |
36 | .replace("&", "&") |
37 | .replace("<", "<") |
38 | .replace(">", ">") |
39 | .replace("\"", """) |
40 | .replace("\'", "'"); |
41 | } |
42 | |
43 | /** |
44 | * Useful to replace the escaped characters their unescaped counterparts |
45 | * Ex: &amp; -> & |
46 | * |
47 | * @param input the string to unescape |
48 | * @return the unescaped string |
49 | */ |
50 | public static String unescape(String input) { |
51 | return input |
52 | .replace("&", "&") |
53 | .replace("<", "<") |
54 | .replace(">", ">") |
55 | .replace(""", "\"") |
56 | .replace("'", "\'"); |
57 | } |
58 | } |