Configuration.java revision 296
306N/A/*
306N/A * CDDL HEADER START
810N/A *
810N/A * The contents of this file are subject to the terms of the
306N/A * Common Development and Distribution License (the "License").
306N/A * You may not use this file except in compliance with the License.
306N/A *
306N/A * See LICENSE.txt included in this distribution for the specific
306N/A * language governing permissions and limitations under the License.
306N/A *
306N/A * When distributing Covered Code, include this CDDL HEADER in each
306N/A * file and include the License file at LICENSE.txt.
306N/A * If applicable, add the following below this CDDL HEADER, with the
306N/A * fields enclosed by brackets "[]" replaced with your own identifying
306N/A * information: Portions Copyright [yyyy] [name of copyright owner]
306N/A *
306N/A * CDDL HEADER END
306N/A */
306N/A
306N/A/*
306N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
306N/A * Use is subject to license terms.
306N/A */
306N/Apackage org.opensolaris.opengrok.configuration;
306N/A
306N/Aimport java.beans.XMLDecoder;
306N/Aimport java.beans.XMLEncoder;
306N/Aimport java.io.BufferedInputStream;
306N/Aimport java.io.BufferedOutputStream;
306N/Aimport java.io.File;
306N/Aimport java.io.FileInputStream;
493N/Aimport java.io.FileOutputStream;
493N/Aimport java.io.IOException;
306N/Aimport java.util.ArrayList;
493N/Aimport java.util.HashMap;
306N/Aimport java.util.List;
493N/Aimport java.util.Map;
493N/Aimport org.opensolaris.opengrok.history.Repository;
810N/Aimport org.opensolaris.opengrok.index.IgnoredNames;
810N/A
810N/A/**
493N/A * Placeholder class for all configuration variables. Due to the multithreaded
493N/A * nature of the web application, each thread will use the same instance of the
493N/A * configuration object for each page request. Class and methods should have
493N/A * package scope, but that didn't work with the XMLDecoder/XMLEncoder.
493N/A */
306N/Apublic class Configuration {
306N/A private String ctags;
493N/A private boolean historyCache;
306N/A private int historyCacheTime;
306N/A private List<Project> projects;
561N/A private String sourceRoot;
306N/A private String dataRoot;
306N/A private Map<String, Repository> repositories;
306N/A private String urlPrefix;
306N/A private boolean generateHtml;
306N/A private Project defaultProject;
306N/A private int indexWordLimit;
636N/A private boolean verbose;
636N/A private boolean allowLeadingWildcard;
636N/A private IgnoredNames ignoredNames;
636N/A private String userPage;
636N/A private String bugPage;
636N/A private String bugPattern;
715N/A private String webappLAF;
715N/A private boolean remoteScmSupported;
private boolean optimizeDatabase;
private boolean useLuceneLocking;
/** Creates a new instance of Configuration */
public Configuration() {
setHistoryCache(true);
setHistoryCacheTime(30);
setProjects(new ArrayList<Project>());
setRepositories(new HashMap<String, Repository>());
setUrlPrefix("/source/s?");
setCtags("ctags");
setIndexWordLimit(60000);
setVerbose(false);
setGenerateHtml(true);
setQuickContextScan(true);
setIgnoredNames(new IgnoredNames());
setUserPage("http://www.opensolaris.org/viewProfile.jspa?username=");
setBugPage("http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=");
setBugPattern("\\b([12456789][0-9]{6})\\b");
setWebappLAF("default");
setRemoteScmSupported(false);
setOptimizeDatabase(true);
setUsingLuceneLocking(false);
}
public String getCtags() {
return ctags;
}
public void setCtags(String ctags) {
this.ctags = ctags;
}
public boolean isHistoryCache() {
return historyCache;
}
public void setHistoryCache(boolean historyCache) {
this.historyCache = historyCache;
}
public int getHistoryCacheTime() {
return historyCacheTime;
}
public void setHistoryCacheTime(int historyCacheTime) {
this.historyCacheTime = historyCacheTime;
}
public List<Project> getProjects() {
return projects;
}
public void setProjects(List<Project> projects) {
this.projects = projects;
}
public String getSourceRoot() {
return sourceRoot;
}
public void setSourceRoot(String sourceRoot) {
this.sourceRoot = sourceRoot;
}
public String getDataRoot() {
return dataRoot;
}
public void setDataRoot(String dataRoot) {
this.dataRoot = dataRoot;
}
public Map<String, Repository> getRepositories() {
return repositories;
}
public void setRepositories(Map<String, Repository> repositories) {
this.repositories = repositories;
}
public String getUrlPrefix() {
return urlPrefix;
}
public void setUrlPrefix(String urlPrefix) {
this.urlPrefix = urlPrefix;
}
public void setGenerateHtml(boolean generateHtml) {
this.generateHtml = generateHtml;
}
public boolean isGenerateHtml() {
return generateHtml;
}
public void setDefaultProject(Project defaultProject) {
this.defaultProject = defaultProject;
}
public Project getDefaultProject() {
return defaultProject;
}
public int getIndexWordLimit() {
return indexWordLimit;
}
public void setIndexWordLimit(int indexWordLimit) {
this.indexWordLimit = indexWordLimit;
}
public boolean isVerbose() {
return verbose;
}
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
this.allowLeadingWildcard = allowLeadingWildcard;
}
public boolean isAllowLeadingWildcard() {
return allowLeadingWildcard;
}
private boolean quickContextScan;
public boolean isQuickContextScan() {
return quickContextScan;
}
public void setQuickContextScan(boolean quickContextScan) {
this.quickContextScan = quickContextScan;
}
public void setIgnoredNames(IgnoredNames ignoredNames) {
this.ignoredNames = ignoredNames;
}
public IgnoredNames getIgnoredNames() {
return ignoredNames;
}
public void setUserPage(String userPage) {
this.userPage = userPage;
}
public String getUserPage() {
return userPage;
}
public void setBugPage(String bugPage) {
this.bugPage = bugPage;
}
public String getBugPage() {
return bugPage;
}
public void setBugPattern(String bugPattern) {
this.bugPattern = bugPattern;
}
public String getBugPattern() {
return bugPattern;
}
public String getWebappLAF() {
return webappLAF;
}
public void setWebappLAF(String webappLAF) {
this.webappLAF = webappLAF;
}
public boolean isRemoteScmSupported() {
return remoteScmSupported;
}
public void setRemoteScmSupported(boolean remoteScmSupported) {
this.remoteScmSupported = remoteScmSupported;
}
public boolean isOptimizeDatabase() {
return optimizeDatabase;
}
public void setOptimizeDatabase(boolean optimizeDatabase) {
this.optimizeDatabase = optimizeDatabase;
}
public boolean isUsingLuceneLocking() {
return useLuceneLocking;
}
public void setUsingLuceneLocking(boolean useLuceneLocking) {
this.useLuceneLocking = useLuceneLocking;
}
/**
* Write the current configuration to a file
* @param file the file to write the configuration into
* @throws IOException if an error occurs
*/
public void write(File file) throws IOException {
XMLEncoder e = new XMLEncoder(
new BufferedOutputStream(new FileOutputStream(file)));
e.writeObject(this);
e.close();
}
public static Configuration read(File file) throws IOException {
XMLDecoder d = new XMLDecoder(
new BufferedInputStream(new FileInputStream(file)));
Object ret = d.readObject();
d.close();
if (!(ret instanceof Configuration)) {
throw new IOException("Not a valid config file");
}
return (Configuration)ret;
}
}