You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2010/08/31 21:51:08 UTC

svn commit: r991312 - in /myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main: java/org/apache/myfaces/tobago/example/demo/ServerInfo.java webapp/WEB-INF/faces-config.xml webapp/server-info.jsp

Author: lofwyr
Date: Tue Aug 31 19:51:08 2010
New Revision: 991312

URL: http://svn.apache.org/viewvc?rev=991312&view=rev
Log:
- print out JSF implementation and version
- make enabled/disabled configurable via file

Modified:
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ServerInfo.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/server-info.jsp

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ServerInfo.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ServerInfo.java?rev=991312&r1=991311&r2=991312&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ServerInfo.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/ServerInfo.java Tue Aug 31 19:51:08 2010
@@ -22,22 +22,52 @@ import org.slf4j.LoggerFactory;
 
 import javax.faces.context.FacesContext;
 import javax.servlet.ServletContext;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+/**
+ * The server info class makes some information about the system and application available in the demo.
+ * This is enabled by default, but can be disabled by configuration in a properties file with the key
+ * <code>{@value #ENABLED_KEY}</code>.
+ * The default file name is <code>{@value #CONFIG_FILE_DEFAULT}</code>.
+ * The file name can be changed with a system property with name <code>{@value #CONFIG_FILE}</code>.
+ *
+ */
 public class ServerInfo {
 
   private static final Logger LOG = LoggerFactory.getLogger(ServerInfo.class);
 
+  private static final String CONFIG_FILE = "org.apache.myfaces.tobago.example.demo.config.file";
+  private static final String CONFIG_FILE_DEFAULT = "/etc/tobago-example-demo.properties";
+  private static final String ENABLED_KEY = "server.info.enabled";
+
   private String version;
 
-  private boolean enabled;
+  /**
+   * Enabled the Server Info. May be disabled for security reasons. Default is true.
+   */
+  private boolean enabled = true;
 
   public ServerInfo() {
-    Package tobagoPackage = Package.getPackage("org.apache.myfaces.tobago.component");
-    version = tobagoPackage.getImplementationVersion();
+    String file = System.getProperty(CONFIG_FILE);
+    try {
+      if (file == null) {
+        file = CONFIG_FILE_DEFAULT;
+      }
+      LOG.info("Loading properties from file '" + file + "'");
+      Properties config = new Properties();
+      config.load(new FileInputStream(file));
+      enabled = Boolean.parseBoolean(config.getProperty(ENABLED_KEY));
+      LOG.info("server.info.enabled=" + enabled);
+    } catch (IOException e) {
+      LOG.error("Can't load properties from file '" + file + "'", e);
+    }
+    // the tobago version should be set in any case
+    version = Package.getPackage("org.apache.myfaces.tobago.component").getImplementationVersion();
   }
 
   public String getServerInfo() {
@@ -49,30 +79,26 @@ public class ServerInfo {
   }
 
   public Properties getSystemProperties() {
-    if (enabled) {
-      return System.getProperties();
-    } else {
-      return null;
-    }
+    return enabled ? System.getProperties() : null;
   }
 
   public List<Map.Entry<Object, Object>> getSystemPropertiesAsList() {
-    return new ArrayList<Map.Entry<Object, Object>>(getSystemProperties().entrySet());
+    return enabled ? new ArrayList<Map.Entry<Object, Object>>(getSystemProperties().entrySet()) : null;
   }
 
   public String getVersion() {
     return version;
   }
 
-  public void setVersion(String version) {
-    this.version = version;
+  public String getJsfTitle() {
+    return enabled ? FacesContext.class.getPackage().getImplementationTitle() : null;
   }
 
-  public boolean isEnabled() {
-    return enabled;
+  public String getJsfVersion() {
+    return enabled ? FacesContext.class.getPackage().getImplementationVersion() : null;
   }
 
-  public void setEnabled(boolean enabled) {
-    this.enabled = enabled;
+  public boolean isEnabled() {
+    return enabled;
   }
 }

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml?rev=991312&r1=991311&r2=991312&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/WEB-INF/faces-config.xml Tue Aug 31 19:51:08 2010
@@ -87,13 +87,6 @@
     <managed-bean-name>info</managed-bean-name>
     <managed-bean-class>org.apache.myfaces.tobago.example.demo.ServerInfo</managed-bean-class>
     <managed-bean-scope>application</managed-bean-scope>
-    <managed-property>
-      <description>Enabled the Server Info. May be disabled for security reasons.</description>
-      <property-name>enabled</property-name>
-      <property-class>boolean</property-class>
-      <value>false</value>
-      <!--<value>true</value>-->
-    </managed-property>
   </managed-bean>
 
   <managed-bean>

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/server-info.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/server-info.jsp?rev=991312&r1=991311&r2=991312&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/server-info.jsp (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/server-info.jsp Tue Aug 31 19:51:08 2010
@@ -23,12 +23,18 @@
   <jsp:body>
     <tc:box label="Server Info">
       <f:facet name="layout">
-        <tc:gridLayout rows="fixed;fixed;fixed;fixed;*;3*" />
+        <tc:gridLayout rows="fixed;fixed;fixed;fixed;fixed;fixed;*" />
       </f:facet>
 
       <tx:in value="#{info.version}" readonly="true"
           label="Tobago Version" />
 
+      <tx:in value="#{info.jsfTitle}" readonly="true"
+          label="JSF Implementation" />
+
+      <tx:in value="#{info.jsfVersion}" readonly="true"
+          label="JSF Version" />
+
       <tx:in value="#{info.serverInfo}" readonly="true"
           label="Server Info" />
 
@@ -38,14 +44,6 @@
       <tx:in value="#{info.systemProperties['os.name']} - #{info.systemProperties['os.version']} - #{info.systemProperties['os.arch']}" readonly="true"
           label="Operating System" />
 
-      <tx:textarea value="#{info.systemProperties['java.class.path']}" readonly="true"
-          label="Java Classpath" />
-
-<%-- todo: not tested jet
-      <tx:textarea value="#{applicationScope['org.apache.catalina.jsp_classpath']}" readonly="true"
-          label="JSP Java Classpath" />
-
---%>
       <tc:sheet var="entry" value="#{info.systemPropertiesAsList}" columns="*;2*" rows="1000">
         <tc:column label="Key">
           <tc:out value="#{entry.key}"/>