1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.tinyjee.maven.dim.extensions;
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.HashMap;
24 import java.util.Map;
25
26 import static org.tinyjee.maven.dim.IncludeMacroSignature.PARAM_SOURCE;
27 import static org.tinyjee.maven.dim.IncludeMacroSignature.PARAM_SOURCE_CLASS;
28
29
30
31
32
33
34 public abstract class AbstractParameterTransformer implements RequestParameterTransformer {
35
36 protected abstract boolean doTransformParameters(Map<String, Object> requestParams);
37
38 protected boolean isSourceSet(Map<String, Object> requestParams) {
39 return requestParams.containsKey(PARAM_SOURCE) && requestParams.containsKey(PARAM_SOURCE_CLASS);
40 }
41
42 public final void transformParameters(Map<String, Object> requestParams) {
43 final Log log = Globals.getLog();
44 if (!isSourceSet(requestParams)) {
45 final Map<String, Object> originalParams = new HashMap<String, Object>(requestParams);
46 if (doTransformParameters(requestParams)) {
47 if (log.isDebugEnabled()) {
48 log.debug("The parameter transformer " + this + " changed the request parameters from " + originalParams +
49 " to " + requestParams);
50 }
51 } else if (!originalParams.equals(requestParams)) {
52 log.warn("The parameter transformer " + this + " changed the request parameters from " + originalParams +
53 " to " + requestParams + " without reporting it.");
54 }
55 }
56 }
57 }