001    /*
002     * Copyright 1999-2004 The Apache Software Foundation.
003     * Modifications, Copyright 2005 Stephen Colebourne
004     * 
005     * Licensed under the Apache License, Version 2.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.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    package org.joda.time.contrib.jsptag;
018    
019    import java.util.Locale;
020    
021    import javax.servlet.jsp.JspTagException;
022    
023    import org.joda.time.DateTimeZone;
024    
025    /**
026     * <p>
027     * A handler for &lt;parseDate&gt; that supports rtexprvalue-based attributes.
028     * </p>
029     * 
030     * @author Jan Luehe
031     * @author Jim Newsham
032     */
033    
034    public class ParseDateTimeTag extends ParseDateTimeSupport {
035    
036        /**
037         * Sets the value attribute.
038         * 
039         * @param value  the value
040         */
041        public void setValue(String value) throws JspTagException {
042            this.value = value;
043            this.valueSpecified = true;
044        }
045    
046        /**
047         * Sets the style attribute.
048         * 
049         * @param style  the style
050         */
051        public void setStyle(String style) throws JspTagException {
052            this.style = style;
053        }
054    
055        /**
056         * Sets the pattern attribute.
057         * 
058         * @param pattern  the pattern
059         */
060        public void setPattern(String pattern) throws JspTagException {
061            this.pattern = pattern;
062        }
063    
064        /**
065         * Sets the zone attribute.
066         * 
067         * @param dtz  the zone
068         */
069        public void setDateTimeZone(Object dtz) throws JspTagException {
070            if (dtz == null || dtz instanceof String
071                    && ((String) dtz).length() == 0) {
072                this.dateTimeZone = null;
073            } else if (dtz instanceof DateTimeZone) {
074                this.dateTimeZone = (DateTimeZone) dtz;
075            } else {
076                try {
077                    this.dateTimeZone = DateTimeZone.forID((String) dtz);
078                } catch (IllegalArgumentException iae) {
079                    this.dateTimeZone = DateTimeZone.UTC;
080                }
081            }
082        }
083    
084        /**
085         * Sets the style attribute.
086         * 
087         * @param loc  the locale
088         */
089        public void setLocale(Object loc) throws JspTagException {
090            if (loc == null
091                    || (loc instanceof String && ((String) loc).length() == 0)) {
092                this.locale = null;
093            } else if (loc instanceof Locale) {
094                this.locale = (Locale) loc;
095            } else {
096                locale = Util.parseLocale((String) loc);
097            }
098        }
099    
100    }