Clover Coverage Report - KS Contract Documentation Generator 0.0.1-SNAPSHOT
Coverage timestamp: Wed Dec 31 1969 19:00:00 EST
../../../../../img/srcFileCovDistChart0.png 0% of files have more coverage
78   185   36   3.9
20   137   0.46   20
20     1.8  
1    
 
  XmlWriter       Line # 24 78 0% 36 118 0% 0.0
 
No Tests
 
1    /*
2    * Copyright 2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.osedu.org/licenses/ECL-2.0
9    *
10    * Unless required by applicable law or agreed to in writing, software
11    * distributed under the License is distributed on an "AS IS" BASIS,
12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    * See the License for the specific language governing permissions and
14    * limitations under the License.
15    */
16    package org.kuali.student.contract.writer;
17   
18    import java.io.PrintStream;
19   
20    /**
21    * Base class for all XML writers
22    * @author nwright
23    */
 
24    public class XmlWriter {
25   
26    private char indentChar = '\t';
27    private int indent;
28    private PrintStream out;
29   
 
30  0 toggle public XmlWriter() {
31    }
32   
 
33  0 toggle public XmlWriter(PrintStream out, int indent) {
34  0 this.indent = indent;
35  0 this.out = out;
36    }
37   
 
38  0 toggle public void setOut(PrintStream out) {
39  0 this.out = out;
40    }
41   
 
42  0 toggle public void setIndent(int indent) {
43  0 this.indent = indent;
44    }
45   
 
46  0 toggle public int getIndent() {
47  0 return indent;
48    }
49   
 
50  0 toggle public void incrementIndent() {
51  0 indent++;
52    }
53   
 
54  0 toggle public void decrementIndent() {
55  0 indent--;
56    }
57   
 
58  0 toggle public PrintStream getOut() {
59  0 return out;
60    }
61   
 
62  0 toggle public void indent() {
63  0 indent(out, indentChar);
64    }
65   
 
66  0 toggle public void indent(PrintStream o, char indentCharacter) {
67  0 for (int i = 0; i < indent; i++) {
68  0 o.print(indentCharacter);
69    }
70    }
71   
 
72  0 toggle public void println(String str) {
73  0 out.println(str);
74    }
75   
 
76  0 toggle public void indentPrintln(String str) {
77  0 indent();
78  0 out.println(str);
79    }
80   
 
81  0 toggle public void indentPrint(String str) {
82  0 indent();
83  0 out.print(str);
84    }
85   
 
86  0 toggle public void print(String str) {
87  0 out.print(str);
88    }
89   
 
90  0 toggle 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   
 
104  0 toggle public void writeTag(String tag, String value) {
105  0 writeTag(tag, null, value);
106    }
107   
 
108  0 toggle 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   
 
127  0 toggle 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   
 
140  0 toggle 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    // http://www.hdfgroup.org/HDF5/XML/xml_escape_chars.htm
145  0 char c = s.charAt(i);
146  0 switch (c) {
147  0 case '"':
148  0 sb.append("&quot;");
149  0 break;
150  0 case '\'':
151  0 sb.append("&apos;");
152  0 break;
153  0 case '&':
154  0 sb.append("&amp;");
155  0 break;
156  0 case '<':
157  0 sb.append("&lt;");
158  0 break;
159  0 case '>':
160  0 sb.append("&gt;");
161  0 break;
162   
163   
164    //case ' ': sb.append("&nbsp;");break;
165   
166  0 default:
167  0 sb.append(c);
168  0 break;
169    }
170    }
171  0 return sb.toString();
172    }
173   
 
174  0 toggle 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    }