
org.apache.myfaces.webapp.webxml.WebXml Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of myfaces-commons Show documentation
Show all versions of myfaces-commons Show documentation
The MyFaces Commons Subproject provides base classes for usage in both the
MyFaces implementation and the MyFaces Tomahawk components. This is also
a general set of utility classes for usage in your JSF projects independent
of the implementation you might be deciding upon.
The newest version!
/*
* Copyright 2004 The Apache Software Foundation.
*
* 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 org.apache.myfaces.webapp.webxml;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.faces.context.ExternalContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.myfaces.util.ClassUtils;
/**
* @author Manfred Geiler (latest modification by $Author: svieujot $)
* @version $Revision: 280367 $ $Date: 2005-09-12 16:54:36 +0000 (Mon, 12 Sep 2005) $
*/
public class WebXml
{
private static final Log log = LogFactory.getLog(WebXmlParser.class);
private Map _servlets = new HashMap();
private Map _servletMappings = new HashMap();
private List _facesServletMappings = null;
void addServlet(String servletName, String servletClass)
{
if (_servlets.get(servletName) != null)
{
log.warn("Servlet " + servletName + " defined more than once, first definition will be used.");
}
else
{
_servlets.put(servletName, servletClass);
}
}
boolean containsServlet(String servletName)
{
return _servlets.containsKey(servletName);
}
void addServletMapping(String servletName, String urlPattern)
{
List mappings = (List)_servletMappings.get(servletName);
if (mappings == null)
{
mappings = new ArrayList();
_servletMappings.put(servletName, mappings);
}
mappings.add(urlPattern);
}
public List getFacesServletMappings()
{
if (_facesServletMappings != null) return _facesServletMappings;
_facesServletMappings = new ArrayList();
for (Iterator it = _servlets.entrySet().iterator(); it.hasNext(); )
{
Map.Entry entry = (Map.Entry)it.next();
String servletName = (String)entry.getKey();
if (null == entry.getValue())
{
// the value is null in the case of jsp files listed as servlets
// in cactus
//
// JspRedirector
// /jspRedirector.jsp
//
continue;
}
Class servletClass = ClassUtils.simpleClassForName((String)entry.getValue());
// if (FacesServlet.class.isAssignableFrom(servletClass) ||
// DelegatedFacesServlet.class.isAssignableFrom(servletClass))
// {
List urlPatterns = (List)_servletMappings.get(servletName);
if( urlPatterns != null )
{
for (Iterator it2 = urlPatterns.iterator(); it2.hasNext(); )
{
String urlpattern = (String)it2.next();
_facesServletMappings.add(new ServletMapping(servletName,
servletClass,
urlpattern));
if (log.isTraceEnabled())
log.trace("adding mapping for servlet + " + servletName + " urlpattern = " + urlpattern);
}
}
// }
// else
// {
// if (log.isTraceEnabled()) log.trace("ignoring servlet + " + servletName + " " + servletClass + " (no FacesServlet)");
// }
}
return _facesServletMappings;
}
private static final String WEB_XML_ATTR = WebXml.class.getName();
public static WebXml getWebXml(ExternalContext context)
{
WebXml webXml = (WebXml)context.getApplicationMap().get(WEB_XML_ATTR);
if (webXml == null)
{
log.error(WebXml.class.getName() + ".init must be called before!");
throw new IllegalStateException(WebXml.class.getName() + ".init must be called before!");
}
return webXml;
}
/**
* should be called when initialising Servlet
* @param context
*/
public static void init(ExternalContext context)
{
WebXmlParser parser = new WebXmlParser(context);
WebXml webXml = parser.parse();
context.getApplicationMap().put(WEB_XML_ATTR, webXml);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy