Configuration.java revision 234
98N/A/*
98N/A * CDDL HEADER START
98N/A *
98N/A * The contents of this file are subject to the terms of the
493N/A * Common Development and Distribution License (the "License").
98N/A * You may not use this file except in compliance with the License.
98N/A *
98N/A * See LICENSE.txt included in this distribution for the specific
98N/A * language governing permissions and limitations under the License.
98N/A *
98N/A * When distributing Covered Code, include this CDDL HEADER in each
98N/A * file and include the License file at LICENSE.txt.
98N/A * If applicable, add the following below this CDDL HEADER, with the
98N/A * fields enclosed by brackets "[]" replaced with your own identifying
98N/A * information: Portions Copyright [yyyy] [name of copyright owner]
98N/A *
98N/A * CDDL HEADER END
98N/A */
98N/A
98N/A/*
98N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
98N/A * Use is subject to license terms.
98N/A */
98N/Apackage org.opensolaris.opengrok.configuration;
98N/A
98N/Aimport java.beans.XMLDecoder;
98N/Aimport java.beans.XMLEncoder;
98N/Aimport java.io.BufferedInputStream;
98N/Aimport java.io.BufferedOutputStream;
98N/Aimport java.io.File;
98N/Aimport java.io.FileInputStream;
98N/Aimport java.io.FileOutputStream;
557N/Aimport java.io.IOException;
98N/Aimport java.util.ArrayList;
98N/Aimport java.util.HashMap;
235N/Aimport java.util.List;
156N/Aimport java.util.Map;
156N/Aimport org.opensolaris.opengrok.history.ExternalRepository;
156N/Aimport org.opensolaris.opengrok.index.IgnoredNames;
156N/A
98N/A/**
98N/A * Placeholder class for all configuration variables. Due to the multithreaded
98N/A * nature of the web application, each thread will use the same instance of the
98N/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 */
98N/Apublic class Configuration {
98N/A private String ctags;
235N/A private boolean historyCache;
493N/A private int historyCacheTime;
98N/A private List<Project> projects;
98N/A private String sourceRoot;
98N/A private String dataRoot;
98N/A private Map<String, ExternalRepository> repositories;
98N/A private String urlPrefix;
98N/A private boolean generateHtml;
98N/A private Project defaultProject;
98N/A private int indexWordLimit;
98N/A private boolean verbose;
98N/A private boolean allowLeadingWildcard;
98N/A private IgnoredNames ignoredNames;
98N/A private String userPage;
98N/A private String bugPage;
493N/A private String bugPattern;
493N/A private String webappLAF;
493N/A private boolean remoteScmSupported;
98N/A
235N/A /** Creates a new instance of Configuration */
235N/A public Configuration() {
493N/A setHistoryCache(true);
493N/A setHistoryCacheTime(30);
493N/A setProjects(new ArrayList<Project>());
493N/A setRepositories(new HashMap<String, ExternalRepository>());
235N/A setUrlPrefix("/source/s?");
98N/A setCtags("ctags");
98N/A setIndexWordLimit(60000);
98N/A setVerbose(false);
493N/A setGenerateHtml(true);
493N/A setQuickContextScan(true);
493N/A setIgnoredNames(new IgnoredNames());
493N/A setUserPage("http://www.opensolaris.org/viewProfile.jspa?username=");
493N/A setBugPage("http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=");
493N/A setBugPattern("\\b([12456789][0-9]{6})\\b");
493N/A setWebappLAF("default");
493N/A setRemoteScmSupported(false);
493N/A }
493N/A
555N/A public String getCtags() {
493N/A return ctags;
557N/A }
557N/A
493N/A public void setCtags(String ctags) {
493N/A this.ctags = ctags;
493N/A }
493N/A
493N/A public boolean isHistoryCache() {
493N/A return historyCache;
493N/A }
98N/A
235N/A public void setHistoryCache(boolean historyCache) {
98N/A this.historyCache = historyCache;
98N/A }
98N/A
343N/A public int getHistoryCacheTime() {
343N/A return historyCacheTime;
527N/A }
527N/A
98N/A public void setHistoryCacheTime(int historyCacheTime) {
98N/A this.historyCacheTime = historyCacheTime;
493N/A }
493N/A
493N/A public List<Project> getProjects() {
493N/A return projects;
98N/A }
493N/A
98N/A public void setProjects(List<Project> projects) {
212N/A this.projects = projects;
212N/A }
212N/A
212N/A public String getSourceRoot() {
493N/A return sourceRoot;
111N/A }
111N/A
111N/A public void setSourceRoot(String sourceRoot) {
111N/A this.sourceRoot = sourceRoot;
111N/A }
111N/A
493N/A public String getDataRoot() {
493N/A return dataRoot;
98N/A }
98N/A
98N/A public void setDataRoot(String dataRoot) {
212N/A this.dataRoot = dataRoot;
212N/A }
212N/A
212N/A public Map<String, ExternalRepository> getRepositories() {
98N/A return repositories;
98N/A }
98N/A
98N/A public void setRepositories(Map<String, ExternalRepository> repositories) {
182N/A this.repositories = repositories;
98N/A }
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;
}
/**
* 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;
}
}