|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * Replaces special characters with escape sequences |
|
17 * |
|
18 */ |
|
19 package com.nokia.tracecompiler.decodeplugins.dictionary.encoder; |
|
20 |
|
21 /** |
|
22 * Replaces special characters with escape sequences |
|
23 * |
|
24 */ |
|
25 class XMLDataFilter { |
|
26 |
|
27 /** |
|
28 * XML start tag |
|
29 */ |
|
30 private static final String LEFT_ARROW = "<"; //$NON-NLS-1$ |
|
31 |
|
32 /** |
|
33 * XML end tag |
|
34 */ |
|
35 private static final String RIGHT_ARROW = ">"; //$NON-NLS-1$ |
|
36 |
|
37 /** |
|
38 * XML entity tag |
|
39 */ |
|
40 private static final String AMPERSAND = "&"; //$NON-NLS-1$ |
|
41 |
|
42 /** |
|
43 * XML start tag escaped |
|
44 */ |
|
45 private static final String LEFT_ARROW_SUBST = "<"; //$NON-NLS-1$ |
|
46 |
|
47 /** |
|
48 * XML end tag escaped |
|
49 */ |
|
50 private static final String RIGHT_ARROW_SUBST = ">"; //$NON-NLS-1$ |
|
51 |
|
52 /** |
|
53 * XML entity tag escaped |
|
54 */ |
|
55 private static final String AMPERSAND_SUBST = "&"; //$NON-NLS-1$ |
|
56 |
|
57 /** |
|
58 * Not found result |
|
59 */ |
|
60 private static final int NOT_FOUND = -1; |
|
61 |
|
62 /** |
|
63 * Changes XML data |
|
64 * |
|
65 * @param data |
|
66 * data to be changed |
|
67 * @return changed data |
|
68 */ |
|
69 static String changeData(String data) { |
|
70 |
|
71 // This must be before any other that will add & marks to the text. |
|
72 // Otherwise those will be replaced also. |
|
73 if (data.indexOf(AMPERSAND) != NOT_FOUND) { |
|
74 data = data.replaceAll(AMPERSAND, AMPERSAND_SUBST); |
|
75 } |
|
76 if (data.indexOf(LEFT_ARROW) != NOT_FOUND) { |
|
77 data = data.replaceAll(LEFT_ARROW, LEFT_ARROW_SUBST); |
|
78 } |
|
79 if (data.indexOf(RIGHT_ARROW) != NOT_FOUND) { |
|
80 data = data.replaceAll(RIGHT_ARROW, RIGHT_ARROW_SUBST); |
|
81 } |
|
82 |
|
83 return data; |
|
84 } |
|
85 } |