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