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   * @author baba
26   */
27  public class FormatPatternImpl implements FormatPattern {
28  
29  	/**
30  	 * 日付フォーマットパターン
31  	 */
32  	private String datePattern = "yyyy-MM-dd";
33  
34  	/**
35  	 * 時刻フォーマットパターン
36  	 */
37  	private String timePattern = "HH:mm:ss";
38  
39  	/**
40  	 * 日付時刻フォーマットパターン
41  	 */
42  	private String timestampPattern = "yyyy-MM-dd HH:mm:ss";
43  
44  	/**
45  	 * 日付フォーマットパターンを取得します。
46  	 */
47  	public String getDatePattern() {
48  		return datePattern;
49  	}
50  
51  	/**
52  	 * 日付フォーマットパターンをセットします。
53  	 * @param datePattern 日付フォーマットパターン
54  	 */
55  	public void setDatePattern(String datePattern) {
56  		this.datePattern = datePattern;
57  	}
58  
59  	/**
60  	 * 時刻フォーマットパターンを取得します。
61  	 */
62  	public String getTimePattern() {
63  		return timePattern;
64  	}
65  
66  	/**
67  	 * 時刻フォーマットパターンをセットします。
68  	 * @param timePattern 時刻フォーマットパターン
69  	 */
70  	public void setTimePattern(String timePattern) {
71  		this.timePattern = timePattern;
72  	}
73  
74  	/**
75  	 * 日付時刻フォーマットパターンを取得します。
76  	 */
77  	public String getTimestampPattern() {
78  		return timestampPattern;
79  	}
80  
81  	/**
82  	 * 日付時刻フォーマットパターンをセットします。
83  	 * @param timestampPattern 日付時刻フォーマットパターン
84  	 */
85  	public void setTimestampPattern(String timestampPattern) {
86  		this.timestampPattern = timestampPattern;
87  	}
88  
89  	/**
90  	 * 日付フォーマットを取得します。
91  	 */
92  	public DateFormat getDateFormat() {
93  		return new SimpleDateFormat(this.datePattern);
94  	}
95  
96  	/**
97  	 * 時刻フォーマットを取得します。
98  	 */
99  	public DateFormat getTimeFormat() {
100 		return new SimpleDateFormat(this.timePattern);
101 	}
102 
103 	/**
104 	 * 日付時刻フォーマットを取得します。
105 	 */
106 	public DateFormat getTimestampFormat() {
107 		return new SimpleDateFormat(this.timestampPattern);
108 	}
109 
110 	@Override
111 	public String toString() {
112 		StringBuilder builder = new StringBuilder();
113 		builder.append(super.toString());
114 		builder.append("[datePattern=");
115 		builder.append(datePattern);
116 		builder.append(",timePattern=");
117 		builder.append(timePattern);
118 		builder.append(",timestampPattern=");
119 		builder.append(timestampPattern);
120 		builder.append("]");
121 		return builder.toString();
122 	}
123 
124 }