All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ja.smarkdown.config.servletcontext.ServletContextConfigurationProvider Maven / Gradle / Ivy

Go to download

Reads Smarkdown configuration from the web.xml file. Uses a default configuration if no specific configuration is defined in web.xml.

There is a newer version: 0.8.0
Show newest version
package com.ja.smarkdown.config.servletcontext;

import java.io.StringReader;

import javax.inject.Inject;
import javax.servlet.ServletContext;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;

import com.ja.smarkdown.config.ConfigurationProvider;
import com.ja.smarkdown.model.config.SmarkdownConfiguration;

@Slf4j
public class ServletContextConfigurationProvider implements
		ConfigurationProvider {
	private static final String SMARKDOWN_CONFIGURATION = "smarkdown.configuration";

	@Inject
	private ServletContext servletContext;
	@Inject
	private SmarkdownConfigurationParser parser;

	@Override
	public SmarkdownConfiguration getConfiguration() {
		final String configString = servletContext
				.getInitParameter(SMARKDOWN_CONFIGURATION);
		log.debug("Configuration from web.xml is: {}", configString);

		SmarkdownConfiguration config = null;
		if (StringUtils.isEmpty(configString)) {
			log.info("Using default configuration.");
			config = new DefaultSmarkdownConfiguration();
		} else {
			config = parser.parse(new StringReader(configString));
		}
		return config;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy