View Javadoc
1   package org.apache.maven.doxia.siterenderer;
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.io.FileNotFoundException;
24  import java.io.IOException;
25  import java.io.UnsupportedEncodingException;
26  import java.io.Writer;
27  import java.net.MalformedURLException;
28  import java.util.Collection;
29  import java.util.Locale;
30  import java.util.Map;
31  
32  import org.apache.maven.artifact.Artifact;
33  import org.apache.maven.doxia.site.decoration.DecorationModel;
34  import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
35  
36  /**
37   * <p>Site Renderer interface: render a collection of documents into a site, ie decored with a site template
38   * (eventually packaged as skin).</p>
39   *
40   * @author <a href="mailto:evenisse@codehaus.org">Emmanuel Venisse</a>
41   */
42  public interface Renderer // TODO rename to SiteRenderer
43  {
44      /**
45       * Plexus lookup role.
46       */
47      String ROLE = Renderer.class.getName();
48  
49      /**
50       * Render a collection of documents into a site.
51       *
52       * @param documents the documents to render.
53       * @param siteRenderingContext the SiteRenderingContext to use.
54       * @param outputDirectory the output directory to write results.
55       * @throws RendererException if it bombs.
56       * @throws IOException if it bombs.
57       */
58      void render( Collection<DocumentRenderer> documents, SiteRenderingContext siteRenderingContext,
59                   File outputDirectory )
60          throws RendererException, IOException;
61  
62      /**
63       * Generate a document output from a Doxia SiteRenderer Sink, i.e. merge the document content into
64       * the site template.
65       *
66       * @param writer the Writer to use.
67       * @param sink the Site Renderer Sink that received the Doxia events during document content rendering.
68       * @param siteRenderingContext the SiteRenderingContext to use.
69       * @throws RendererException if it bombs.
70       * @deprecated since 1.8, use mergeDocumentIntoSite
71       */
72      void generateDocument( Writer writer, SiteRendererSink sink, SiteRenderingContext siteRenderingContext )
73          throws RendererException;
74  
75      /**
76       * Generate a document output integrated in a site from a document content,
77       * i.e. merge the document content into the site template.
78       *
79       * @param writer the Writer to use.
80       * @param content the document content to be merged.
81       * @param siteRenderingContext the SiteRenderingContext to use.
82       * @throws RendererException if it bombs.
83       * @since 1.8
84       */
85      void mergeDocumentIntoSite( Writer writer, DocumentContent content, SiteRenderingContext siteRenderingContext )
86          throws RendererException;
87  
88      /**
89       * Create a Site Rendering Context for a site using a skin.
90       *
91       * @param skin a skin
92       * @param attributes attributes to use
93       * @param decoration a decoration model
94       * @param defaultWindowTitle default window title
95       * @param locale locale to use
96       * @return a SiteRenderingContext.
97       * @throws RendererException if it bombs.
98       * @throws java.io.IOException if it bombs.
99       * @since 1.7.3 was previously with skin as File instead of Artifact
100      */
101     SiteRenderingContext createContextForSkin( Artifact skin, Map<String, ?> attributes, DecorationModel decoration,
102                                                String defaultWindowTitle, Locale locale )
103         throws RendererException, IOException;
104 
105     /**
106      * Create a Site Rendering Context for a site using a local template.
107      *
108      * @param templateFile template file
109      * @param attributes attributes to use
110      * @param decoration a decoration model
111      * @param defaultWindowTitle default window title
112      * @param locale locale to use
113      * @return a SiteRenderingContext.
114      * @throws MalformedURLException if it bombs.
115      * @since 1.7, had an additional skinFile parameter before
116      * @deprecated Deprecated without replacement, use skins only.
117      * @see #createContextForSkin(Artifact, Map, DecorationModel, String, Locale)
118      */
119     @Deprecated
120     SiteRenderingContext createContextForTemplate( File templateFile, Map<String, ?> attributes,
121                                                    DecorationModel decoration, String defaultWindowTitle,
122                                                    Locale locale )
123         throws MalformedURLException;
124 
125     /**
126      * Copy resource files.
127      *
128      * @param siteRenderingContext the SiteRenderingContext to use
129      * @param resourcesDirectory resources directory as file
130      * @param outputDirectory output directory as file
131      * @throws IOException if it bombs.
132      * @deprecated since 1.7, use copyResources without resourcesDirectory parameter
133      */
134     void copyResources( SiteRenderingContext siteRenderingContext, File resourcesDirectory, File outputDirectory )
135         throws IOException;
136 
137     /**
138      * Copy resource files from skin, template, and site resources.
139      *
140      * @param siteRenderingContext the SiteRenderingContext to use.
141      * @param outputDirectory output directory as file
142      * @throws IOException if it bombs.
143      * @since 1.7
144      */
145     void copyResources( SiteRenderingContext siteRenderingContext, File outputDirectory )
146         throws IOException;
147 
148     /**
149      * Locate Doxia document source files in the site source context.
150      *
151      * @param siteRenderingContext the SiteRenderingContext to use
152      * @return the Doxia document renderers in a Map keyed by output file name.
153      * @throws IOException if it bombs.
154      * @throws RendererException if it bombs.
155      * @deprecated since 1.8, use locateDocumentFiles with editable parameter
156      */
157     Map<String, DocumentRenderer> locateDocumentFiles( SiteRenderingContext siteRenderingContext )
158         throws IOException, RendererException;
159 
160     /**
161      * Locate Doxia document source files in the site source context.
162      *
163      * @param siteRenderingContext the SiteRenderingContext to use
164      * @param editable Doxia document renderer as editable? (should not set editable if generated Doxia source)
165      * @return the Doxia document renderers in a Map keyed by output file name.
166      * @throws IOException if it bombs.
167      * @throws RendererException if it bombs.
168      * @since 1.8
169      */
170     Map<String, DocumentRenderer> locateDocumentFiles( SiteRenderingContext siteRenderingContext, boolean editable )
171         throws IOException, RendererException;
172 
173     /**
174      * Render a document written in a Doxia markup language. This method is an internal method, used by
175      * {@link DoxiaDocumentRenderer}.
176      *
177      * @param writer the writer to render the document to.
178      * @param docRenderingContext the document's rendering context, which is expected to have a non-null parser id.
179      * @param siteContext the site's rendering context
180      * @throws RendererException if it bombs.
181      * @throws FileNotFoundException if it bombs.
182      * @throws UnsupportedEncodingException if it bombs.
183      */
184     void renderDocument( Writer writer, RenderingContext docRenderingContext, SiteRenderingContext siteContext )
185         throws RendererException, FileNotFoundException, UnsupportedEncodingException;
186 }