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