Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MessageContractReader |
|
| 4.666666666666667;4.667 |
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; | |
17 | ||
18 | import java.io.BufferedReader; | |
19 | import java.io.File; | |
20 | import java.io.FileNotFoundException; | |
21 | import java.io.IOException; | |
22 | import java.net.URL; | |
23 | ||
24 | public class MessageContractReader extends ContractReader { | |
25 | ||
26 | /** | |
27 | * @param url | |
28 | * @throws IOException | |
29 | */ | |
30 | public MessageContractReader(URL url, String jsessionId) throws IOException { | |
31 | 0 | super(url, jsessionId); |
32 | // TODO Auto-generated constructor stub | |
33 | 0 | } |
34 | ||
35 | public MessageContractReader(File file) throws FileNotFoundException, | |
36 | IOException { | |
37 | 0 | super(file); |
38 | // TODO Auto-generated constructor stub | |
39 | 0 | } |
40 | ||
41 | /* | |
42 | * (non-Javadoc) | |
43 | * | |
44 | * @see org.kuali.student.contract.ContractReader#trimContract(java.io.BufferedReader) | |
45 | */ | |
46 | @Override | |
47 | protected String trimContract(BufferedReader reader) throws IOException { | |
48 | 0 | StringBuilder builder = new StringBuilder(); |
49 | String line; | |
50 | ||
51 | // Add in xml header and entity definitions | |
52 | 0 | builder.append("<?xml version=\"1.0\"?>" + "<!DOCTYPE xsl:stylesheet [" |
53 | + "<!ENTITY nbsp ' '>" + "]>"); | |
54 | ||
55 | 0 | boolean description = false; |
56 | 0 | boolean meta = false; |
57 | 0 | boolean struct = false; |
58 | ||
59 | 0 | builder.append("\n<content>\n"); |
60 | ||
61 | 0 | while ((line = reader.readLine()) != null) { |
62 | 0 | if (line.contains("<h2>")) { |
63 | 0 | builder.append(line + "\n"); |
64 | 0 | continue; |
65 | } | |
66 | ||
67 | 0 | if (line.contains("Description</h3>")) { |
68 | 0 | description = true; |
69 | 0 | builder.append(line + "\n"); |
70 | 0 | continue; |
71 | } | |
72 | ||
73 | 0 | if (description) { |
74 | 0 | builder.append(line + "\n"); |
75 | 0 | if (line.contains("</p>")) { |
76 | 0 | description = false; |
77 | } | |
78 | } | |
79 | ||
80 | 0 | if (line.contains("<table id=\"structureMetaTable\"")) { |
81 | 0 | meta = true; |
82 | 0 | builder.append(line + "\n"); |
83 | 0 | continue; |
84 | } | |
85 | ||
86 | 0 | if (meta) { |
87 | 0 | builder.append(line + "\n"); |
88 | 0 | if (line.contains("</table>")) { |
89 | 0 | meta = false; |
90 | } | |
91 | } | |
92 | ||
93 | 0 | if (line.contains("<table class=\"structTable\"")) { |
94 | 0 | struct = true; |
95 | 0 | builder.append(line + "\n"); |
96 | 0 | continue; |
97 | } | |
98 | ||
99 | 0 | if (struct) { |
100 | 0 | builder.append(line + "\n"); |
101 | 0 | if (line.contains("</table>")) { |
102 | 0 | struct = false; |
103 | } | |
104 | } | |
105 | } | |
106 | ||
107 | 0 | builder.append("\n</content>\n"); |
108 | 0 | return builder.toString(); |
109 | } | |
110 | ||
111 | } |