001    /**
002     * Copyright 2005-2011 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.kew.rule;
017    
018    import org.jdom.Document;
019    import org.jdom.Element;
020    import org.kuali.rice.core.api.util.xml.XmlHelper;
021    import org.kuali.rice.kew.routeheader.DocumentContent;
022    
023    import java.io.StringReader;
024    import java.util.ArrayList;
025    import java.util.Collection;
026    import java.util.List;
027    import java.util.Map;
028    
029    
030    /**
031     * @author Kuali Rice Team (rice.collab@kuali.org)
032     */
033    public class MockWorkflowAttribute implements WorkflowRuleAttribute {
034        
035        private static final String MOCK_VALUE_ELEMENT = "mockValue";
036        //private static final String VALUE_KEY = "value";
037        
038        private String value;
039        
040        public MockWorkflowAttribute() {}
041        
042        public MockWorkflowAttribute(String value) {
043            setValue(value);
044        }
045    
046        public String getDocContent() {
047            if (value == null) return "";
048            return "<"+MOCK_VALUE_ELEMENT+">"+value+"</"+MOCK_VALUE_ELEMENT+">";
049        }
050        
051        public List parseDocContent(String docContent) {
052            try {
053                Document doc = XmlHelper.buildJDocument(new StringReader(docContent));
054                Collection<Element> elements = XmlHelper.findElements(doc.getRootElement(), MOCK_VALUE_ELEMENT);
055                Element mockValueElement = elements.iterator().next();
056                List attributes = new ArrayList();
057                if (mockValueElement != null) {
058                    attributes.add(new MockWorkflowAttribute(mockValueElement.getText()));
059                }
060                return attributes;
061            } catch (Exception e) {
062                throw new RuntimeException(e);
063            }
064        }
065        
066        public String getIdFieldName() {
067            return null;
068        }
069        public String getLockFieldName() {
070            return null;
071        }
072        public List getRoutingDataRows() {
073            return null;
074        }
075        public List getRuleExtensionValues() {
076            return null;
077        }
078        public List getRuleRows() {
079            return null;
080        }
081        public boolean isMatch(DocumentContent docContent, List ruleExtensions) {
082            return false;
083        }
084        public boolean isRequired() {
085            return false;
086        }
087        
088        public void setRequired(boolean required) {
089        }
090        public List validateRoutingData(Map paramMap) {
091            return null;
092        }
093        public List validateRuleData(Map paramMap) {
094            return null;
095        }
096        
097        public String getValue() {
098            return value;
099        }
100        
101        public void setValue(String value) {
102            this.value = value;
103        }
104        
105        
106    }