
org.apache.maven.doxia.siterenderer.RenderingContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doxia-site-renderer Show documentation
Show all versions of doxia-site-renderer Show documentation
The Site Renderer handles the rendering of sites, merging site decoration with document content.
package org.apache.maven.doxia.siterenderer;
/*
* 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.Map;
import org.codehaus.plexus.util.PathTool;
import org.codehaus.plexus.util.StringUtils;
/**
* The rendering context of a document.
*
* @author Jason van Zyl
* @version $Id: RenderingContext.java 1720929 2015-12-19 14:09:41Z hboutemy $
* @since 1.5 (was since 1.1 in o.a.m.d.sink.render)
*/
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 attributes;
/**
*
* Constructor for RenderingContext when document is not rendered from a Doxia source.
*
*
* @param basedir the pseudo-source base directory.
* @param document the pseudo-source document name: will be used to compute output name (same name with extension
* replaced with .html
).
*/
public RenderingContext( File basedir, String document )
{
this( basedir, document, null, null );
}
/**
*
* Constructor for RenderingContext.
*
*
* @param basedir the source base directory.
* @param document the source document name.
* @param parserId the Doxia module parser id associated to this document, may be null if document not rendered from
* a Doxia source.
* @param extension the source document filename extension.
*/
public RenderingContext( File basedir, String document, String parserId, String extension )
{
this.basedir = basedir;
this.extension = extension;
this.inputName = document;
this.parserId = parserId;
this.attributes = new HashMap();
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
if ( DefaultSiteRenderer.endsWithIgnoreCase( document, ".vm" ) )
{
document = document.substring( 0, document.length() - 3 );
}
String fileNameWithoutExt = document.substring( 0, document.length() - extension.length() - 1 );
this.outputName = fileNameWithoutExt + ".html";
}
else
{
this.outputName = document.substring( 0, document.lastIndexOf( '.' ) ).replace( '\\', '/' ) + ".html";
}
this.relativePath = PathTool.getRelativePath( basedir.getPath(), new File( basedir, inputName ).getPath() );
}
/**
* Getter for the field basedir
.
*
* @return a {@link java.io.File} object.
*/
public File getBasedir()
{
return basedir;
}
/**
* Getter for the field inputName
.
*
* @return a {@link java.lang.String} object.
*/
public String getInputName()
{
return inputName;
}
/**
* Getter for the field outputName
.
*
* @return a {@link java.lang.String} object.
*/
public String getOutputName()
{
return outputName;
}
/**
* Getter for the field parserId
.
*
* @return a {@link java.lang.String} object.
*/
public String getParserId()
{
return parserId;
}
/**
* Getter for the field relativePath
.
*
* @return a {@link java.lang.String} object.
*/
public String getRelativePath()
{
return relativePath;
}
/**
* setAttribute.
*
* @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 );
}
/**
* getAttribute.
*
* @param key a {@link java.lang.String} object.
* @return a {@link java.lang.String} object.
*/
public String getAttribute( String key )
{
return attributes.get( key );
}
/**
* Getter for the field extension
.
*
* @return a {@link java.lang.String} object.
*/
public String getExtension()
{
return extension;
}
}