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 * @version $Id: MacroRequest.java 1728197 2016-02-02 19:52:10Z hboutemy $
34 * @since 1.0
35 */
36 public class MacroRequest
37 {
38 private static final String PARAM_SOURCE_CONTENT = "sourceContent";
39 private static final String PARAM_PARSER = "parser";
40
41 /** The current base directory. */
42 private File basedir;
43
44 /** A map of parameters. */
45 private Map<String, Object> parameters;
46
47 /**
48 * Constructor.
49 *
50 * @param param A map of parameters.
51 * @param base The current base directory.
52 * @deprecated prefer other constructor
53 */
54 public MacroRequest( Map<String, Object> param, File base )
55 {
56 this.parameters = param;
57 this.basedir = base;
58 }
59
60 public MacroRequest( String sourceContent, AbstractParser parser, Map<String, Object> param, File base )
61 {
62 this.parameters = param;
63 this.basedir = base;
64 param.put( PARAM_SOURCE_CONTENT, sourceContent );
65 parser.setSecondParsing( true );
66 param.put( PARAM_PARSER, parser );
67 }
68
69 /**
70 * Returns the current base directory.
71 *
72 * @return The base dir.
73 */
74 public File getBasedir()
75 {
76 return basedir;
77 }
78
79 /**
80 * Sets the current base directory.
81 *
82 * @param base The current base directory.
83 */
84 public void setBasedir( File base )
85 {
86 this.basedir = base;
87 }
88
89 /**
90 * Returns the map of parameters.
91 *
92 * @return The map of parameters.
93 */
94 public Map<String, Object> getParameters()
95 {
96 return parameters;
97 }
98
99 /**
100 * Returns on object from the map of parameters
101 * that corresponds to the given key.
102 *
103 * @param key The key to lookup the object.
104 * @return The value object.
105 */
106 public Object getParameter( String key )
107 {
108 return parameters.get( key );
109 }
110
111 public String getSourceContent()
112 {
113 return (String) getParameter( PARAM_SOURCE_CONTENT );
114 }
115
116 public Parser getParser()
117 {
118 return (Parser) getParameter( PARAM_PARSER );
119 }
120
121 public static boolean isInternalParameter( String name )
122 {
123 return PARAM_PARSER.equals( name ) || PARAM_SOURCE_CONTENT.equals( name );
124 }
125 }