dom4j - 1.6.1

Clover coverage report - dom4j - 1.6.1
Coverage timestamp: ma mei 16 2005 14:23:01 GMT+01:00
FRAMES NO FRAMES

file stats: | LOC: | 172 |  | Methods: | 8
| NCLOC: | 67 |  | Classes: | 1

Source file | Conditionals | Statements | Methods | TOTAL

InternalEntityDecl.java

83,3%

70%

62,5%

70,4%

1 |  | /*
2 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
3 |  | *
4 |  | * This software is open source.
5 |  | * See the bottom of this file for the licence.
6 |  | */
7 |  |
8 |  | package org.dom4j.dtd;
9 |  |
10 |  | /**
11 |  | * <p>
12 |  | * <code>InternalEntityDecl</code> represents an internal entity declaration
13 |  | * in a DTD.
14 |  | * </p>
15 |  | *
16 |  | * @author <a href="mailto:james.strachan@metastuff.com">James Strachan </a>
17 |  | * @version $Revision: 1.9 $
18 |  | */
19 |  | public class InternalEntityDecl {
20 |  | /** Holds value of property name. */
21 |  | private String name;
22 |  |
23 |  | /** Holds value of property value. */
24 |  | private String value;
25 |  |
26 | 0 | public InternalEntityDecl() {
27 |  | }
28 |  |
29 | 19 | public InternalEntityDecl(String name, String value) {
30 | 19 | this.name = name;
31 | 19 | this.value = value;
32 |  | }
33 |  |
34 |  | /**
35 |  | * Getter for property name.
36 |  | *
37 |  | * @return Value of property name.
38 |  | */
39 | 6 | public String getName() {
40 | 6 | return name;
41 |  | }
42 |  |
43 |  | /**
44 |  | * Setter for property name.
45 |  | *
46 |  | * @param name
47 |  | * New value of property name.
48 |  | */
49 | 0 | public void setName(String name) {
50 | 0 | this.name = name;
51 |  | }
52 |  |
53 |  | /**
54 |  | * Getter for property value.
55 |  | *
56 |  | * @return Value of property value.
57 |  | */
58 | 6 | public String getValue() {
59 | 6 | return value;
60 |  | }
61 |  |
62 |  | /**
63 |  | * Setter for property value.
64 |  | *
65 |  | * @param value
66 |  | * New value of property value.
67 |  | */
68 | 0 | public void setValue(String value) {
69 | 0 | this.value = value;
70 |  | }
71 |  |
72 | 22 | public String toString() {
73 | 22 | StringBuffer buffer = new StringBuffer("<!ENTITY ");
74 |  |
75 | 22 | if (name.startsWith("%")) {
76 | 10 | buffer.append("% ");
77 | 10 | buffer.append(name.substring(1));
78 |  | } else {
79 | 12 | buffer.append(name);
80 |  | }
81 |  |
82 | 22 | buffer.append(" \"");
83 | 22 | buffer.append(escapeEntityValue(value));
84 | 22 | buffer.append("\">");
85 |  |
86 | 22 | return buffer.toString();
87 |  | }
88 |  |
89 | 22 | private String escapeEntityValue(String text) {
90 | 22 | StringBuffer result = new StringBuffer();
91 |  |
92 | 22 | for (int i = 0; i < text.length(); i++) {
93 | 167 | char c = text.charAt(i);
94 |  |
95 | 167 | switch (c) {
96 | 0 | case '<':
97 | 0 | result.append("&#38;#60;");
98 |  |
99 | 0 | break;
100 |  |
101 | 1 | case '>':
102 | 1 | result.append("&#62;");
103 |  |
104 | 1 | break;
105 |  |
106 | 0 | case '&':
107 | 0 | result.append("&#38;#38;");
108 |  |
109 | 0 | break;
110 |  |
111 | 0 | case '\'':
112 | 0 | result.append("&#39;");
113 |  |
114 | 0 | break;
115 |  |
116 | 1 | case '\"':
117 | 1 | result.append("&#34;");
118 |  |
119 | 1 | break;
120 |  |
121 | 165 | default:
122 |  |
123 | 165 | if (c < 32) {
124 | 0 | result.append("&#" + (int) c + ";");
125 |  | } else {
126 | 165 | result.append(c);
127 |  | }
128 |  |
129 | 165 | break;
130 |  | }
131 |  | }
132 |  |
133 | 22 | return result.toString();
134 |  | }
135 |  | }
136 |  |
137 |  | /*
138 |  | * Redistribution and use of this software and associated documentation
139 |  | * ("Software"), with or without modification, are permitted provided that the
140 |  | * following conditions are met:
141 |  | *
142 |  | * 1. Redistributions of source code must retain copyright statements and
143 |  | * notices. Redistributions must also contain a copy of this document.
144 |  | *
145 |  | * 2. Redistributions in binary form must reproduce the above copyright notice,
146 |  | * this list of conditions and the following disclaimer in the documentation
147 |  | * and/or other materials provided with the distribution.
148 |  | *
149 |  | * 3. The name "DOM4J" must not be used to endorse or promote products derived
150 |  | * from this Software without prior written permission of MetaStuff, Ltd. For
151 |  | * written permission, please contact dom4j-info@metastuff.com.
152 |  | *
153 |  | * 4. Products derived from this Software may not be called "DOM4J" nor may
154 |  | * "DOM4J" appear in their names without prior written permission of MetaStuff,
155 |  | * Ltd. DOM4J is a registered trademark of MetaStuff, Ltd.
156 |  | *
157 |  | * 5. Due credit should be given to the DOM4J Project - http://www.dom4j.org
158 |  | *
159 |  | * THIS SOFTWARE IS PROVIDED BY METASTUFF, LTD. AND CONTRIBUTORS ``AS IS'' AND
160 |  | * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
161 |  | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
162 |  | * ARE DISCLAIMED. IN NO EVENT SHALL METASTUFF, LTD. OR ITS CONTRIBUTORS BE
163 |  | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
164 |  | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
165 |  | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
166 |  | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
167 |  | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
168 |  | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
169 |  | * POSSIBILITY OF SUCH DAMAGE.
170 |  | *
171 |  | * Copyright 2001-2005 (C) MetaStuff, Ltd. All Rights Reserved.
172 |  | */