001 /** 002 * Copyright 2005-2012 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 */ 016 package org.kuali.rice.krad.workflow.attribute; 017 018 import org.kuali.rice.kew.api.extension.ExtensionDefinition; 019 import org.w3c.dom.Element; 020 021 /** 022 * This is an XML KEW search attribute that can be used where the XML of the attribute has an xpath expression that returns a 023 * boolean. This attribute takes that boolean expression and translates it into true and false values based on the 024 * {@link #getValueForXPathTrueEvaluation()} and {@link #getValueForXPathFalseEvaluation()} method's return variables. 025 * 026 * NOTE: This will not longer be necessary if the version of xPath being used is every upgrade to 2.x or higher 027 */ 028 public class KualiXMLBooleanTranslatorSearchableAttributeImpl extends KualiXmlSearchableAttributeImpl { 029 private static final long serialVersionUID = -4627314389844574461L; 030 031 public static final String VALUE_FOR_TRUE = "Yes"; 032 public static final String VALUE_FOR_FALSE = "No"; 033 034 035 036 /** 037 * This overriden method does the translation of the given xPath expression from the XML definition of the attribute and 038 * translates it into the true and false values based on the {@link #getValueForXPathTrueEvaluation()} and 039 * {@link #getValueForXPathFalseEvaluation()} method's return variables 040 */ 041 @Override 042 public Element getConfigXML(ExtensionDefinition extensionDefinition) { 043 String[] xpathElementsToInsert = new String[3]; 044 xpathElementsToInsert[0] = "concat( substring('" + getValueForXPathTrueEvaluation() + "', number(not("; 045 xpathElementsToInsert[1] = "))*string-length('" + getValueForXPathTrueEvaluation() + "')+1), substring('" + getValueForXPathFalseEvaluation() + "', number("; 046 xpathElementsToInsert[2] = ")*string-length('" + getValueForXPathFalseEvaluation() + "')+1))"; 047 Element root = super.getConfigXML(extensionDefinition); 048 return new KualiXmlAttributeHelper().processConfigXML(root, xpathElementsToInsert); 049 } 050 051 public String getValueForXPathTrueEvaluation() { 052 return VALUE_FOR_TRUE; 053 } 054 055 public String getValueForXPathFalseEvaluation() { 056 return VALUE_FOR_FALSE; 057 } 058 059 }