001 /* 002 * Copyright 2007-2008 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 edu.sampleu.travel.workflow; 017 018 import java.util.ArrayList; 019 import java.util.HashMap; 020 import java.util.List; 021 import java.util.Map; 022 023 import org.kuali.rice.kew.rule.GenericWorkflowAttribute; 024 import org.kuali.rice.kew.rule.WorkflowAttributeValidationError; 025 import org.kuali.rice.kns.web.ui.Field; 026 import org.kuali.rice.kns.web.ui.Row; 027 028 public class DestinationRuleAttribute extends GenericWorkflowAttribute { 029 030 private static final String DEST_LABEL = "Destination"; 031 private static final String DEST_FIELD_KEY = "destination"; 032 033 private final List<Row> rows = new ArrayList<Row>(); 034 035 private String destination; 036 037 public DestinationRuleAttribute() { 038 super("destination"); 039 } 040 041 public DestinationRuleAttribute(String destination) { 042 super("destination"); 043 this.destination = destination; 044 } 045 046 /* 047 public boolean isMatch(DocumentContent docContent, List<RuleExtension> ruleExtensions) { 048 try { 049 boolean foundDestRule = false; 050 for (Iterator extensionsIterator = ruleExtensions.iterator(); extensionsIterator.hasNext();) { 051 RuleExtension extension = (RuleExtension) extensionsIterator.next(); 052 if (extension.getRuleTemplateAttribute().getRuleAttribute().getClassName().equals(getClass().getName())) { 053 for (Iterator valuesIterator = extension.getExtensionValues().iterator(); valuesIterator.hasNext();) { 054 RuleExtensionValue extensionValue = (RuleExtensionValue) valuesIterator.next(); 055 String key = extensionValue.getKey(); 056 String value = extensionValue.getValue(); 057 if (key.equals(DEST_FIELD_KEY)) { 058 destination = value; 059 foundDestRule = true; 060 } 061 } 062 } 063 } 064 if (! foundDestRule) { 065 return false; 066 } 067 068 Element element = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( 069 new InputSource(new BufferedReader(new StringReader(docContent.getDocContent())))).getDocumentElement(); 070 XPath xpath = XPathFactory.newInstance().newXPath(); 071 String docContentDest = xpath.evaluate("//destination", element); 072 return destination.equals(docContentDest); 073 } catch (Exception e) { 074 throw new RuntimeException(e); 075 } 076 }*/ 077 078 public List<Row> getRuleRows() { 079 return getRows(); 080 } 081 082 public List<Row> getRoutingDataRows() { 083 return getRows(); 084 } 085 086 private List<Row> getRows() { 087 log.info("Returning rows: " + rows); 088 List<Field> fields = new ArrayList<Field>(); 089 fields.add(new Field(DEST_LABEL, "", Field.TEXT, false, DEST_FIELD_KEY, "", false, false, null, null)); 090 List<Row> rows = new ArrayList<Row>(); 091 rows.add(new Row(fields)); 092 return rows; 093 } 094 095 /* setter for edoclite field */ 096 public void setDestination(String destination) { 097 this.destination = destination; 098 } 099 100 public Map<String, String> getProperties() { 101 Map<String, String> props = new HashMap<String, String>(); 102 props.put("destination", destination); 103 return props; 104 } 105 106 public List validateRoutingData(Map paramMap) { 107 return validateInputMap(paramMap); 108 } 109 110 public List validateRuleData(Map paramMap) { 111 return validateInputMap(paramMap); 112 } 113 114 private List validateInputMap(Map paramMap) { 115 List errors = new ArrayList(); 116 this.destination = (String) paramMap.get(DEST_FIELD_KEY); 117 if (this.destination == null && required) { 118 errors.add(new WorkflowAttributeValidationError(DEST_FIELD_KEY, "Destination is required.")); 119 } 120 return errors; 121 } 122 }