View Javadoc

1   /**
2    * Copyright 2005-2014 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.opensource.org/licenses/ecl2.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.rice.krms.impl.repository.language;
17  
18  import java.util.Map;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplate;
22  import org.kuali.rice.krms.api.repository.language.NaturalLanguageTemplaterContract;
23  
24  /**
25   * A dead simple implementation of the templater contract for testing
26   * @author nwright
27   */
28  public class SimpleNaturalLanguageTemplater implements NaturalLanguageTemplaterContract {
29  
30      @Override
31      public String translate(NaturalLanguageTemplate naturalLanguageTemplate, Map<String, Object> contextMap) {
32          String template = naturalLanguageTemplate != null ? naturalLanguageTemplate.getTemplate() : "Empty Template";
33  
34          StringBuilder sb = new StringBuilder(template);
35          sb.append(" applied with the following ");
36          sb.append (contextMap.size());        
37          sb.append(" variables: ");
38          String comma = "";
39          for (String key : contextMap.keySet()) {
40              sb.append (comma);
41              comma = ",";
42              sb.append ("[");
43              sb.append (key);
44              sb.append ("=");
45              sb.append (contextMap.get(key));
46              sb.append ("]");
47          }
48          return sb.toString();
49      }
50       
51  }