KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > beehive > netui > pageflow > config > PageFlowControllerConfig


1 /*
2  * Copyright 2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * $Header:$
17  */

18 package org.apache.beehive.netui.pageflow.config;
19
20 import org.apache.struts.config.ControllerConfig;
21 import org.apache.struts.upload.CommonsMultipartRequestHandler;
22 import org.apache.struts.upload.DiskMultipartRequestHandler;
23 import org.apache.beehive.netui.util.config.bean.PageflowConfig;
24 import org.apache.beehive.netui.pageflow.internal.InternalUtils;
25
26 import java.util.LinkedHashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * Bean class to handle our extensions to the Struts <controller> element.
31  */

32 public class PageFlowControllerConfig extends ControllerConfig
33 {
34     private static final String JavaDoc MEMORY_MULTIPART_HANDLER_CLASS = CommonsMultipartRequestHandler.class.getName();
35     private static final String JavaDoc DISK_MULTIPART_HANDLER_CLASS = DiskMultipartRequestHandler.class.getName();
36     
37     private boolean _isNestedPageFlow;
38     private boolean _isLongLivedPageFlow;
39     private boolean _isReturnToPageDisabled;
40     private boolean _isReturnToActionDisabled;
41     private boolean _isMissingDefaultMessages;
42     private LinkedHashMap JavaDoc/*< String, String >*/ _sharedFlowTypes;
43     private String JavaDoc _controllerClass;
44     private boolean _isSharedFlow;
45     private String JavaDoc _overrideMultipartClass = null;
46     private boolean _forceMultipartDisabled = false;
47
48     
49     public boolean isNestedPageFlow()
50     {
51         return _isNestedPageFlow;
52     }
53
54     public void setIsNestedPageFlow( boolean nestedPageFlow )
55     {
56         _isNestedPageFlow = nestedPageFlow;
57     }
58
59     public boolean isLongLivedPageFlow()
60     {
61         return _isLongLivedPageFlow;
62     }
63
64     public void setIsLongLivedPageFlow( boolean longLivedPageFlow )
65     {
66         _isLongLivedPageFlow = longLivedPageFlow;
67     }
68
69     public boolean isReturnToPageDisabled()
70     {
71         return _isReturnToPageDisabled;
72     }
73
74     public void setIsReturnToPageDisabled( boolean returnToPageDisabled )
75     {
76         _isReturnToPageDisabled = returnToPageDisabled;
77     }
78
79     public boolean isReturnToActionDisabled()
80     {
81         return _isReturnToActionDisabled;
82     }
83
84     public void setIsReturnToActionDisabled( boolean returnToActionDisabled )
85     {
86         _isReturnToActionDisabled = returnToActionDisabled;
87     }
88
89     public boolean isMissingDefaultMessages()
90     {
91         return _isMissingDefaultMessages;
92     }
93
94     public void setIsMissingDefaultMessages( boolean missingDefaultMessages )
95     {
96         _isMissingDefaultMessages = missingDefaultMessages;
97     }
98
99     public void setSharedFlows( String JavaDoc sharedFlows )
100     {
101         if ( sharedFlows == null || sharedFlows.length() == 0 )
102         {
103             _sharedFlowTypes = null;
104             return;
105         }
106         
107         String JavaDoc[] keyValues = sharedFlows.split( "," );
108         _sharedFlowTypes = new LinkedHashMap JavaDoc/*< String, String >*/();
109         
110         for ( int i = 0; i < keyValues.length; i++ )
111         {
112             String JavaDoc keyValue = keyValues[i];
113             int delim = keyValue.indexOf( '=' );
114             assert delim != -1 : "no delimiter in " + keyValue;
115             assert delim < keyValue.length() - 1 : "missing value in " + keyValue;
116             _sharedFlowTypes.put( keyValue.substring( 0, delim ), keyValue.substring( delim + 1 ) );
117         }
118     }
119     
120     public String JavaDoc getSharedFlows()
121     {
122         throw new UnsupportedOperationException JavaDoc( "not implemented; uses getSharedFlowTypes" );
123     }
124     
125     public Map JavaDoc/*< String, String >*/ getSharedFlowTypes()
126     {
127         return _sharedFlowTypes;
128     }
129
130     public String JavaDoc getControllerClass()
131     {
132         return _controllerClass;
133     }
134
135     public void setControllerClass( String JavaDoc controllerClass )
136     {
137         _controllerClass = controllerClass;
138     }
139
140     public boolean isSharedFlow()
141     {
142         return _isSharedFlow;
143     }
144
145     public void setIsSharedFlow( boolean sharedFlow )
146     {
147         _isSharedFlow = sharedFlow;
148     }
149
150     public String JavaDoc getMultipartClass()
151     {
152         if ( _forceMultipartDisabled ) return null;
153         if ( _overrideMultipartClass != null ) return _overrideMultipartClass;
154         
155         PageflowConfig.MultipartHandler.Enum mpHandler = InternalUtils.getMultipartHandlerType();
156         
157         if ( mpHandler != null )
158         {
159             switch ( mpHandler.intValue() )
160             {
161                 case PageflowConfig.MultipartHandler.INT_DISABLED: return null;
162                 case PageflowConfig.MultipartHandler.INT_MEMORY: return MEMORY_MULTIPART_HANDLER_CLASS;
163                 case PageflowConfig.MultipartHandler.INT_DISK: return DISK_MULTIPART_HANDLER_CLASS;
164                 default: assert false : "unknown value for multipart handler: " + mpHandler.toString();
165             }
166         }
167         
168         return null;
169     }
170
171     /**
172      * Get the directory for DiskMultipartRequestHandler temporary files.
173      * @return directory string
174      */

175     public String JavaDoc getTempDir()
176     {
177         // TODO: In the Struts 1.1 version of DiskMultipartRequestHandler, there is an NPE on line 295
178
// (in retrieveTempDir). When this is fixed, we can remove our override of getTempDir().
179
return tempDir != null ? tempDir : System.getProperty( "java.io.tmpdir" );
180     }
181
182     public void setMultipartClass( String JavaDoc overrideMultipartClass )
183     {
184         if ( overrideMultipartClass.equals( "none" ) )
185         {
186             _forceMultipartDisabled = true;
187         }
188         else
189         {
190             _overrideMultipartClass = overrideMultipartClass;
191         }
192     }
193 }
194
Popular Tags