01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.faces.taglib;
18:
19: import org.xml.sax.Attributes;
20: import org.xml.sax.SAXException;
21:
22: import javax.faces.validator.Validator;
23: import javax.faces.validator.LengthValidator;
24:
25: import org.apache.cocoon.faces.FacesUtils;
26:
27: /**
28: * @version CVS $Id: ValidateLengthTag.java 433543 2006-08-22 06:22:54Z crossley $
29: */
30: public class ValidateLengthTag extends ValidatorTag {
31:
32: private String minimum;
33: private String maximum;
34:
35: public void setMaximum(String maximum) {
36: this .maximum = maximum;
37: }
38:
39: public void setMinimum(String minimum) {
40: this .minimum = minimum;
41: }
42:
43: public int doStartTag(String namespaceURI, String localName,
44: String qName, Attributes atts) throws SAXException {
45: super .setValidatorId("javax.faces.Length");
46: return super .doStartTag(namespaceURI, localName, qName, atts);
47: }
48:
49: protected Validator createValidator() {
50: final UIComponentTag tag = FacesUtils
51: .findParentUIComponentTag(this );
52: LengthValidator validator = (LengthValidator) super
53: .createValidator();
54:
55: if (maximum != null) {
56: validator.setMaximum(tag.evaluateInteger(maximum));
57: }
58: if (minimum != null) {
59: validator.setMinimum(tag.evaluateInteger(minimum));
60: }
61:
62: return validator;
63: }
64:
65: public void recycle() {
66: super.recycle();
67: this.minimum = null;
68: this.maximum = null;
69: }
70: }
|