8439ae9143ca0e077ae83f3d222c31aae43d4601
[phpeclipse.git] /
1 /*
2  * (c) Copyright IBM Corp. 2000, 2001.
3  * All Rights Reserved.
4  */
5 package net.sourceforge.phpdt.internal.corext.template.php;
6
7 import java.text.DateFormat;
8 import java.util.Calendar;
9
10 import net.sourceforge.phpdt.internal.corext.template.SimpleTemplateVariable;
11 import net.sourceforge.phpdt.internal.corext.template.TemplateContext;
12
13 /**
14  * Global variables which are available in any context.
15  */
16 public class GlobalVariables {
17
18         /**
19          * The cursor variable determines the cursor placement after template edition.
20          */
21         static class Cursor extends SimpleTemplateVariable {
22                 public Cursor() {
23                         super(PHPTemplateMessages.getString("GlobalVariables.variable.name.cursor"), PHPTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$ //$NON-NLS-2$
24                         setEvaluationString(""); //$NON-NLS-1$
25                         setResolved(true);
26                 }
27         }
28
29         /**
30          * The dollar variable inserts an escaped dollar symbol.
31          */
32         static class Dollar extends SimpleTemplateVariable {
33                 public Dollar() {
34                         super(PHPTemplateMessages.getString("GlobalVariables.variable.name.dollar"), PHPTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$
35                         setEvaluationString("$"); //$NON-NLS-1$
36                         setResolved(true);
37                 }
38         }
39
40         /**
41          * The date variable evaluates to the current date.
42          */
43         static class Date extends SimpleTemplateVariable {
44                 public Date() {
45                         super(PHPTemplateMessages.getString("GlobalVariables.variable.name.date"), PHPTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
46                         setResolved(true);
47                 }
48                 public String evaluate(TemplateContext context) {
49                         return DateFormat.getDateInstance().format(new java.util.Date());
50                 }
51         }               
52         
53   /**
54    * The year variable evaluates to the current year.
55    */
56   static class Year extends SimpleTemplateVariable {
57     public Year() {
58       super(PHPTemplateMessages.getString("GlobalVariables.variable.name.year"), PHPTemplateMessages.getString("GlobalVariables.variable.description.year")); //$NON-NLS-1$ //$NON-NLS-2$
59       setResolved(true);
60     }
61     public String evaluate(TemplateContext context) {
62       return Integer.toString(Calendar.getInstance().get(Calendar.YEAR));
63     }
64   }
65         /**
66          * The time variable evaluates to the current time.
67          */
68         static class Time extends SimpleTemplateVariable {
69                 public Time() {
70                         super(PHPTemplateMessages.getString("GlobalVariables.variable.name.time"), PHPTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$
71                         setResolved(true);
72                 }
73                 public String evaluate(TemplateContext context) {
74                         return DateFormat.getTimeInstance().format(new java.util.Date());
75                 }
76         }
77
78         /**
79          * The user variable evaluates to the current user.
80          */
81         static class User extends SimpleTemplateVariable {
82                 public User() {
83                         super(PHPTemplateMessages.getString("GlobalVariables.variable.name.user"), PHPTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$
84                         setResolved(true);
85                 }
86                 public String evaluate(TemplateContext context) {
87                         return System.getProperty("user.name"); //$NON-NLS-1$
88                 }       
89         }
90 }