001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.maven.doxia.macro; 020 021import java.io.File; 022import java.util.Map; 023 024import org.apache.maven.doxia.parser.AbstractParser; 025import org.apache.maven.doxia.parser.Parser; 026 027/** 028 * <p>MacroRequest class.</p> 029 * 030 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a> 031 * @since 1.0 032 */ 033public class MacroRequest { 034 private static final String PARAM_SOURCE_CONTENT = "sourceContent"; 035 private static final String PARAM_PARSER = "parser"; 036 037 /** The current base directory. */ 038 private File basedir; 039 040 /** A map of parameters. */ 041 private Map<String, Object> parameters; 042 043 /** 044 * <p>Constructor for MacroRequest.</p> 045 * 046 * @param sourceContent a {@link java.lang.String} object. 047 * @param parser a new {@link org.apache.maven.doxia.parser.AbstractParser} object acting as secondary parser. 048 * @param param a {@link java.util.Map} object. 049 * @param basedir a {@link java.io.File} object. 050 */ 051 public MacroRequest(String sourceContent, AbstractParser parser, Map<String, Object> param, File basedir) { 052 this.parameters = param; 053 this.basedir = basedir; 054 param.put(PARAM_SOURCE_CONTENT, sourceContent); 055 parser.setSecondParsing(true); 056 param.put(PARAM_PARSER, parser); 057 } 058 059 /** 060 * Returns the current base directory. 061 * 062 * @return The base dir. 063 */ 064 public File getBasedir() { 065 return basedir; 066 } 067 068 /** 069 * Sets the current base directory. 070 * 071 * @param base The current base directory. 072 */ 073 public void setBasedir(File base) { 074 this.basedir = base; 075 } 076 077 /** 078 * Returns the map of parameters. 079 * 080 * @return The map of parameters. 081 */ 082 public Map<String, Object> getParameters() { 083 return parameters; 084 } 085 086 /** 087 * Returns on object from the map of parameters 088 * that corresponds to the given key. 089 * 090 * @param key The key to lookup the object. 091 * @return The value object. 092 */ 093 public Object getParameter(String key) { 094 return parameters.get(key); 095 } 096 097 /** 098 * <p>getSourceContent.</p> 099 * 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}