001/**
002 * Copyright 2005-2016 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 */
016package org.kuali.rice.krms.impl.repository.language;
017
018import java.util.Map;
019
020import org.apache.commons.lang.StringUtils;
021import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate;
022import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplaterContract;
023
024/**
025 * A dead simple implementation of the templater contract for testing
026 * @author nwright
027 */
028public class SimpleNaturalLanguageTemplater implements NaturalLanguageTemplaterContract {
029
030    @Override
031    public String translate(NaturalLanguageTemplate naturalLanguageTemplate, Map<String, Object> contextMap) {
032        String template = naturalLanguageTemplate != null ? naturalLanguageTemplate.getTemplate() : "Empty Template";
033
034        StringBuilder sb = new StringBuilder(template);
035        sb.append(" applied with the following ");
036        sb.append (contextMap.size());        
037        sb.append(" variables: ");
038        String comma = "";
039        for (String key : contextMap.keySet()) {
040            sb.append (comma);
041            comma = ",";
042            sb.append ("[");
043            sb.append (key);
044            sb.append ("=");
045            sb.append (contextMap.get(key));
046            sb.append ("]");
047        }
048        return sb.toString();
049    }
050     
051}