SystemSettings.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.pentaho.core.system |
![]() |
![]() |
Pentaho |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* Copyright 2006 Pentaho Corporation. All rights reserved.
* This software was developed by Pentaho Corporation and is provided under the terms
* of the Mozilla Public License, Version 1.1, or any later version. You may not use
* this file except in compliance with the license. If you need a copy of the license,
* please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
* BI Platform. The Initial Developer is Pentaho Corporation.
*
* Software distributed under the Mozilla Public License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
* the license for the specific language governing your rights and limitations.
*
* @created Jul 19, 2005
* @author Marc Batchelor
*
*/
package org.pentaho.core.system;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.Document;
import org.dom4j.Node;
import org.pentaho.core.util.XmlHelper;
import org.pentaho.messages.Messages;
/**
* Provides system settings data for system configuration files located in
* the system folder of the repository. System settings for </code>PentahoSystem</code>
* are hardcoded to exist in <repository>/system/pentaho.xml. Provides a settings
* cache so that settings are read from the file once, and the associated DOM
* document is cached in memory for future lookups.
*
* @author unknown
*
*/
public class SystemSettings extends PentahoBase implements ISystemSettings {
/**
*
*/
private static final long serialVersionUID = 3727605230748352557L;
/**
* This constant is for the overall system settings file name.
*/
public static final String PENTAHOSETTINGSFILENAME = "pentaho.xml"; //$NON-NLS-1$
private static String LOG_NAME = Messages.getString("SYSTEMSETTINGS.CODE_LOG_NAME"); //$NON-NLS-1$
private static final Log logger = LogFactory.getLog(SystemSettings.class);
private final Map settingsDocumentMap = Collections.synchronizedMap(new HashMap());
String logId;
public SystemSettings() {
// TODO apply session-base security to the system settings
logId = LOG_NAME + ":"; //$NON-NLS-1$
// TODO sbarkdull clean up
// Document doc = getSystemSettingsDocument(DEFAULT_PENTAHOSETTINGSFILENAME);
// if (doc == null) {
// throw new IllegalArgumentException(Messages.getErrorString("SYSTEMSETTINGS.ERROR_0003_INVALID_OR_MISSING_FILE")); //$NON-NLS-1$
// }
}
public String getSystemSetting(String path, String settingName, String defaultValue) {
debug(Messages.getString("SYSTEMSETTINGS.DEBUG_GET_SYSTEM_SETTING_PATH", File.separator + path)); //$NON-NLS-1$
Document doc = getSystemSettingsDocument(path);
if (doc == null) {
return null;
}
Node node = doc.selectSingleNode("//" + settingName); //$NON-NLS-1$
if (node == null) {
return defaultValue;
}
return node.getText();
}
public String getSystemSetting(String settingName, String defaultValue) {
return getSystemSetting(PENTAHOSETTINGSFILENAME, settingName, defaultValue);
}
public List getSystemSettings(String path, String settingName) {
Document doc = getSystemSettingsDocument(path);
if (doc == null) {
return null;
}
return doc.selectNodes("//" + settingName); //$NON-NLS-1$
}
public List getSystemSettings(String settingName) {
return getSystemSettings(PENTAHOSETTINGSFILENAME, settingName);
}
/**
* Get the DOM document initialized by the file specified in the <code>actionPath</code>
* parameter. If this is the first time the document associated with <code>actionPath</code>
* has been requested, cache the DOM document. If this is not the first time the document
* has been requested, return the document from the cache.
*/
public Document getSystemSettingsDocument(String actionPath) {
// S logId =
// runtimeContext.getInstanceId()+":"+LOG_NAME+":"+runtimeContext.getActionName(); //$NON-NLS-1$ //$NON-NLS-2$
Document systemSettingsDocument = (Document) settingsDocumentMap.get(actionPath);
if (systemSettingsDocument == null) {
File f = getFile(actionPath);
if (f == null) {
return null;
}
systemSettingsDocument = XmlHelper.getDocFromFile(f);
settingsDocumentMap.put(actionPath, systemSettingsDocument);
}
return systemSettingsDocument;
}
/**
* Get a <code>File</code> object that references a file in the system folder of
* the repository. The <code>path</code> parameter is relative to the
* system folder in the repository.
* @param path String containing the path of a file relative to the system folder in the
* repository
* @return File referencing the file specified by <code>path</code> relative to repository's
* system folder.
*/
private File getFile(String path) {
File f = new File(getAbsolutePath(path));
if (!f.exists()) {
error(Messages.getErrorString("SYSTEMSETTINGS.ERROR_0002_FILE_NOT_IN_SOLUTION", f.getAbsolutePath())); //$NON-NLS-1$
return null;
}
debug(Messages.getString("SYSTEMSETTINGS.DEBUG_SYSTEM_SETTINGS_GET_FILE", f.getAbsolutePath())); //$NON-NLS-1$
return f;
}
/**
* Create a String containing the complete path to the system folder in the repository,
* and append the parameter <code>path</code> to it.
* @param path String containing the path of a file relative to the system folder in the
* repository
* @return String containing the path
*/
protected String getAbsolutePath(String path) {
return PentahoSystem.getApplicationContext().getSolutionPath("system" + File.separator + path); //$NON-NLS-1$
}
public Log getLogger() {
return logger;
}
public void resetSettingsCache() {
settingsDocumentMap.clear();
}
//TODO sbarkdull, this props could be cached in a map similar to how the xml docs are cached
public Properties getSystemSettingsProperties(String path) {
String fullPath = PentahoSystem.getApplicationContext().getSolutionPath("system" + File.separator + path); //$NON-NLS-1$
File propsFile = new File(fullPath);
if (!propsFile.exists()) {
return null;
}
try {
Properties props = new Properties();
InputStream iStream = new BufferedInputStream(new FileInputStream(propsFile));
props.load(iStream);
return props;
} catch (FileNotFoundException e) {
logger.error(Messages.getErrorString("SystemSettings.ERROR_0003_FAILED_INITIALIZE", path), e); //$NON-NLS-1$
} catch (IOException ioe) {
logger.error(Messages.getErrorString("SystemSettings.ERROR_0003_FAILED_INITIALIZE", path), ioe); //$NON-NLS-1$
}
return null;
}
public String getSystemCfgSourceName() {
return getAbsolutePath(PENTAHOSETTINGSFILENAME);
}
}
The table below shows all metrics for SystemSettings.java.




