| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.datadictionary.util; |
| 17 | |
|
| 18 | |
import java.io.File; |
| 19 | |
import java.io.FileNotFoundException; |
| 20 | |
import java.io.FileOutputStream; |
| 21 | |
import java.io.OutputStream; |
| 22 | |
import java.io.PrintStream; |
| 23 | |
import java.util.ArrayList; |
| 24 | |
import java.util.Collections; |
| 25 | |
import java.util.Comparator; |
| 26 | |
import java.util.Date; |
| 27 | |
import java.util.List; |
| 28 | |
import java.util.Map; |
| 29 | |
import java.util.Stack; |
| 30 | |
import org.kuali.rice.krad.datadictionary.AttributeDefinition; |
| 31 | |
import org.kuali.rice.krad.datadictionary.AttributeDefinitionBase; |
| 32 | |
import org.kuali.rice.krad.datadictionary.CollectionDefinition; |
| 33 | |
import org.kuali.rice.krad.datadictionary.ComplexAttributeDefinition; |
| 34 | |
import org.kuali.rice.krad.datadictionary.DataObjectEntry; |
| 35 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.BaseConstraint; |
| 36 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.CaseConstraint; |
| 37 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.CommonLookupParam; |
| 38 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.LookupConstraint; |
| 39 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.ValidCharactersConstraint; |
| 40 | |
import org.kuali.rice.krad.datadictionary.validation.constraint.WhenConstraint; |
| 41 | |
import org.kuali.rice.krad.uif.control.Control; |
| 42 | |
import org.kuali.rice.krad.uif.control.TextControl; |
| 43 | |
|
| 44 | |
public class DictionaryFormatter { |
| 45 | |
|
| 46 | |
private DataObjectEntry doe; |
| 47 | |
private Map<String, DataObjectEntry> beansOfType; |
| 48 | |
private String beanId; |
| 49 | |
private String outputFileName; |
| 50 | |
|
| 51 | 0 | public DictionaryFormatter(DataObjectEntry doe, Map<String, DataObjectEntry> beansOfType, String beanId, String outputFileName) { |
| 52 | 0 | this.doe = doe; |
| 53 | 0 | this.beansOfType = beansOfType; |
| 54 | 0 | this.beanId = beanId; |
| 55 | 0 | this.outputFileName = outputFileName; |
| 56 | 0 | } |
| 57 | |
|
| 58 | |
public void formatForHtml() { |
| 59 | 0 | File file = new File(this.outputFileName); |
| 60 | |
OutputStream outputStream; |
| 61 | |
try { |
| 62 | 0 | outputStream = new FileOutputStream(file, false); |
| 63 | 0 | } catch (FileNotFoundException ex) { |
| 64 | 0 | throw new IllegalArgumentException(this.outputFileName, ex); |
| 65 | 0 | } |
| 66 | 0 | PrintStream out = new PrintStream(outputStream); |
| 67 | 0 | writeHeader(out, beanId); |
| 68 | 0 | writeBody(out); |
| 69 | 0 | writeFooter(out); |
| 70 | 0 | out.close(); |
| 71 | 0 | } |
| 72 | |
|
| 73 | |
public static void writeHeader(PrintStream out, String title) { |
| 74 | 0 | out.println("<html>"); |
| 75 | 0 | out.println("<head>"); |
| 76 | 0 | writeTag(out, "title", title); |
| 77 | 0 | out.println("</head>"); |
| 78 | 0 | out.println("<body bgcolor=\"#ffffff\" topmargin=0 marginheight=0>"); |
| 79 | 0 | } |
| 80 | |
|
| 81 | |
public static void writeFooter(PrintStream out) { |
| 82 | 0 | out.println("</body>"); |
| 83 | 0 | out.println("</html>"); |
| 84 | 0 | } |
| 85 | |
|
| 86 | |
private String initUpper(String str) { |
| 87 | 0 | if (str == null) { |
| 88 | 0 | return null; |
| 89 | |
} |
| 90 | 0 | if (str.length() == 0) { |
| 91 | 0 | return str; |
| 92 | |
} |
| 93 | 0 | if (str.length() == 1) { |
| 94 | 0 | return str.toUpperCase(); |
| 95 | |
} |
| 96 | 0 | return str.substring(0, 1).toUpperCase() + str.substring(1); |
| 97 | |
} |
| 98 | |
|
| 99 | |
private void writeBody(PrintStream out) { |
| 100 | 0 | out.println("<a href=\"index.html\">home</a>"); |
| 101 | 0 | out.println("<a href=\"../contractdocs/" + initUpper(doe.getName()) + ".html\">contract doc</a>"); |
| 102 | 0 | out.println("<br>"); |
| 103 | 0 | out.println("(!) This page was automatically generated on " + new Date()); |
| 104 | |
|
| 105 | 0 | out.println("<h1>" + this.beanId + "</h1>"); |
| 106 | |
|
| 107 | 0 | out.println("<br>"); |
| 108 | 0 | out.println("<table border=1>"); |
| 109 | |
|
| 110 | 0 | out.println("<tr>"); |
| 111 | 0 | out.println("<th bgcolor=lightblue>"); |
| 112 | 0 | out.println("Name"); |
| 113 | 0 | out.println("</th>"); |
| 114 | 0 | out.println("<td>"); |
| 115 | 0 | out.println(doe.getName()); |
| 116 | 0 | out.println("</td>"); |
| 117 | 0 | out.println("</tr>"); |
| 118 | |
|
| 119 | 0 | out.println("<tr>"); |
| 120 | 0 | out.println("<th bgcolor=lightblue>"); |
| 121 | 0 | out.println("Label"); |
| 122 | 0 | out.println("</th>"); |
| 123 | 0 | out.println("<td>"); |
| 124 | 0 | out.println(doe.getObjectLabel()); |
| 125 | 0 | out.println("</td>"); |
| 126 | 0 | out.println("</tr>"); |
| 127 | |
|
| 128 | 0 | out.println("<tr>"); |
| 129 | 0 | out.println("<th bgcolor=lightblue>"); |
| 130 | 0 | out.println("JSTL Key"); |
| 131 | 0 | out.println("</th>"); |
| 132 | 0 | out.println("<td>"); |
| 133 | 0 | out.println(doe.getJstlKey()); |
| 134 | 0 | out.println("</td>"); |
| 135 | 0 | out.println("</tr>"); |
| 136 | |
|
| 137 | 0 | out.println("<tr>"); |
| 138 | 0 | out.println("<th bgcolor=lightblue>"); |
| 139 | 0 | out.println("Java Class"); |
| 140 | 0 | out.println("</th>"); |
| 141 | 0 | out.println("<td>"); |
| 142 | 0 | out.println(doe.getFullClassName()); |
| 143 | 0 | out.println("</td>"); |
| 144 | 0 | out.println("</tr>"); |
| 145 | 0 | out.println("<tr>"); |
| 146 | |
|
| 147 | 0 | if (!doe.getDataObjectClass().getName().equals(doe.getFullClassName())) { |
| 148 | 0 | out.println("<tr>"); |
| 149 | 0 | out.println("<th bgcolor=lightblue>"); |
| 150 | 0 | out.println("Object Class"); |
| 151 | 0 | out.println("</th>"); |
| 152 | 0 | out.println("<td>"); |
| 153 | 0 | out.println(doe.getDataObjectClass().getName()); |
| 154 | 0 | out.println("</td>"); |
| 155 | 0 | out.println("</tr>"); |
| 156 | 0 | out.println("<tr>"); |
| 157 | |
} |
| 158 | |
|
| 159 | 0 | if (!doe.getEntryClass().getName().equals(doe.getFullClassName())) { |
| 160 | 0 | out.println("<tr>"); |
| 161 | 0 | out.println("<th bgcolor=lightblue>"); |
| 162 | 0 | out.println("Entry Class"); |
| 163 | 0 | out.println("</th>"); |
| 164 | 0 | out.println("<td>"); |
| 165 | 0 | out.println(doe.getEntryClass().getName()); |
| 166 | 0 | out.println("</td>"); |
| 167 | 0 | out.println("</tr>"); |
| 168 | 0 | out.println("<tr>"); |
| 169 | |
} |
| 170 | |
|
| 171 | 0 | out.println("<tr>"); |
| 172 | 0 | out.println("<th bgcolor=lightblue>"); |
| 173 | 0 | out.println("Description"); |
| 174 | 0 | out.println("</th>"); |
| 175 | 0 | out.println("<td>"); |
| 176 | 0 | out.println(doe.getObjectDescription()); |
| 177 | 0 | out.println("</td>"); |
| 178 | 0 | out.println("</tr>"); |
| 179 | |
|
| 180 | 0 | out.println("<tr>"); |
| 181 | 0 | out.println("<th bgcolor=lightblue>"); |
| 182 | 0 | out.println("Primary Key(s)"); |
| 183 | 0 | out.println("</th>"); |
| 184 | 0 | out.println("<td>"); |
| 185 | 0 | StringBuilder bldr = new StringBuilder(); |
| 186 | 0 | String comma = ""; |
| 187 | 0 | if (doe.getPrimaryKeys() != null) { |
| 188 | 0 | for (String pk : doe.getPrimaryKeys()) { |
| 189 | 0 | bldr.append(comma); |
| 190 | 0 | comma = ", "; |
| 191 | 0 | bldr.append(pk); |
| 192 | |
} |
| 193 | |
} |
| 194 | 0 | out.println(bldr.toString()); |
| 195 | 0 | out.println("</td>"); |
| 196 | 0 | out.println("</tr>"); |
| 197 | |
|
| 198 | 0 | out.println("<tr>"); |
| 199 | 0 | out.println("<th bgcolor=lightblue>"); |
| 200 | 0 | out.println("Field to use as the title (or name)"); |
| 201 | 0 | out.println("</th>"); |
| 202 | 0 | out.println("<td>"); |
| 203 | 0 | out.println(doe.getTitleAttribute()); |
| 204 | 0 | out.println("</td>"); |
| 205 | 0 | out.println("</tr>"); |
| 206 | |
|
| 207 | 0 | out.println("</table>"); |
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | 0 | out.println("<h1>Field Definitions</h1>"); |
| 212 | |
|
| 213 | 0 | List<String> discrepancies = new Dictionary2BeanComparer(doe.getFullClassName(), doe).compare(); |
| 214 | 0 | if (discrepancies.isEmpty()) { |
| 215 | 0 | out.println("No discrepancies were found between the dictionary definition and the java object -- "); |
| 216 | 0 | out.println("WARNING: take this with a grain of salt - the comparison does not dig into complex sub-objects nor collections so..."); |
| 217 | |
} else { |
| 218 | 0 | out.println("<b>" + discrepancies.size() + " discrepancie(s) were found between the dictionary definition and the java object" + "</b>"); |
| 219 | 0 | out.println("<ol>"); |
| 220 | 0 | for (String discrepancy : discrepancies) { |
| 221 | 0 | out.println("<li>" + discrepancy); |
| 222 | |
} |
| 223 | 0 | out.println("</ol>"); |
| 224 | |
} |
| 225 | |
|
| 226 | 0 | out.println("<table border=1>"); |
| 227 | 0 | out.println("<tr bgcolor=lightblue>"); |
| 228 | 0 | out.println("<th>"); |
| 229 | 0 | out.println("Field"); |
| 230 | 0 | out.println("</th>"); |
| 231 | 0 | out.println("<th>"); |
| 232 | 0 | out.println("Required?"); |
| 233 | 0 | out.println("</th>"); |
| 234 | 0 | out.println("<th>"); |
| 235 | 0 | out.println("DataType"); |
| 236 | 0 | out.println("</th>"); |
| 237 | 0 | out.println("<th>"); |
| 238 | 0 | out.println("Length"); |
| 239 | 0 | out.println("</th>"); |
| 240 | 0 | out.println("<th>"); |
| 241 | 0 | out.println("Short Label"); |
| 242 | 0 | out.println("</th>"); |
| 243 | 0 | out.println("<th>"); |
| 244 | 0 | out.println("Summary"); |
| 245 | 0 | out.println("</th>"); |
| 246 | 0 | out.println("<th>"); |
| 247 | 0 | out.println("Label"); |
| 248 | 0 | out.println("</th>"); |
| 249 | 0 | out.println("<th>"); |
| 250 | 0 | out.println("Description"); |
| 251 | 0 | out.println("</th>"); |
| 252 | 0 | out.println("<th>"); |
| 253 | 0 | out.println("Read Only, Dynamic, or Hidden"); |
| 254 | 0 | out.println("</th>"); |
| 255 | 0 | out.println("<th>"); |
| 256 | 0 | out.println("Default"); |
| 257 | 0 | out.println("</th>"); |
| 258 | 0 | out.println("<th>"); |
| 259 | 0 | out.println("Repeats?"); |
| 260 | 0 | out.println("</th>"); |
| 261 | 0 | out.println("<th>"); |
| 262 | 0 | out.println("Valid Characters"); |
| 263 | 0 | out.println("</th>"); |
| 264 | 0 | out.println("<th>"); |
| 265 | 0 | out.println("Lookup"); |
| 266 | 0 | out.println("</th>"); |
| 267 | 0 | out.println("<th>"); |
| 268 | 0 | out.println("Cross Field"); |
| 269 | 0 | out.println("</th>"); |
| 270 | 0 | out.println("<th>"); |
| 271 | 0 | out.println("Default Control"); |
| 272 | 0 | out.println("</th>"); |
| 273 | 0 | out.println("</tr>"); |
| 274 | 0 | this.writeAttributes(out, doe, new Stack<String>(), new Stack<DataObjectEntry>()); |
| 275 | 0 | out.println("</table>"); |
| 276 | 0 | return; |
| 277 | |
} |
| 278 | |
|
| 279 | |
private void writeAttributes(PrintStream out, DataObjectEntry ode, Stack<String> parentNames, Stack<DataObjectEntry> parents) { |
| 280 | |
|
| 281 | 0 | if (parents.contains(ode)) { |
| 282 | 0 | return; |
| 283 | |
} |
| 284 | |
|
| 285 | 0 | if (ode.getAttributes() != null) { |
| 286 | 0 | for (AttributeDefinition ad : ode.getAttributes()) { |
| 287 | 0 | out.println("<tr>"); |
| 288 | 0 | out.println("<td>"); |
| 289 | 0 | out.println(nbsp(calcName(ad.getName(), parentNames))); |
| 290 | 0 | out.println("</td>"); |
| 291 | 0 | out.println("<td>"); |
| 292 | 0 | out.println(nbsp(calcRequired(ad))); |
| 293 | 0 | out.println("</td>"); |
| 294 | 0 | out.println("<td>"); |
| 295 | 0 | out.println(nbsp(calcDataType(ad))); |
| 296 | 0 | out.println("</td>"); |
| 297 | 0 | out.println("<td>"); |
| 298 | 0 | out.println(nbsp(calcLength(ad))); |
| 299 | 0 | out.println("</td>"); |
| 300 | 0 | out.println("<td>"); |
| 301 | 0 | out.println(nbsp(calcShortLabel(ad))); |
| 302 | 0 | out.println("</td>"); |
| 303 | 0 | out.println("<td>"); |
| 304 | 0 | out.println(nbsp(calcSummary(ad))); |
| 305 | 0 | out.println("</td>"); |
| 306 | 0 | out.println("<td>"); |
| 307 | 0 | out.println(nbsp(calcLabel(ad))); |
| 308 | 0 | out.println("</td>"); |
| 309 | 0 | out.println("<td>"); |
| 310 | 0 | out.println(nbsp(calcDescription(ad))); |
| 311 | 0 | out.println("</td>"); |
| 312 | 0 | out.println("<td>"); |
| 313 | 0 | out.println(nbsp(calcDynamicHiddenReadOnly(ad))); |
| 314 | 0 | out.println("</td>"); |
| 315 | 0 | out.println("<td>"); |
| 316 | 0 | out.println(nbsp(calcDefaultValue(ad))); |
| 317 | 0 | out.println("</td>"); |
| 318 | 0 | out.println("<td>"); |
| 319 | 0 | out.println(nbsp(null)); |
| 320 | 0 | out.println("</td>"); |
| 321 | 0 | out.println("<td>"); |
| 322 | 0 | out.println(nbsp(calcForceUpperValidCharsMinMax(ad))); |
| 323 | 0 | out.println("</td>"); |
| 324 | 0 | out.println("<td>"); |
| 325 | 0 | out.println(nbsp(calcLookup(ad))); |
| 326 | 0 | out.println("</td>"); |
| 327 | 0 | out.println("<td>"); |
| 328 | 0 | out.println(nbsp(calcCrossField(ad))); |
| 329 | 0 | out.println("</td>"); |
| 330 | 0 | out.println("<td>"); |
| 331 | 0 | out.println(nbsp(calcControl(ad))); |
| 332 | 0 | out.println("</td>"); |
| 333 | 0 | out.println("</tr>"); |
| 334 | |
} |
| 335 | |
} |
| 336 | 0 | if (ode.getComplexAttributes() != null) { |
| 337 | 0 | for (ComplexAttributeDefinition cad : ode.getComplexAttributes()) { |
| 338 | 0 | out.println("<tr>"); |
| 339 | 0 | out.println("<td>"); |
| 340 | 0 | out.println(nbsp(calcName(cad.getName(), parentNames))); |
| 341 | 0 | out.println("</td>"); |
| 342 | 0 | out.println("<td>"); |
| 343 | 0 | out.println(nbsp(calcRequired(cad))); |
| 344 | 0 | out.println("</td>"); |
| 345 | 0 | out.println("<td>"); |
| 346 | 0 | out.println("Complex"); |
| 347 | 0 | out.println("</td>"); |
| 348 | 0 | out.println("<td>"); |
| 349 | 0 | out.println(nbsp(null)); |
| 350 | 0 | out.println("</td>"); |
| 351 | 0 | out.println("<td>"); |
| 352 | 0 | out.println(nbsp(calcShortLabel(cad))); |
| 353 | 0 | out.println("</td>"); |
| 354 | 0 | out.println("<td>"); |
| 355 | 0 | out.println(nbsp(calcSummary(cad))); |
| 356 | 0 | out.println("</td>"); |
| 357 | 0 | out.println("<td>"); |
| 358 | 0 | out.println(nbsp(calcLabel(cad))); |
| 359 | 0 | out.println("</td>"); |
| 360 | 0 | out.println("<td>"); |
| 361 | 0 | out.println(nbsp(calcDescription(cad))); |
| 362 | 0 | out.println("</td>"); |
| 363 | 0 | out.println("<td>"); |
| 364 | 0 | out.println(nbsp(null)); |
| 365 | 0 | out.println("</td>"); |
| 366 | 0 | out.println("<td>"); |
| 367 | 0 | out.println(nbsp(null)); |
| 368 | 0 | out.println("</td>"); |
| 369 | 0 | out.println("<td>"); |
| 370 | 0 | out.println(nbsp(null)); |
| 371 | 0 | out.println("</td>"); |
| 372 | 0 | out.println("<td>"); |
| 373 | 0 | out.println(nbsp(null)); |
| 374 | 0 | out.println("</td>"); |
| 375 | 0 | out.println("<td>"); |
| 376 | 0 | out.println(nbsp(null)); |
| 377 | 0 | out.println("</td>"); |
| 378 | 0 | out.println("<td>"); |
| 379 | 0 | out.println(nbsp(null)); |
| 380 | 0 | out.println("</td>"); |
| 381 | 0 | out.println("<td>"); |
| 382 | 0 | out.println(nbsp(null)); |
| 383 | 0 | out.println("</td>"); |
| 384 | 0 | out.println("</tr>"); |
| 385 | 0 | parentNames.push(cad.getName()); |
| 386 | 0 | parents.push(ode); |
| 387 | 0 | this.writeAttributes(out, (DataObjectEntry) cad.getDataObjectEntry(), parentNames, parents); |
| 388 | 0 | parentNames.pop(); |
| 389 | 0 | parents.pop(); |
| 390 | |
} |
| 391 | |
} |
| 392 | 0 | if (ode.getCollections() != null) { |
| 393 | 0 | for (CollectionDefinition cd : ode.getCollections()) { |
| 394 | 0 | out.println("<tr>"); |
| 395 | 0 | out.println("<td>"); |
| 396 | 0 | out.println(nbsp(calcName(cd.getName(), parentNames))); |
| 397 | 0 | out.println("</td>"); |
| 398 | 0 | out.println("<td>"); |
| 399 | 0 | out.println(nbsp(calcRequired(cd))); |
| 400 | 0 | out.println("</td>"); |
| 401 | 0 | out.println("<td>"); |
| 402 | 0 | out.println("Complex"); |
| 403 | 0 | out.println("</td>"); |
| 404 | 0 | out.println("<td>"); |
| 405 | 0 | out.println(nbsp(null)); |
| 406 | 0 | out.println("</td>"); |
| 407 | 0 | out.println("<td>"); |
| 408 | 0 | out.println(nbsp(calcShortLabel(cd))); |
| 409 | 0 | out.println("</td>"); |
| 410 | 0 | out.println("<td>"); |
| 411 | 0 | out.println(nbsp(calcSummary(cd))); |
| 412 | 0 | out.println("</td>"); |
| 413 | 0 | out.println("<td>"); |
| 414 | 0 | out.println(nbsp(calcLabel(cd))); |
| 415 | 0 | out.println("</td>"); |
| 416 | 0 | out.println("<td>"); |
| 417 | 0 | out.println(nbsp(calcDescription(cd))); |
| 418 | 0 | out.println("</td>"); |
| 419 | 0 | out.println("<td>"); |
| 420 | 0 | out.println(nbsp(null)); |
| 421 | 0 | out.println("</td>"); |
| 422 | 0 | out.println("<td>"); |
| 423 | 0 | out.println(nbsp(null)); |
| 424 | 0 | out.println("</td>"); |
| 425 | 0 | out.println("<td>"); |
| 426 | 0 | out.println(nbsp("Repeating")); |
| 427 | 0 | out.println("</td>"); |
| 428 | 0 | out.println("<td>"); |
| 429 | 0 | out.println(nbsp(null)); |
| 430 | 0 | out.println("</td>"); |
| 431 | 0 | out.println("<td>"); |
| 432 | 0 | out.println(nbsp(null)); |
| 433 | 0 | out.println("</td>"); |
| 434 | 0 | out.println("<td>"); |
| 435 | 0 | out.println(nbsp(null)); |
| 436 | 0 | out.println("</td>"); |
| 437 | 0 | out.println("<td>"); |
| 438 | 0 | out.println(nbsp(null)); |
| 439 | 0 | out.println("</td>"); |
| 440 | 0 | out.println("</tr>"); |
| 441 | 0 | DataObjectEntry childDoe = this.getDataOjbectEntry(cd.getDataObjectClass()); |
| 442 | 0 | if (childDoe == null) { |
| 443 | |
|
| 444 | |
|
| 445 | 0 | System.out.println("Could not find a data object entry, " + cd.getDataObjectClass() + " for field " + calcName(cd.getName(), parentNames)); |
| 446 | |
} else { |
| 447 | 0 | parentNames.push(cd.getName()); |
| 448 | 0 | parents.push(ode); |
| 449 | 0 | this.writeAttributes(out, (DataObjectEntry) childDoe, parentNames, parents); |
| 450 | 0 | parentNames.pop(); |
| 451 | 0 | parents.pop(); |
| 452 | |
} |
| 453 | 0 | } |
| 454 | |
} |
| 455 | 0 | } |
| 456 | |
|
| 457 | |
private DataObjectEntry getDataOjbectEntry(String className) { |
| 458 | 0 | for (DataObjectEntry doe : this.beansOfType.values()) { |
| 459 | 0 | if (doe.getDataObjectClass().getName().equals(className)) { |
| 460 | 0 | return doe; |
| 461 | |
} |
| 462 | |
} |
| 463 | 0 | return null; |
| 464 | |
} |
| 465 | |
|
| 466 | |
private String calcName(String name, Stack<String> parents) { |
| 467 | 0 | StringBuilder sb = new StringBuilder(); |
| 468 | 0 | for (String parent : parents) { |
| 469 | 0 | sb.append(parent); |
| 470 | 0 | sb.append("."); |
| 471 | |
} |
| 472 | 0 | sb.append(name); |
| 473 | 0 | return sb.toString(); |
| 474 | |
} |
| 475 | |
|
| 476 | |
private String calcShortLabel(CollectionDefinition cd) { |
| 477 | 0 | return cd.getShortLabel(); |
| 478 | |
} |
| 479 | |
|
| 480 | |
private String calcShortLabel(AttributeDefinitionBase ad) { |
| 481 | 0 | return ad.getShortLabel(); |
| 482 | |
} |
| 483 | |
|
| 484 | |
private String calcLabel(CollectionDefinition cd) { |
| 485 | 0 | return cd.getLabel(); |
| 486 | |
} |
| 487 | |
|
| 488 | |
private String calcLabel(AttributeDefinitionBase ad) { |
| 489 | 0 | return ad.getLabel(); |
| 490 | |
} |
| 491 | |
|
| 492 | |
private String calcSummary(CollectionDefinition ad) { |
| 493 | 0 | return ad.getSummary(); |
| 494 | |
} |
| 495 | |
|
| 496 | |
private String calcSummary(AttributeDefinitionBase ad) { |
| 497 | 0 | return ad.getSummary(); |
| 498 | |
} |
| 499 | |
|
| 500 | |
private String calcDescription(CollectionDefinition cd) { |
| 501 | 0 | return cd.getDescription(); |
| 502 | |
} |
| 503 | |
|
| 504 | |
private String calcDescription(AttributeDefinitionBase ad) { |
| 505 | 0 | return ad.getDescription(); |
| 506 | |
} |
| 507 | |
|
| 508 | |
private List<AttributeDefinition> getSortedFields() { |
| 509 | 0 | List<AttributeDefinition> fields = doe.getAttributes(); |
| 510 | 0 | Collections.sort(fields, new AttributeDefinitionNameComparator()); |
| 511 | 0 | return fields; |
| 512 | |
} |
| 513 | |
|
| 514 | 0 | private static class AttributeDefinitionNameComparator implements Comparator<AttributeDefinition> { |
| 515 | |
|
| 516 | |
@Override |
| 517 | |
public int compare(AttributeDefinition o1, AttributeDefinition o2) { |
| 518 | 0 | return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase()); |
| 519 | |
} |
| 520 | |
} |
| 521 | |
|
| 522 | |
private String formatAsString(List<String> discrepancies) { |
| 523 | 0 | int i = 0; |
| 524 | 0 | StringBuilder builder = new StringBuilder(); |
| 525 | 0 | for (String discrep : discrepancies) { |
| 526 | 0 | i++; |
| 527 | 0 | builder.append(i + ". " + discrep + "\n"); |
| 528 | |
} |
| 529 | 0 | return builder.toString(); |
| 530 | |
} |
| 531 | |
|
| 532 | |
private String calcDataType(AttributeDefinition ad) { |
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
|
| 544 | |
|
| 545 | |
|
| 546 | |
|
| 547 | |
|
| 548 | |
|
| 549 | |
|
| 550 | |
|
| 551 | 0 | return ad.getDataType().toString(); |
| 552 | |
} |
| 553 | |
|
| 554 | |
private String calcDefaultValue(AttributeDefinition ad) { |
| 555 | |
|
| 556 | |
|
| 557 | |
|
| 558 | 0 | return " "; |
| 559 | |
} |
| 560 | |
|
| 561 | |
private String calcDynamicHiddenReadOnly(AttributeDefinition ad) { |
| 562 | 0 | StringBuilder sb = new StringBuilder(); |
| 563 | 0 | String comma = ""; |
| 564 | 0 | comma = this.appendIfNotNull(sb, this.calcDynamic(ad), comma); |
| 565 | 0 | comma = this.appendIfNotNull(sb, this.calcHidden(ad), comma); |
| 566 | 0 | comma = this.appendIfNotNull(sb, this.calcReadOnly(ad), comma); |
| 567 | 0 | return sb.toString(); |
| 568 | |
} |
| 569 | |
|
| 570 | |
private String appendIfNotNull(StringBuilder sb, String value, String comma) { |
| 571 | 0 | if (value == null) { |
| 572 | 0 | return comma; |
| 573 | |
} |
| 574 | 0 | sb.append(comma); |
| 575 | 0 | sb.append(value); |
| 576 | 0 | return ", "; |
| 577 | |
} |
| 578 | |
|
| 579 | |
private String calcDynamic(AttributeDefinition ad) { |
| 580 | |
|
| 581 | |
|
| 582 | |
|
| 583 | |
|
| 584 | 0 | return null; |
| 585 | |
} |
| 586 | |
|
| 587 | |
private String calcHidden(AttributeDefinition ad) { |
| 588 | 0 | if (ad.getAttributeSecurity() == null) { |
| 589 | 0 | return null; |
| 590 | |
} |
| 591 | 0 | if (ad.getAttributeSecurity().isHide()) { |
| 592 | 0 | return "Hidden"; |
| 593 | |
} |
| 594 | 0 | return null; |
| 595 | |
|
| 596 | |
} |
| 597 | |
|
| 598 | |
private String calcReadOnly(AttributeDefinition ad) { |
| 599 | 0 | if (ad.getAttributeSecurity() == null) { |
| 600 | 0 | return null; |
| 601 | |
} |
| 602 | 0 | if (ad.getAttributeSecurity().isReadOnly()) { |
| 603 | 0 | return "Read only"; |
| 604 | |
} |
| 605 | 0 | return null; |
| 606 | |
|
| 607 | |
} |
| 608 | |
|
| 609 | |
private String calcComplexSubStructureName(AttributeDefinition ad) { |
| 610 | |
|
| 611 | |
|
| 612 | |
|
| 613 | |
|
| 614 | |
|
| 615 | 0 | return " "; |
| 616 | |
} |
| 617 | |
|
| 618 | |
private String calcSimpleName(String simpleName) { |
| 619 | 0 | if (simpleName.lastIndexOf(".") != -1) { |
| 620 | 0 | simpleName = simpleName.substring(simpleName.lastIndexOf(".") + 1); |
| 621 | |
} |
| 622 | 0 | return simpleName; |
| 623 | |
} |
| 624 | |
|
| 625 | |
private String calcNotSoSimpleName(String name) { |
| 626 | 0 | if (name.lastIndexOf(".") == -1) { |
| 627 | 0 | return name; |
| 628 | |
} |
| 629 | 0 | String simpleName = calcSimpleName(name); |
| 630 | 0 | String fieldName = calcSimpleName(name.substring(0, name.length() |
| 631 | |
- simpleName.length() |
| 632 | |
- 1)); |
| 633 | 0 | return fieldName + "." + simpleName; |
| 634 | |
} |
| 635 | |
|
| 636 | |
private String calcRequired(CollectionDefinition cd) { |
| 637 | 0 | if (cd.getMinOccurs() != null) { |
| 638 | 0 | if (cd.getMinOccurs() >= 1) { |
| 639 | 0 | return "required"; |
| 640 | |
} |
| 641 | |
} |
| 642 | |
|
| 643 | |
|
| 644 | |
|
| 645 | |
|
| 646 | |
|
| 647 | |
|
| 648 | |
|
| 649 | |
|
| 650 | |
|
| 651 | |
|
| 652 | |
|
| 653 | |
|
| 654 | 0 | return " "; |
| 655 | |
|
| 656 | |
} |
| 657 | |
|
| 658 | |
private String calcRequired(AttributeDefinitionBase ad) { |
| 659 | 0 | if (ad.isRequired() != null) { |
| 660 | 0 | if (ad.isRequired()) { |
| 661 | 0 | return "required"; |
| 662 | |
} |
| 663 | |
} |
| 664 | |
|
| 665 | |
|
| 666 | |
|
| 667 | |
|
| 668 | |
|
| 669 | |
|
| 670 | |
|
| 671 | |
|
| 672 | |
|
| 673 | |
|
| 674 | |
|
| 675 | |
|
| 676 | 0 | return " "; |
| 677 | |
|
| 678 | |
} |
| 679 | |
|
| 680 | |
private String calcForceUpperCase(AttributeDefinition ad) { |
| 681 | 0 | if (ad.getForceUppercase() != null && ad.getForceUppercase()) { |
| 682 | 0 | return "FORCE UPPER CASE"; |
| 683 | |
} |
| 684 | 0 | return " "; |
| 685 | |
} |
| 686 | |
|
| 687 | |
private String calcValidChars(AttributeDefinition ad) { |
| 688 | 0 | if (ad.getValidCharactersConstraint() == null) { |
| 689 | 0 | return " "; |
| 690 | |
} |
| 691 | 0 | return calcValidChars(ad.getValidCharactersConstraint()); |
| 692 | |
} |
| 693 | |
|
| 694 | |
private String calcValidChars(ValidCharactersConstraint cons) { |
| 695 | 0 | String labelKey = cons.getLabelKey(); |
| 696 | 0 | if (labelKey == null) { |
| 697 | 0 | labelKey = "validation.validChars"; |
| 698 | |
} |
| 699 | 0 | String validChars = escapeXML(cons.getValue()); |
| 700 | 0 | String descr = labelKey + "<br>" + validChars; |
| 701 | 0 | return descr; |
| 702 | |
} |
| 703 | |
|
| 704 | |
private String calcLookup(AttributeDefinition ad) { |
| 705 | 0 | if (ad.getLookupDefinition() == null) { |
| 706 | 0 | return " "; |
| 707 | |
} |
| 708 | 0 | return calcLookup(ad.getLookupDefinition()); |
| 709 | |
} |
| 710 | |
|
| 711 | |
private String calcLookup(LookupConstraint lc) { |
| 712 | 0 | StringBuilder bldr = new StringBuilder(); |
| 713 | 0 | bldr.append(lc.getId()); |
| 714 | |
|
| 715 | |
|
| 716 | |
|
| 717 | 0 | String and = ""; |
| 718 | 0 | bldr.append("<br>"); |
| 719 | 0 | bldr.append("\n"); |
| 720 | 0 | bldr.append("Implemented using search: "); |
| 721 | 0 | String searchPage = calcWikiSearchPage(lc.getSearchTypeId()); |
| 722 | 0 | bldr.append("[" + lc.getSearchTypeId() + "|" + searchPage + "#" |
| 723 | |
+ lc.getSearchTypeId() + "]"); |
| 724 | 0 | List<CommonLookupParam> configuredParameters = filterConfiguredParams( |
| 725 | |
lc.getParams()); |
| 726 | 0 | if (configuredParameters.size() > 0) { |
| 727 | 0 | bldr.append("<br>"); |
| 728 | 0 | bldr.append("\n"); |
| 729 | 0 | bldr.append(" where "); |
| 730 | 0 | and = ""; |
| 731 | 0 | for (CommonLookupParam param : configuredParameters) { |
| 732 | 0 | bldr.append(and); |
| 733 | 0 | and = " and "; |
| 734 | 0 | bldr.append(param.getName()); |
| 735 | 0 | bldr.append("="); |
| 736 | 0 | if (param.getDefaultValueString() != null) { |
| 737 | 0 | bldr.append(param.getDefaultValueString()); |
| 738 | 0 | continue; |
| 739 | |
} |
| 740 | 0 | if (param.getDefaultValueList() != null) { |
| 741 | 0 | String comma = ""; |
| 742 | 0 | for (String defValue : param.getDefaultValueList()) { |
| 743 | 0 | bldr.append(comma); |
| 744 | 0 | comma = ", "; |
| 745 | 0 | bldr.append(defValue); |
| 746 | |
} |
| 747 | 0 | } |
| 748 | |
} |
| 749 | |
} |
| 750 | 0 | return bldr.toString(); |
| 751 | |
} |
| 752 | |
|
| 753 | |
private String calcForceUpperValidCharsMinMax(AttributeDefinition ad) { |
| 754 | 0 | StringBuilder bldr = new StringBuilder(); |
| 755 | 0 | String brk = ""; |
| 756 | 0 | String forceUpper = calcForceUpperCase(ad); |
| 757 | 0 | if (!forceUpper.trim().isEmpty()) { |
| 758 | 0 | bldr.append(forceUpper); |
| 759 | 0 | brk = "<BR>"; |
| 760 | |
} |
| 761 | |
|
| 762 | 0 | String validChars = calcValidChars(ad); |
| 763 | 0 | if (!validChars.trim().isEmpty()) { |
| 764 | 0 | bldr.append(brk); |
| 765 | 0 | brk = "<BR>"; |
| 766 | 0 | bldr.append(validChars); |
| 767 | |
} |
| 768 | |
|
| 769 | 0 | String minMax = calcMinMax(ad); |
| 770 | 0 | if (!minMax.trim().isEmpty()) { |
| 771 | 0 | bldr.append(brk); |
| 772 | 0 | brk = "<BR>"; |
| 773 | 0 | bldr.append(minMax); |
| 774 | |
} |
| 775 | |
|
| 776 | 0 | return bldr.toString(); |
| 777 | |
} |
| 778 | |
|
| 779 | |
private String calcMinMax(AttributeDefinition ad) { |
| 780 | 0 | if (ad.getExclusiveMin() == null) { |
| 781 | 0 | if (ad.getInclusiveMax() == null) { |
| 782 | 0 | return " "; |
| 783 | |
} |
| 784 | 0 | return "Must be <= " + ad.getInclusiveMax(); |
| 785 | |
} |
| 786 | 0 | if (ad.getInclusiveMax() == null) { |
| 787 | 0 | return "Must be > " + ad.getExclusiveMin(); |
| 788 | |
} |
| 789 | 0 | return "Must be > " + ad.getExclusiveMin() + " and < " |
| 790 | |
+ ad.getInclusiveMax(); |
| 791 | |
} |
| 792 | |
private static final String PAGE_PREFIX = "Formatted View of "; |
| 793 | |
private static final String PAGE_SUFFIX = " Searches"; |
| 794 | |
|
| 795 | |
private String calcWikiSearchPage(String searchType) { |
| 796 | 0 | return PAGE_PREFIX + calcWikigPageAbbrev(searchType) + PAGE_SUFFIX; |
| 797 | |
} |
| 798 | |
|
| 799 | |
private String calcWikigPageAbbrev(String searchType) { |
| 800 | 0 | if (searchType == null) { |
| 801 | 0 | return null; |
| 802 | |
} |
| 803 | 0 | if (searchType.equals("enumeration.management.search")) { |
| 804 | 0 | return "EM"; |
| 805 | |
} |
| 806 | 0 | if (searchType.startsWith("lu.")) { |
| 807 | 0 | return "LU"; |
| 808 | |
} |
| 809 | 0 | if (searchType.startsWith("cluset.")) { |
| 810 | 0 | return "LU"; |
| 811 | |
} |
| 812 | 0 | if (searchType.startsWith("lo.")) { |
| 813 | 0 | return "LO"; |
| 814 | |
} |
| 815 | 0 | if (searchType.startsWith("lrc.")) { |
| 816 | 0 | return "LRC"; |
| 817 | |
} |
| 818 | 0 | if (searchType.startsWith("comment.")) { |
| 819 | 0 | return "Comment"; |
| 820 | |
} |
| 821 | 0 | if (searchType.startsWith("org.")) { |
| 822 | 0 | return "Organization"; |
| 823 | |
} |
| 824 | 0 | if (searchType.startsWith("atp.")) { |
| 825 | 0 | return "ATP"; |
| 826 | |
} |
| 827 | 0 | throw new IllegalArgumentException("Unknown type of search: " + searchType); |
| 828 | |
} |
| 829 | |
|
| 830 | |
private List<CommonLookupParam> filterConfiguredParams( |
| 831 | |
List<CommonLookupParam> params) { |
| 832 | 0 | List list = new ArrayList(); |
| 833 | 0 | if (params == null) { |
| 834 | 0 | return list; |
| 835 | |
} |
| 836 | 0 | if (params.size() == 0) { |
| 837 | 0 | return list; |
| 838 | |
} |
| 839 | 0 | for (CommonLookupParam param : params) { |
| 840 | 0 | if (param.getDefaultValueString() != null) { |
| 841 | 0 | list.add(param); |
| 842 | 0 | continue; |
| 843 | |
} |
| 844 | 0 | if (param.getDefaultValueList() != null) { |
| 845 | 0 | list.add(param); |
| 846 | |
} |
| 847 | |
} |
| 848 | 0 | return list; |
| 849 | |
} |
| 850 | |
|
| 851 | |
private String calcLength(AttributeDefinition ad) { |
| 852 | 0 | if (ad.getMaxLength() != null) { |
| 853 | 0 | if (ad.getMinLength() != null && ad.getMinLength() != 0) { |
| 854 | 0 | if (ad.getMaxLength() == ad.getMinLength()) { |
| 855 | 0 | return ("must be " + ad.getMaxLength()); |
| 856 | |
} |
| 857 | 0 | return ad.getMinLength() + " to " + ad.getMaxLength(); |
| 858 | |
} |
| 859 | 0 | return "up to " + ad.getMaxLength(); |
| 860 | |
} |
| 861 | 0 | if (ad.getMinLength() != null) { |
| 862 | 0 | return "at least " + ad.getMinLength(); |
| 863 | |
} |
| 864 | 0 | return " "; |
| 865 | |
} |
| 866 | |
|
| 867 | |
private String calcControl(AttributeDefinition ad) { |
| 868 | 0 | Control control = ad.getControlField(); |
| 869 | 0 | if (control == null) { |
| 870 | 0 | return " "; |
| 871 | |
} |
| 872 | 0 | if (control instanceof TextControl) { |
| 873 | 0 | TextControl textControl = (TextControl) control; |
| 874 | 0 | if (textControl.getDatePicker() != null) { |
| 875 | 0 | return "DateControl"; |
| 876 | |
} |
| 877 | 0 | if (textControl.getStyleClasses() != null) { |
| 878 | 0 | if (textControl.getStyleClasses().contains("amount")) { |
| 879 | 0 | return "CurrencyControl"; |
| 880 | |
} |
| 881 | |
} |
| 882 | |
} |
| 883 | 0 | return control.getClass().getSimpleName(); |
| 884 | |
} |
| 885 | |
|
| 886 | |
private String calcCrossField(AttributeDefinition ad) { |
| 887 | 0 | StringBuilder b = new StringBuilder(); |
| 888 | 0 | String semicolon = ""; |
| 889 | 0 | String cfr = calcCrossFieldRequire(ad); |
| 890 | 0 | if (cfr != null) { |
| 891 | 0 | b.append(semicolon); |
| 892 | 0 | semicolon = "; "; |
| 893 | 0 | b.append(cfr); |
| 894 | |
} |
| 895 | 0 | String cfw = calcCrossFieldWhen(ad); |
| 896 | 0 | if (cfw != null) { |
| 897 | 0 | b.append(semicolon); |
| 898 | 0 | semicolon = "; "; |
| 899 | 0 | b.append(cfw); |
| 900 | |
} |
| 901 | 0 | if (b.length() == 0) { |
| 902 | 0 | return " "; |
| 903 | |
} |
| 904 | 0 | return b.toString(); |
| 905 | |
} |
| 906 | |
|
| 907 | |
private String calcCrossFieldRequire(AttributeDefinitionBase ad) { |
| 908 | |
|
| 909 | |
|
| 910 | |
|
| 911 | |
|
| 912 | |
|
| 913 | |
|
| 914 | 0 | StringBuilder b = new StringBuilder(); |
| 915 | |
|
| 916 | |
|
| 917 | |
|
| 918 | |
|
| 919 | |
|
| 920 | |
|
| 921 | |
|
| 922 | |
|
| 923 | |
|
| 924 | |
|
| 925 | |
|
| 926 | |
|
| 927 | |
|
| 928 | 0 | return b.toString(); |
| 929 | |
} |
| 930 | |
|
| 931 | |
private String calcCrossFieldWhen(AttributeDefinition ad) { |
| 932 | 0 | if (ad.getCaseConstraint() == null) { |
| 933 | 0 | return null; |
| 934 | |
} |
| 935 | 0 | StringBuilder b = new StringBuilder(); |
| 936 | 0 | CaseConstraint cc = ad.getCaseConstraint(); |
| 937 | 0 | for (WhenConstraint wc : cc.getWhenConstraint()) { |
| 938 | 0 | b.append("\\\\"); |
| 939 | 0 | b.append("\n"); |
| 940 | 0 | b.append("when "); |
| 941 | 0 | b.append(cc.getPropertyName()); |
| 942 | 0 | b.append(" "); |
| 943 | 0 | if (!cc.isCaseSensitive()) { |
| 944 | 0 | b.append("ignoring case "); |
| 945 | |
} |
| 946 | 0 | b.append(cc.getOperator()); |
| 947 | 0 | b.append(" "); |
| 948 | |
|
| 949 | 0 | b.append("\\\\"); |
| 950 | 0 | b.append("\n"); |
| 951 | 0 | String comma = ""; |
| 952 | 0 | for (Object value : wc.getValues()) { |
| 953 | 0 | b.append(comma); |
| 954 | 0 | comma = " or "; |
| 955 | 0 | b.append(asString(value)); |
| 956 | |
} |
| 957 | 0 | b.append("\\\\"); |
| 958 | 0 | b.append("\n"); |
| 959 | 0 | b.append("then override constraint:" |
| 960 | |
+ calcOverride(ad, (BaseConstraint) wc.getConstraint())); |
| 961 | 0 | } |
| 962 | 0 | return b.toString(); |
| 963 | |
} |
| 964 | |
|
| 965 | |
private String calcOverride(AttributeDefinition ad, BaseConstraint cons) { |
| 966 | 0 | StringBuilder b = new StringBuilder(); |
| 967 | |
|
| 968 | |
|
| 969 | |
|
| 970 | |
|
| 971 | |
|
| 972 | |
|
| 973 | |
|
| 974 | |
|
| 975 | |
|
| 976 | |
|
| 977 | |
|
| 978 | |
|
| 979 | |
|
| 980 | |
|
| 981 | |
|
| 982 | |
|
| 983 | |
|
| 984 | |
|
| 985 | |
|
| 986 | 0 | return b.toString(); |
| 987 | |
} |
| 988 | |
|
| 989 | |
private String calcOverride(String attribute, LookupConstraint val1, |
| 990 | |
LookupConstraint val2) { |
| 991 | 0 | if (val1 == val2) { |
| 992 | 0 | return ""; |
| 993 | |
} |
| 994 | 0 | if (val1 == null && val2 != null) { |
| 995 | 0 | return " add lookup " + this.calcLookup(val2); |
| 996 | |
} |
| 997 | 0 | if (val1 != null && val2 == null) { |
| 998 | 0 | return " remove lookup constraint"; |
| 999 | |
} |
| 1000 | 0 | return " change lookup to " + calcLookup(val2); |
| 1001 | |
} |
| 1002 | |
|
| 1003 | |
private String calcOverride(String attribute, ValidCharactersConstraint val1, |
| 1004 | |
ValidCharactersConstraint val2) { |
| 1005 | 0 | if (val1 == val2) { |
| 1006 | 0 | return ""; |
| 1007 | |
} |
| 1008 | 0 | if (val1 == null && val2 != null) { |
| 1009 | 0 | return " add validchars " + calcValidChars(val2); |
| 1010 | |
} |
| 1011 | 0 | if (val1 != null && val2 == null) { |
| 1012 | 0 | return " remove validchars constraint"; |
| 1013 | |
} |
| 1014 | 0 | return " change validchars to " + calcValidChars(val2); |
| 1015 | |
} |
| 1016 | |
|
| 1017 | |
private String calcOverride(String attribute, boolean val1, boolean val2) { |
| 1018 | 0 | if (val1 == val2) { |
| 1019 | 0 | return ""; |
| 1020 | |
} |
| 1021 | 0 | return " " + attribute + "=" + val2; |
| 1022 | |
} |
| 1023 | |
|
| 1024 | |
private String calcOverride(String attribute, String val1, String val2) { |
| 1025 | 0 | if (val1 == null && val2 == null) { |
| 1026 | 0 | return ""; |
| 1027 | |
} |
| 1028 | 0 | if (val1 == val2) { |
| 1029 | 0 | return ""; |
| 1030 | |
} |
| 1031 | 0 | if (val1 == null) { |
| 1032 | 0 | return " " + attribute + "=" + val2; |
| 1033 | |
} |
| 1034 | 0 | if (val1.equals(val2)) { |
| 1035 | 0 | return ""; |
| 1036 | |
} |
| 1037 | 0 | return " " + attribute + "=" + val2; |
| 1038 | |
} |
| 1039 | |
|
| 1040 | |
private String calcOverride(String attribute, Object val1, Object val2) { |
| 1041 | 0 | if (val1 == null && val2 == null) { |
| 1042 | 0 | return ""; |
| 1043 | |
} |
| 1044 | 0 | if (val1 == val2) { |
| 1045 | 0 | return ""; |
| 1046 | |
} |
| 1047 | 0 | if (val1 == null) { |
| 1048 | 0 | return " " + attribute + "=" + val2; |
| 1049 | |
} |
| 1050 | 0 | if (val1.equals(val2)) { |
| 1051 | 0 | return ""; |
| 1052 | |
} |
| 1053 | 0 | return " " + attribute + "=" + asString(val2); |
| 1054 | |
} |
| 1055 | |
|
| 1056 | |
private String asString(Object value) { |
| 1057 | 0 | if (value == null) { |
| 1058 | 0 | return "null"; |
| 1059 | |
} |
| 1060 | 0 | if (value instanceof String) { |
| 1061 | 0 | return (String) value; |
| 1062 | |
} |
| 1063 | 0 | return value.toString(); |
| 1064 | |
} |
| 1065 | |
|
| 1066 | |
private String nbsp(String str) { |
| 1067 | 0 | if (str == null) { |
| 1068 | 0 | return " "; |
| 1069 | |
} |
| 1070 | 0 | if (str.trim().isEmpty()) { |
| 1071 | 0 | return " "; |
| 1072 | |
} |
| 1073 | 0 | return str; |
| 1074 | |
} |
| 1075 | |
|
| 1076 | |
public static void writeTag(PrintStream out, String tag, String value) { |
| 1077 | 0 | writeTag(out, tag, null, value); |
| 1078 | 0 | } |
| 1079 | |
|
| 1080 | |
public static void writeTag(PrintStream out, String tag, String modifiers, String value) { |
| 1081 | 0 | if (value == null) { |
| 1082 | 0 | return; |
| 1083 | |
} |
| 1084 | 0 | if (value.equals("")) { |
| 1085 | 0 | return; |
| 1086 | |
} |
| 1087 | 0 | out.print("<" + tag); |
| 1088 | 0 | if (modifiers != null && !modifiers.isEmpty()) { |
| 1089 | 0 | out.print(" " + modifiers); |
| 1090 | |
} |
| 1091 | 0 | out.print(">"); |
| 1092 | 0 | out.print(escapeXML(value)); |
| 1093 | 0 | out.print("</" + tag + ">"); |
| 1094 | 0 | out.println(""); |
| 1095 | 0 | } |
| 1096 | |
|
| 1097 | |
public static String escapeXML(String s) { |
| 1098 | 0 | StringBuffer sb = new StringBuffer(); |
| 1099 | 0 | int n = s.length(); |
| 1100 | 0 | for (int i = 0; i < n; i++) { |
| 1101 | |
|
| 1102 | 0 | char c = s.charAt(i); |
| 1103 | 0 | switch (c) { |
| 1104 | |
case '"': |
| 1105 | 0 | sb.append("""); |
| 1106 | 0 | break; |
| 1107 | |
case '\'': |
| 1108 | 0 | sb.append("'"); |
| 1109 | 0 | break; |
| 1110 | |
case '&': |
| 1111 | 0 | sb.append("&"); |
| 1112 | 0 | break; |
| 1113 | |
case '<': |
| 1114 | 0 | sb.append("<"); |
| 1115 | 0 | break; |
| 1116 | |
case '>': |
| 1117 | 0 | sb.append(">"); |
| 1118 | 0 | break; |
| 1119 | |
|
| 1120 | |
default: |
| 1121 | 0 | sb.append(c); |
| 1122 | |
break; |
| 1123 | |
} |
| 1124 | |
} |
| 1125 | 0 | return sb.toString(); |
| 1126 | |
} |
| 1127 | |
|
| 1128 | |
private void writeLink(PrintStream out, String url, String value) { |
| 1129 | 0 | out.print("<a href=\"" + url + "\">" + value + "</a>"); |
| 1130 | 0 | } |
| 1131 | |
} |