Coverage Report - org.kuali.student.datadictionary.util.DictionaryFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
DictionaryFormatter
61%
301/492
33%
63/186
4.326
DictionaryFormatter$1
N/A
N/A
4.326
DictionaryFormatter$AttributeDefinitionNameComparator
0%
0/2
N/A
4.326
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.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.opensource.org/licenses/ecl1.php
 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.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 org.kuali.rice.kns.datadictionary.AttributeDefinition;
 29  
 import org.kuali.rice.kns.datadictionary.DataObjectEntry;
 30  
 import org.kuali.rice.kns.datadictionary.control.ControlDefinition;
 31  
 import org.kuali.rice.kns.datadictionary.validation.constraint.BaseConstraint;
 32  
 import org.kuali.rice.kns.datadictionary.validation.constraint.CaseConstraint;
 33  
 import org.kuali.rice.kns.datadictionary.validation.constraint.CommonLookupParam;
 34  
 import org.kuali.rice.kns.datadictionary.validation.constraint.LookupConstraint;
 35  
 import org.kuali.rice.kns.datadictionary.validation.constraint.ValidCharactersConstraint;
 36  
 import org.kuali.rice.kns.datadictionary.validation.constraint.WhenConstraint;
 37  
 
 38  
 public class DictionaryFormatter {
 39  
 
 40  
     private DataObjectEntry ode;
 41  
     private String projectUrl;
 42  
     private String dictFileName;
 43  
     private String outputFileName;
 44  
 
 45  4
     public DictionaryFormatter(DataObjectEntry ode, String projectUrl, String dictFileName, String outputFileName) {
 46  4
         this.ode = ode;
 47  4
         this.projectUrl = projectUrl;
 48  4
         this.dictFileName = dictFileName;
 49  4
         this.outputFileName = outputFileName;
 50  4
     }
 51  
 
 52  
     public void formatForHtml() {
 53  4
         File file = new File(this.outputFileName);
 54  
         OutputStream outputStream;
 55  
         try {
 56  4
             outputStream = new FileOutputStream(file, false);
 57  0
         } catch (FileNotFoundException ex) {
 58  0
             throw new IllegalArgumentException(ex);
 59  4
         }
 60  4
         PrintStream out = new PrintStream(outputStream);
 61  4
         writeHeader(out);
 62  4
         writeBody(out);
 63  4
         writeFooter(out);
 64  4
         out.close();
 65  4
     }
 66  
 
 67  
     private void writeHeader(PrintStream out) {
 68  4
         out.println("<html>");
 69  4
         out.println("<head>");
 70  4
         writeTag(out, "title", dictFileName);
 71  4
         out.println("</head>");
 72  4
         out.println("<body bgcolor=\"#ffffff\" topmargin=0 marginheight=0>");
 73  4
     }
 74  
 
 75  
     private void writeFooter(PrintStream out) {
 76  4
         out.println("</body>");
 77  4
         out.println("</html>");
 78  4
     }
 79  
 
 80  
     private void writeBody(PrintStream out) {
 81  4
         out.println("(!) This page was automatically generated on " + new Date());
 82  4
         out.print(" and is a formatted view of ");
 83  4
         writeLink(out, projectUrl + "/" + this.dictFileName, "this file");
 84  4
         out.print(" out on subversion.");
 85  
 //  builder.append ("======= start dump of object structure definition ========");
 86  4
         out.println("<h1>" + this.dictFileName + "</h1>");
 87  
 
 88  4
         out.println("<br>");
 89  4
         out.println("<table border=1>");
 90  
 
 91  4
         out.println("<tr>");
 92  4
         out.println("<th bgcolor=lightblue>");
 93  4
         out.println("Name");
 94  4
         out.println("</th>");
 95  4
         out.println("<td>");
 96  4
         out.println(ode.getName());
 97  4
         out.println("</td>");
 98  4
         out.println("</tr>");
 99  
 
 100  4
         out.println("<tr>");
 101  4
         out.println("<th bgcolor=lightblue>");
 102  4
         out.println("Label");
 103  4
         out.println("</th>");
 104  4
         out.println("<td>");
 105  4
         out.println(ode.getObjectLabel());
 106  4
         out.println("</td>");
 107  4
         out.println("</tr>");
 108  
 
 109  4
         out.println("<tr>");
 110  4
         out.println("<th bgcolor=lightblue>");
 111  4
         out.println("JSTL Key");
 112  4
         out.println("</th>");
 113  4
         out.println("<td>");
 114  4
         out.println(ode.getJstlKey());
 115  4
         out.println("</td>");
 116  4
         out.println("</tr>");
 117  
 
 118  4
         out.println("<tr>");
 119  4
         out.println("<th bgcolor=lightblue>");
 120  4
         out.println("Java Class");
 121  4
         out.println("</th>");
 122  4
         out.println("<td>");
 123  4
         out.println(ode.getFullClassName());
 124  4
         out.println("</td>");
 125  4
         out.println("</tr>");
 126  4
         out.println("<tr>");
 127  
 
 128  4
         if (!ode.getObjectClass().getName().equals(ode.getFullClassName())) {
 129  0
             out.println("<tr>");
 130  0
             out.println("<th bgcolor=lightblue>");
 131  0
             out.println("Object Class");
 132  0
             out.println("</th>");
 133  0
             out.println("<td>");
 134  0
             out.println(ode.getObjectClass().getName());
 135  0
             out.println("</td>");
 136  0
             out.println("</tr>");
 137  0
             out.println("<tr>");
 138  
         }
 139  
 
 140  4
         if (!ode.getEntryClass().getName().equals(ode.getFullClassName())) {
 141  0
             out.println("<tr>");
 142  0
             out.println("<th bgcolor=lightblue>");
 143  0
             out.println("Entry Class");
 144  0
             out.println("</th>");
 145  0
             out.println("<td>");
 146  0
             out.println(ode.getEntryClass().getName());
 147  0
             out.println("</td>");
 148  0
             out.println("</tr>");
 149  0
             out.println("<tr>");
 150  
         }
 151  
 
 152  4
         out.println("<tr>");
 153  4
         out.println("<th bgcolor=lightblue>");
 154  4
         out.println("Description");
 155  4
         out.println("</th>");
 156  4
         out.println("<td>");
 157  4
         out.println(ode.getObjectDescription());
 158  4
         out.println("</td>");
 159  4
         out.println("</tr>");
 160  
 
 161  4
         out.println("<tr>");
 162  4
         out.println("<th bgcolor=lightblue>");
 163  4
         out.println("Primary Key(s)");
 164  4
         out.println("</th>");
 165  4
         out.println("<td>");
 166  4
         StringBuilder bldr = new StringBuilder();
 167  4
         String comma = "";
 168  4
         for (String pk : ode.getPrimaryKeys()) {
 169  4
             bldr.append(comma);
 170  4
             comma = ", ";
 171  4
             bldr.append(pk);
 172  
         }
 173  4
         out.println(bldr.toString());
 174  4
         out.println("</td>");
 175  4
         out.println("</tr>");
 176  
 
 177  4
         out.println("<tr>");
 178  4
         out.println("<th bgcolor=lightblue>");
 179  4
         out.println("Field to use as the title (or name)");
 180  4
         out.println("</th>");
 181  4
         out.println("<td>");
 182  4
         out.println(ode.getTitleAttribute());
 183  4
         out.println("</td>");
 184  4
         out.println("</tr>");
 185  
 
 186  4
         out.println("</table>");
 187  
 //        out.println("<br>");
 188  
 
 189  
         // fields
 190  4
         out.println("<h1>Field Definitions</h1>");
 191  
         // check for discrepancies first
 192  4
         List<String> discrepancies = new Dictionary2BeanComparer(ode.getFullClassName(), ode).compare();
 193  4
         out.println("No discrepancies were found between the dictionary definition and the java object");
 194  4
         if (discrepancies.size() > 0) {
 195  4
             out.println("<b>" + discrepancies.size() + " discrepancie(s) were found between the dictionary definition and the java object" + "</b>");
 196  4
             out.println("<ol>");
 197  4
             for (String discrepancy : discrepancies) {
 198  44
                 out.println("<li>" + discrepancy);
 199  
             }
 200  4
             out.println("</ol>");
 201  
         }
 202  
         // field table
 203  4
         out.println("<table border=1>");
 204  4
         out.println("<tr bgcolor=lightblue>");
 205  4
         out.println("<th>");
 206  4
         out.println("Field");
 207  4
         out.println("</th>");
 208  4
         out.println("<th>");
 209  4
         out.println("Required?");
 210  4
         out.println("</th>");
 211  4
         out.println("<th>");
 212  4
         out.println("DataType");
 213  4
         out.println("</th>");
 214  4
         out.println("<th>");
 215  4
         out.println("Length");
 216  4
         out.println("</th>");
 217  4
         out.println("<th>");
 218  4
         out.println("Labels");
 219  4
         out.println("</th>");
 220  4
         out.println("<th>");
 221  4
         out.println("Descriptions");
 222  4
         out.println("</th>");
 223  4
         out.println("<th>");
 224  4
         out.println("Dynamic or Hidden");
 225  4
         out.println("</th>");
 226  4
         out.println("<th>");
 227  4
         out.println("Default");
 228  4
         out.println("</th>");
 229  4
         out.println("<th>");
 230  4
         out.println("Repeats?");
 231  4
         out.println("</th>");
 232  4
         out.println("<th>");
 233  4
         out.println("Valid Characters");
 234  4
         out.println("</th>");
 235  4
         out.println("<th>");
 236  4
         out.println("Lookup");
 237  4
         out.println("</th>");
 238  4
         out.println("<th>");
 239  4
         out.println("Cross Field");
 240  4
         out.println("</th>");
 241  4
         out.println("<th>");
 242  4
         out.println("Default Widget");
 243  4
         out.println("</th>");
 244  4
         out.println("</tr>");
 245  
 //        for (AttributeDefinition ad : getSortedFields()) {
 246  4
         for (AttributeDefinition ad : ode.getAttributes()) {
 247  29
             out.println("<tr>");
 248  29
             out.println("<td>");
 249  29
             out.println(nbsp(ad.getName()));
 250  29
             out.println("</td>");
 251  29
             out.println("<td>");
 252  29
             out.println(nbsp(calcRequired(ad)));
 253  29
             out.println("</td>");
 254  29
             out.println("<td>");
 255  29
             out.println(nbsp(calcDataType(ad)));
 256  29
             out.println("</td>");
 257  29
             out.println("<td>");
 258  29
             out.println(nbsp(calcLength(ad)));
 259  29
             out.println("</td>");
 260  29
             out.println("<td>");
 261  29
             out.println(nbsp(calcLabels(ad)));
 262  29
             out.println("</td>");
 263  29
             out.println("<td>");
 264  29
             out.println(nbsp(calcDescriptions(ad)));
 265  29
             out.println("</td>");
 266  29
             out.println("<td>");
 267  29
             out.println(nbsp(calcDynamic(ad)));
 268  29
             out.println("</td>");
 269  29
             out.println("<td>");
 270  29
             out.println(nbsp(calcDefaultValue(ad)));
 271  29
             out.println("</td>");
 272  29
             out.println("<td>");
 273  29
             out.println(nbsp(calcRepeating(ad)));
 274  29
             out.println("</td>");
 275  29
             out.println("<td>");
 276  29
             out.println(nbsp(calcForceUpperValidCharsMinMax(ad)));
 277  29
             out.println("</td>");
 278  29
             out.println("<td>");
 279  29
             out.println(nbsp(calcLookup(ad)));
 280  29
             out.println("</td>");
 281  29
             out.println("<td>");
 282  29
             out.println(nbsp(calcCrossField(ad)));
 283  29
             out.println("</td>");
 284  29
             out.println("<td>");
 285  29
             out.println(nbsp(calcWidget(ad)));
 286  29
             out.println("</td>");
 287  29
             out.println("</tr>");
 288  
         }
 289  4
         out.println("</table>");
 290  4
         return;
 291  
     }
 292  
 
 293  
     private String calcLabels(AttributeDefinition ad) {
 294  29
         if (ad.getShortLabel() == null) {
 295  13
             return ad.getLabel();
 296  
         }
 297  16
         if (ad.getLabel() == null) {
 298  0
             return ad.getShortLabel();
 299  
         }
 300  16
         if (ad.getShortLabel().equals(ad.getLabel())) {
 301  10
             return ad.getShortLabel();
 302  
         }
 303  6
         return ad.getSummary() + "<br>" + ad.getDescription();
 304  
     }
 305  
 
 306  
     private String calcDescriptions(AttributeDefinition ad) {
 307  29
         if (ad.getSummary() == null) {
 308  13
             return ad.getDescription();
 309  
         }
 310  16
         if (ad.getDescription() == null) {
 311  0
             return ad.getSummary();
 312  
         }
 313  16
         if (ad.getSummary().equals(ad.getDescription())) {
 314  1
             return ad.getSummary();
 315  
         }
 316  15
         return ad.getSummary() + "<br>" + ad.getDescription();
 317  
     }
 318  
 
 319  
     private List<AttributeDefinition> getSortedFields() {
 320  0
         List<AttributeDefinition> fields = ode.getAttributes();
 321  0
         Collections.sort(fields, new AttributeDefinitionNameComparator());
 322  0
         return fields;
 323  
     }
 324  
 
 325  0
     private static class AttributeDefinitionNameComparator implements Comparator<AttributeDefinition> {
 326  
 
 327  
         @Override
 328  
         public int compare(AttributeDefinition o1, AttributeDefinition o2) {
 329  0
             return o1.getName().toLowerCase().compareTo(o2.getName().toLowerCase());
 330  
         }
 331  
     }
 332  
 
 333  
     private Class getClass(String className) {
 334  
         try {
 335  0
             return Class.forName(className);
 336  0
         } catch (ClassNotFoundException ex) {
 337  0
             return null;
 338  
 //   throw new IllegalArgumentException ("Could not find class for " + className);
 339  
         }
 340  
     }
 341  
 
 342  
     private String formatAsString(List<String> discrepancies) {
 343  0
         int i = 0;
 344  0
         StringBuilder builder = new StringBuilder();
 345  0
         for (String discrep : discrepancies) {
 346  0
             i++;
 347  0
             builder.append(i + ". " + discrep + "\n");
 348  
         }
 349  0
         return builder.toString();
 350  
     }
 351  
 
 352  
     private String calcDataType(AttributeDefinition ad) {
 353  
 //        if (ad.getDataType().equals(DataType.COMPLEX)) {
 354  
 //            if (ad.getDataObjectStructure() == null) {
 355  
 //                throw new IllegalArgumentException(
 356  
 //                        ad.getName() + " is complex but does not have a sub-structure defined");
 357  
 //            }
 358  
 //            Class subClazz = this.getClass(ad.getDataObjectStructure().getName());
 359  
 //            String subStrucName = calcComplexSubStructureName(ad);
 360  
 //            // process if explicity asking for substructures OR the field is a freestanding field
 361  
 //            // so it won't be processed by just processing all of the DTO's and their sub-objects
 362  
 //            if (this.processSubstructures || subClazz == null) {
 363  
 //                if (!this.subStructuresAlreadyProcessed.contains(
 364  
 //                        ad.getDataObjectStructure())) {
 365  
 ////     System.out.println ("Adding " + subStrucName + " to set to be processed");
 366  
 //                    this.subStructuresToProcess.put(subStrucName, ad.getDataObjectStructure());
 367  
 //                }
 368  
 //            }
 369  
 //            return "[" + calcNotSoSimpleName(subStrucName) + "|#" + subStrucName + "]";
 370  
 //        }
 371  29
         return ad.getDataType().toString();
 372  
     }
 373  
 
 374  
     private String calcDefaultValue(AttributeDefinition ad) {
 375  
 //        if (ad.getDefaultValue() != null) {
 376  
 //            return ad.getDefaultValue().toString();
 377  
 //        }
 378  29
         return " ";
 379  
     }
 380  
 
 381  
     private String calcDynamic(AttributeDefinition ad) {
 382  
 //        if (ad.isDynamic()) {
 383  
 //            return "dynamic";
 384  
 //        }
 385  29
         return " ";
 386  
     }
 387  
 
 388  
     private String calcComplexSubStructureName(AttributeDefinition ad) {
 389  
 //        if (this.processSubstructures) {
 390  
 //            return name + "." + ad.getName() + "." + calcSimpleName(
 391  
 //                    ad.getDataObjectStructure().getName());
 392  
 //        }
 393  
 //        return calcSimpleName(ad.getDataObjectStructure().getName());
 394  0
         return " ";
 395  
     }
 396  
 
 397  
     private String calcSimpleName(String name) {
 398  0
         if (name.lastIndexOf(".") != -1) {
 399  0
             name = name.substring(name.lastIndexOf(".") + 1);
 400  
         }
 401  0
         return name;
 402  
     }
 403  
 
 404  
     private String calcNotSoSimpleName(String name) {
 405  0
         if (name.lastIndexOf(".") == -1) {
 406  0
             return name;
 407  
         }
 408  0
         String simpleName = calcSimpleName(name);
 409  0
         String fieldName = calcSimpleName(name.substring(0, name.length()
 410  
                 - simpleName.length()
 411  
                 - 1));
 412  0
         return fieldName + "." + simpleName;
 413  
     }
 414  
 
 415  
     private String calcRequired(AttributeDefinition ad) {
 416  29
         if (ad.isRequired() != null) {
 417  29
             if (ad.isRequired()) {
 418  9
                 return "required";
 419  
             }
 420  
         }
 421  
         // TODO: Deal with collections
 422  
 //        if (ad.getMaximumNumberOfElements() != null) {
 423  
 //            if (ad.getMaximumNumberOfElements().intValue() == 0) {
 424  
 //                return "Not allowed";
 425  
 //            }
 426  
 //        }
 427  
 //
 428  
 //        if (ad.getMinimumNumberOfElements() != null) {
 429  
 //            if (ad.getMinimumNumberOfElements().intValue() >= 1) {
 430  
 //                return "required";
 431  
 //            }
 432  
 //        }
 433  20
         return " ";
 434  
 //  return "optional";
 435  
     }
 436  
 
 437  
     private String calcForceUpperCase(AttributeDefinition ad) {
 438  29
         if (ad.getForceUppercase() != null && ad.getForceUppercase()) {
 439  0
             return "FORCE UPPER CASE";
 440  
         }
 441  29
         return " ";
 442  
     }
 443  
 
 444  
     private String calcValidChars(AttributeDefinition ad) {
 445  29
         if (ad.getValidCharactersConstraint() == null) {
 446  11
             return " ";
 447  
         }
 448  18
         return calcValidChars(ad.getValidCharactersConstraint());
 449  
     }
 450  
 
 451  
     private String calcValidChars(ValidCharactersConstraint cons) {
 452  18
         String labelKey = cons.getLabelKey();
 453  18
         if (labelKey == null) {
 454  10
             labelKey = "validation.validChars";
 455  
         }
 456  18
         String validChars = escapeXML(cons.getValue());
 457  18
         String descr = labelKey + "<br>" + validChars;
 458  18
         return descr;
 459  
     }
 460  
 
 461  
     private String calcLookup(AttributeDefinition ad) {
 462  29
         if (ad.getLookupDefinition() == null) {
 463  29
             return " ";
 464  
         }
 465  0
         return calcLookup(ad.getLookupDefinition());
 466  
     }
 467  
 
 468  
     private String calcLookup(LookupConstraint lc) {
 469  0
         StringBuilder bldr = new StringBuilder();
 470  0
         bldr.append(lc.getId());
 471  
 //  this is the search description not the lookup description
 472  
 //  builder.append (" - ");
 473  
 //  builder.append (lc.getDesc ());
 474  0
         String and = "";
 475  0
         bldr.append("<br>");
 476  0
         bldr.append("\n");
 477  0
         bldr.append("Implemented using search: ");
 478  0
         String searchPage = calcWikiSearchPage(lc.getSearchTypeId());
 479  0
         bldr.append("[" + lc.getSearchTypeId() + "|" + searchPage + "#"
 480  
                 + lc.getSearchTypeId() + "]");
 481  0
         List<CommonLookupParam> configuredParameters = filterConfiguredParams(
 482  
                 lc.getParams());
 483  0
         if (configuredParameters.size() > 0) {
 484  0
             bldr.append("<br>");
 485  0
             bldr.append("\n");
 486  0
             bldr.append(" where ");
 487  0
             and = "";
 488  0
             for (CommonLookupParam param : configuredParameters) {
 489  0
                 bldr.append(and);
 490  0
                 and = " and ";
 491  0
                 bldr.append(param.getName());
 492  0
                 bldr.append("=");
 493  0
                 if (param.getDefaultValueString() != null) {
 494  0
                     bldr.append(param.getDefaultValueString());
 495  0
                     continue;
 496  
                 }
 497  0
                 if (param.getDefaultValueList() != null) {
 498  0
                     String comma = "";
 499  0
                     for (String defValue : param.getDefaultValueList()) {
 500  0
                         bldr.append(comma);
 501  0
                         comma = ", ";
 502  0
                         bldr.append(defValue);
 503  
                     }
 504  0
                 }
 505  
             }
 506  
         }
 507  0
         return bldr.toString();
 508  
     }
 509  
 
 510  
     private String calcForceUpperValidCharsMinMax(AttributeDefinition ad) {
 511  29
         StringBuilder bldr = new StringBuilder();
 512  29
         String brk = "";
 513  29
         String forceUpper = calcForceUpperCase(ad);
 514  29
         if (!forceUpper.trim().isEmpty()) {
 515  0
             bldr.append(forceUpper);
 516  0
             brk = "<BR>";
 517  
         }
 518  
 
 519  29
         String validChars = calcValidChars(ad);
 520  29
         if (!validChars.trim().isEmpty()) {
 521  18
             bldr.append(brk);
 522  18
             brk = "<BR>";
 523  18
             bldr.append(validChars);
 524  
         }
 525  
 
 526  29
         String minMax = calcMinMax(ad);
 527  29
         if (!minMax.trim().isEmpty()) {
 528  0
             bldr.append(brk);
 529  0
             brk = "<BR>";
 530  0
             bldr.append(minMax);
 531  
         }
 532  
 
 533  29
         return bldr.toString();
 534  
     }
 535  
 
 536  
     private String calcMinMax(AttributeDefinition ad) {
 537  29
         if (ad.getExclusiveMin() == null) {
 538  29
             if (ad.getInclusiveMax() == null) {
 539  29
                 return " ";
 540  
             }
 541  0
             return "Must be <= " + ad.getInclusiveMax();
 542  
         }
 543  0
         if (ad.getInclusiveMax() == null) {
 544  0
             return "Must be > " + ad.getExclusiveMin();
 545  
         }
 546  0
         return "Must be > " + ad.getExclusiveMin() + " and < "
 547  
                 + ad.getInclusiveMax();
 548  
     }
 549  
     private static final String PAGE_PREFIX = "Formatted View of ";
 550  
     private static final String PAGE_SUFFIX = " Searches";
 551  
 
 552  
     private String calcWikiSearchPage(String searchType) {
 553  0
         return PAGE_PREFIX + calcWikigPageAbbrev(searchType) + PAGE_SUFFIX;
 554  
     }
 555  
 
 556  
     private String calcWikigPageAbbrev(String searchType) {
 557  0
         if (searchType == null) {
 558  0
             return null;
 559  
         }
 560  0
         if (searchType.equals("enumeration.management.search")) {
 561  0
             return "EM";
 562  
         }
 563  0
         if (searchType.startsWith("lu.")) {
 564  0
             return "LU";
 565  
         }
 566  0
         if (searchType.startsWith("cluset.")) {
 567  0
             return "LU";
 568  
         }
 569  0
         if (searchType.startsWith("lo.")) {
 570  0
             return "LO";
 571  
         }
 572  0
         if (searchType.startsWith("lrc.")) {
 573  0
             return "LRC";
 574  
         }
 575  0
         if (searchType.startsWith("comment.")) {
 576  0
             return "Comment";
 577  
         }
 578  0
         if (searchType.startsWith("org.")) {
 579  0
             return "Organization";
 580  
         }
 581  0
         if (searchType.startsWith("atp.")) {
 582  0
             return "ATP";
 583  
         }
 584  0
         throw new IllegalArgumentException("Unknown type of search: " + searchType);
 585  
     }
 586  
 
 587  
     private List<CommonLookupParam> filterConfiguredParams(
 588  
             List<CommonLookupParam> params) {
 589  0
         List list = new ArrayList();
 590  0
         if (params == null) {
 591  0
             return list;
 592  
         }
 593  0
         if (params.size() == 0) {
 594  0
             return list;
 595  
         }
 596  0
         for (CommonLookupParam param : params) {
 597  0
             if (param.getDefaultValueString() != null) {
 598  0
                 list.add(param);
 599  0
                 continue;
 600  
             }
 601  0
             if (param.getDefaultValueList() != null) {
 602  0
                 list.add(param);
 603  
             }
 604  
         }
 605  0
         return list;
 606  
     }
 607  
 
 608  
     private String calcRepeating(AttributeDefinition ad) {
 609  
         // TODO: deal with collections
 610  29
         return "????";
 611  
 //        if (ad.getMaximumNumberOfElements() == null) {
 612  
 //            return "???";
 613  
 //        }
 614  
 //        if (ad.getMaximumNumberOfElements().intValue() == DictionaryConstants.UNBOUNDED) {
 615  
 //            if (ad.getMinimumNumberOfElements() != null && ad.getMinimumNumberOfElements() > 1) {
 616  
 //                return "repeating: minimum " + ad.getMinimumNumberOfElements() + " times";
 617  
 //            }
 618  
 //            return "repeating: unlimited";
 619  
 //        }
 620  
 //        if (ad.getMaximumNumberOfElements().intValue() == 0) {
 621  
 //            return "NOT USED";
 622  
 //        }
 623  
 //        if (ad.getMaximumNumberOfElements().intValue() == 1) {
 624  
 //            return " ";
 625  
 ////   return "single";
 626  
 //        }
 627  
 //
 628  
 //        if (ad.getMinimumNumberOfElements() != null) {
 629  
 //            if (ad.getMinimumNumberOfElements().intValue() > 1) {
 630  
 //                return "repeating: " + ad.getMinimumNumberOfElements() + " to " + ad.getMaximumNumberOfElements()
 631  
 //                        + " times";
 632  
 //            }
 633  
 //        }
 634  
 //        return "repeating: maximum " + ad.getMaximumNumberOfElements() + " times";
 635  
     }
 636  
 
 637  
     private String calcLength(AttributeDefinition ad) {
 638  29
         if (ad.getMaxLength() != null) {
 639  26
             if (ad.getMinLength() != null && ad.getMinLength() != 0) {
 640  26
                 if (ad.getMaxLength() == ad.getMinLength()) {
 641  8
                     return ("must be " + ad.getMaxLength());
 642  
                 }
 643  18
                 return ad.getMinLength() + " to " + ad.getMaxLength();
 644  
             }
 645  0
             return "up to " + ad.getMaxLength();
 646  
         }
 647  3
         if (ad.getMinLength() != null) {
 648  0
             return "at least " + ad.getMinLength();
 649  
         }
 650  3
         return " ";
 651  
     }
 652  
 
 653  
     private String calcWidget(AttributeDefinition ad) {
 654  29
         ControlDefinition control = ad.getControl();
 655  29
         if (control == null) {
 656  3
             return " ";
 657  
         }
 658  26
         return control.getClass().getSimpleName();
 659  
     }
 660  
 
 661  
     private String calcCrossField(AttributeDefinition ad) {
 662  29
         StringBuilder b = new StringBuilder();
 663  29
         String semicolon = "";
 664  29
         String cfr = calcCrossFieldRequire(ad);
 665  29
         if (cfr != null) {
 666  29
             b.append(semicolon);
 667  29
             semicolon = "; ";
 668  29
             b.append(cfr);
 669  
         }
 670  29
         String cfw = calcCrossFieldWhen(ad);
 671  29
         if (cfw != null) {
 672  0
             b.append(semicolon);
 673  0
             semicolon = "; ";
 674  0
             b.append(cfw);
 675  
         }
 676  29
         if (b.length() == 0) {
 677  29
             return " ";
 678  
         }
 679  0
         return b.toString();
 680  
     }
 681  
 
 682  
     private String calcCrossFieldRequire(AttributeDefinition ad) {
 683  
 //        if (ad.getRequireConstraint() == null) {
 684  
 //            return null;
 685  
 //        }
 686  
 //        if (ad.getRequireConstraint().size() == 0) {
 687  
 //            return null;
 688  
 //        }
 689  29
         StringBuilder b = new StringBuilder();
 690  
 //        String comma = "";
 691  
 //        b.append("if not empty then ");
 692  
 //        for (RequiredConstraint rc : ad.getRequireConstraint()) {
 693  
 //            b.append(comma);
 694  
 //            comma = ", ";
 695  
 //            b.append(rc.getFieldPath());
 696  
 //        }
 697  
 //        if (ad.getRequireConstraint().size() == 1) {
 698  
 //            b.append(" is");
 699  
 //        } else {
 700  
 //            b.append(" are");
 701  
 //        }
 702  
 //        b.append(" also required");
 703  29
         return b.toString();
 704  
     }
 705  
 
 706  
     private String calcCrossFieldWhen(AttributeDefinition ad) {
 707  29
         if (ad.getCaseConstraint() == null) {
 708  29
             return null;
 709  
         }
 710  0
         StringBuilder b = new StringBuilder();
 711  0
         CaseConstraint cc = ad.getCaseConstraint();
 712  0
         for (WhenConstraint wc : cc.getWhenConstraint()) {
 713  0
             b.append("\\\\");
 714  0
             b.append("\n");
 715  0
             b.append("when ");
 716  0
             b.append(cc.getFieldPath());
 717  0
             b.append(" ");
 718  0
             if (!cc.isCaseSensitive()) {
 719  0
                 b.append("ignoring case ");
 720  
             }
 721  0
             b.append(cc.getOperator());
 722  0
             b.append(" ");
 723  
 
 724  0
             b.append("\\\\");
 725  0
             b.append("\n");
 726  0
             String comma = "";
 727  0
             for (Object value : wc.getValues()) {
 728  0
                 b.append(comma);
 729  0
                 comma = " or ";
 730  0
                 b.append(asString(value));
 731  
             }
 732  0
             b.append("\\\\");
 733  0
             b.append("\n");
 734  0
             b.append("then override constraint:"
 735  
                     + calcOverride(ad, (BaseConstraint) wc.getConstraint()));
 736  0
         }
 737  0
         return b.toString();
 738  
     }
 739  
 
 740  
     private String calcOverride(AttributeDefinition ad, BaseConstraint cons) {
 741  0
         StringBuilder b = new StringBuilder();
 742  
 //        b.append(calcOverride("serviceSide", ad.(),
 743  
 //                cons.getApplyClientSide()));
 744  
 //        b.append(calcOverride("exclusiveMin", ad.getExclusiveMin(),
 745  
 //                cons.getExclusiveMin()));
 746  
 //        b.append(calcOverride("inclusiveMax", ad.getInclusiveMax(),
 747  
 //                cons.getInclusiveMax()));
 748  
 //        String minOccursMessage = calcOverride("minOccurs", ad.getMinimumNumberOfElements(),
 749  
 //                cons.getMinimumNumberOfElements());
 750  
 //        if (!minOccursMessage.trim().equals("")) {
 751  
 //            if (cons.getMinimumNumberOfElements() != null && cons.getMinimumNumberOfElements() == 1) {
 752  
 //                minOccursMessage = " REQUIRED";
 753  
 //            }
 754  
 //        }
 755  
 //        b.append(minOccursMessage);
 756  
 //        b.append(calcOverride("validchars", ad.getValidCharactersConstraint(),
 757  
 //                cons.getValidCharactersConstraint()));
 758  
 //        b.append(calcOverride("lookup", ad.getLookupDefinition(),
 759  
 //                cons.getLookupDefinition()));
 760  
         //TODO: other more complex constraints
 761  0
         return b.toString();
 762  
     }
 763  
 
 764  
     private String calcOverride(String attribute, LookupConstraint val1,
 765  
             LookupConstraint val2) {
 766  0
         if (val1 == val2) {
 767  0
             return "";
 768  
         }
 769  0
         if (val1 == null && val2 != null) {
 770  0
             return " add lookup " + this.calcLookup(val2);
 771  
         }
 772  0
         if (val1 != null && val2 == null) {
 773  0
             return " remove lookup constraint";
 774  
         }
 775  0
         return " change lookup to " + calcLookup(val2);
 776  
     }
 777  
 
 778  
     private String calcOverride(String attribute, ValidCharactersConstraint val1,
 779  
             ValidCharactersConstraint val2) {
 780  0
         if (val1 == val2) {
 781  0
             return "";
 782  
         }
 783  0
         if (val1 == null && val2 != null) {
 784  0
             return " add validchars " + calcValidChars(val2);
 785  
         }
 786  0
         if (val1 != null && val2 == null) {
 787  0
             return " remove validchars constraint";
 788  
         }
 789  0
         return " change validchars to " + calcValidChars(val2);
 790  
     }
 791  
 
 792  
     private String calcOverride(String attribute, boolean val1, boolean val2) {
 793  0
         if (val1 == val2) {
 794  0
             return "";
 795  
         }
 796  0
         return " " + attribute + "=" + val2;
 797  
     }
 798  
 
 799  
     private String calcOverride(String attribute, String val1, String val2) {
 800  0
         if (val1 == null && val2 == null) {
 801  0
             return "";
 802  
         }
 803  0
         if (val1 == val2) {
 804  0
             return "";
 805  
         }
 806  0
         if (val1 == null) {
 807  0
             return " " + attribute + "=" + val2;
 808  
         }
 809  0
         if (val1.equals(val2)) {
 810  0
             return "";
 811  
         }
 812  0
         return " " + attribute + "=" + val2;
 813  
     }
 814  
 
 815  
     private String calcOverride(String attribute, Object val1, Object val2) {
 816  0
         if (val1 == null && val2 == null) {
 817  0
             return "";
 818  
         }
 819  0
         if (val1 == val2) {
 820  0
             return "";
 821  
         }
 822  0
         if (val1 == null) {
 823  0
             return " " + attribute + "=" + val2;
 824  
         }
 825  0
         if (val1.equals(val2)) {
 826  0
             return "";
 827  
         }
 828  0
         return " " + attribute + "=" + asString(val2);
 829  
     }
 830  
 
 831  
     private String asString(Object value) {
 832  0
         if (value == null) {
 833  0
             return "null";
 834  
         }
 835  0
         if (value instanceof String) {
 836  0
             return (String) value;
 837  
         }
 838  0
         return value.toString();
 839  
     }
 840  
 
 841  
     private String nbsp(String str) {
 842  377
         if (str == null) {
 843  26
             return "&nbsp;";
 844  
         }
 845  351
         if (str.trim().isEmpty()) {
 846  153
             return "&nbsp;";
 847  
         }
 848  198
         return str;
 849  
     }
 850  
 
 851  
     public void writeTag(PrintStream out, String tag, String value) {
 852  4
         writeTag(out, tag, null, value);
 853  4
     }
 854  
 
 855  
     public void writeTag(PrintStream out, String tag, String modifiers, String value) {
 856  4
         if (value == null) {
 857  0
             return;
 858  
         }
 859  4
         if (value.equals("")) {
 860  0
             return;
 861  
         }
 862  4
         out.print("<" + tag);
 863  4
         if (modifiers != null && !modifiers.isEmpty()) {
 864  0
             out.print(" " + modifiers);
 865  
         }
 866  4
         out.print(">");
 867  4
         out.print(escapeXML(value));
 868  4
         out.print("</" + tag + ">");
 869  4
         out.println("");
 870  4
     }
 871  
 
 872  
     public String escapeXML(String s) {
 873  22
         StringBuffer sb = new StringBuffer();
 874  22
         int n = s.length();
 875  847
         for (int i = 0; i < n; i++) {
 876  
             // http://www.hdfgroup.org/HDF5/XML/xml_escape_chars.htm
 877  825
             char c = s.charAt(i);
 878  825
             switch (c) {
 879  
                 case '"':
 880  10
                     sb.append("&quot;");
 881  10
                     break;
 882  
                 case '\'':
 883  10
                     sb.append("&apos;");
 884  10
                     break;
 885  
                 case '&':
 886  10
                     sb.append("&amp;");
 887  10
                     break;
 888  
                 case '<':
 889  10
                     sb.append("&lt;");
 890  10
                     break;
 891  
                 case '>':
 892  10
                     sb.append("&gt;");
 893  10
                     break;
 894  
                 //case ' ': sb.append("&nbsp;");break;\
 895  
                 default:
 896  775
                     sb.append(c);
 897  
                     break;
 898  
             }
 899  
         }
 900  22
         return sb.toString();
 901  
     }
 902  
 
 903  
     private void writeLink(PrintStream out, String url, String value) {
 904  4
         out.print("<a href=\"" + url + "\">" + value + "</a>");
 905  4
     }
 906  
 }
 907