View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.doxia.macro;
20  
21  import java.io.File;
22  import java.util.Map;
23  
24  import org.apache.maven.doxia.parser.AbstractParser;
25  import org.apache.maven.doxia.parser.Parser;
26  
27  /**
28   * <p>MacroRequest class.</p>
29   *
30   * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
31   * @since 1.0
32   */
33  public class MacroRequest {
34      private static final String PARAM_SOURCE_CONTENT = "sourceContent";
35      private static final String PARAM_PARSER = "parser";
36  
37      /** The current base directory. */
38      private File basedir;
39  
40      /** A map of parameters. */
41      private Map<String, Object> parameters;
42  
43      /**
44       * <p>Constructor for MacroRequest.</p>
45       *
46       * @param sourceContent a {@link java.lang.String} object.
47       * @param parser a new {@link org.apache.maven.doxia.parser.AbstractParser} object acting as secondary parser.
48       * @param param a {@link java.util.Map} object.
49       * @param basedir a {@link java.io.File} object.
50       */
51      public MacroRequest(String sourceContent, AbstractParser parser, Map<String, Object> param, File basedir) {
52          this.parameters = param;
53          this.basedir = basedir;
54          param.put(PARAM_SOURCE_CONTENT, sourceContent);
55          parser.setSecondParsing(true);
56          param.put(PARAM_PARSER, parser);
57      }
58  
59      /**
60       * Returns the current base directory.
61       *
62       * @return The base dir.
63       */
64      public File getBasedir() {
65          return basedir;
66      }
67  
68      /**
69       * Sets the current base directory.
70       *
71       * @param base The current base directory.
72       */
73      public void setBasedir(File base) {
74          this.basedir = base;
75      }
76  
77      /**
78       * Returns the map of parameters.
79       *
80       * @return The map of parameters.
81       */
82      public Map<String, Object> getParameters() {
83          return parameters;
84      }
85  
86      /**
87       * Returns on object from the map of parameters
88       * that corresponds to the given key.
89       *
90       * @param key The key to lookup the object.
91       * @return The value object.
92       */
93      public Object getParameter(String key) {
94          return parameters.get(key);
95      }
96  
97      /**
98       * <p>getSourceContent.</p>
99       *
100      * @return a {@link java.lang.String} object.
101      */
102     public String getSourceContent() {
103         return (String) getParameter(PARAM_SOURCE_CONTENT);
104     }
105 
106     /**
107      * <p>getParser.</p>
108      *
109      * @return a {@link org.apache.maven.doxia.parser.Parser} object. This is a new secondary parser.
110      */
111     public Parser getParser() {
112         return (Parser) getParameter(PARAM_PARSER);
113     }
114 
115     /**
116      * <p>isInternalParameter.</p>
117      *
118      * @param name a {@link java.lang.String} object.
119      * @return a boolean.
120      */
121     public static boolean isInternalParameter(String name) {
122         return PARAM_PARSER.equals(name) || PARAM_SOURCE_CONTENT.equals(name);
123     }
124 }