📄 configurationprovider.java
字号:
/*
* Copyright (c) 2004, 2005 Polarion Software, All rights reserved.
* Email: community@polarion.org
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. Copy of the License is
* located in the file LICENSE.txt in the project distribution. You may also
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
*
* POLARION SOFTWARE MAKES NO REPRESENTATIONS OR WARRANTIES
* ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESSED OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. POLARION SOFTWARE
* SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT
* OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
*/
package org.polarion.svnwebclient.configuration;
import org.apache.log4j.Logger;
import org.polarion.svnwebclient.decorations.IAlternativeViewProvider;
import org.polarion.svnwebclient.decorations.IRevisionDecorator;
/**
*
* @author <A HREF="mailto:svnbrowser@polarion.org">Polarion Software </A>
*/
public class ConfigurationProvider implements IConfigurationProvider {
protected static ConfigurationProvider instance;
protected IRevisionDecorator revisionDecorator;
protected IAlternativeViewProvider alternativeViewProvider;
private ConfigurationProvider() {
}
public static synchronized ConfigurationProvider getInstance() {
if (ConfigurationProvider.instance == null) {
ConfigurationProvider.instance = new ConfigurationProvider();
}
return ConfigurationProvider.instance;
}
public void checkConfiguration() throws ConfigurationException {
this.checkBoolean(WebConfigurationProvider.EMBEDDED);
this.checkBoolean(WebConfigurationProvider.BASIC_AUTH);
if (this.isBasicAuth()) {
this.checkNotNullOrEmpty(WebConfigurationProvider.BASIC_REALM);
}
String parentUrl = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.PARENT_REPOSITORY_DIRECTORY);
if (parentUrl == null) {
this.checkNotNullOrEmpty(WebConfigurationProvider.REPOSITORY_URL);
this.checkNotNull(WebConfigurationProvider.USERNAME);
this.checkNotNull(WebConfigurationProvider.PASSWORD);
} else {
String reposUrl = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.REPOSITORY_URL);
String userName = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.USERNAME);
String password = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.PASSWORD);
if (reposUrl != null || userName != null || password != null) {
throw new ConfigurationException("You have to specify only either ParentRepositoryDirectory or " +
"RepositoryUrl and password, userName in web.xml, don't mix them.");
}
}
this.checkNotNullOrEmpty(WebConfigurationProvider.TEMP_DIRECTORY);
this.checkLong(WebConfigurationProvider.VERSIONS_COUNT);
this.checkBoolean(WebConfigurationProvider.PATH_AUTODETECT);
if (this.isPathAutodetect()) {
this.checkNotNullOrEmpty(WebConfigurationProvider.TRUNK_NAME);
this.checkNotNullOrEmpty(WebConfigurationProvider.BRANCHES_NAME);
this.checkNotNullOrEmpty(WebConfigurationProvider.TAGS_NAME);
}
this.checkNotNullOrEmpty(WebConfigurationProvider.DEFAULT_ENCODING);
this.checkNotNullOrEmpty(WebConfigurationProvider.ZIP_ENCODING);
this.checkBoolean(WebConfigurationProvider.SHOW_STACK_TRACE);
this.checkNotNullOrEmpty(WebConfigurationProvider.CACHE_DIRECTORY);
this.checkLong(WebConfigurationProvider.CACHE_PAGE_SIZE);
this.checkLong(WebConfigurationProvider.CACHE_PREFETCH_MESSAGES_COUNT);
}
public boolean isEmbedded() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.EMBEDDED);
value = value.trim();
if (WebConfigurationProvider.VALUE_TRUE.equalsIgnoreCase(value)) {
return true;
} else {
return false;
}
}
public boolean isBasicAuth() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.BASIC_AUTH);
value = value.trim();
if (WebConfigurationProvider.VALUE_TRUE.equalsIgnoreCase(value)) {
return true;
} else {
return false;
}
}
public String getBasicRealm() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.BASIC_REALM);
return value.trim();
}
public String getParentRepositoryDirectory() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.PARENT_REPOSITORY_DIRECTORY);
if (value == null) {
return null;
} else {
return value.trim();
}
}
public boolean isMultiRepositoryMode() {
return this.getParentRepositoryDirectory() == null ? false : true;
}
public String getRepositoryUrl() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.REPOSITORY_URL);
return value.trim();
}
public String getUsername() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.USERNAME);
return value.trim();
}
public String getPassword() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.PASSWORD);
return value.trim();
}
public long getSvnConnectionsCount() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.SVN_CONNECTIONS_COUNT);
return Long.parseLong(value);
}
public String getTempDirectory() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.TEMP_DIRECTORY);
return value.trim();
}
public long getVersionsCount() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.VERSIONS_COUNT);
return Long.parseLong(value);
}
public boolean isPathAutodetect() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.PATH_AUTODETECT);
value = value.trim();
if (WebConfigurationProvider.VALUE_TRUE.equalsIgnoreCase(value)) {
return true;
} else {
return false;
}
}
public String getTrunkName() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.TRUNK_NAME);
if (value != null) {
value = value.trim();
}
return value;
}
public String getBranchesName() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.BRANCHES_NAME);
if (value != null) {
value = value.trim();
}
return value;
}
public String getTagsName() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.TAGS_NAME);
if (value != null) {
value = value.trim();
}
return value;
}
public String getDefaultEncoding() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.DEFAULT_ENCODING);
return value.trim();
}
public String getZipEncoding() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.ZIP_ENCODING);
return value.trim();
}
public String getEnscriptPath() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.ENSCRIPT_PATH);
if (value != null) {
value = value.trim();
}
return value;
}
public boolean isShowStackTrace() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.SHOW_STACK_TRACE);
value = value.trim();
if (WebConfigurationProvider.VALUE_TRUE.equalsIgnoreCase(value)) {
return true;
} else {
return false;
}
}
public String getCacheDirectory() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.CACHE_DIRECTORY);
return value.trim();
}
public long getCachePageSize() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.CACHE_PAGE_SIZE);
return Long.parseLong(value);
}
public long getCachePrefetchMessagesCount() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.CACHE_PREFETCH_MESSAGES_COUNT);
return Long.parseLong(value);
}
public boolean isLogout() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.LOGOUT);
return new Boolean(value).booleanValue();
}
public IRevisionDecorator getRevisionDecorator() {
if (this.revisionDecorator == null) {
this.revisionDecorator = (IRevisionDecorator) this.instantiate(WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.REVISION_DECORATOR));
}
return this.revisionDecorator;
}
public IAlternativeViewProvider getAlternativeViewProvider() {
if (this.alternativeViewProvider == null) {
this.alternativeViewProvider = (IAlternativeViewProvider) this.instantiate(WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.ALTERNATIVE_VIEW_PROVIDER));
}
return this.alternativeViewProvider;
}
protected void checkNotNull(String parameterName) throws ConfigurationException {
String value = WebConfigurationProvider.getInstance().getParameter(parameterName);
if (value == null) {
throw new ConfigurationException(parameterName + " configuration parameter must be defined");
}
}
protected Object instantiate(String className) {
try {
Class clazz = Class.forName(className);
return clazz.newInstance();
} catch (ClassNotFoundException e) {
Logger.getLogger(this.getClass()).error(e,e);
} catch (InstantiationException e) {
Logger.getLogger(this.getClass()).error(e,e);
} catch (IllegalAccessException e) {
Logger.getLogger(this.getClass()).error(e,e);
}
return null;
}
protected void checkNotNullOrEmpty(String parameterName) throws ConfigurationException {
String value = WebConfigurationProvider.getInstance().getParameter(parameterName);
if (value == null) {
throw new ConfigurationException(parameterName + " configuration parameter must be defined");
}
value = value.trim();
if (value.length() == 0) {
throw new ConfigurationException("Invalid value \"" + value + "\" of " + parameterName + " configuration parameter. " +
"It must be not empty string");
}
}
protected void checkBoolean(String parameterName) throws ConfigurationException {
String value = WebConfigurationProvider.getInstance().getParameter(parameterName);
if (value == null) {
throw new ConfigurationException(parameterName + " configuration parameter must be defined");
}
value = value.trim();
if (!(WebConfigurationProvider.VALUE_TRUE.equalsIgnoreCase(value) || WebConfigurationProvider.VALUE_FALSE.equalsIgnoreCase(value))) {
throw new ConfigurationException("Invalid value \"" + value + "\" of " + parameterName + " configuration parameter. " +
"Only " + WebConfigurationProvider.VALUE_TRUE + " and " + WebConfigurationProvider.VALUE_FALSE + " are allowed");
}
}
protected void checkLong(String parameterName) throws ConfigurationException {
String value = WebConfigurationProvider.getInstance().getParameter(parameterName);
if (value == null) {
throw new ConfigurationException(parameterName + " configuration parameter must be defined");
}
try {
Long.parseLong(value);
} catch (NumberFormatException e) {
throw new ConfigurationException("Invalid value \"" + value + "\" of " + parameterName + " configuration parameter. " +
"It must be numeric");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -