001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.edl.components;
018:
019: import java.util.ArrayList;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import org.w3c.dom.Document;
024: import org.w3c.dom.Element;
025:
026: import edu.iu.uis.eden.edl.EDLContext;
027: import edu.iu.uis.eden.edl.EDLModelComponent;
028: import edu.iu.uis.eden.edl.EDLXmlUtils;
029: import edu.iu.uis.eden.edl.RequestParser;
030:
031: /**
032: * Matches request params to fields defined in edl configs. Places matched value on the dom for rendering. Places
033: * currentDefinitionElement definition ( the element used to get the param from the request) element on the
034: * dom for rendering.
035: *
036: * This is the base EDL Config Component for dealing with defined elements in an edl definition. Most
037: * custom edl element behavior can be achieved by subclassing this.
038: *
039: * @author rkirkend
040: *
041: */
042: public class SimpleWorkflowEDLConfigComponent implements
043: EDLModelComponent {
044:
045: protected Element definitionElement;
046: private EDLContext edlContext;
047:
048: public void updateDOM(Document dom,
049: Element currentDefinitionElement, EDLContext edlContext) {
050:
051: RequestParser requestParser = edlContext.getRequestParser();
052: this .edlContext = edlContext;
053:
054: this .definitionElement = currentDefinitionElement;
055: Element configElementForDOM = getReplacementConfigElement(currentDefinitionElement);
056: if (configElementForDOM == null) {
057: configElementForDOM = currentDefinitionElement;
058: }
059:
060: Element edlContentElement = EDLXmlUtils.getEDLContent(dom,
061: false);
062: edlContentElement.appendChild(configElementForDOM);
063:
064: Element currentVersion = VersioningPreprocessor
065: .findCurrentVersion(dom);
066:
067: List matchingParams = getMatchingParams(configElementForDOM,
068: requestParser, edlContext);
069: for (Iterator iter = matchingParams.iterator(); iter.hasNext();) {
070: MatchingParam matchingParam = (MatchingParam) iter.next();
071: EDLXmlUtils.createFieldDataElement(currentVersion,
072: matchingParam);
073: }
074: }
075:
076: public Element getReplacementConfigElement(Element element) {
077: return null;
078: }
079:
080: public List getMatchingParams(Element originalConfigElement,
081: RequestParser requestParser, EDLContext edlContext) {
082: List params = new ArrayList();
083: String paramName = originalConfigElement.getAttribute("name");
084: String[] paramValues = requestParser
085: .getParameterValues(paramName);
086: if (paramValues == null) {
087: return params;
088: }
089: for (int i = 0; i < paramValues.length; i++) {
090: String value = paramValues[i];
091: MatchingParam matchingParam = new MatchingParam();
092: matchingParam.setParamName(paramName);
093: matchingParam.setParamValue(value);
094: String errorMessage = getErrorMessage(
095: originalConfigElement, requestParser, matchingParam);
096: if (errorMessage != null) {
097: matchingParam.setError(Boolean.TRUE);
098: matchingParam.setErrorMessage(errorMessage);
099: edlContext.setInError(true);
100: }
101: params.add(matchingParam);
102: }
103: return params;
104: }
105:
106: public String getErrorMessage(Element originalConfigElement,
107: RequestParser requestParser, MatchingParam matchingParam) {
108: return null;
109: }
110:
111: public Element getDefinitionElement() {
112: return definitionElement;
113: }
114:
115: public void setDefinitionElement(Element definitionElement) {
116: this .definitionElement = definitionElement;
117: }
118:
119: public EDLContext getEdlContext() {
120: return edlContext;
121: }
122:
123: public void setEdlContext(EDLContext edlContext) {
124: this.edlContext = edlContext;
125: }
126: }
|