    001/*
    002    Licensed to the Apache Software Foundation (ASF) under one
    003    or more contributor license agreements.  See the NOTICE file
    004    distributed with this work for additional information
    005    regarding copyright ownership.  The ASF licenses this file
    006    to you under the Apache License, Version 2.0 (the
    007    "License"); you may not use this file except in compliance
    008    with the License.  You may obtain a copy of the License at
    009
    010       http://www.apache.org/licenses/LICENSE-2.0
    011
    012    Unless required by applicable law or agreed to in writing,
    013    software distributed under the License is distributed on an
    014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015    KIND, either express or implied.  See the License for the
    016    specific language governing permissions and limitations
    017    under the License.
    018 */
    019package org.apache.wiki.markdown;
    020
    021import org.apache.logging.log4j.LogManager;
    022import org.apache.logging.log4j.Logger;
    023import org.apache.wiki.api.engine.EngineLifecycleExtension;
    024
    025import java.util.Properties;
    026
    027
    028/**
    029 * {@link EngineLifecycleExtension} that sets up all the relevant properties to enable markdown syntax if the
    030 * {@code jspwiki.syntax} property has been given, with the {@code markdown} value.
    031 */
    032public class MarkdownSetupEngineLifecycleExtension implements EngineLifecycleExtension {
    033
    034    private static final Logger LOG = LogManager.getLogger( MarkdownSetupEngineLifecycleExtension.class );
    035
    036    /** {@inheritDoc} */
    037    @Override
    038    public void onInit( final Properties properties ) {
    039        if( "markdown".equalsIgnoreCase( properties.getProperty( "jspwiki.syntax" ) ) ) {
    040            setWikiProperty( properties, "jspwiki.renderingManager.markupParser", "org.apache.wiki.parser.markdown.MarkdownParser" );
    041            setWikiProperty( properties, "jspwiki.renderingManager.renderer", "org.apache.wiki.render.markdown.MarkdownRenderer" );
    042            setWikiProperty( properties, "jspwiki.renderingManager.renderer.wysiwyg", "org.apache.wiki.render.markdown.MarkdownRenderer" );
    043            setWikiProperty( properties, "jspwiki.syntax.decorator", "org.apache.wiki.htmltowiki.syntax.markdown.MarkdownSyntaxDecorator" );
    044            setWikiProperty( properties, "jspwiki.syntax.plain", "plain/wiki-snips-markdown.js" );
    045        }
    046    }
    047
    048    void setWikiProperty( final Properties properties, final String key, final String value ) {
    049        properties.setProperty( key, value );
    050        LOG.info( "{} set to {}", key, value );
    051    }
    052
    053}