1 /* 2 * Copyright 2007-2008 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.kns.workflow.attribute; 17 18 import org.w3c.dom.Element; 19 20 /** 21 * This is an XML KEW search attribute that can be used where the XML of the attribute has an xpath expression that returns a 22 * boolean. This attribute takes that boolean expression and translates it into true and false values based on the 23 * {@link #getValueForXPathTrueEvaluation()} and {@link #getValueForXPathFalseEvaluation()} method's return variables. 24 * 25 * NOTE: This will not longer be necessary if the version of xPath being used is every upgrade to 2.x or higher 26 */ 27 public class KualiXMLBooleanTranslatorSearchableAttributeImpl extends KualiXmlSearchableAttributeImpl { 28 private static final long serialVersionUID = -4627314389844574461L; 29 30 public static final String VALUE_FOR_TRUE = "Yes"; 31 public static final String VALUE_FOR_FALSE = "No"; 32 33 /** 34 * This overriden method does the translation of the given xPath expression from the XML definition of the attribute and 35 * translates it into the true and false values based on the {@link #getValueForXPathTrueEvaluation()} and 36 * {@link #getValueForXPathFalseEvaluation()} method's return variables 37 * 38 * @see org.kuali.rice.kns.workflow.attribute.KualiXmlSearchableAttributeImpl#getConfigXML() 39 */ 40 @Override 41 public Element getConfigXML() { 42 String[] xpathElementsToInsert = new String[3]; 43 xpathElementsToInsert[0] = "concat( substring('" + getValueForXPathTrueEvaluation() + "', number(not("; 44 xpathElementsToInsert[1] = "))*string-length('" + getValueForXPathTrueEvaluation() + "')+1), substring('" + getValueForXPathFalseEvaluation() + "', number("; 45 xpathElementsToInsert[2] = ")*string-length('" + getValueForXPathFalseEvaluation() + "')+1))"; 46 Element root = super.getAttributeConfigXML(); 47 return new KualiXmlAttributeHelper().processConfigXML(root, xpathElementsToInsert); 48 } 49 50 public String getValueForXPathTrueEvaluation() { 51 return VALUE_FOR_TRUE; 52 } 53 54 public String getValueForXPathFalseEvaluation() { 55 return VALUE_FOR_FALSE; 56 } 57 58 }