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 2020/10/16 16:31:17 UTC
[myfaces] branch master updated: cosmetics
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 e4b32ff cosmetics
e4b32ff is described below
commit e4b32ffef1d1a626fe89c85908cadb559d2dfaae
Author: Thomas Andraschko <ta...@apache.org>
AuthorDate: Fri Oct 16 18:31:08 2020 +0200
cosmetics
---
.../myfaces/webapp/AbstractFacesInitializer.java | 49 ++++++++--------------
.../myfaces/webapp/FaceletsInitilializer.java | 6 +--
.../myfaces/webapp/FacesELContextListener.java | 6 ++-
.../apache/myfaces/webapp/SourceCodeServlet.java | 12 +-----
.../test/core/runner/AbstractJsfTestContainer.java | 42 +------------------
5 files changed, 27 insertions(+), 88 deletions(-)
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
index a1b7dba..dcd172c 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/AbstractFacesInitializer.java
@@ -92,6 +92,8 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
/**
* Performs all necessary initialization tasks like configuring this JSF
* application.
+ *
+ * @param servletContext The current {@link ServletContext}
*/
@Override
public void initFaces(ServletContext servletContext)
@@ -289,7 +291,7 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
* Note if this does not work out
* move the event handler into the application factory
*
- * @param servletContext the servlet context to be passed down
+ * @param servletContext The current {@link ServletContext}
* @param eventClass the class to be passed down into the dispatching
* code
*/
@@ -302,11 +304,12 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
/**
* Cleans up all remaining resources (well, theoretically).
+ *
+ * @param servletContext The current {@link ServletContext}
*/
@Override
public void destroyFaces(ServletContext servletContext)
{
-
FacesContext facesContext = FacesContext.getCurrentInstance();
if (!WebConfigParamUtils.getBooleanInitParameter(facesContext.getExternalContext(),
@@ -534,10 +537,10 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
/**
* The intention of this method is provide a point where CDI integration is done.
- * Faces Flow and javax.faces.view.ViewScope requires CDI in order to work, so
- * this method should set a BeanManager instance on application map under
- * the key "oam.cdi.BEAN_MANAGER_INSTANCE". The default implementation look on
- * ServletContext first and then use JNDI.
+ * {@link javax.faces.flow.FlowScoped} and {@link javax.faces.view.ViewScoped} requires CDI in order to work,
+ * so this method should set a BeanManager instance on application map under
+ * the key "oam.cdi.BEAN_MANAGER_INSTANCE".
+ * The default implementation look on ServletContext first and then use JNDI.
*
* @param servletContext
* @param externalContext
@@ -550,8 +553,7 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
// directly, so if no CDI api is on the classpath no exception will be thrown.
// Try with servlet context
- Object beanManager = servletContext.getAttribute(
- CDI_SERVLET_CONTEXT_BEAN_MANAGER_ATTRIBUTE);
+ Object beanManager = servletContext.getAttribute(CDI_SERVLET_CONTEXT_BEAN_MANAGER_ATTRIBUTE);
if (beanManager == null)
{
beanManager = lookupBeanManagerFromCDI();
@@ -576,18 +578,15 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
{
try
{
- Class cdiClass = null;
- Method cdiCurrentMethod = null;
- Method cdiGetBeanManagerMethod = null;
- cdiClass = simpleClassForNameNoException("javax.enterprise.inject.spi.CDI");
+ Class cdiClass = ClassUtils.simpleClassForName("javax.enterprise.inject.spi.CDI", false);
if (cdiClass != null)
{
- cdiCurrentMethod = cdiClass.getMethod("current");
+ Method currentMethod = cdiClass.getMethod("current");
+ Object cdi = currentMethod.invoke(null);
- Object cdiInstance = cdiCurrentMethod.invoke(null);
-
- cdiGetBeanManagerMethod = cdiClass.getMethod("getBeanManager");
- return cdiGetBeanManagerMethod.invoke(cdiInstance);
+ Method getBeanManagerMethod = cdiClass.getMethod("getBeanManager");
+ Object beanManager = getBeanManagerMethod.invoke(cdi);
+ return beanManager;
}
}
catch (Exception e)
@@ -596,20 +595,6 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
}
return null;
}
-
- private static Class simpleClassForNameNoException(String type)
- {
- try
- {
- return ClassUtils.classForName(type);
- }
- catch (ClassNotFoundException e)
- {
- //log.log(Level.SEVERE, "Class " + type + " not found", e);
- //Ignore
- return null;
- }
- }
/**
* Try to lookup the CDI BeanManager from JNDI.
@@ -631,7 +616,7 @@ public abstract class AbstractFacesInitializer implements FacesInitializer
}
catch (Throwable t)
{
- //
+ // noop
}
if (lookupMethod != null)
{
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java b/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
index aa4be22..a18b484 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/FaceletsInitilializer.java
@@ -52,7 +52,7 @@ public class FaceletsInitilializer extends org.apache.myfaces.webapp.AbstractFac
{
if (log.isLoggable(Level.FINE))
{
- log.fine("javax.el.ExpressionFactory implementation found: " + candidate);
+ log.fine(ExpressionFactory.class.getName() + " implementation found: " + candidate);
}
break;
}
@@ -61,8 +61,8 @@ public class FaceletsInitilializer extends org.apache.myfaces.webapp.AbstractFac
if (expressionFactory == null)
{
- throw new FacesException("No javax.el.ExpressionFactory found. Please provide" +
- " <context-param> in web.xml: org.apache.myfaces.EXPRESSION_FACTORY");
+ throw new FacesException("No " + ExpressionFactory.class.getName() + " implementation found. "
+ + "Please provide <context-param> in web.xml: org.apache.myfaces.EXPRESSION_FACTORY");
}
buildConfiguration(servletContext, externalContext, expressionFactory);
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/FacesELContextListener.java b/impl/src/main/java/org/apache/myfaces/webapp/FacesELContextListener.java
index bf43725..359c498 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/FacesELContextListener.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/FacesELContextListener.java
@@ -23,14 +23,16 @@ import javax.el.ELContextListener;
import javax.faces.context.FacesContext;
/**
- * EL context listener which installs the faces context (if present) into el context and dispatches el context events to
- * faces application el context listeners.
+ * {@link ELContextListener} which installs the {@link FacesContext} (if present),
+ * into the {@link javax.el.ELContext} and dispatches ELContext events to
+ * the Faces application #{@link ELContextListener}.
*
* @author Mathias Broekelmann (latest modification by $Author$)
* @version $Revision$ $Date$
*/
public class FacesELContextListener implements ELContextListener
{
+ @Override
public void contextCreated(ELContextEvent ece)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
diff --git a/impl/src/main/java/org/apache/myfaces/webapp/SourceCodeServlet.java b/impl/src/main/java/org/apache/myfaces/webapp/SourceCodeServlet.java
index c4b4f32..4e9de0a 100644
--- a/impl/src/main/java/org/apache/myfaces/webapp/SourceCodeServlet.java
+++ b/impl/src/main/java/org/apache/myfaces/webapp/SourceCodeServlet.java
@@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletResponse;
public class SourceCodeServlet extends HttpServlet
{
+ @Override
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
@@ -52,22 +53,13 @@ public class SourceCodeServlet extends HttpServlet
ServletOutputStream out = res.getOutputStream();
// print the file
- InputStream in = null;
- try
+ try (InputStream in = new BufferedInputStream(new FileInputStream(realPath)))
{
- in = new BufferedInputStream(new FileInputStream(realPath));
int ch;
while ((ch = in.read()) !=-1)
{
out.print((char)ch);
}
}
- finally
- {
- if (in != null)
- {
- in.close(); // very important
- }
- }
}
}
diff --git a/impl/src/test/java/org/apache/myfaces/test/core/runner/AbstractJsfTestContainer.java b/impl/src/test/java/org/apache/myfaces/test/core/runner/AbstractJsfTestContainer.java
index eb6ed84..07c0f4b 100644
--- a/impl/src/test/java/org/apache/myfaces/test/core/runner/AbstractJsfTestContainer.java
+++ b/impl/src/test/java/org/apache/myfaces/test/core/runner/AbstractJsfTestContainer.java
@@ -1567,8 +1567,7 @@ public class AbstractJsfTestContainer
}
if (beanManager != null)
{
- externalContext.getApplicationMap().put(CDI_BEAN_MANAGER_INSTANCE,
- beanManager);
+ externalContext.getApplicationMap().put(CDI_BEAN_MANAGER_INSTANCE, beanManager);
}
}
@@ -1648,105 +1647,66 @@ public class AbstractJsfTestContainer
private FacesConfig metaInfServicesFacesConfig;
private List<FacesConfig> contextSpecifiedFacesConfig;
- /**
- * @return the annotationFacesConfig
- */
public FacesConfig getAnnotationsFacesConfig()
{
return annotationFacesConfig;
}
- /**
- * @param annotationFacesConfig the annotationFacesConfig to set
- */
public void setAnnotationFacesConfig(FacesConfig annotationFacesConfig)
{
this.annotationFacesConfig = annotationFacesConfig;
}
- /**
- * @return the annotationFacesConfig
- */
public FacesConfig getAnnotationFacesConfig()
{
return annotationFacesConfig;
}
- /**
- * @return the faceletTaglibFacesConfig
- */
public List<FacesConfig> getFaceletTaglibFacesConfig()
{
return faceletTaglibFacesConfig;
}
- /**
- * @param faceletTaglibFacesConfig the faceletTaglibFacesConfig to set
- */
public void setFaceletTaglibFacesConfig(List<FacesConfig> faceletTaglibFacesConfig)
{
this.faceletTaglibFacesConfig = faceletTaglibFacesConfig;
}
- /**
- * @return the facesFlowFacesConfig
- */
public List<FacesConfig> getFacesFlowFacesConfig()
{
return facesFlowFacesConfig;
}
- /**
- * @param facesFlowFacesConfig the facesFlowFacesConfig to set
- */
public void setFacesFlowFacesConfig(List<FacesConfig> facesFlowFacesConfig)
{
this.facesFlowFacesConfig = facesFlowFacesConfig;
}
- /**
- * @return the metaInfServicesFacesConfig
- */
public FacesConfig getMetaInfServicesFacesConfig()
{
return metaInfServicesFacesConfig;
}
- /**
- * @param metaInfServicesFacesConfig the metaInfServicesFacesConfig to set
- */
public void setMetaInfServicesFacesConfig(FacesConfig metaInfServicesFacesConfig)
{
this.metaInfServicesFacesConfig = metaInfServicesFacesConfig;
}
- /**
- * @return the contextSpecifiedFacesConfig
- */
public List<FacesConfig> getContextSpecifiedFacesConfig()
{
return contextSpecifiedFacesConfig;
}
- /**
- * @param contextSpecifiedFacesConfig the contextSpecifiedFacesConfig to set
- */
public void setContextSpecifiedFacesConfig(List<FacesConfig> contextSpecifiedFacesConfig)
{
this.contextSpecifiedFacesConfig = contextSpecifiedFacesConfig;
}
- /**
- * @return the classloaderFacesConfigList
- */
public List<FacesConfig> getClassloaderFacesConfig()
{
return classloaderFacesConfig;
}
- /**
- * @param classloaderFacesConfigList the classloaderFacesConfigList to set
- */
public void setClassloaderFacesConfig(List<FacesConfig> classloaderFacesConfigList)
{
this.classloaderFacesConfig = classloaderFacesConfigList;