View Javadoc

1   /*
2    * Copyright 2010 - org.tinyjee.maven
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *        http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  
17  package org.tinyjee.maven.dim.spi;
18  
19  import org.tinyjee.maven.dim.spi.backport.ServiceLoader;
20  
21  import java.util.Map;
22  
23  /**
24   * {@link RequestParameterTransformer} defines an interface that may be implemented and registered via service loading
25   * to plug parameter transformers that adjust macro parameters on the fly before any other operation is triggered.
26   * <p/>
27   * <b>Implementation</b>:<code><pre>
28   * package my.package;
29   * public class MyRequestParameterTransformer implements RequestParameterTransformer {
30   *      public void transformParameters(Map&lt;String, Object&gt; requestParams) {
31   *          Object value = requestParams.get("my-input-param");
32   *          if (value != null) {
33   *              requestParams.put("myText", value);
34   *              requestParams.put("source", "classpath:my-template.vm");
35   *          }
36   *      }
37   * }
38   * </pre></code>
39   * <p/>
40   * <b>Register the implementation using service loading</b>:<ul>
41   * <li>
42   * Create the following file:<code><pre>
43   * META-INF/services/
44   *    org.tinyjee.maven.dim.spi.RequestParameterTransformer
45   * </pre></code></li>
46   * <li>Add the fully qualified class name of your implementation to the file
47   * "org.tinyjee.maven.dim.spi.RequestParameterTransformer":<code><pre>
48   * my.package.MyRequestParameterTransformer
49   * </pre></code></li>
50   * </ul>
51   *
52   * @version 1.1
53   * @since 1.0
54   * @author Juergen_Kellerer, 2010-09-08
55   */
56  public interface RequestParameterTransformer {
57  
58  	/**
59  	 * Is an iterable over all transformers within the classpath.
60  	 */
61  	Iterable<RequestParameterTransformer> TRANSFORMERS = ServiceLoader.load(RequestParameterTransformer.class);
62  
63  	/**
64  	 * Transforms the specified request parameters.
65  	 *
66  	 * @param requestParams the request params to modify.
67  	 */
68  	void transformParameters(Map<String, Object> requestParams);
69  }