|
@@ -29,6 +29,7 @@ import com.dmdirc.ServerState;
|
29
|
29
|
import com.dmdirc.commandparser.CommandArguments;
|
30
|
30
|
import com.dmdirc.config.ConfigManager;
|
31
|
31
|
import com.dmdirc.config.IdentityManager;
|
|
32
|
+import com.dmdirc.interfaces.ActionController;
|
32
|
33
|
import com.dmdirc.interfaces.actions.ActionComponent;
|
33
|
34
|
import com.dmdirc.interfaces.actions.ActionType;
|
34
|
35
|
import com.dmdirc.interfaces.ui.Window;
|
|
@@ -70,18 +71,33 @@ public class ActionSubstitutor {
|
70
|
71
|
/** Pattern to determine if a substitution is a server component type. */
|
71
|
72
|
private static final Pattern SERVER_PATTERN = Pattern.compile("[A-Z_]+(\\.[A-Z_]+)*");
|
72
|
73
|
|
|
74
|
+ /** The action controller to use to find components. */
|
|
75
|
+ private final ActionController actionController;
|
73
|
76
|
/** The action type this substitutor is for. */
|
74
|
77
|
private final ActionType type;
|
75
|
78
|
|
76
|
79
|
/**
|
77
|
80
|
* Creates a new substitutor for the specified action type.
|
78
|
81
|
*
|
|
82
|
+ * @param actionController The action controller to use to find components.
|
79
|
83
|
* @param type The action type this substitutor is for
|
80
|
84
|
*/
|
81
|
|
- public ActionSubstitutor(final ActionType type) {
|
|
85
|
+ public ActionSubstitutor(final ActionController actionController, final ActionType type) {
|
|
86
|
+ this.actionController = actionController;
|
82
|
87
|
this.type = type;
|
83
|
88
|
}
|
84
|
89
|
|
|
90
|
+ /**
|
|
91
|
+ * Creates a new substitutor for the specified action type.
|
|
92
|
+ *
|
|
93
|
+ * @param type The action type this substitutor is for
|
|
94
|
+ * @deprecated Should use {@link #ActionSubstitutor(ActionController, ActionType)}.
|
|
95
|
+ */
|
|
96
|
+ @Deprecated
|
|
97
|
+ public ActionSubstitutor(final ActionType type) {
|
|
98
|
+ this(ActionManager.getActionManager(), type);
|
|
99
|
+ }
|
|
100
|
+
|
85
|
101
|
/**
|
86
|
102
|
* Retrieves a list of global config variables that will be substituted.
|
87
|
103
|
* Note: does not include initial $.
|
|
@@ -100,12 +116,11 @@ public class ActionSubstitutor {
|
100
|
116
|
* @return A map of component substitution names and their descriptions
|
101
|
117
|
*/
|
102
|
118
|
public Map<String, String> getComponentSubstitutions() {
|
103
|
|
- final Map<String, String> res = new HashMap<String, String>();
|
|
119
|
+ final Map<String, String> res = new HashMap<>();
|
104
|
120
|
|
105
|
121
|
int i = 0;
|
106
|
122
|
for (Class<?> myClass : type.getType().getArgTypes()) {
|
107
|
|
- for (ActionComponent comp : ActionManager.getActionManager()
|
108
|
|
- .findCompatibleComponents(myClass)) {
|
|
123
|
+ for (ActionComponent comp : actionController.findCompatibleComponents(myClass)) {
|
109
|
124
|
final String key = "{" + i + "." + comp.toString() + "}";
|
110
|
125
|
final String desc = type.getType().getArgNames()[i] + "'s " + comp.getName();
|
111
|
126
|
|
|
@@ -126,11 +141,10 @@ public class ActionSubstitutor {
|
126
|
141
|
* @return A map of server substitution names and their descriptions.
|
127
|
142
|
*/
|
128
|
143
|
public Map<String, String> getServerSubstitutions() {
|
129
|
|
- final Map<String, String> res = new HashMap<String, String>();
|
|
144
|
+ final Map<String, String> res = new HashMap<>();
|
130
|
145
|
|
131
|
146
|
if (hasFrameContainer()) {
|
132
|
|
- for (ActionComponent comp : ActionManager.getActionManager()
|
133
|
|
- .findCompatibleComponents(Server.class)) {
|
|
147
|
+ for (ActionComponent comp : actionController.findCompatibleComponents(Server.class)) {
|
134
|
148
|
final String key = "{" + comp.toString() + "}";
|
135
|
149
|
final String desc = "The connection's " + comp.getName();
|
136
|
150
|
|
|
@@ -248,7 +262,8 @@ public class ActionSubstitutor {
|
248
|
262
|
|
249
|
263
|
try {
|
250
|
264
|
final ActionComponentChain chain = new ActionComponentChain(
|
251
|
|
- type.getType().getArgTypes()[argument], compMatcher.group(2));
|
|
265
|
+ type.getType().getArgTypes()[argument], compMatcher.group(2),
|
|
266
|
+ actionController);
|
252
|
267
|
return escape(checkConnection(chain, args, args[argument]));
|
253
|
268
|
} catch (IllegalArgumentException ex) {
|
254
|
269
|
return ERR_ILLEGAL_COMPONENT;
|
|
@@ -267,7 +282,7 @@ public class ActionSubstitutor {
|
267
|
282
|
if (server != null) {
|
268
|
283
|
try {
|
269
|
284
|
final ActionComponentChain chain = new ActionComponentChain(
|
270
|
|
- Server.class, substitution);
|
|
285
|
+ Server.class, substitution, actionController);
|
271
|
286
|
return escape(checkConnection(chain, args, server));
|
272
|
287
|
} catch (IllegalArgumentException ex) {
|
273
|
288
|
return ERR_ILLEGAL_COMPONENT;
|