You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ta...@apache.org on 2018/12/16 19:31:00 UTC
[myfaces] branch master updated: removed unused code
This is an automated email from the ASF dual-hosted git repository.
tandraschko pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces.git
The following commit(s) were added to refs/heads/master by this push:
new ae3da45 removed unused code
ae3da45 is described below
commit ae3da459a80115650e81ca89d870183f0c9c434b
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Sun Dec 16 20:31:07 2018 +0100
removed unused code
---
.../myfaces/webapp/webxml/ServletMapping.java | 84 ----------
.../org/apache/myfaces/webapp/webxml/WebXml.java | 129 ---------------
.../apache/myfaces/webapp/webxml/WebXmlParser.java | 183 ---------------------
.../webapp/webxml/WebXmlParserErrorHandler.java | 3 +-
.../myfaces/webapp/webxml/WebXmlParserUtils.java | 105 ------------
.../shared/webapp/webxml/ServletMappingTest.java | 53 ------
6 files changed, 1 insertion(+), 556 deletions(-)
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/webxml/ServletMapping.java b/impl/src/main/java/org/apache/myfaces/webapp/webxml/ServletMapping.java
deleted file mode 100755
index 5d1e15a..0000000
--- a/impl/src/main/java/org/apache/myfaces/webapp/webxml/ServletMapping.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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;
-
-public class ServletMapping
-{
- private final String _servletName;
- private final Class _servletClass;
- private final String _urlPattern;
- private final String _extension;
- private final String _prefix;
-
- public ServletMapping(String servletName, Class servletClass, String urlPattern)
- {
- _servletName = servletName;
- _servletClass = servletClass;
- _urlPattern = urlPattern;
- _extension = _urlPattern != null && _urlPattern.startsWith("*.")
- ? _urlPattern.substring(_urlPattern.indexOf('.'))
- : null;
- if (_extension == null)
- {
- int index = _urlPattern.indexOf("/*");
- if (index != -1)
- {
- _prefix = _urlPattern.substring(0, _urlPattern.indexOf("/*"));
- }
- else
- {
- _prefix = _urlPattern;
- }
- }
- else
- {
- _prefix = null;
- }
- }
-
- public boolean isExtensionMapping()
- {
- return _extension != null;
- }
-
- public String getExtension()
- {
- return _extension;
- }
-
- public String getPrefix()
- {
- return _prefix;
- }
-
- public String getServletName()
- {
- return _servletName;
- }
-
- public Class getServletClass()
- {
- return _servletClass;
- }
-
- public String getUrlPattern()
- {
- return _urlPattern;
- }
-}
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXml.java b/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXml.java
index 632910f..677e888 100755
--- a/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXml.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXml.java
@@ -18,16 +18,9 @@
*/
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 java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.context.ExternalContext;
-import javax.faces.webapp.FacesServlet;
import org.apache.myfaces.config.MyfacesConfig;
@@ -35,134 +28,12 @@ public class WebXml
{
private static final Logger log = Logger.getLogger(WebXml.class.getName());
-
private static long refreshPeriod;
private long parsingTime;
- private Map _servlets = new HashMap();
- private Map _servletMappings = new HashMap();
- private Map _filters = new HashMap();
- private Map _filterMappings = new HashMap();
-
- private volatile List _facesServletMappings = null;
-
private String _delegateFacesServlet = null;
private boolean errorPagePresent = false;
- void addServlet(String servletName, String servletClass)
- {
- if (_servlets.get(servletName) != null)
- {
- log.warning("Servlet " + servletName + " defined more than once, first definition will be used.");
- }
- else
- {
- _servlets.put(servletName, servletClass);
- }
- }
-
- void addFilter(String filterName, String filterClass)
- {
- if (_filters.get(filterName) != null)
- {
- log.warning("Filter " + filterName + " defined more than once, first definition will be used.");
- }
- else
- {
- _filters.put(filterName, filterClass);
- }
- }
-
- boolean containsServlet(String servletName)
- {
- return _servlets.containsKey(servletName);
- }
-
- boolean containsFilter(String filterName)
- {
- return _filters.containsKey(filterName);
- }
-
- 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);
- }
-
- void addFilterMapping(String filterName, String urlPattern)
- {
- List mappings = (List)_filterMappings.get(filterName);
- if (mappings == null)
- {
- mappings = new ArrayList();
- _filterMappings.put(filterName, mappings);
- }
- mappings.add(urlPattern);
- }
-
- public List getFacesServletMappings()
- {
- if (_facesServletMappings != null)
- {
- return _facesServletMappings;
- }
-
- List tempFacesServletMappings = 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
- // <servlet>
- // <servlet-name>JspRedirector</servlet-name>
- // <jsp-file>/jspRedirector.jsp</jsp-file>
- // </servlet>
- continue;
- }
- Class servletClass = org.apache.myfaces.util.ClassUtils.simpleClassForName((String)entry.getValue());
- if (FacesServlet.class.isAssignableFrom(servletClass) ||
- DelegatedFacesServlet.class.isAssignableFrom(servletClass) ||
- servletClass.getName().equals(_delegateFacesServlet))
- {
- List urlPatterns = (List)_servletMappings.get(servletName);
- if( urlPatterns != null )
- {
- for (Iterator it2 = urlPatterns.iterator(); it2.hasNext(); )
- {
- String urlpattern = (String)it2.next();
- tempFacesServletMappings.add(new org.apache.myfaces.webapp.webxml.ServletMapping(servletName,
- servletClass,
- urlpattern));
- if (log.isLoggable(Level.FINEST))
- {
- log.finest("adding mapping for servlet + " + servletName + " urlpattern = " + urlpattern);
- }
- }
- }
- }
- else
- {
- if (log.isLoggable(Level.FINEST))
- {
- log.finest("ignoring servlet + " + servletName + ' ' + servletClass + " (no FacesServlet)");
- }
- }
- }
-
- //Expose to all threads
- _facesServletMappings = tempFacesServletMappings;
-
- return _facesServletMappings;
- }
-
protected void setParsingTime(long parsingTime)
{
this.parsingTime = parsingTime;
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParser.java b/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParser.java
index ee6ae71..d790bf4 100755
--- a/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParser.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParser.java
@@ -195,22 +195,6 @@ public class WebXmlParser
Node n = nodeList.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE)
{
- if (n.getNodeName().equals("servlet"))
- {
- readServlet((Element)n);
- }
- if (n.getNodeName().equals("servlet-mapping"))
- {
- readServletMapping((Element)n);
- }
- if (n.getNodeName().equals("filter"))
- {
- readFilter((Element)n);
- }
- if (n.getNodeName().equals("filter-mapping"))
- {
- readFilterMapping((Element)n);
- }
if (n.getNodeName().equals("error-page"))
{
_webXml.setErrorPagePresent(true);
@@ -226,171 +210,4 @@ public class WebXmlParser
}
}
- private void readServlet(Element servletElem)
- {
- String servletName = null;
- String servletClass = null;
- NodeList nodeList = servletElem.getChildNodes();
- for (int i = 0, len = nodeList.getLength(); i < len; i++)
- {
- Node n = nodeList.item(i);
- if (n.getNodeType() == Node.ELEMENT_NODE)
- {
- if (n.getNodeName().equals("servlet-name"))
- {
- servletName = WebXmlParserUtils.getElementText((Element)n);
- }
- else if (n.getNodeName().equals("servlet-class"))
- {
- servletClass = WebXmlParserUtils.getElementText((Element)n).trim();
- }
- else if (n.getNodeName().equals("description") || n.getNodeName().equals("load-on-startup")
- || n.getNodeName().equals("init-param"))
- {
- //ignore
- }
- else
- {
- if (log.isLoggable(Level.FINE))
- {
- log.fine("Ignored element '" + n.getNodeName() + "' as child of '" +
- servletElem.getNodeName() + "'.");
- }
- }
- }
- else
- {
- if (log.isLoggable(Level.FINE))
- {
- log.fine("Ignored node '" + n.getNodeName() + "' of type " + n.getNodeType());
- }
- }
- }
- _webXml.addServlet(servletName, servletClass);
- }
-
-
- private void readServletMapping(Element servletMappingElem)
- {
- String servletName = null;
- String urlPattern = null;
- NodeList nodeList = servletMappingElem.getChildNodes();
- for (int i = 0, len = nodeList.getLength(); i < len; i++)
- {
- Node n = nodeList.item(i);
- if (n.getNodeType() == Node.ELEMENT_NODE)
- {
- if (n.getNodeName().equals("servlet-name"))
- {
- servletName = WebXmlParserUtils.getElementText((Element)n);
- }
- else if (n.getNodeName().equals("url-pattern"))
- {
- urlPattern = WebXmlParserUtils.getElementText((Element)n).trim();
- }
- else
- {
- if (log.isLoggable(Level.FINE))
- {
- log.fine("Ignored element '" + n.getNodeName() + "' as child of '" +
- servletMappingElem.getNodeName() + "'.");
- }
- }
- }
- else
- {
- if (log.isLoggable(Level.FINE))
- {
- log.fine("Ignored node '" + n.getNodeName() + "' of type " + n.getNodeType());
- }
- }
- }
- urlPattern = urlPattern.trim();
- _webXml.addServletMapping(servletName, urlPattern);
- }
-
- private void readFilter(Element filterElem)
- {
- String filterName = null;
- String filterClass = null;
- NodeList nodeList = filterElem.getChildNodes();
- for (int i = 0, len = nodeList.getLength(); i < len; i++)
- {
- Node n = nodeList.item(i);
- if (n.getNodeType() == Node.ELEMENT_NODE)
- {
- if (n.getNodeName().equals("filter-name"))
- {
- filterName = WebXmlParserUtils.getElementText((Element)n).trim();
- }
- else if (n.getNodeName().equals("filter-class"))
- {
- filterClass = WebXmlParserUtils.getElementText((Element)n).trim();
- }
- else if (n.getNodeName().equals("description") || n.getNodeName().equals("init-param"))
- {
- //ignore
- }
- else
- {
- if (log.isLoggable(Level.FINE))
- {
- log.fine("Ignored element '" + n.getNodeName() + "' as child of '" +
- filterElem.getNodeName() + "'.");
- }
- }
- }
- else
- {
- if (log.isLoggable(Level.FINE))
- {
- log.fine("Ignored node '" + n.getNodeName() + "' of type " + n.getNodeType());
- }
- }
- }
- _webXml.addFilter(filterName, filterClass);
- }
-
-
- private void readFilterMapping(Element filterMappingElem)
- {
- String filterName = null;
- String urlPattern = null;
- NodeList nodeList = filterMappingElem.getChildNodes();
- for (int i = 0, len = nodeList.getLength(); i < len; i++)
- {
- Node n = nodeList.item(i);
- if (n.getNodeType() == Node.ELEMENT_NODE)
- {
- if (n.getNodeName().equals("filter-name"))
- {
- filterName = WebXmlParserUtils.getElementText((Element)n).trim();
- }
- else if (n.getNodeName().equals("url-pattern"))
- {
- urlPattern = WebXmlParserUtils.getElementText((Element)n).trim();
- }
- else if (n.getNodeName().equals("servlet-name"))
- {
- // we are not interested in servlet-name based mapping - for now
- }
- else
- {
- if (log.isLoggable(Level.FINE))
- {
- log.fine("Ignored element '" + n.getNodeName() + "' as child of '" +
- filterMappingElem.getNodeName() + "'.");
- }
- }
- }
- else
- {
- if (log.isLoggable(Level.FINE))
- {
- log.fine("Ignored node '" + n.getNodeName() + "' of type " + n.getNodeType());
- }
- }
- }
- _webXml.addFilterMapping(filterName, urlPattern);
- }
}
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParserErrorHandler.java b/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParserErrorHandler.java
index b5e6de8..4df13f1 100755
--- a/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParserErrorHandler.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParserErrorHandler.java
@@ -27,8 +27,7 @@ import org.xml.sax.SAXParseException;
/**
* Convenient error handler for xml sax parsing.
*/
-public class WebXmlParserErrorHandler
- implements ErrorHandler
+public class WebXmlParserErrorHandler implements ErrorHandler
{
private Logger _log;
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParserUtils.java b/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParserUtils.java
deleted file mode 100755
index 7274d6d..0000000
--- a/impl/src/main/java/org/apache/myfaces/webapp/webxml/WebXmlParserUtils.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-public class WebXmlParserUtils
-{
- private WebXmlParserUtils()
- {
- // hide from public access
- }
-
- public static String getElementText(Element elem)
- {
- StringBuilder buf = new StringBuilder();
- NodeList nodeList = elem.getChildNodes();
- for (int i = 0, len = nodeList.getLength(); i < len; i++)
- {
- Node n = nodeList.item(i);
- if (n.getNodeType() == Node.TEXT_NODE)
- {
- buf.append(n.getNodeValue());
- }
- else
- {
- //TODO see jsf-samples
- //throw new FacesException("Unexpected node type " + n.getNodeType());
- }
- }
- return buf.toString();
- }
-
-
-
- /**
- * Return content of child element with given tag name.
- * If more than one children with this name are present, the content of the last
- * element is returned.
- *
- * @param elem
- * @param childTagName
- * @return content of child element or null if no child element with this name was found
- */
- public static String getChildText(Element elem, String childTagName)
- {
- NodeList nodeList = elem.getElementsByTagName(childTagName);
- int len = nodeList.getLength();
- if (len == 0)
- {
- return null;
- }
-
- return getElementText((Element)nodeList.item(len - 1));
-
- }
-
-
- /**
- * Return list of content Strings of all child elements with given tag name.
- * @param elem
- * @param childTagName
- * @return List
- */
- public static List getChildTextList(Element elem, String childTagName)
- {
- NodeList nodeList = elem.getElementsByTagName(childTagName);
- int len = nodeList.getLength();
- if (len == 0)
- {
- return Collections.EMPTY_LIST;
- }
-
- List list = new ArrayList(len);
- for (int i = 0; i < len; i++)
- {
- list.add(getElementText((Element)nodeList.item(i)));
- }
- return list;
-
- }
-
-}
diff --git a/impl/src/test/java/org/apache/myfaces/shared/webapp/webxml/ServletMappingTest.java b/impl/src/test/java/org/apache/myfaces/shared/webapp/webxml/ServletMappingTest.java
deleted file mode 100644
index 43bd76a..0000000
--- a/impl/src/test/java/org/apache/myfaces/shared/webapp/webxml/ServletMappingTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.shared.webapp.webxml;
-
-import org.apache.myfaces.webapp.webxml.ServletMapping;
-import org.junit.Assert;
-import org.junit.Test;
-
-public class ServletMappingTest
-{
-
- /**
- * Test method for
- * {@link org.apache.myfaces.shared.webapp.webxml.ServletMapping#ServletMapping(java.lang.String, java.lang.Class, java.lang.String)}.
- */
- @Test
- public void testExtensionServletMapping()
- {
- ServletMapping mapping = new ServletMapping("xxx", Object.class, "*.faces");
- Assert.assertTrue(mapping.isExtensionMapping());
- Assert.assertEquals(".faces", mapping.getExtension());
- Assert.assertEquals("*.faces", mapping.getUrlPattern());
- }
-
- /**
- * Test method for
- * {@link org.apache.myfaces.shared.webapp.webxml.ServletMapping#ServletMapping(java.lang.String, java.lang.Class, java.lang.String)}.
- */
- @Test
- public void testPrefixServletMapping()
- {
- ServletMapping mapping = new ServletMapping("xxx", Object.class, "/faces/*");
- Assert.assertFalse(mapping.isExtensionMapping());
- Assert.assertEquals("/faces/*", mapping.getUrlPattern());
- Assert.assertEquals("/faces", mapping.getPrefix());
- }
-}