⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 strutsxmlconfigurationprovider.java

📁 struts 2 核心包 的源码 有错误是难免的
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   StrutsXmlConfigurationProvider.java

package org.apache.struts2.config;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import com.opensymphony.xwork2.inject.*;
import com.opensymphony.xwork2.util.location.LocatableProperties;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class StrutsXmlConfigurationProvider extends XmlConfigurationProvider
{

	private static final Log LOG = LogFactory.getLog(org/apache/struts2/config/StrutsXmlConfigurationProvider);
	private File baseDir;
	private String filename;
	private String reloadKey;
	private ServletContext servletContext;

	public StrutsXmlConfigurationProvider(boolean errorIfMissing)
	{
		this("struts.xml", errorIfMissing, null);
	}

	public StrutsXmlConfigurationProvider(String filename, boolean errorIfMissing, ServletContext ctx)
	{
		super(filename, errorIfMissing);
		baseDir = null;
		servletContext = ctx;
		this.filename = filename;
		reloadKey = (new StringBuilder()).append("configurationReload-").append(filename).toString();
		Map dtdMappings = new HashMap(getDtdMappings());
		dtdMappings.put("-//Apache Software Foundation//DTD Struts Configuration 2.0//EN", "struts-2.0.dtd");
		setDtdMappings(dtdMappings);
		File file = new File(filename);
		if (file.getParent() != null)
			baseDir = file.getParentFile();
	}

	public void register(ContainerBuilder containerBuilder, LocatableProperties props)
		throws ConfigurationException
	{
		if (servletContext != null && !containerBuilder.contains(javax/servlet/ServletContext))
			containerBuilder.factory(javax/servlet/ServletContext, new Factory() {

				final StrutsXmlConfigurationProvider this$0;

				public Object create(Context context)
					throws Exception
				{
					return servletContext;
				}

			
			{
				this$0 = StrutsXmlConfigurationProvider.this;
				super();
			}
			});
		super.register(containerBuilder, props);
	}

	public void loadPackages()
	{
		ActionContext ctx = ActionContext.getContext();
		ctx.put(reloadKey, Boolean.TRUE);
		super.loadPackages();
	}

	protected Iterator getConfigurationUrls(String fileName)
		throws IOException
	{
		URL url = null;
		if (baseDir != null)
		{
			url = findInFileSystem(fileName);
			if (url == null)
				return super.getConfigurationUrls(fileName);
		}
		if (url != null)
		{
			List list = new ArrayList();
			list.add(url);
			return list.iterator();
		} else
		{
			return super.getConfigurationUrls(fileName);
		}
	}

	protected URL findInFileSystem(String fileName)
		throws IOException
	{
		URL url = null;
		File file = new File(fileName);
		if (LOG.isDebugEnabled())
			LOG.debug((new StringBuilder()).append("Trying to load file ").append(file).toString());
		if (!file.exists())
			file = new File(baseDir, fileName);
		if (file.exists())
			try
			{
				url = file.toURL();
			}
			catch (MalformedURLException e)
			{
				throw new IOException((new StringBuilder()).append("Unable to convert ").append(file).append(" to a URL").toString());
			}
		return url;
	}

	public boolean needsReload()
	{
		ActionContext ctx = ActionContext.getContext();
		return ctx.get(reloadKey) == null && super.needsReload();
	}

	public String toString()
	{
		return (new StringBuilder()).append("Struts XML configuration provider (").append(filename).append(")").toString();
	}


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -