001 /*
002 * Copyright 2009 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.osedu.org/licenses/ECL-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.student.contract.writer.search;
017
018 import org.kuali.student.contract.model.SearchResult;
019 import org.kuali.student.contract.model.SearchResultColumn;
020 import org.kuali.student.contract.writer.XmlWriter;
021
022 import java.io.PrintStream;
023
024 /**
025 * Writes out a constraint in XML format.
026 * @author nwright
027 */
028 public class SearchResultWriter extends XmlWriter {
029
030 private SearchResult searchResult;
031
032 public SearchResultWriter(PrintStream out, int indent,
033 SearchResult searchResult) {
034 super(out, indent);
035 this.searchResult = searchResult;
036 }
037
038 public void write() {
039
040 println("");
041 indentPrint("<search:searchResultTypeInfo");
042 //TODO: not sure what to put in the key attribute
043 writeAttribute("id", searchResult.getKey());
044 println(">");
045 incrementIndent();
046 // write out comments
047 writeComment(searchResult.getComments());
048
049 writeTag("search:name", searchResult.getName());
050 writeTag("search:desc", searchResult.getDescription());
051 indentPrintln("<search:resultColumns>");
052 incrementIndent();
053 for (SearchResultColumn col : searchResult.getResultColumns()) {
054 indentPrintln(calcRefBean(col.getKey()));
055 }
056 decrementIndent();
057 indentPrintln("</search:resultColumns>");
058 indentPrintln("</search:searchResultTypeInfo>");
059 decrementIndent();
060 }
061
062 private String calcRefBean(String id) {
063 return "<ref bean=\"" + id + "\" />";
064 }
065 }