1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.kuali.student.contract.writer; |
17 |
|
|
18 |
|
import java.io.PrintStream; |
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
@author |
23 |
|
|
|
|
| 0% |
Uncovered Elements: 118 (118) |
Complexity: 36 |
Complexity Density: 0.46 |
|
24 |
|
public class XmlWriter { |
25 |
|
|
26 |
|
private char indentChar = '\t'; |
27 |
|
private int indent; |
28 |
|
private PrintStream out; |
29 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
30 |
0
|
public XmlWriter() {... |
31 |
|
} |
32 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
33 |
0
|
public XmlWriter(PrintStream out, int indent) {... |
34 |
0
|
this.indent = indent; |
35 |
0
|
this.out = out; |
36 |
|
} |
37 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
0
|
public void setOut(PrintStream out) {... |
39 |
0
|
this.out = out; |
40 |
|
} |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
42 |
0
|
public void setIndent(int indent) {... |
43 |
0
|
this.indent = indent; |
44 |
|
} |
45 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
46 |
0
|
public int getIndent() {... |
47 |
0
|
return indent; |
48 |
|
} |
49 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
50 |
0
|
public void incrementIndent() {... |
51 |
0
|
indent++; |
52 |
|
} |
53 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
0
|
public void decrementIndent() {... |
55 |
0
|
indent--; |
56 |
|
} |
57 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
58 |
0
|
public PrintStream getOut() {... |
59 |
0
|
return out; |
60 |
|
} |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
62 |
0
|
public void indent() {... |
63 |
0
|
indent(out, indentChar); |
64 |
|
} |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
66 |
0
|
public void indent(PrintStream o, char indentCharacter) {... |
67 |
0
|
for (int i = 0; i < indent; i++) { |
68 |
0
|
o.print(indentCharacter); |
69 |
|
} |
70 |
|
} |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
0
|
public void println(String str) {... |
73 |
0
|
out.println(str); |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
76 |
0
|
public void indentPrintln(String str) {... |
77 |
0
|
indent(); |
78 |
0
|
out.println(str); |
79 |
|
} |
80 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
81 |
0
|
public void indentPrint(String str) {... |
82 |
0
|
indent(); |
83 |
0
|
out.print(str); |
84 |
|
} |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0
|
public void print(String str) {... |
87 |
0
|
out.print(str); |
88 |
|
} |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
90 |
0
|
public void writeAttribute(String attribute, String value) {... |
91 |
0
|
if (value == null) { |
92 |
0
|
return; |
93 |
|
} |
94 |
0
|
if (value.equals("")) { |
95 |
0
|
return; |
96 |
|
} |
97 |
0
|
out.print(" "); |
98 |
0
|
out.print(attribute); |
99 |
0
|
out.print("=\""); |
100 |
0
|
out.print(value); |
101 |
0
|
out.print("\""); |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
0
|
public void writeTag(String tag, String value) {... |
105 |
0
|
writeTag(tag, null, value); |
106 |
|
} |
107 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 5 |
Complexity Density: 0.42 |
|
108 |
0
|
public void writeTag(String tag, String modifiers, String value) {... |
109 |
0
|
if (value == null) { |
110 |
0
|
return; |
111 |
|
} |
112 |
0
|
if (value.equals("")) { |
113 |
0
|
return; |
114 |
|
} |
115 |
0
|
indent(); |
116 |
0
|
out.print("<" + tag); |
117 |
0
|
if (modifiers != null && !modifiers.isEmpty()) { |
118 |
0
|
out.print(" " + modifiers); |
119 |
|
} |
120 |
0
|
out.print(">"); |
121 |
|
|
122 |
0
|
out.print(value); |
123 |
0
|
out.print("</" + tag + ">"); |
124 |
0
|
out.println(""); |
125 |
|
} |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
127 |
0
|
public void writeComment(String comment) {... |
128 |
0
|
if (comment == null) { |
129 |
0
|
return; |
130 |
|
} |
131 |
0
|
if (comment.equals("")) { |
132 |
0
|
return; |
133 |
|
} |
134 |
0
|
indent(); |
135 |
0
|
out.print("<!-- "); |
136 |
0
|
out.print(comment); |
137 |
0
|
out.println(" -->"); |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 7 |
Complexity Density: 0.29 |
|
140 |
0
|
public String escapeXML(String s) {... |
141 |
0
|
StringBuffer sb = new StringBuffer(); |
142 |
0
|
int n = s.length(); |
143 |
0
|
for (int i = 0; i < n; i++) { |
144 |
|
|
145 |
0
|
char c = s.charAt(i); |
146 |
0
|
switch (c) { |
147 |
0
|
case '"': |
148 |
0
|
sb.append("""); |
149 |
0
|
break; |
150 |
0
|
case '\'': |
151 |
0
|
sb.append("'"); |
152 |
0
|
break; |
153 |
0
|
case '&': |
154 |
0
|
sb.append("&"); |
155 |
0
|
break; |
156 |
0
|
case '<': |
157 |
0
|
sb.append("<"); |
158 |
0
|
break; |
159 |
0
|
case '>': |
160 |
0
|
sb.append(">"); |
161 |
0
|
break; |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
0
|
default: |
167 |
0
|
sb.append(c); |
168 |
0
|
break; |
169 |
|
} |
170 |
|
} |
171 |
0
|
return sb.toString(); |
172 |
|
} |
173 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
174 |
0
|
public void writeCommentBox(String comment) {... |
175 |
0
|
String border = |
176 |
|
"***************************************************************"; |
177 |
0
|
while (border.length() < comment.length()) { |
178 |
0
|
border = border + border; |
179 |
|
} |
180 |
0
|
border = border.substring(0, comment.length()); |
181 |
0
|
writeComment(border); |
182 |
0
|
writeComment(comment); |
183 |
0
|
writeComment(border); |
184 |
|
} |
185 |
|
} |