configurationprovider.java
来自「web版的SVN客户端」· Java 代码 · 共 330 行
JAVA
330 行
/*
* 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 java.io.File;
import org.polarion.svnwebclient.decorations.IAlternativeViewProvider;
import org.polarion.svnwebclient.decorations.IRevisionDecorator;
import org.polarion.svnwebclient.decorations.impl.AlternativeViewsProvider;
import org.polarion.svnwebclient.decorations.impl.RevisionDecorator;
import com.polarion.vcs.svn.SvnClient;
import com.polarion.xray.core.config.XrayConfig;
/**
*
*
* @author <A HREF="mailto:svnbrowser@polarion.org">Polarion Software </A>
*/
public class ConfigurationProvider implements IConfigurationProvider {
protected static ConfigurationProvider instance = new ConfigurationProvider();
private ConfigurationProvider() {
}
public static ConfigurationProvider getInstance() {
return instance;
}
public String getParentRepositoryDirectory() {
return null;
}
public boolean isLogout() {
return false;
}
public boolean isMultiRepositoryMode() {
return false;
}
/**
* @return Returns the embeddedMode.
*/
public boolean isEmbedded() {
return true;
}
public String getBasicRealm() {
return null;
}
public boolean isBasicAuth() {
return false;
}
/**
* @return Returns the repositoryUrl.
*/
public String getRepositoryUrl() {
return SvnClient.getInstance().getSvnConnectionUrl();
}
/**
* @return Returns the username.
*/
public String getUsername() {
return SvnClient.getInstance().getDefaultSVNUser();
}
/**
* @return Returns the password.
*/
public String getPassword() {
return SvnClient.getInstance().getDefaultSVNPassword();
}
/**
* @return Number of shared SVN connections
*/
public long getSvnConnectionsCount() {
return 20;
}
/**
* @return Returns the tempDir.
*/
public String getTempDirectory() {
return XrayConfig.getInstance().getTempPath();
}
/**
* @return Returns the maxVersions.
*/
public long getVersionsCount() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.VERSIONS_COUNT);
return Long.parseLong(value);
}
protected void checkVersionsCount() throws ConfigurationException {
this.checkLong(WebConfigurationProvider.VERSIONS_COUNT);
}
/**
* @return Returns the pathAutodetectMode.
*/
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;
}
}
protected void checkPathAutodetect() throws ConfigurationException {
this.checkBoolean(WebConfigurationProvider.PATH_AUTODETECT);
}
public String getTrunkName() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.TRUNK_NAME);
if (value != null) {
value = value.trim();
}
return value;
}
protected void checkTrunkName() throws ConfigurationException {
this.checkNotNullOrEmpty(WebConfigurationProvider.TRUNK_NAME);
}
public String getBranchesName() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.BRANCHES_NAME);
if (value != null) {
value = value.trim();
}
return value;
}
protected void checkBranchesName() throws ConfigurationException {
this.checkNotNullOrEmpty(WebConfigurationProvider.BRANCHES_NAME);
}
public String getTagsName() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.TAGS_NAME);
if (value != null) {
value = value.trim();
}
return value;
}
protected void checkTagsName() throws ConfigurationException {
this.checkNotNullOrEmpty(WebConfigurationProvider.TAGS_NAME);
}
/**
* @return Returns the defaultEncoding instance.
*/
public String getDefaultEncoding() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.DEFAULT_ENCODING);
return value.trim();
}
protected void checkDefaultEncoding() throws ConfigurationException {
this.checkNotNullOrEmpty(WebConfigurationProvider.DEFAULT_ENCODING);
}
/**
* @return Returns the zip encoding.
*/
public String getZipEncoding() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.ZIP_ENCODING);
return value.trim();
}
protected void checkZipEncoding() throws ConfigurationException {
this.checkNotNullOrEmpty(WebConfigurationProvider.ZIP_ENCODING);
}
/**
* @return Returns the enscriptPath.
*/
public String getEnscriptPath() {
String value = WebConfigurationProvider.getInstance().getParameter(WebConfigurationProvider.ENSCRIPT_PATH);
if (value != null) {
value = value.trim();
}
return value;
}
protected void checkEnscriptPath() throws ConfigurationException {
//is optional
}
/**
* @return Show stack trace in
*/
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;
}
}
protected void checkShowStackTrace() throws ConfigurationException {
this.checkBoolean(WebConfigurationProvider.SHOW_STACK_TRACE);
}
private IRevisionDecorator revDecorator = new RevisionDecorator();
/**
* @return Returns the revisionDecorator instance.
*/
public IRevisionDecorator getRevisionDecorator() {
return revDecorator;
}
private IAlternativeViewProvider viewProvider = new AlternativeViewsProvider();
/**
* @return Returns the alternativeViewProvider instance.
*/
public IAlternativeViewProvider getAlternativeViewProvider() {
return viewProvider;
}
/**
* @return Returns path to log messages cache
*/
public String getCacheDirectory() {
// TODO This is a little hack to get the working directory
// Should be fixed after patching build
String prjCache = XrayConfig.getInstance().getProjectsConfiguration().getCacheFile();
return new File(new File(prjCache).getParentFile(), "log-messages-cache").getAbsolutePath();
}
/**
* @return Returns number of revisions in one cache page
*/
public long getCachePageSize() {
return 100;
}
/**
* @return Returns number of prefetched messages. Use -1 to prefetch all messages
*/
public long getCachePrefetchMessagesCount() {
return 100;
}
public boolean isShowFullErrorReport() {
return true;
}
public void checkConfiguration() throws ConfigurationException {
this.checkVersionsCount();
this.checkPathAutodetect();
if (this.isPathAutodetect()) {
this.checkTrunkName();
this.checkBranchesName();
this.checkTagsName();
}
this.checkDefaultEncoding();
this.checkZipEncoding();
this.checkEnscriptPath();
this.checkShowStackTrace();
}
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 + =
减小字号Ctrl + -
显示快捷键?