Configuration.java revision 335
58N/A/*
58N/A * CDDL HEADER START
58N/A *
58N/A * The contents of this file are subject to the terms of the
58N/A * Common Development and Distribution License (the "License").
58N/A * You may not use this file except in compliance with the License.
58N/A *
58N/A * See LICENSE.txt included in this distribution for the specific
58N/A * language governing permissions and limitations under the License.
58N/A *
58N/A * When distributing Covered Code, include this CDDL HEADER in each
58N/A * file and include the License file at LICENSE.txt.
58N/A * If applicable, add the following below this CDDL HEADER, with the
58N/A * fields enclosed by brackets "[]" replaced with your own identifying
58N/A * information: Portions Copyright [yyyy] [name of copyright owner]
58N/A *
58N/A * CDDL HEADER END
58N/A */
58N/A
58N/A/*
1291N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
1356N/A * Use is subject to license terms.
58N/A */
58N/Apackage org.opensolaris.opengrok.configuration;
58N/A
234N/Aimport java.beans.XMLDecoder;
234N/Aimport java.beans.XMLEncoder;
234N/Aimport java.io.BufferedInputStream;
234N/Aimport java.io.BufferedOutputStream;
1287N/Aimport java.io.File;
639N/Aimport java.io.FileInputStream;
639N/Aimport java.io.FileOutputStream;
234N/Aimport java.io.IOException;
234N/Aimport java.util.ArrayList;
234N/Aimport java.util.HashMap;
1289N/Aimport java.util.List;
234N/Aimport java.util.Map;
639N/Aimport org.opensolaris.opengrok.history.Repository;
639N/Aimport org.opensolaris.opengrok.index.IgnoredNames;
58N/A
1185N/A/**
667N/A * Placeholder class for all configuration variables. Due to the multithreaded
1185N/A * nature of the web application, each thread will use the same instance of the
1016N/A * configuration object for each page request. Class and methods should have
1291N/A * package scope, but that didn't work with the XMLDecoder/XMLEncoder.
58N/A */
1185N/Apublic class Configuration {
1016N/A private String ctags;
1185N/A private boolean historyCache;
664N/A private int historyCacheTime;
1026N/A private List<Project> projects;
112N/A private String sourceRoot;
1195N/A private String dataRoot;
58N/A private Map<String, Repository> repositories;
58N/A private String urlPrefix;
77N/A private boolean generateHtml;
77N/A private Project defaultProject;
77N/A private int indexWordLimit;
77N/A private boolean verbose;
58N/A private boolean allowLeadingWildcard;
418N/A private IgnoredNames ignoredNames;
1327N/A private String userPage;
1327N/A private String bugPage;
1327N/A private String bugPattern;
1327N/A private String reviewPage;
1327N/A private String reviewPattern;
1327N/A private String webappLAF;
1356N/A private boolean remoteScmSupported;
1356N/A private boolean optimizeDatabase;
1356N/A private boolean useLuceneLocking;
58N/A private boolean compressXref;
773N/A
773N/A /** Creates a new instance of Configuration */
58N/A public Configuration() {
773N/A setHistoryCache(true);
773N/A setHistoryCacheTime(30);
773N/A setProjects(new ArrayList<Project>());
773N/A setRepositories(new HashMap<String, Repository>());
58N/A setUrlPrefix("/source/s?");
773N/A setCtags("ctags");
773N/A setIndexWordLimit(60000);
773N/A setVerbose(false);
773N/A setGenerateHtml(true);
58N/A setQuickContextScan(true);
58N/A setIgnoredNames(new IgnoredNames());
58N/A setUserPage("http://www.opensolaris.org/viewProfile.jspa?username=");
664N/A setBugPage("http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=");
58N/A setBugPattern("\\b([12456789][0-9]{6})\\b");
65N/A setReviewPage("http://www.opensolaris.org/os/community/arc/caselog/");
894N/A setReviewPattern("\\b(\\d{4}/\\d{3})\\b"); // in form e.g. PSARC 2008/305
77N/A setWebappLAF("default");
99N/A setRemoteScmSupported(false);
99N/A setOptimizeDatabase(true);
1115N/A setUsingLuceneLocking(false);
1115N/A setCompressXref(true);
125N/A }
112N/A
1026N/A public String getCtags() {
129N/A return ctags;
1100N/A }
129N/A
129N/A public void setCtags(String ctags) {
318N/A this.ctags = ctags;
318N/A }
144N/A
173N/A public boolean isHistoryCache() {
253N/A return historyCache;
296N/A }
335N/A
480N/A public void setHistoryCache(boolean historyCache) {
816N/A this.historyCache = historyCache;
816N/A }
833N/A
833N/A public int getHistoryCacheTime() {
1185N/A return historyCacheTime;
1016N/A }
1123N/A
1125N/A public void setHistoryCacheTime(int historyCacheTime) {
1218N/A this.historyCacheTime = historyCacheTime;
1185N/A }
1326N/A
993N/A public List<Project> getProjects() {
1185N/A return projects;
1185N/A }
1190N/A
1185N/A public void setProjects(List<Project> projects) {
1185N/A this.projects = projects;
1252N/A }
1185N/A
1185N/A public String getSourceRoot() {
1185N/A return sourceRoot;
1185N/A }
1185N/A
1185N/A public void setSourceRoot(String sourceRoot) {
1185N/A this.sourceRoot = sourceRoot;
1185N/A }
1185N/A
1185N/A public String getDataRoot() {
1252N/A return dataRoot;
1185N/A }
1185N/A
1185N/A public void setDataRoot(String dataRoot) {
1185N/A this.dataRoot = dataRoot;
1185N/A }
1185N/A
993N/A public Map<String, Repository> getRepositories() {
993N/A return repositories;
993N/A }
1185N/A
993N/A public void setRepositories(Map<String, Repository> repositories) {
993N/A this.repositories = repositories;
937N/A }
58N/A
58N/A public String getUrlPrefix() {
816N/A return urlPrefix;
58N/A }
58N/A
773N/A public void setUrlPrefix(String urlPrefix) {
58N/A this.urlPrefix = urlPrefix;
664N/A }
58N/A
850N/A public void setGenerateHtml(boolean generateHtml) {
1327N/A this.generateHtml = generateHtml;
870N/A }
870N/A
99N/A public boolean isGenerateHtml() {
1115N/A return generateHtml;
101N/A }
106N/A
112N/A public void setDefaultProject(Project defaultProject) {
1026N/A this.defaultProject = defaultProject;
129N/A }
129N/A
129N/A public Project getDefaultProject() {
875N/A return defaultProject;
318N/A }
1356N/A
173N/A public int getIndexWordLimit() {
253N/A return indexWordLimit;
296N/A }
335N/A
480N/A public void setIndexWordLimit(int indexWordLimit) {
816N/A this.indexWordLimit = indexWordLimit;
816N/A }
993N/A
1016N/A public boolean isVerbose() {
1315N/A return verbose;
1185N/A }
58N/A
937N/A public void setVerbose(boolean verbose) {
1185N/A this.verbose = verbose;
1185N/A }
1185N/A
1190N/A public void setAllowLeadingWildcard(boolean allowLeadingWildcard) {
1185N/A this.allowLeadingWildcard = allowLeadingWildcard;
1185N/A }
1185N/A
1185N/A public boolean isAllowLeadingWildcard() {
1185N/A return allowLeadingWildcard;
1185N/A }
1185N/A
1185N/A private boolean quickContextScan;
1185N/A
1185N/A public boolean isQuickContextScan() {
1185N/A return quickContextScan;
1185N/A }
1185N/A
1185N/A public void setQuickContextScan(boolean quickContextScan) {
1190N/A this.quickContextScan = quickContextScan;
1185N/A }
1185N/A
1185N/A public void setIgnoredNames(IgnoredNames ignoredNames) {
1185N/A this.ignoredNames = ignoredNames;
1190N/A }
58N/A
58N/A public IgnoredNames getIgnoredNames() {
58N/A return ignoredNames;
937N/A }
58N/A
58N/A public void setUserPage(String userPage) {
58N/A this.userPage = userPage;
937N/A }
816N/A
816N/A public String getUserPage() {
816N/A return userPage;
816N/A }
816N/A
816N/A public void setBugPage(String bugPage) {
816N/A this.bugPage = bugPage;
816N/A }
816N/A
816N/A public String getBugPage() {
816N/A return bugPage;
816N/A }
816N/A
816N/A public void setBugPattern(String bugPattern) {
816N/A this.bugPattern = bugPattern;
773N/A }
773N/A
773N/A public String getBugPattern() {
773N/A return bugPattern;
773N/A }
773N/A
58N/A public String getReviewPage() {
58N/A return reviewPage;
58N/A }
773N/A
773N/A public void setReviewPage(String reviewPage) {
773N/A this.reviewPage = reviewPage;
773N/A }
773N/A
58N/A public String getReviewPattern() {
58N/A return reviewPattern;
58N/A }
773N/A
773N/A public void setReviewPattern(String reviewPattern) {
773N/A this.reviewPattern = reviewPattern;
773N/A }
773N/A
773N/A public String getWebappLAF() {
773N/A return webappLAF;
773N/A }
773N/A
58N/A public void setWebappLAF(String webappLAF) {
58N/A this.webappLAF = webappLAF;
58N/A }
773N/A
773N/A public boolean isRemoteScmSupported() {
773N/A return remoteScmSupported;
773N/A }
773N/A
773N/A public void setRemoteScmSupported(boolean remoteScmSupported) {
773N/A this.remoteScmSupported = remoteScmSupported;
58N/A }
58N/A
58N/A public boolean isOptimizeDatabase() {
773N/A return optimizeDatabase;
773N/A }
773N/A
773N/A public void setOptimizeDatabase(boolean optimizeDatabase) {
773N/A this.optimizeDatabase = optimizeDatabase;
773N/A }
773N/A
773N/A public boolean isUsingLuceneLocking() {
773N/A return useLuceneLocking;
773N/A }
773N/A
773N/A public void setUsingLuceneLocking(boolean useLuceneLocking) {
773N/A this.useLuceneLocking = useLuceneLocking;
773N/A }
773N/A
773N/A public void setCompressXref(boolean compressXref) {
773N/A this.compressXref = compressXref;
773N/A }
773N/A
773N/A public boolean isCompressXref() {
773N/A return compressXref;
773N/A }
773N/A
937N/A /**
58N/A * Write the current configuration to a file
58N/A * @param file the file to write the configuration into
58N/A * @throws IOException if an error occurs
937N/A */
58N/A public void write(File file) throws IOException {
58N/A XMLEncoder e = new XMLEncoder(
58N/A new BufferedOutputStream(new FileOutputStream(file)));
937N/A e.writeObject(this);
58N/A e.close();
58N/A }
58N/A
937N/A public static Configuration read(File file) throws IOException {
58N/A XMLDecoder d = new XMLDecoder(
58N/A new BufferedInputStream(new FileInputStream(file)));
58N/A Object ret = d.readObject();
937N/A d.close();
58N/A
58N/A if (!(ret instanceof Configuration)) {
58N/A throw new IOException("Not a valid config file");
937N/A }
58N/A return (Configuration)ret;
58N/A }
58N/A}
937N/A