/* Copyright 2006 - 2011 Under Dusken Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package no.dusken.aranea.filter; import no.dusken.aranea.plugin.AraneaPlugin; import no.dusken.aranea.plugin.RewriteRule; import org.kantega.jexmec.PluginManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; import org.tuckey.web.filters.urlrewrite.Conf; import org.tuckey.web.filters.urlrewrite.NormalRule; import javax.servlet.ServletContext; import java.io.InputStream; /** * @author Marvin B. Lillehaug <lillehau@underdusken.no> */ public class PluginAwareConf extends Conf { private final Logger log = LoggerFactory.getLogger(PluginAwareConf.class); private final String araneaPluginManagerName = "pluginManagerAraneaPlugin"; private PluginManager<AraneaPlugin> pluginManager; public PluginAwareConf(ServletContext context, InputStream inputStream, String fileName, String systemId) { super(context, inputStream, fileName, systemId); WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(context); pluginManager = webApplicationContext.getBean(araneaPluginManagerName, PluginManager.class); addPluginRules(context); } private void addPluginRules(ServletContext context) { for(AraneaPlugin plugin : pluginManager.getPlugins()){ for(RewriteRule rewriteRule : plugin.getRewriteRules()){ NormalRule rule = new NormalRule(); String from = rewriteRule.getFrom(); rule.setFrom(from); String to = rewriteRule.getTo(); rule.setTo(to); rule.setMatchType(rewriteRule.getMatchType().name()); log.info("Creating plugin rewriterule from: {} to {}", from, to); rule.initialise(context); insertRule(rule); } } } }