myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From manol...@apache.org
Subject svn commit: r379755 - in /myfaces/commons/trunk/src/main/java/org/apache/myfaces: config/MyfacesConfig.java renderkit/html/util/AddResourceFactory.java
Date Wed, 22 Feb 2006 11:44:48 GMT
Author: manolito
Date: Wed Feb 22 03:44:39 2006
New Revision: 379755

URL: http://svn.apache.org/viewcvs?rev=379755&view=rev
Log:
Additional javadoc, setter methods and all String constants private instead of public

Modified:
    myfaces/commons/trunk/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
    myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResourceFactory.java

Modified: myfaces/commons/trunk/src/main/java/org/apache/myfaces/config/MyfacesConfig.java
URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/config/MyfacesConfig.java?rev=379755&r1=379754&r2=379755&view=diff
==============================================================================
--- myfaces/commons/trunk/src/main/java/org/apache/myfaces/config/MyfacesConfig.java (original)
+++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/config/MyfacesConfig.java Wed Feb
22 03:44:39 2006
@@ -16,15 +16,12 @@
 
 package org.apache.myfaces.config;
 
-/**
- * @author Manfred Geiler (latest modification by $Author$)
- * @version $Revision$ $Date$
- */
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.renderkit.html.util.DefaultAddResource;
 
 import javax.faces.context.ExternalContext;
+import javax.servlet.ServletContext;
 
 /**
  * Holds all configuration init parameters (from web.xml) that are independent
@@ -32,6 +29,15 @@
  * all shared, component and implementation classes.
  * See RuntimeConfig for configuration infos that come from the faces-config
  * files and are needed by the core implementation.
+ *
+ * MyfacesConfig is meant for components that implement some of the extended features
+ * of MyFaces. Anyhow, using the MyFaces JSF implementation is no precondition for using
+ * MyfacesConfig in custom components. Upon using another JSF implementation
+ * (or omitting the extended init parameters) all config properties will simply have
+ * their default values.
+ *
+ * @author Manfred Geiler (latest modification by $Author$)
+ * @version $Revision$ $Date$
  */
 public class MyfacesConfig
 {
@@ -51,8 +57,9 @@
     private static final String  INIT_PARAM_AUTO_SCROLL = "org.apache.myfaces.AUTO_SCROLL";
     private static final boolean INIT_PARAM_AUTO_SCROLL_DEFAULT = false;
 
-	public static final String INIT_PARAM_ADD_RESOURCE_CLASS = "org.apache.myfaces.ADD_RESOURCE_CLASS";
-	    
+    private static final String INIT_PARAM_ADD_RESOURCE_CLASS = "org.apache.myfaces.ADD_RESOURCE_CLASS";
+    private static final String INIT_PARAM_ADD_RESOURCE_CLASS_DEFAULT = DefaultAddResource.class.getName();
+
     private boolean _prettyHtml;
     private boolean _detectJavascript;
     private boolean _allowJavascript;
@@ -69,15 +76,15 @@
         extCtx.getApplicationMap().put(APPLICATION_MAP_PARAM_NAME, myfacesConfig);
 
         myfacesConfig.setPrettyHtml(getBooleanInitParameter(extCtx, INIT_PARAM_PRETTY_HTML,
-                                                                    INIT_PARAM_PRETTY_HTML_DEFAULT));
+                                                            INIT_PARAM_PRETTY_HTML_DEFAULT));
         myfacesConfig.setAllowJavascript(getBooleanInitParameter(extCtx, INIT_PARAM_ALLOW_JAVASCRIPT,
-                                                                         INIT_PARAM_ALLOW_JAVASCRIPT_DEFAULT));
+                                                                 INIT_PARAM_ALLOW_JAVASCRIPT_DEFAULT));
         myfacesConfig.setDetectJavascript(getBooleanInitParameter(extCtx, INIT_PARAM_DETECT_JAVASCRIPT,
-                                                                          INIT_PARAM_DETECT_JAVASCRIPT_DEFAULT));
+                                                                  INIT_PARAM_DETECT_JAVASCRIPT_DEFAULT));
         myfacesConfig.setAutoScroll(getBooleanInitParameter(extCtx, INIT_PARAM_AUTO_SCROLL,
-                                                                    INIT_PARAM_AUTO_SCROLL_DEFAULT));
-        myfacesConfig.setAddResourceClass(extCtx.getInitParameter(INIT_PARAM_ADD_RESOURCE_CLASS));
-
+                                                            INIT_PARAM_AUTO_SCROLL_DEFAULT));
+        myfacesConfig.setAddResourceClass(getStringInitParameter(extCtx, INIT_PARAM_ADD_RESOURCE_CLASS,
+                                                                 INIT_PARAM_ADD_RESOURCE_CLASS_DEFAULT));
         return myfacesConfig;
     }
 
@@ -106,12 +113,28 @@
         }
     }
 
+    private static String getStringInitParameter(ExternalContext externalContext,
+                                                 String paramName,
+                                                 String defaultValue)
+    {
+        String strValue = externalContext.getInitParameter(paramName);
+        if (strValue == null)
+        {
+            if (log.isInfoEnabled()) log.info("No context init parameter '" + paramName +
"' found, using default value " + defaultValue); //defaultValue==null should not be a problem
here
+            return defaultValue;
+        }
+        else
+        {
+            return strValue;
+        }
+    }
+
     public boolean isPrettyHtml()
     {
         return _prettyHtml;
     }
 
-    public void setPrettyHtml(boolean prettyHtml)
+    private void setPrettyHtml(boolean prettyHtml)
     {
         _prettyHtml = prettyHtml;
     }
@@ -121,7 +144,7 @@
         return _detectJavascript;
     }
 
-    public void setDetectJavascript(boolean detectJavascript)
+    private void setDetectJavascript(boolean detectJavascript)
     {
         _detectJavascript = detectJavascript;
     }
@@ -136,7 +159,7 @@
         return _allowJavascript;
     }
 
-    public void setAllowJavascript(boolean allowJavascript)
+    private void setAllowJavascript(boolean allowJavascript)
     {
         _allowJavascript = allowJavascript;
     }
@@ -146,18 +169,35 @@
         return _autoScroll;
     }
 
-    public void setAutoScroll(boolean autoScroll)
+    private void setAutoScroll(boolean autoScroll)
     {
         _autoScroll = autoScroll;
     }
 
-    public void setAddResourceClass(String addResourceClass)
+    private void setAddResourceClass(String addResourceClass)
     {
-    	_addResourceClass = addResourceClass;
+        _addResourceClass = addResourceClass;
     }
-    
+
     public String getAddResourceClass()
     {
-		return _addResourceClass;
-	}
+        return _addResourceClass;
+    }
+
+    /**
+     * ExtensionFilter needs access to AddResourceClass init param without having
+     * an ExternalContext at hand.
+     */
+    public static String getAddResourceClassFromServletContext(ServletContext servletContext)
+    {
+        String addResourceClass = servletContext.getInitParameter(INIT_PARAM_ADD_RESOURCE_CLASS);
+        if (addResourceClass == null)
+        {
+            return INIT_PARAM_ADD_RESOURCE_CLASS_DEFAULT;
+        }
+        else
+        {
+            return addResourceClass;
+        }
+    }
 }

Modified: myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResourceFactory.java
URL: http://svn.apache.org/viewcvs/myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResourceFactory.java?rev=379755&r1=379754&r2=379755&view=diff
==============================================================================
--- myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResourceFactory.java
(original)
+++ myfaces/commons/trunk/src/main/java/org/apache/myfaces/renderkit/html/util/AddResourceFactory.java
Wed Feb 22 03:44:39 2006
@@ -159,13 +159,14 @@
     public static AddResource getInstance(FacesContext context)
     {
         return getInstance(context.getExternalContext().getRequestContextPath(),
-        		MyfacesConfig.getCurrentInstance(context.getExternalContext()).getAddResourceClass());
+                           MyfacesConfig.getCurrentInstance(context.getExternalContext()).getAddResourceClass());
     }
 
     public static AddResource getInstance(HttpServletRequest request)
     {
         ServletContext servletContext = ((HttpServletRequest)request).getSession().getServletContext();
-        return getInstance(request.getContextPath(), servletContext.getInitParameter(MyfacesConfig.INIT_PARAM_ADD_RESOURCE_CLASS));
+        return getInstance(request.getContextPath(),
+                           MyfacesConfig.getAddResourceClassFromServletContext(servletContext));
     }
 
 }



Mime
View raw message