~ubuntu-branches/ubuntu/vivid/doxia/vivid-proposed

« back to all changes in this revision

Viewing changes to doxia-core/src/main/java/org/apache/maven/doxia/sink/render/RenderingContext.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-10-08 14:20:22 UTC
  • mfrom: (2.3.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091008142022-f6ccxganfr2tbaig
Tags: 1.1-3build1
Upload to karmic, avoiding new version from unstable. LP: #443292.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.apache.maven.doxia.sink.render;
 
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.io.File;
 
23
import java.util.HashMap;
 
24
import java.util.Map;
 
25
 
 
26
import org.codehaus.plexus.util.PathTool;
 
27
import org.codehaus.plexus.util.StringUtils;
 
28
 
 
29
/**
 
30
 * <p>RenderingContext class.</p>
 
31
 *
 
32
 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
 
33
 * @version $Id: RenderingContext.java 747735 2009-02-25 10:43:09Z ltheussl $
 
34
 * @since 1.0
 
35
 */
 
36
public class RenderingContext
 
37
{
 
38
    private final File basedir;
 
39
 
 
40
    private final String inputName;
 
41
 
 
42
    private final String outputName;
 
43
 
 
44
    private final String parserId;
 
45
 
 
46
    private final String relativePath;
 
47
 
 
48
    private final String extension;
 
49
 
 
50
    private Map attributes;
 
51
 
 
52
    /**
 
53
     * <p>Constructor for RenderingContext.</p>
 
54
     *
 
55
     * @param basedir a {@link java.io.File} object.
 
56
     * @param document a {@link java.lang.String} object.
 
57
     */
 
58
    public RenderingContext( File basedir, String document )
 
59
    {
 
60
        this( basedir, document, null );
 
61
    }
 
62
 
 
63
    /**
 
64
     * <p>Constructor for RenderingContext.</p>
 
65
     *
 
66
     * @param basedir a {@link java.io.File} object.
 
67
     * @param document a {@link java.lang.String} object.
 
68
     * @param parserId a {@link java.lang.String} object.
 
69
     */
 
70
    public RenderingContext( File basedir, String document, String parserId )
 
71
    {
 
72
        this( basedir, document, null, null );
 
73
 
 
74
    }
 
75
 
 
76
    /**
 
77
     * <p>Constructor for RenderingContext.</p>
 
78
     *
 
79
     * @param basedir a {@link java.io.File} object.
 
80
     * @param document a {@link java.lang.String} object.
 
81
     * @param parserId a {@link java.lang.String} object.
 
82
     * @param extension a {@link java.lang.String} object.
 
83
     */
 
84
    public RenderingContext( File basedir, String document, String parserId, String extension )
 
85
    {
 
86
        this.basedir = basedir;
 
87
        this.extension = extension;
 
88
        if ( StringUtils.isNotEmpty( extension ) )
 
89
        {
 
90
            // here we now the parserId we can play with this
 
91
            // index.xml -> index.html
 
92
            // index.xml.vm -> index.html
 
93
            // download.apt.vm --> download.html
 
94
            int startIndexOfExtension = document.indexOf( "." + extension );
 
95
            String fileNameWithoutExt = document.substring( 0, startIndexOfExtension );
 
96
            this.outputName = fileNameWithoutExt + ".html";
 
97
        }
 
98
        else
 
99
        {
 
100
            this.outputName = document.substring( 0, document.indexOf( "." ) ).replace( '\\', '/' ) + ".html";
 
101
        }
 
102
        this.relativePath = PathTool.getRelativePath( basedir.getPath(), new File( basedir, document ).getPath() );
 
103
 
 
104
        this.inputName = document;
 
105
 
 
106
        this.parserId = parserId;
 
107
 
 
108
        this.attributes = new HashMap();
 
109
    }
 
110
 
 
111
    /**
 
112
     * <p>Getter for the field <code>basedir</code>.</p>
 
113
     *
 
114
     * @return a {@link java.io.File} object.
 
115
     */
 
116
    public File getBasedir()
 
117
    {
 
118
        return basedir;
 
119
    }
 
120
 
 
121
    /**
 
122
     * <p>Getter for the field <code>inputName</code>.</p>
 
123
     *
 
124
     * @return a {@link java.lang.String} object.
 
125
     */
 
126
    public String getInputName()
 
127
    {
 
128
        return inputName;
 
129
    }
 
130
 
 
131
    /**
 
132
     * <p>Getter for the field <code>outputName</code>.</p>
 
133
     *
 
134
     * @return a {@link java.lang.String} object.
 
135
     */
 
136
    public String getOutputName()
 
137
    {
 
138
        return outputName;
 
139
    }
 
140
 
 
141
    /**
 
142
     * <p>Getter for the field <code>parserId</code>.</p>
 
143
     *
 
144
     * @return a {@link java.lang.String} object.
 
145
     */
 
146
    public String getParserId()
 
147
    {
 
148
        return parserId;
 
149
    }
 
150
 
 
151
    /**
 
152
     * <p>Getter for the field <code>relativePath</code>.</p>
 
153
     *
 
154
     * @return a {@link java.lang.String} object.
 
155
     */
 
156
    public String getRelativePath()
 
157
    {
 
158
        return relativePath;
 
159
    }
 
160
 
 
161
    /**
 
162
     * <p>setAttribute</p>
 
163
     *
 
164
     * @param key a {@link java.lang.String} object.
 
165
     * @param value a {@link java.lang.String} object.
 
166
     */
 
167
    public void setAttribute( String key, String value )
 
168
    {
 
169
        attributes.put( key, value );
 
170
    }
 
171
 
 
172
    /**
 
173
     * <p>getAttribute</p>
 
174
     *
 
175
     * @param key a {@link java.lang.String} object.
 
176
     * @return a {@link java.lang.String} object.
 
177
     */
 
178
    public String getAttribute( String key )
 
179
    {
 
180
        return (String) attributes.get( key );
 
181
    }
 
182
 
 
183
    /**
 
184
     * <p>Getter for the field <code>extension</code>.</p>
 
185
     *
 
186
     * @return a {@link java.lang.String} object.
 
187
     */
 
188
    public String getExtension()
 
189
    {
 
190
        return extension;
 
191
    }
 
192
}