001 package org.apache.myfaces.tobago.example.demo;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one or more
005 * contributor license agreements. See the NOTICE file distributed with
006 * this work for additional information regarding copyright ownership.
007 * The ASF licenses this file to You under the Apache License, Version 2.0
008 * (the "License"); you may not use this file except in compliance with
009 * the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020 import org.apache.commons.io.IOUtils;
021 import org.apache.commons.logging.Log;
022 import org.apache.commons.logging.LogFactory;
023
024 import javax.faces.context.FacesContext;
025 import javax.servlet.ServletContext;
026 import java.util.Properties;
027 import java.io.InputStream;
028 import java.io.IOException;
029
030 public class ServerInfo {
031
032 private static final Log LOG = LogFactory.getLog(ServerInfo.class);
033
034 private String version;
035
036 private boolean enabled;
037
038 public ServerInfo() {
039 InputStream pom = null;
040 try {
041 pom = getClass().getClassLoader().getResourceAsStream(
042 "META-INF/maven/org.apache.myfaces.tobago/tobago-core/pom.properties");
043 Properties properties = new Properties();
044 properties.load(pom);
045 version = properties.getProperty("version");
046
047 /*
048 This should work, too.
049 Package tobagoPackage = Package.getPackage("org.apache.myfaces.tobago.component");
050 version = tobagoPackage.getImplementationVersion();
051 */
052 } catch (IOException e) {
053 LOG.warn("No version info found.", e);
054 } finally {
055 IOUtils.closeQuietly(pom);
056 }
057 }
058
059 public String getServerInfo() {
060 if (enabled) {
061 return ((ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext()).getServerInfo();
062 } else {
063 return null;
064 }
065 }
066
067 public Properties getSystemProperties() {
068 if (enabled) {
069 return System.getProperties();
070 } else {
071 return null;
072 }
073 }
074
075 public String getVersion() {
076 return version;
077 }
078
079 public void setVersion(String version) {
080 this.version = version;
081 }
082
083 public boolean isEnabled() {
084 return enabled;
085 }
086
087 public void setEnabled(boolean enabled) {
088 this.enabled = enabled;
089 }
090 }