001    /**
002     * Copyright 2004-2014 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.opensource.org/licenses/ecl2.php
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.SearchCriteria;
019    import org.kuali.student.contract.model.SearchCriteriaParameter;
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 SearchCriteriaWriter extends XmlWriter {
029    
030        private SearchCriteria searchCriteria;
031    
032        public SearchCriteriaWriter(PrintStream out, int indent,
033                SearchCriteria searchCriteria) {
034            super(out, indent);
035            this.searchCriteria = searchCriteria;
036        }
037    
038        public void write() {
039    
040            println("");
041            indentPrint("<search:searchCriteriaTypeInfo");
042            //TODO: not sure what to put in the key attribute
043            writeAttribute("id", searchCriteria.getKey());
044            println(">");
045            incrementIndent();
046    
047            // write out comments
048            writeComment(searchCriteria.getComments());
049    
050            writeTag("search:name", searchCriteria.getName());
051            writeTag("search:desc", searchCriteria.getDescription());
052            indentPrintln("<search:queryParams>");
053            incrementIndent();
054            for (SearchCriteriaParameter col : searchCriteria.getParameters()) {
055                indentPrintln(calcRefBean(col.getKey()));
056            }
057            decrementIndent();
058            indentPrintln("</search:queryParams>");
059            // end
060            indentPrintln("</search:searchCriteriaTypeInfo>");
061            decrementIndent();
062        }
063    
064        private String calcRefBean(String id) {
065            return "<ref bean=\"" + id + "\" />";
066        }
067    }