View Javadoc

1   package org.apache.jcs.utils.config;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.IOException;
23  import java.io.InputStream;
24  import java.util.Properties;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  /**
30   * This can hold some constants used by various utilities. We should probably
31   * just get rid of this.
32   * <p>
33   * It loads properties from jcsutil.properties on initialization.
34   */
35  public interface IUtilConstants
36  {
37      /** Description of the Field */
38      public final static String ADMIN_USERID = Config.ADMIN_USERID;
39  
40      /** Description of the Field */
41      public final static String ADMIN_PASSWORD = Config.ADMIN_PASSWORD;
42  
43      /**
44       * Description of the Class
45       */
46      final static class Config
47      {
48          /** The logger */
49          private final static Log log = LogFactory.getLog( Config.class );
50  
51          /** username */
52          protected final static String ADMIN_USERID;
53  
54          /** password */
55          protected final static String ADMIN_PASSWORD;
56  
57          static
58          {
59              Properties props = new Properties();
60              InputStream is = null;
61              try
62              {
63                  props.load( is = IUtilConstants.class.getResourceAsStream( "/jcsutils.properties" ) );
64              }
65              catch ( IOException ex )
66              {
67                  log.warn( ex.getMessage() );
68              }
69              finally
70              {
71                  if ( is != null )
72                  {
73                      try
74                      {
75                          is.close();
76                      }
77                      catch ( IOException ignore )
78                      {
79                          // swallow
80                      }
81                  }
82              }
83              ADMIN_USERID = props.getProperty( "admin.userid", "admin" );
84              ADMIN_PASSWORD = props.getProperty( "admin.password", "system" );
85          }
86  
87          /** No instances please. */
88          private Config()
89          {
90              super();
91          }
92      }
93  }