View Javadoc

1   /**
2    * Copyright 2005-2013 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.tree;
17  
18  import org.apache.commons.lang.StringEscapeUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.core.api.util.tree.Node;
21  import org.kuali.rice.core.api.util.tree.Tree;
22  import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract;
23  import org.kuali.rice.krms.dto.PropositionEditor;
24  import org.kuali.rice.krms.dto.RuleEditor;
25  import org.kuali.rice.krms.tree.node.CompareTreeNode;
26  import org.kuali.rice.krms.util.NaturalLanguageHelper;
27  
28  import java.util.Map;
29  
30  /**
31   * @author Kuali Student Team
32   */
33  public abstract class AbstractTreeBuilder implements TreeBuilder {
34  
35      protected String buildNodeLabel(PropositionEditor prop){
36          return this.getDescription(prop);
37      }
38  
39      protected String getDescription(PropositionEditor proposition) {
40          if (proposition == null) {
41              return StringUtils.EMPTY;
42          }
43  
44          //Get the natural language from the map
45          Map<String, String> nlMap = proposition.getNaturalLanguage();
46          String description = nlMap.get(this.getNaturalLanguageUsageKey());
47          if (description==null){
48              return StringUtils.EMPTY;
49          }
50  
51          return description;
52      }
53  
54      protected String getPropositionPrefix(PropositionEditor prop){
55          return "<b>" + prop.getKey() + ".</b> ";
56      }
57  
58      public abstract String getNaturalLanguageUsageKey();
59  
60      protected void addNodeType(Node node, String type){
61          if ((node.getNodeType()==null)||(node.getNodeType().length()==0)){
62              node.setNodeType(type);
63          } else {
64              node.setNodeType(node.getNodeType() + " " + type);
65          }
66      }
67  
68  }