Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/obinary/cms/taglibs/util/Date.java


1   /**
2    *
3    * Magnolia and its source-code is licensed under the LGPL.
4    * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5    * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6    * you are required to provide proper attribution to obinary.
7    * If you reproduce or distribute the document without making any substantive modifications to its content,
8    * please use the following attribution line:
9    *
10   * Copyright 1993-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11   *
12   * */
13  
14  
15  
16  
17  
18  
19  package com.obinary.cms.taglibs.util;
20  
21  import com.obinary.cms.util.Resource;
22  import com.obinary.cms.core.Content;
23  import com.obinary.cms.core.Atom;
24  
25  import javax.servlet.jsp.tagext.TagSupport;
26  import javax.servlet.jsp.JspWriter;
27  import javax.servlet.http.HttpServletRequest;
28  import javax.jcr.PropertyType;
29  import java.util.Locale;
30  import java.text.SimpleDateFormat;
31  
32  
33  /**
34   * Date: Apr 28, 2003
35   * Time: 11:20:59 AM
36   * @author Marcel Salathe
37   * @version 1.0
38   */
39  
40  
41  public class Date extends TagSupport{
42  
43      private String pattern = "";
44      private String atomName;
45      private String language = "";
46  
47      private Content container;
48      private Atom atom;
49      private String actpage = "false";
50  
51      public void setPattern(String pattern) {
52          this.pattern = pattern;
53      }
54  
55      public void setAtomName(String atomName) {
56          this.atomName = atomName;
57      }
58  
59      public void setActpage(String actpage) {
60          this.actpage = actpage;
61      }
62  
63      public void setLanguage(String language) {
64          this.language = language;
65      }
66  
67  
68  
69      public int doStartTag() {
70          if (this.actpage == "true") {
71              this.container = Resource.getCurrentActivePage((HttpServletRequest)pageContext.getRequest());
72          }
73          else {
74              this.container = (Content) Resource.getLocalContainer((HttpServletRequest)pageContext.getRequest());
75              if (this.container == null) {
76                  this.container = (Content) Resource.getGlobalContainer((HttpServletRequest)pageContext.getRequest());
77              }
78          }
79          String printDate = getDateString();
80          JspWriter out = pageContext.getOut();
81          try {
82              out.print(printDate);
83          }
84          catch (Exception e) {
85              e.printStackTrace();
86          }
87          return EVAL_PAGE;
88      }
89  
90      public String getDateString() {
91          String date = "";
92          if (this.container == null) return "";
93          this.atom = this.container.getAtom(this.atomName);
94          if (!this.atom.isExist()) return "";
95          if (this.atom.getDate() == null) return "";
96          SimpleDateFormat formatter;
97          if (this.language.equals("")) formatter = new SimpleDateFormat(this.pattern);
98          else formatter = new SimpleDateFormat(this.pattern,new Locale(this.language));
99          date = formatter.format(this.atom.getDate().getTime());
100         return date;
101     }
102 }