001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
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: * $Header:$
018: */
019: package org.apache.beehive.netui.pageflow.config;
020:
021: import org.apache.struts.config.ControllerConfig;
022: import org.apache.struts.upload.CommonsMultipartRequestHandler;
023: import org.apache.beehive.netui.pageflow.internal.InternalUtils;
024: import org.apache.beehive.netui.util.config.bean.MultipartHandler;
025:
026: import java.util.LinkedHashMap;
027: import java.util.Map;
028:
029: /**
030: * Bean class to handle our extensions to the Struts <controller> element.
031: */
032: public class PageFlowControllerConfig extends ControllerConfig {
033: private static final String COMMONS_MULTIPART_HANDLER_CLASS = CommonsMultipartRequestHandler.class
034: .getName();
035:
036: private boolean _isNestedPageFlow;
037: private boolean _isLongLivedPageFlow;
038: private boolean _isReturnToPageDisabled;
039: private boolean _isReturnToActionDisabled;
040: private boolean _isMissingDefaultMessages;
041: private LinkedHashMap/*< String, String >*/_sharedFlowTypes;
042: private String _controllerClass;
043: private boolean _isSharedFlow;
044: private boolean _isAbstract = false;
045: private String _overrideMultipartClass = null;
046: private String _overrideMemFileSize = null;
047: private boolean _forceMultipartDisabled = false;
048:
049: public boolean isNestedPageFlow() {
050: return _isNestedPageFlow;
051: }
052:
053: public void setIsNestedPageFlow(boolean nestedPageFlow) {
054: _isNestedPageFlow = nestedPageFlow;
055: }
056:
057: public boolean isLongLivedPageFlow() {
058: return _isLongLivedPageFlow;
059: }
060:
061: public void setIsLongLivedPageFlow(boolean longLivedPageFlow) {
062: _isLongLivedPageFlow = longLivedPageFlow;
063: }
064:
065: public boolean isReturnToPageDisabled() {
066: return _isReturnToPageDisabled;
067: }
068:
069: public void setIsReturnToPageDisabled(boolean returnToPageDisabled) {
070: _isReturnToPageDisabled = returnToPageDisabled;
071: }
072:
073: public boolean isReturnToActionDisabled() {
074: return _isReturnToActionDisabled;
075: }
076:
077: public void setIsReturnToActionDisabled(
078: boolean returnToActionDisabled) {
079: _isReturnToActionDisabled = returnToActionDisabled;
080: }
081:
082: public boolean isMissingDefaultMessages() {
083: return _isMissingDefaultMessages;
084: }
085:
086: public void setIsMissingDefaultMessages(
087: boolean missingDefaultMessages) {
088: _isMissingDefaultMessages = missingDefaultMessages;
089: }
090:
091: public void setSharedFlows(String sharedFlows) {
092: if (sharedFlows == null || sharedFlows.length() == 0) {
093: _sharedFlowTypes = null;
094: return;
095: }
096:
097: String[] keyValues = sharedFlows.split(",");
098: _sharedFlowTypes = new LinkedHashMap/*< String, String >*/();
099:
100: for (int i = 0; i < keyValues.length; i++) {
101: String keyValue = keyValues[i];
102: int delim = keyValue.indexOf('=');
103: assert delim != -1 : "no delimiter in " + keyValue;
104: assert delim < keyValue.length() - 1 : "missing value in "
105: + keyValue;
106: _sharedFlowTypes.put(keyValue.substring(0, delim), keyValue
107: .substring(delim + 1));
108: }
109: }
110:
111: public String getSharedFlows() {
112: throw new UnsupportedOperationException(
113: "not implemented; uses getSharedFlowTypes");
114: }
115:
116: public Map/*< String, String >*/getSharedFlowTypes() {
117: return _sharedFlowTypes;
118: }
119:
120: public String getControllerClass() {
121: return _controllerClass;
122: }
123:
124: public void setControllerClass(String controllerClass) {
125: _controllerClass = controllerClass;
126: }
127:
128: public boolean isSharedFlow() {
129: return _isSharedFlow;
130: }
131:
132: public void setIsSharedFlow(boolean sharedFlow) {
133: _isSharedFlow = sharedFlow;
134: }
135:
136: /**
137: * This gets the multipart class. If it was explicitly set on the associated <controller> element, just use that;
138: * otherwise, get the value from WEB-INF/beehive-netui-config.xml.
139: */
140: public String getMultipartClass() {
141: if (_forceMultipartDisabled)
142: return null;
143: if (_overrideMultipartClass != null)
144: return _overrideMultipartClass;
145:
146: MultipartHandler mpHandler = InternalUtils
147: .getMultipartHandlerType();
148:
149: if (mpHandler != null) {
150: switch (mpHandler.getValue()) {
151: case MultipartHandler.INT_DISABLED:
152: return null;
153: case MultipartHandler.INT_MEMORY:
154: return COMMONS_MULTIPART_HANDLER_CLASS;
155: case MultipartHandler.INT_DISK:
156: return COMMONS_MULTIPART_HANDLER_CLASS;
157: default:
158: assert false : "unknown value for multipart handler: "
159: + mpHandler.toString();
160: }
161: }
162:
163: return null;
164: }
165:
166: public String getMemFileSize() {
167: if (_overrideMemFileSize != null)
168: return _overrideMemFileSize;
169:
170: MultipartHandler mpHandler = InternalUtils
171: .getMultipartHandlerType();
172:
173: if (mpHandler != null) {
174: switch (mpHandler.getValue()) {
175: case MultipartHandler.INT_DISABLED:
176: return super .getMemFileSize();
177: case MultipartHandler.INT_MEMORY:
178: return super .getMemFileSize();
179: case MultipartHandler.INT_DISK:
180: return "0K"; // memory filesize threshold of zero.
181: default:
182: assert false : "unknown value for multipart handler: "
183: + mpHandler.toString();
184: }
185: }
186:
187: return super .getMemFileSize();
188: }
189:
190: public void setMultipartClass(String overrideMultipartClass) {
191: if (overrideMultipartClass.equals("none")) {
192: _forceMultipartDisabled = true;
193: } else {
194: _overrideMultipartClass = overrideMultipartClass;
195: }
196: }
197:
198: public void setMemFileSize(String fileSize) {
199: _overrideMemFileSize = fileSize;
200: }
201:
202: public boolean isAbstract() {
203: return _isAbstract;
204: }
205:
206: public void setIsAbstract(boolean isAbstract) {
207: _isAbstract = isAbstract;
208: }
209: }
|