01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: **/package org.araneaframework.uilib.form.control;
16:
17: import org.apache.commons.lang.StringUtils;
18:
19: /**
20: * This is a simple class that should be inherited by those controls,
21: * which find that blank <code>String</code> in request is same as
22: * <code>null</code>.
23: *
24: * @author Jevgeni Kabanov (ekabanov <i>at</i> araneaframework <i>dot</i> org)
25: * TODO: rename to BlankStringNullableControl in Aranea 2.0
26: */
27: public abstract class EmptyStringNullableControl extends
28: StringRequestControl {
29:
30: //*********************************************************************
31: //* INTERNAL METHODS
32: //*********************************************************************
33:
34: /**
35: * Preprocesses the request parameter, substituting empty or blank String
36: * with null.
37: */
38: protected String preprocessRequestParameter(String parameterValue) {
39: if (StringUtils.isBlank(parameterValue)) {
40: return null;
41: }
42: return parameterValue;
43: }
44:
45: public boolean isRead() {
46: // semantically this is not right, as innerData may be not null when value was not
47: // actually read from current request: ie in cases when update() is not called.
48: return (innerData != null && ((String[]) innerData)[0].trim()
49: .length() != 0);
50: }
51:
52: }
|