View Javadoc

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.search;
17  
18  import org.kuali.student.contract.model.SearchCriteria;
19  import org.kuali.student.contract.model.SearchCriteriaParameter;
20  import org.kuali.student.contract.writer.XmlWriter;
21  
22  import java.io.PrintStream;
23  
24  /**
25   * Writes out a constraint in XML format.
26   * @author nwright
27   */
28  public class SearchCriteriaWriter extends XmlWriter {
29  
30      private SearchCriteria searchCriteria;
31  
32      public SearchCriteriaWriter(PrintStream out, int indent,
33              SearchCriteria searchCriteria) {
34          super(out, indent);
35          this.searchCriteria = searchCriteria;
36      }
37  
38      public void write() {
39  
40          println("");
41          indentPrint("<search:searchCriteriaTypeInfo");
42          //TODO: not sure what to put in the key attribute
43          writeAttribute("id", searchCriteria.getKey());
44          println(">");
45          incrementIndent();
46  
47          // write out comments
48          writeComment(searchCriteria.getComments());
49  
50          writeTag("search:name", searchCriteria.getName());
51          writeTag("search:desc", searchCriteria.getDescription());
52          indentPrintln("<search:queryParams>");
53          incrementIndent();
54          for (SearchCriteriaParameter col : searchCriteria.getParameters()) {
55              indentPrintln(calcRefBean(col.getKey()));
56          }
57          decrementIndent();
58          indentPrintln("</search:queryParams>");
59          // end
60          indentPrintln("</search:searchCriteriaTypeInfo>");
61          decrementIndent();
62      }
63  
64      private String calcRefBean(String id) {
65          return "<ref bean=\"" + id + "\" />";
66      }
67  }