⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmssetup.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/boot/CmsSetup.java,v $
* Date   : $Date: 2001/12/18 15:26:18 $
* Version: $Revision: 1.12 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.opencms.boot;

import source.org.apache.java.util.*;
import java.io.*;
import java.util.*;

/**
 * Bean with get / set methods for all properties stored in the
 * 'opencms.properties' file. The path to the opencms home folder and
 * its config folder can also be stored an retrieved as well as a vector
 * containing possible error messages thrown by the setup.
 *
 * @author Magnus Meurer
 */
public class CmsSetup {

  /** Contains error messages, displayed by the setup wizard */
  private static Vector errors = new Vector();

  /** Contains the properties from the opencms.properties file */
  private ExtendedProperties m_extProp;

  /** properties from dbsetup.properties */
  private Properties m_dbSetupProps;

  /** Contains the absolute path to the opencms home directory */
  private String m_basePath;

  /** Indicates if the user has chosen standard (false)
   *  or advanced (true) setup
   */
  private boolean m_setupType;

  /**
   * name of the database (mysql)
   */
  private String m_database;


  /**
   * database password used to drop and create database
   */
  private String m_dbCreatePwd;

  /**
   * replacer string
   */
  private Hashtable m_replacer;


  /** This method reads the properties from the opencms.propertie file
   *  and sets the CmsSetup properties with the matching values.
   *  This method should be called when the first page of the OpenCms
   *  Setup Wizard is called, so the input fields of the wizard are pre-defined
   */
  public void initProperties(String props)  {
    String path = getConfigFolder() + props;
    try {
      FileInputStream fis = new FileInputStream(new File(path));
      m_extProp = new ExtendedProperties();
      m_extProp.load(fis);
      fis.close();
      m_dbSetupProps = new Properties();
      m_dbSetupProps.load(getClass().getClassLoader().getResourceAsStream("com/opencms/boot/dbsetup.properties"));
    }
    catch (Exception e) {
        e.printStackTrace();
        errors.add(e.toString());
    }
  }

  /** This method sets the extended Properties by the given key with
   *  the given value. A backslash ('\') is added before each comma (',')
   *  in the value string, so the properties can be read correctly afterwards.
   *  @param key The key of the property
   *  @param value The value of the property
   */
  public void setProperties(String key, String value) {
    try {
      char [] chars = value.toCharArray();
      String modifiedValue = "";
      for(int i = 0; i < chars.length; i++) {
        if (chars[i] == ',')  {
          modifiedValue += '\\';
        }
        modifiedValue +=chars[i];
      }
      m_extProp.put(key,modifiedValue);
    }
    catch (Exception e) {
    }
  }


  /** Sets the path to the OpenCms home directory */
  public void setBasePath(String basePath)  {
    m_basePath = basePath;
  }

  /** Returns the absolute path to the OpenCms home directory */
  public String getBasePath() {
    return m_basePath.replace('\\','/').replace('/',File.separatorChar);
  }

  /** Sets the setup type to the given value: standard (false), advanced (true) */
  public void setSetupType(boolean setupType)  {
    m_setupType = setupType;
  }

  /** Returns the value of the setup type: standard (false), advanced (true) */
  public boolean getSetupType() {
    return m_setupType;
  }

  /** Sets the resource broker to the given value */
  public void setResourceBroker(String resourceBroker)  {
    setProperties("resourcebroker",resourceBroker);
  }

  /** Gets the resource broker */
  public String getResourceBroker() {
    Object temp =  m_extProp.get("resourcebroker");
    if(temp != null)  {
        return temp.toString();
    }
    else  {
      return "";
    }

  }

  /** Returns all resource Broker found in 'dbsetupscripts.properties' */
  public Vector getResourceBrokers() {
      Vector values = new Vector();

      String value = m_dbSetupProps.getProperty("resourceBrokers");
      StringTokenizer tokenizer = new StringTokenizer(value,",");
      while(tokenizer.hasMoreTokens())  {
          values.add(tokenizer.nextToken());
      }
      return values;
  }



  /** Sets the connection string to the database to the given value */
  public void setDbWorkConStr(String dbWorkConStr)  {
    setProperties("pool." + getResourceBroker() + ".url",dbWorkConStr);
    setProperties("pool." + getResourceBroker() + "backup.url",dbWorkConStr);
    setProperties("pool." + getResourceBroker() + "online.url",dbWorkConStr);
  }


  /** Sets the user of the database to the given value */
  public void setDbWorkUser(String dbWorkUser)  {
    setProperties("pool." + getResourceBroker() + ".user",dbWorkUser);
    setProperties("pool." + getResourceBroker() + "backup.user",dbWorkUser);
    setProperties("pool." + getResourceBroker() + "online.user",dbWorkUser);
  }

  /** Returns the user of the database from the properties */
  public String getDbWorkUser()  {
    Object ConStr =  m_extProp.get("pool." + getResourceBroker() + ".user");
    if(ConStr != null)  {
      return m_extProp.get("pool." + getResourceBroker() + ".user").toString();
    }
    else  {
      return "";
    }
  }

  /** Sets the password of the database to the given value */
  public void setDbWorkPwd(String dbWorkPwd)  {
    setProperties("pool." + getResourceBroker() + ".password",dbWorkPwd);
    setProperties("pool." + getResourceBroker() + "backup.password",dbWorkPwd);
    setProperties("pool." + getResourceBroker() + "online.password",dbWorkPwd);
  }

  /** Returns a conenction string */
  public String getDbWorkConStr()  {
    Object ConStr =  m_extProp.get("pool." + getResourceBroker() + ".url");
    if(ConStr != null)  {
      return ConStr.toString();
    }
    else  {
      return "";
    }
  }



  /** Returns the password of the database from the properties */
  public String getDbWorkPwd()  {
    Object ConStr =  m_extProp.get("pool." + getResourceBroker() + ".password");
    if(ConStr != null)  {
      return m_extProp.get("pool." + getResourceBroker() + ".password").toString();
    }
    else  {
      return "";
    }
  }


  /** Returns the extended properties */
  public ExtendedProperties getProperties() {
    return m_extProp;
  }


  /** Adds a new error message to the vector */
  public static void setErrors(String error) {
    errors.add(error);
  }

  /** Returns the error messages */
  public Vector getErrors() {
    return errors;
  }

  /** Returns the path to the opencms config folder */
  public String getConfigFolder() {
    return (m_basePath + "WEB-INF/config/").replace('\\','/').replace('/',File.separatorChar);
  }

  /** Returns the database driver belonging to the resource broker */
  public String getDbDriver() {
    return m_extProp.get("pool."+getResourceBroker()+".driver").toString();
  }

  /** Sets the minimum connections to the given value */
  public void setMinConn(String minConn)  {
    setProperties("pool." + getResourceBroker() + ".minConn",minConn);
  }

  /** Returns the min. connections */
  public String getMinConn()  {
    Object temp =  m_extProp.get("pool." + getResourceBroker() + ".minConn");
    if(temp != null)  {
      return temp.toString();
    }
    else  {
      return "";
    }
  }

  /** Sets the maximum connections to the given value */
  public void setMaxConn(String maxConn)  {
    setProperties("pool." + getResourceBroker() + ".maxConn",maxConn);
  }

  /** Returns the max. connections */
  public String getMaxConn()  {
    Object temp =  m_extProp.get("pool." + getResourceBroker() + ".maxConn");
    if(temp != null)  {
      return temp.toString();
    }
    else  {
      return "";
    }
  }

  /** Sets the increase rate to the given value */
  public void setIncreaseRate(String increaseRate)  {
    setProperties("pool." + getResourceBroker() + ".increaseRate",increaseRate);
  }

  /** Returns the increase rate */
  public String getIncreaseRate()  {
    Object temp =  m_extProp.get("pool." + getResourceBroker() + ".increaseRate");
    if(temp != null)  {
      return temp.toString();
    }
    else  {
      return "";
    }
  }

  /** Sets the timeout to the given value */
  public void setTimeout(String timeout)  {
    setProperties("pool." + getResourceBroker() + ".timeout",timeout);
  }

  /** Returns the timeout value */
  public String getTimeout()  {
    Object temp =  m_extProp.get("pool." + getResourceBroker() + ".timeout");
    if(temp != null)  {
      return temp.toString();
    }
    else  {
      return "";
    }
  }

  /** Sets the max. age to the given value */
  public void setMaxAge(String maxAge)  {
    setProperties("pool." + getResourceBroker() + ".maxage",maxAge);
  }

  /** Returns the max. age */
  public String getMaxAge()  {
    Object temp =  m_extProp.get("pool." + getResourceBroker() + ".maxage");
    if(temp != null)  {
      return temp.toString();
    }
    else  {
      return "";
    }
  }

  /** Sets the cache value for user to the given value */
  public void setCacheUser(String cacheUser)  {
    setProperties("cache.user",cacheUser);
  }

  /** Returns the cache value for user */
  public String getCacheUser()  {
    Object temp =  m_extProp.get("cache.user");
    if(temp != null)  {
      return temp.toString();
    }
    else  {
      return "";
    }
  }

  /** Sets the cache value for group to the given value */
  public void setCacheGroup(String cacheGroup)  {
    setProperties("cache.group",cacheGroup);
  }

  /** Returns the cache value for group */
  public String getCacheGroup()  {
    Object temp =  m_extProp.get("cache.group");
    if(temp != null)  {
      return temp.toString();
    }
    else  {
      return "";
    }
  }

  /** Sets the cache value for usergroups to the given value */
  public void setCacheUserGroups(String cacheUserGroups)  {
    setProperties("cache.usergroups",cacheUserGroups);
  }

  /** Returns the cache value for usergroups */
  public String getCacheUserGroups()  {
    Object temp =  m_extProp.get("cache.usergroups");
    if(temp != null)  {
      return temp.toString();
    }
    else  {
      return "";
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -