public void mergeDocumentIntoSite()

in doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java [642:699]


    public void mergeDocumentIntoSite(Writer writer, DocumentContent content, SiteRenderingContext siteRenderingContext)
            throws RendererException {
        String templateName = siteRenderingContext.getTemplateName();

        LOGGER.debug("Processing Velocity for template " + templateName + " on "
                + content.getRenderingContext().getDoxiaSourcePath());

        Context context = createSiteTemplateVelocityContext(content, siteRenderingContext);

        ClassLoader old = null;

        if (siteRenderingContext.getTemplateClassLoader() != null) {
            // -------------------------------------------------------------------------
            // If no template classloader was set we'll just use the context classloader
            // -------------------------------------------------------------------------

            old = Thread.currentThread().getContextClassLoader();

            Thread.currentThread().setContextClassLoader(siteRenderingContext.getTemplateClassLoader());
        }

        try {
            Template template;
            Artifact skin = siteRenderingContext.getSkin();

            try {
                SkinModel skinModel = siteRenderingContext.getSkinModel();
                String encoding = (skinModel == null) ? null : skinModel.getEncoding();

                template = (encoding == null)
                        ? velocity.getEngine().getTemplate(templateName)
                        : velocity.getEngine().getTemplate(templateName, encoding);
            } catch (ParseErrorException pee) {
                throw new RendererException(
                        "Velocity parsing error while reading the site template " + "from " + skin.getId() + " skin",
                        pee);
            } catch (ResourceNotFoundException rnfe) {
                throw new RendererException(
                        "Could not find the site template " + "from " + skin.getId() + " skin", rnfe);
            }

            try {
                StringWriter sw = new StringWriter();
                template.merge(context, sw);
                writer.write(sw.toString().replaceAll("\r?\n", SystemUtils.LINE_SEPARATOR));
            } catch (VelocityException ve) {
                throw new RendererException("Velocity error while merging site template.", ve);
            } catch (IOException ioe) {
                throw new RendererException("IO exception while merging site template.", ioe);
            }
        } finally {
            IOUtil.close(writer);

            if (old != null) {
                Thread.currentThread().setContextClassLoader(old);
            }
        }
    }