Search in sources :

Example 1 with DefaultConfiguration

use of org.apache.avalon.framework.configuration.DefaultConfiguration in project xwiki-platform by xwiki.

the class FOPXSLFORenderer method extendConfiguration.

private void extendConfiguration(DefaultConfiguration writableConfiguration) {
    // Add XWiki fonts folder to the configuration.
    try {
        String fontsPath = this.environment.getResource(FONTS_PATH).getPath();
        XWikiContext xcontext = this.xcontextProvider.get();
        if (xcontext != null) {
            XWikiRequest request = xcontext.getRequest();
            if (request != null && request.getSession() != null) {
                fontsPath = request.getSession().getServletContext().getRealPath(FONTS_PATH);
            }
        }
        // <renderers>
        DefaultConfiguration renderersConfiguration = (DefaultConfiguration) writableConfiguration.getChild(RENDERERS, false);
        if (renderersConfiguration == null) {
            renderersConfiguration = new DefaultConfiguration(RENDERERS);
            writableConfiguration.addChild(renderersConfiguration);
        }
        // Ensure we have support for PDF rendering.
        // <renderer mime="application/pdf">
        DefaultConfiguration pdfRenderer = null;
        for (Configuration renderer : renderersConfiguration.getChildren()) {
            if (MIME_TYPE_PDF.equals(renderer.getAttribute(MIME))) {
                pdfRenderer = (DefaultConfiguration) renderer;
            }
        }
        if (pdfRenderer == null) {
            pdfRenderer = new DefaultConfiguration("renderer");
            pdfRenderer.setAttribute(MIME, MIME_TYPE_PDF);
            renderersConfiguration.addChild(pdfRenderer);
        }
        // <fonts>
        DefaultConfiguration fontsConfiguration = (DefaultConfiguration) pdfRenderer.getChild(FONTS, false);
        if (fontsConfiguration == null) {
            fontsConfiguration = new DefaultConfiguration(FONTS);
            pdfRenderer.addChild(fontsConfiguration);
        }
        // <directory>fontdirectory</directory>
        DefaultConfiguration directoryConfiguration = new DefaultConfiguration("directory");
        directoryConfiguration.setValue(fontsPath);
        fontsConfiguration.addChild(directoryConfiguration);
    } catch (Exception e) {
        this.logger.warn("Starting with 1.5, XWiki uses the WEB-INF/fonts/ directory as the font directory, " + "and it should contain the FreeFont (http://savannah.gnu.org/projects/freefont/) fonts. " + "FOP cannot access this directory. If this is an upgrade from a previous version, " + "make sure you also copy the WEB-INF/fonts directory from the new distribution package.");
    }
}
Also used : XWikiRequest(com.xpn.xwiki.web.XWikiRequest) DefaultConfiguration(org.apache.avalon.framework.configuration.DefaultConfiguration) Configuration(org.apache.avalon.framework.configuration.Configuration) XWikiContext(com.xpn.xwiki.XWikiContext) DefaultConfiguration(org.apache.avalon.framework.configuration.DefaultConfiguration) InitializationException(org.xwiki.component.phase.InitializationException) ConfigurationException(org.apache.avalon.framework.configuration.ConfigurationException)

Aggregations

XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiRequest (com.xpn.xwiki.web.XWikiRequest)1 Configuration (org.apache.avalon.framework.configuration.Configuration)1 ConfigurationException (org.apache.avalon.framework.configuration.ConfigurationException)1 DefaultConfiguration (org.apache.avalon.framework.configuration.DefaultConfiguration)1 InitializationException (org.xwiki.component.phase.InitializationException)1