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