6176cebd620fecf085a944065568094d910eaac5
[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.Date;
9
10 import net.sourceforge.phpdt.internal.corext.template.SimpleTemplateVariable;
11 import net.sourceforge.phpdt.internal.corext.template.TemplateContext;
12
13 import net.sourceforge.phpdt.internal.corext.template.TemplateVariable;
14
15 /**
16  * Global variables which are available in any context.
17  */
18 public class GlobalVariables {
19
20         /**
21          * The cursor variable determines the cursor placement after template edition.
22          */
23         static class Cursor extends SimpleTemplateVariable {
24                 public Cursor() {
25                         super(PHPTemplateMessages.getString("GlobalVariables.variable.name.cursor"), PHPTemplateMessages.getString("GlobalVariables.variable.description.cursor")); //$NON-NLS-1$ //$NON-NLS-2$
26                         setEvaluationString(""); //$NON-NLS-1$
27                         setResolved(true);
28                 }
29         }
30
31         /**
32          * The dollar variable inserts an escaped dollar symbol.
33          */
34         static class Dollar extends SimpleTemplateVariable {
35                 public Dollar() {
36                         super(PHPTemplateMessages.getString("GlobalVariables.variable.name.dollar"), PHPTemplateMessages.getString("GlobalVariables.variable.description.dollar")); //$NON-NLS-1$ //$NON-NLS-2$
37                         setEvaluationString("$"); //$NON-NLS-1$
38                         setResolved(true);
39                 }
40         }
41
42         /**
43          * The date variable evaluates to the current date.
44          */
45         static class Date extends SimpleTemplateVariable {
46                 public Date() {
47                         super(PHPTemplateMessages.getString("GlobalVariables.variable.name.date"), PHPTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$
48                         setResolved(true);
49                 }
50                 public String evaluate(TemplateContext context) {
51                         return DateFormat.getDateInstance().format(new java.util.Date());
52                 }
53         }               
54
55         /**
56          * The time variable evaluates to the current time.
57          */
58         static class Time extends SimpleTemplateVariable {
59                 public Time() {
60                         super(PHPTemplateMessages.getString("GlobalVariables.variable.name.time"), PHPTemplateMessages.getString("GlobalVariables.variable.description.time")); //$NON-NLS-1$ //$NON-NLS-2$
61                         setResolved(true);
62                 }
63                 public String evaluate(TemplateContext context) {
64                         return DateFormat.getTimeInstance().format(new java.util.Date());
65                 }
66         }
67
68         /**
69          * The user variable evaluates to the current user.
70          */
71         static class User extends SimpleTemplateVariable {
72                 public User() {
73                         super(PHPTemplateMessages.getString("GlobalVariables.variable.name.user"), PHPTemplateMessages.getString("GlobalVariables.variable.description.user")); //$NON-NLS-1$ //$NON-NLS-2$
74                         setResolved(true);
75                 }
76                 public String evaluate(TemplateContext context) {
77                         return System.getProperty("user.name"); //$NON-NLS-1$
78                 }       
79         }
80 }