001/**
002 * Copyright 2005-2013 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.tree;
017
018import org.apache.commons.lang.StringEscapeUtils;
019import org.apache.commons.lang.StringUtils;
020import org.kuali.rice.core.api.util.tree.Node;
021import org.kuali.rice.core.api.util.tree.Tree;
022import org.kuali.rice.krms.api.repository.proposition.PropositionDefinitionContract;
023import org.kuali.rice.krms.dto.PropositionEditor;
024import org.kuali.rice.krms.dto.RuleEditor;
025import org.kuali.rice.krms.tree.node.CompareTreeNode;
026import org.kuali.rice.krms.util.NaturalLanguageHelper;
027
028import java.util.Map;
029
030/**
031 * @author Kuali Student Team
032 */
033public abstract class AbstractTreeBuilder implements TreeBuilder {
034
035    protected String buildNodeLabel(PropositionEditor prop){
036        return this.getDescription(prop);
037    }
038
039    protected String getDescription(PropositionEditor proposition) {
040        if (proposition == null) {
041            return StringUtils.EMPTY;
042        }
043
044        //Get the natural language from the map
045        Map<String, String> nlMap = proposition.getNaturalLanguage();
046        String description = nlMap.get(this.getNaturalLanguageUsageKey());
047        if (description==null){
048            return StringUtils.EMPTY;
049        }
050
051        return description;
052    }
053
054    protected String getPropositionPrefix(PropositionEditor prop){
055        return "<b>" + prop.getKey() + ".</b> ";
056    }
057
058    public abstract String getNaturalLanguageUsageKey();
059
060    protected void addNodeType(Node node, String type){
061        if ((node.getNodeType()==null)||(node.getNodeType().length()==0)){
062            node.setNodeType(type);
063        } else {
064            node.setNodeType(node.getNodeType() + " " + type);
065        }
066    }
067
068}