1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.tinyjee.maven.dim.utils;
18
19 import org.apache.maven.doxia.logging.Log;
20 import org.tinyjee.maven.dim.spi.Globals;
21 import org.tinyjee.maven.dim.spi.RequestParameterTransformer;
22
23 import java.util.Map;
24
25 import static org.tinyjee.maven.dim.IncludeMacroSignature.PARAM_SOURCE_CLASS;
26
27
28
29
30 public abstract class AbstractAliasHandler implements RequestParameterTransformer {
31
32 final String triggerParameter, targetParameter, sourceClass;
33
34
35
36
37
38
39
40
41 protected AbstractAliasHandler(String triggerParameter, String targetParameter, String sourceClass) {
42 this.triggerParameter = triggerParameter;
43 this.targetParameter = targetParameter;
44 this.sourceClass = sourceClass;
45 }
46
47
48
49
50 public void transformParameters(Map<String, Object> requestParams) {
51 Log logger = Globals.getLog();
52 Object parameterValue = requestParams.get(triggerParameter);
53 if (parameterValue != null) {
54 if (sourceClass != null) {
55 if (requestParams.containsKey(PARAM_SOURCE_CLASS)) {
56 logger.warn("The request parameter '" + PARAM_SOURCE_CLASS + "' is already set to '" +
57 requestParams.get(PARAM_SOURCE_CLASS) + "'. Will not set the parameter to '" + sourceClass + "' " +
58 "which may break subsequent template execution and may lead to unexpected results.");
59 } else
60 requestParams.put(PARAM_SOURCE_CLASS, sourceClass);
61 }
62
63 if (requestParams.containsKey(targetParameter)) {
64 logger.warn("The request parameter '" + targetParameter + "' is already set to '" +
65 requestParams.get(targetParameter) + "', overwriting it with '" + parameterValue + "'. " +
66 "This may may lead to unexpected results.");
67 }
68
69 requestParams.put(targetParameter, parameterValue);
70 }
71 }
72 }