View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
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,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.cubby.action.impl;
17  
18  import java.text.DateFormat;
19  import java.text.SimpleDateFormat;
20  
21  import org.seasar.cubby.action.FormatPattern;
22  
23  /**
24   * 日付や時刻のフォーマットパターンを保持するクラスの実装です。
25   * 
26   * @author baba
27   * @since 1.0.0
28   */
29  public class FormatPatternImpl implements FormatPattern {
30  
31  	/**
32  	 * 日付フォーマットパターン
33  	 */
34  	private String datePattern = "yyyy-MM-dd";
35  
36  	/**
37  	 * 時刻フォーマットパターン
38  	 */
39  	private String timePattern = "HH:mm:ss";
40  
41  	/**
42  	 * 日付時刻フォーマットパターン
43  	 */
44  	private String timestampPattern = "yyyy-MM-dd HH:mm:ss";
45  
46  	/**
47  	 * 日付フォーマットパターンを取得します。
48  	 * 
49  	 * @return 日付フォーマットパターン
50  	 */
51  	public String getDatePattern() {
52  		return datePattern;
53  	}
54  
55  	/**
56  	 * 日付フォーマットパターンをセットします。
57  	 * 
58  	 * @param datePattern
59  	 *            日付フォーマットパターン
60  	 */
61  	public void setDatePattern(String datePattern) {
62  		this.datePattern = datePattern;
63  	}
64  
65  	/**
66  	 * 時刻フォーマットパターンを取得します。
67  	 * 
68  	 * @return 時刻フォーマットパターン
69  	 */
70  	public String getTimePattern() {
71  		return timePattern;
72  	}
73  
74  	/**
75  	 * 時刻フォーマットパターンをセットします。
76  	 * 
77  	 * @param timePattern
78  	 *            時刻フォーマットパターン
79  	 */
80  	public void setTimePattern(String timePattern) {
81  		this.timePattern = timePattern;
82  	}
83  
84  	/**
85  	 * 日付時刻フォーマットパターンを取得します。
86  	 * 
87  	 * @return 日付時刻フォーマットパターン
88  	 */
89  	public String getTimestampPattern() {
90  		return timestampPattern;
91  	}
92  
93  	/**
94  	 * 日付時刻フォーマットパターンをセットします。
95  	 * 
96  	 * @param timestampPattern
97  	 *            日付時刻フォーマットパターン
98  	 */
99  	public void setTimestampPattern(String timestampPattern) {
100 		this.timestampPattern = timestampPattern;
101 	}
102 
103 	/**
104 	 * 日付フォーマットを取得します。
105 	 * 
106 	 * @return 日付フォーマット
107 	 */
108 	public DateFormat getDateFormat() {
109 		return new SimpleDateFormat(this.datePattern);
110 	}
111 
112 	/**
113 	 * 時刻フォーマットを取得します。
114 	 * 
115 	 * @return 時刻フォーマット
116 	 */
117 	public DateFormat getTimeFormat() {
118 		return new SimpleDateFormat(this.timePattern);
119 	}
120 
121 	/**
122 	 * 日付時刻フォーマットを取得します。
123 	 * 
124 	 * @return 日付時刻フォーマット
125 	 */
126 	public DateFormat getTimestampFormat() {
127 		return new SimpleDateFormat(this.timestampPattern);
128 	}
129 
130 	/**
131 	 * このオブジェクトの文字列表現を取得します。
132 	 * 
133 	 * @return このオブジェクトの文字列表現
134 	 */
135 	@Override
136 	public String toString() {
137 		StringBuilder builder = new StringBuilder();
138 		builder.append(super.toString());
139 		builder.append("[datePattern=");
140 		builder.append(datePattern);
141 		builder.append(",timePattern=");
142 		builder.append(timePattern);
143 		builder.append(",timestampPattern=");
144 		builder.append(timestampPattern);
145 		builder.append("]");
146 		return builder.toString();
147 	}
148 
149 }