View Javadoc

1   /*
2    * Copyright 2004-2006 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.tuigwaa.plugin.basic;
17  
18  import java.text.DateFormat;
19  import java.text.SimpleDateFormat;
20  import java.util.Date;
21  
22  import org.seasar.tuigwaa.cms.core.CmsRequest;
23  import org.seasar.tuigwaa.cms.core.CmsResponse;
24  import org.seasar.tuigwaa.plugin.AbstractPlugin;
25  import org.seasar.tuigwaa.plugin.PluginException;
26  import org.seasar.tuigwaa.plugin.PluginRequest;
27  
28  
29  public class DatePlugin extends AbstractPlugin {
30  
31  	private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd");
32  	private static final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm:ss");
33  	private static final DateFormat NOW_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss (EEE)");
34  		
35  	public String doHTMLView(CmsRequest request, CmsResponse response,
36  			PluginRequest prequest) throws PluginException {
37  		
38  		String name = prequest.getName();
39  		Date date = new Date();
40  		
41  		String ret = null;
42  		if(name.equals("time")){
43  			ret = TIME_FORMAT.format(date);
44  		}else if(name.equals("now")){
45  			ret = NOW_FORMAT.format(date);
46  		}else{ // date or default
47  			ret = DATE_FORMAT.format(date);			
48  		}						
49  		return ret;
50  	}
51  
52  }