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 <format> that supports rtexprvalue-based attributes.
028 * </p>
029 *
030 * @author Jan Luehe
031 * @author Jim Newsham
032 */
033 public class FormatTag extends FormatSupport {
034
035 /**
036 * Sets the value attribute.
037 *
038 * @param value the value
039 */
040 public void setValue(Object value) throws JspTagException {
041 this.value = value;
042 }
043
044 /**
045 * Sets the style attribute.
046 *
047 * @param style the style
048 */
049 public void setStyle(String style) throws JspTagException {
050 this.style = style;
051 }
052
053 /**
054 * Sets the pattern attribute.
055 *
056 * @param pattern the pattern
057 */
058 public void setPattern(String pattern) throws JspTagException {
059 this.pattern = pattern;
060 }
061
062 /**
063 * Sets the zone attribute.
064 *
065 * @param dtz the zone
066 */
067 public void setDateTimeZone(Object dtz) throws JspTagException {
068 if (dtz == null || dtz instanceof String
069 && ((String) dtz).length() == 0) {
070 this.dateTimeZone = null;
071 } else if (dtz instanceof DateTimeZone) {
072 this.dateTimeZone = (DateTimeZone) dtz;
073 } else {
074 try {
075 this.dateTimeZone = DateTimeZone.forID((String) dtz);
076 } catch (IllegalArgumentException iae) {
077 this.dateTimeZone = DateTimeZone.UTC;
078 }
079 }
080 }
081
082 /**
083 * Sets the style attribute.
084 *
085 * @param loc the locale
086 */
087 public void setLocale(Object loc) throws JspTagException {
088 if (loc == null
089 || (loc instanceof String && ((String) loc).length() == 0)) {
090 this.locale = null;
091 } else if (loc instanceof Locale) {
092 this.locale = (Locale) loc;
093 } else {
094 this.locale = Util.parseLocale((String) loc);
095 }
096 }
097
098 }