1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
package org.apache.maven.doxia.sink.render;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.codehaus.plexus.util.PathTool;
import org.codehaus.plexus.util.StringUtils;
/**
* The rendering context of a document.
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id: RenderingContext.java 1090706 2011-04-09 23:15:28Z hboutemy $
* @since 1.1
*/
public class RenderingContext
{
private final File basedir;
private final String inputName;
private final String outputName;
private final String parserId;
private final String relativePath;
private final String extension;
private Map<String, String> attributes;
/**
* <p>Constructor for RenderingContext.</p>
*
* @param basedir a {@link java.io.File} object.
* @param document a {@link java.lang.String} object.
*/
public RenderingContext( File basedir, String document )
{
this( basedir, document, null );
}
/**
* <p>Constructor for RenderingContext.</p>
*
* @param basedir a {@link java.io.File} object.
* @param document a {@link java.lang.String} object.
* @param parserId a {@link java.lang.String} object.
*/
public RenderingContext( File basedir, String document, String parserId )
{
this( basedir, document, parserId, null );
}
/**
* <p>Constructor for RenderingContext.</p>
*
* @param basedir a {@link java.io.File} object.
* @param document a {@link java.lang.String} object.
* @param parserId a {@link java.lang.String} object.
* @param extension a {@link java.lang.String} object.
*/
public RenderingContext( File basedir, String document, String parserId, String extension )
{
this.basedir = basedir;
this.extension = extension;
if ( StringUtils.isNotEmpty( extension ) )
{
// here we now the parserId we can play with this
// index.xml -> index.html
// index.xml.vm -> index.html
// download.apt.vm --> download.html
int startIndexOfExtension =
document.toLowerCase( Locale.ENGLISH ).indexOf( "." + extension.toLowerCase( Locale.ENGLISH ) );
String fileNameWithoutExt = document.substring( 0, startIndexOfExtension );
this.outputName = fileNameWithoutExt + ".html";
}
else
{
this.outputName = document.substring( 0, document.indexOf( '.' ) ).replace( '\\', '/' ) + ".html";
}
this.relativePath = PathTool.getRelativePath( basedir.getPath(), new File( basedir, document ).getPath() );
this.inputName = document;
this.parserId = parserId;
this.attributes = new HashMap<String, String>();
}
/**
* <p>Getter for the field <code>basedir</code>.</p>
*
* @return a {@link java.io.File} object.
*/
public File getBasedir()
{
return basedir;
}
/**
* <p>Getter for the field <code>inputName</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getInputName()
{
return inputName;
}
/**
* <p>Getter for the field <code>outputName</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getOutputName()
{
return outputName;
}
/**
* <p>Getter for the field <code>parserId</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getParserId()
{
return parserId;
}
/**
* <p>Getter for the field <code>relativePath</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getRelativePath()
{
return relativePath;
}
/**
* <p>setAttribute.</p>
*
* @param key a {@link java.lang.String} object.
* @param value a {@link java.lang.String} object.
*/
public void setAttribute( String key, String value )
{
attributes.put( key, value );
}
/**
* <p>getAttribute.</p>
*
* @param key a {@link java.lang.String} object.
* @return a {@link java.lang.String} object.
*/
public String getAttribute( String key )
{
return (String) attributes.get( key );
}
/**
* <p>Getter for the field <code>extension</code>.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getExtension()
{
return extension;
}
}
|