1
2
3
4
5
6
7
8
9
10 package org.dom4j.dtd;
11
12 /*** <p><code>InternalEntityDecl</code> represents an internal entity declaration in a DTD.</p>
13 *
14 * @author <a href="mailto:james.strachan@metastuff.com">James Strachan</a>
15 * @version $Revision: 1.7 $
16 */
17 public class InternalEntityDecl {
18
19 /*** Holds value of property name. */
20 private String name;
21
22 /*** Holds value of property value. */
23 private String value;
24
25
26 public InternalEntityDecl() {
27 }
28
29 public InternalEntityDecl(String name, String value) {
30 this.name = name;
31 this.value = value;
32 }
33
34 /*** Getter for property name.
35 * @return Value of property name.
36 */
37 public String getName() {
38 return name;
39 }
40
41 /*** Setter for property name.
42 * @param name New value of property name.
43 */
44 public void setName(String name) {
45 this.name = name;
46 }
47
48 /*** Getter for property value.
49 * @return Value of property value.
50 */
51 public String getValue() {
52 return value;
53 }
54
55 /*** Setter for property value.
56 * @param value New value of property value.
57 */
58 public void setValue(String value) {
59 this.value = value;
60 }
61
62 public String toString() {
63 StringBuffer buffer = new StringBuffer( "<!ENTITY " );
64
65 if (name.startsWith("%")) {
66 buffer.append("% ");
67 buffer.append(name.substring(1));
68 }
69 else {
70 buffer.append(name);
71 }
72
73 buffer.append(" \"");
74 buffer.append(escapeEntityValue(value));
75 buffer.append("\">");
76
77 return buffer.toString();
78 }
79
80 private String escapeEntityValue(String text) {
81 StringBuffer result = new StringBuffer();
82 for (int i = 0; i < text.length(); i++) {
83 char c = text.charAt(i);
84 switch (c) {
85 case '<':
86 result.append("&#60;");
87 break;
88 case '>':
89 result.append(">");
90 break;
91 case '&':
92 result.append("&#38;");
93 break;
94 case '\'':
95 result.append("'");
96 break;
97 case '\"':
98 result.append(""");
99 break;
100 default:
101 if (c < 32) {
102 result.append("&#" + (int) c + ";");
103 } else {
104 result.append(c);
105 }
106 break;
107 }
108 }
109
110 return result.toString();
111 }
112
113 }
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161