1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.jsieve.commands;
21
22 import java.util.Iterator;
23 import java.util.List;
24
25 import org.apache.jsieve.Arguments;
26 import org.apache.jsieve.Block;
27 import org.apache.jsieve.SieveContext;
28 import org.apache.jsieve.StringListArgument;
29 import org.apache.jsieve.exception.FeatureException;
30 import org.apache.jsieve.exception.LookupException;
31 import org.apache.jsieve.exception.SieveException;
32 import org.apache.jsieve.mail.MailAdapter;
33
34
35
36
37
38 public class Require extends AbstractPrologCommand {
39
40
41
42
43 public Require() {
44 super();
45 }
46
47
48
49
50
51
52
53
54
55
56
57
58 protected Object executeBasic(MailAdapter mail, Arguments arguments,
59 Block block, SieveContext context) throws SieveException {
60 Iterator stringsIter = ((StringListArgument) arguments
61 .getArgumentList().get(0)).getList().iterator();
62
63 while (stringsIter.hasNext()) {
64 validateFeature((String) stringsIter.next(), mail, context);
65 }
66 return null;
67 }
68
69
70
71
72
73
74
75
76
77
78
79 protected void validateFeature(String name, MailAdapter mail,
80 SieveContext context) throws FeatureException {
81
82 try {
83 validateCommand(name, context);
84 return;
85 } catch (LookupException e) {
86
87 }
88
89
90 try {
91 validateTest(name, context);
92 } catch (LookupException e) {
93 throw new FeatureException("Feature \"" + name
94 + "\" is not supported.");
95 }
96 }
97
98
99
100
101
102
103
104 protected void validateCommand(String name, SieveContext context)
105 throws LookupException {
106 context.getCommand(name);
107 }
108
109
110
111
112
113
114
115
116
117 protected void validateTest(String name, SieveContext context)
118 throws LookupException {
119 context.getTest(name);
120 }
121
122
123
124
125
126 protected void validateArguments(Arguments arguments, SieveContext context)
127 throws SieveException {
128 List args = arguments.getArgumentList();
129 if (args.size() != 1)
130 throw context.getCoordinate().syntaxException(
131 "Exactly 1 argument permitted. Found " + args.size());
132
133 Object argument = args.get(0);
134 if (!(argument instanceof StringListArgument))
135 throw context.getCoordinate().syntaxException(
136 "Expecting a string-list");
137 }
138
139 }