Source Code Cross Referenced for Environment.java in  » Wiki-Engine » VeryQuickWiki » vqwiki » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Wiki Engine » VeryQuickWiki » vqwiki 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package vqwiki;
0002:
0003:        import java.io.BufferedReader;
0004:        import java.io.File;
0005:        import java.io.FileInputStream;
0006:        import java.io.FileOutputStream;
0007:        import java.io.IOException;
0008:        import java.io.InputStream;
0009:        import java.io.InputStreamReader;
0010:        import java.io.OutputStream;
0011:        import java.io.OutputStreamWriter;
0012:        import java.io.UnsupportedEncodingException;
0013:        import java.net.URL;
0014:        import java.net.URLDecoder;
0015:        import java.security.AccessControlException;
0016:        import java.util.ArrayList;
0017:        import java.util.HashMap;
0018:        import java.util.List;
0019:        import java.util.Properties;
0020:        import javax.naming.InitialContext;
0021:        import org.apache.commons.pool.impl.GenericObjectPool;
0022:        import org.apache.log4j.Logger;
0023:        import vqwiki.db.DatabaseConnection;
0024:        import vqwiki.servlets.WikiServlet;
0025:        import vqwiki.utils.Encryption;
0026:        import vqwiki.utils.JSPUtils;
0027:
0028:        /*
0029:         Very Quick Wiki - WikiWikiWeb clone
0030:         Copyright (C) 2001-2002 Gareth Cronin
0031:
0032:         This program is free software; you can redistribute it and/or modify
0033:         it under the terms of the latest version of the GNU Lesser General
0034:         Public License as published by the Free Software Foundation;
0035:
0036:         This program is distributed in the hope that it will be useful,
0037:         but WITHOUT ANY WARRANTY; without even the implied warranty of
0038:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0039:         GNU Lesser General Public License for more details.
0040:
0041:         You should have received a copy of the GNU Lesser General Public License
0042:         along with this program (gpl.txt); if not, write to the Free Software
0043:         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0044:         */
0045:
0046:        /**
0047:         * Provides the basic environment
0048:         * This class is a bit confusing at the moment (Nov 2002) - it is in the process of
0049:         * being changed from one system of property defaulting and retrieval to another.
0050:         *
0051:         * To add a new property:
0052:         *
0053:         * - Define constants for property name and default value below
0054:         * - Set the default in the constructor below
0055:         * - Set the property in AdministrationServlet's doPost method, look for the "properties" section
0056:         * - Provide a form element for the property in admin.jsp
0057:         * - Specify literal strings by using properties in ApplicationResources*.properties
0058:         */
0059:
0060:        public class Environment {
0061:
0062:            public final static String WIKI_VERSION = "2.7.91";
0063:            public static final String PROP_FILE = "vqwiki.properties";
0064:            private Properties currentProperties;
0065:            private static Environment instance;
0066:
0067:            /* Old properties system */
0068:            public static final String PROPERTY_HOME_DIR = "homeDir";
0069:            public final static String PROPERTY_UPLOAD_DIR = "uploadDir";
0070:            public final static String PROPERTY_INDEX_REFRESH_INTERVAL = "indexRefreshInterval";
0071:            public final static String PROPERTY_ALLOW_HTML = "allowHTML";
0072:            public final static String PROPERTY_PERSISTENCE_TYPE = "persistenceType";
0073:            public final static String PROPERTY_VERSIONING_ON = "versioningOn";
0074:            public final static String PROPERTY_EDIT_TIME_OUT = "editTimeOut";
0075:            public final static String PROPERTY_ALLOW_BACK_TICK = "allowBackTick";
0076:            public final static String PROPERTY_DRIVER = "driver";
0077:            public final static String PROPERTY_URL = "url";
0078:            public final static String PROPERTY_USERNAME = "username";
0079:            public final static String PROPERTY_PASSWORD = "password";
0080:            public final static String PROPERTY_FORCE_USERNAME = "force-username";
0081:            public static final String DEFAULT_LOGO_IMAGE_NAME = "/images/logo.jpg";
0082:            public static final boolean DEFAULT_ATTACHMENTS_TO_DATABASE = true;
0083:            public static final String PROPERTY_ATTACHMENT_TYPE = "attachment-type";
0084:            public static final String PROPERTY_ATTACHMENT_TIMESTAMP = "attachment-timestamp";
0085:            public static final String PROPERTY_ALLOW_TEMPLATES = "allow-templates";
0086:            public static final String PROPERTY_USE_PREVIEW = "use-preview";
0087:            public static final String PROPERTY_NEW_LINE_BREAKS = "new-line-breaks";
0088:            public static final String PROPERTY_SMTP_HOST = "smtp-host";
0089:            public static final String PROPERTY_REPLY_ADDRESS = "reply-address";
0090:            public static final String PROPERTY_RECENT_CHANGES_DAYS = "recent-changes-days";
0091:            public static final String PROPERTY_MAXIMUM_BACKLINKS = "maximum-backlinks";
0092:            public static final String PROPERTY_MAX_FILE_SIZE = "max-file-size";
0093:            public static final String PROPERTY_TEMP_DIR = "tmp-dir";
0094:            public static final String PROPERTY_SMTP_USERNAME = "smtp-username";
0095:            public static final String PROPERTY_SMTP_PASSWORD = "smtp-password";
0096:            public static final String PROPERTY_PARSER = "parser";
0097:            public static final String PROPERTY_FORMAT_LEXER = "format-lexer";
0098:            public static final String PROPERTY_LINK_LEXER = "link-lexer";
0099:            public static final String PROPERTY_LAYOUT_LEXER = "layout-lexer";
0100:            public static final String PROPERTY_COOKIE_EXPIRE = "cookie-expire";
0101:            public static final String PROPERTY_CONVERT_TABS = "convert-tabs";
0102:            public static final String PROPERTY_BASE_CONTEXT = "base-context";
0103:            public static final String PROPERTY_ADMIN_PASSWORD = "adminPassword";
0104:            public static final String PROPERTY_FIRST_USE = "firstUse";
0105:            public static final String PROPERTY_CONVERT_ENTITIES = "convert-entities";
0106:            public static final String PROPERTY_DEFAULT_TOPIC = "default-topic";
0107:            public static final String DEFAULT_DEFAULT_TOPIC = "StartingPoints";
0108:            public static final String PROPERTY_DATABASE_TYPE = "database-type";
0109:            public static final String PROPERTY_ALLOW_VWIKI_LIST = "allow-vqwiki-list";
0110:            public static final String PROPERTY_DBCP_MAX_ACTIVE = "dbcp-max-active";
0111:            public static final String PROPERTY_DBCP_MAX_IDLE = "dbcp-max-idle";
0112:            public static final String PROPERTY_DBCP_TEST_ON_BORROW = "dbcp-test-on-borrow";
0113:            public static final String PROPERTY_DBCP_TEST_ON_RETURN = "dbcp-test-on-return";
0114:            public static final String PROPERTY_DBCP_TEST_WHILE_IDLE = "dbcp-test-while-idle";
0115:            public static final String PROPERTY_DBCP_MIN_EVICTABLE_IDLE_TIME = "dbcp-min-evictable-idle-time";
0116:            public static final String PROPERTY_DBCP_TIME_BETWEEN_EVICTION_RUNS = "dbcp-time-between-eviction-runs";
0117:            public static final String PROPERTY_DBCP_NUM_TESTS_PER_EVICTION_RUN = "dbcp-num-tests-per-eviction-run";
0118:            public static final String PROPERTY_DBCP_WHEN_EXHAUSTED_ACTION = "dbcp-when-exhausted-action";
0119:            public static final String PROPERTY_DBCP_VALIDATION_QUERY = "dbcp-validation-query";
0120:            public static final String PROPERTY_DBCP_REMOVE_ABANDONED = "dbcp-remove-abandoned";
0121:            public static final String PROPERTY_DBCP_REMOVE_ABANDONED_TIMEOUT = "dbcp-remove-abandoned-timeout";
0122:            public static final String PROPERTY_DBCP_LOG_ABANDONED = "dbcp-log-abandoned";
0123:            public static final String PROPERTY_ATTACHMENT_INDEXING_ENABLED = "attachment-indexing";
0124:            public static final String PROPERTY_EXTLINKS_INDEXING_ENABLED = "extlinks-indexing";
0125:            public static final String PROPERTY_WIKI_SERVER_HOSTNAME = "wiki-server-hostname";
0126:            public static final String PROPERTY_RECENT_CHANGES_REFRESH_INTERVAL = "recentChangesRefreshInterval";
0127:            public static final String PROPERTY_FILE_ENCODING = "file-encoding";
0128:            public static final String PROPERTY_SEPARATE_WIKI_TITLE_WORDS = "separate-wiki-title-words";
0129:            public static final String PROPERTY_SUPPRESS_NOTIFY_WITHIN_SAME_DAY = "supress-notify-within-same-day";
0130:            public static final String PROPERTY_USERGROUP_TYPE = "usergroup-type";
0131:            public static final String PROPERTY_USERGROUP_FACTORY = "usergroupFactory";
0132:            public static final String PROPERTY_USERGROUP_URL = "usergroupUrl";
0133:            public static final String PROPERTY_USERGROUP_USERNAME = "usergroupUsername";
0134:            public static final String PROPERTY_USERGROUP_PASSWORD = "usergroupPassword";
0135:            public static final String PROPERTY_USERGROUP_BASIC_SEARCH = "usergroupBasicSearch";
0136:            public static final String PROPERTY_USERGROUP_SEARCH_RESTRICTIONS = "usergroupSearchRestrictions";
0137:            public static final String PROPERTY_USERGROUP_USERID_FIELD = "usergroupUseridField";
0138:            public static final String PROPERTY_USERGROUP_FULLNAME_FIELD = "usergroupFullnameField";
0139:            public static final String PROPERTY_USERGROUP_MAIL_FIELD = "usergroupMailField";
0140:            public static final String PROPERTY_USERGROUP_DETAILVIEW = "usergroupDetailView";
0141:            public static final String PROPERTY_FORCE_ENCODING = "force-encoding";
0142:            public static final String PROPERTY_MAKE_TOC = "make-toc";
0143:            public static final String PROPERTY_FRANZ_NEWTOPIC_STYLE = "franz-newtopic-style";
0144:            public static final String PROPERTY_ENCODE_PASSWORDS = "encode-passwords";
0145:            // FIXME (PARSER_TEMP) - temporary property until conversion is complete
0146:            public static final String PROPERTY_USE_NEW_PARSER = "new-parser";
0147:            private static final HashMap DEFAULTS = new HashMap();
0148:            private static final Logger logger = Logger
0149:                    .getLogger(Environment.class);
0150:            /** The actual local path that is the base of the context, i.e. where the wiki is installed */
0151:            private String realPath;
0152:            private String logoImageName;
0153:            private boolean attachmentsToDatabase;
0154:            private static List wikinameIgnore;
0155:
0156:            /**
0157:             * Initialise the environment (put defaults in a table)
0158:             */
0159:            private Environment() {
0160:                logger.debug("new Environment");
0161:                DEFAULTS.put(PROPERTY_UPLOAD_DIR, "upload");
0162:                DEFAULTS.put(PROPERTY_INDEX_REFRESH_INTERVAL, "1440");
0163:                DEFAULTS.put(PROPERTY_ALLOW_HTML, "false");
0164:                DEFAULTS.put(PROPERTY_PERSISTENCE_TYPE, "FILE");
0165:                DEFAULTS.put(PROPERTY_VERSIONING_ON, "true");
0166:                DEFAULTS.put(PROPERTY_EDIT_TIME_OUT, "10");
0167:                DEFAULTS.put(PROPERTY_ALLOW_BACK_TICK, "true");
0168:                DEFAULTS.put(PROPERTY_DRIVER, "org.gjt.mm.mysql.Driver");
0169:                DEFAULTS.put(PROPERTY_URL, "jdbc:mysql://localhost/vqwiki");
0170:                DEFAULTS.put(PROPERTY_USERNAME, "vqwiki");
0171:                // FIXME - default should be empty
0172:                DEFAULTS.put(PROPERTY_PASSWORD, "vqwiki");
0173:                DEFAULTS.put(PROPERTY_FORCE_USERNAME, "false");
0174:                DEFAULTS.put(PROPERTY_MAX_FILE_SIZE, "2000000");
0175:                DEFAULTS.put(PROPERTY_TEMP_DIR, "tmp");
0176:                DEFAULTS.put(PROPERTY_SMTP_USERNAME, "");
0177:                DEFAULTS.put(PROPERTY_SMTP_PASSWORD, "");
0178:                DEFAULTS.put(PROPERTY_PARSER, "vqwiki.lex.DefaultWikiParser");
0179:                DEFAULTS.put(PROPERTY_FORMAT_LEXER, "vqwiki.lex.FormatLex");
0180:                DEFAULTS.put(PROPERTY_LINK_LEXER, "vqwiki.lex.LinkLex");
0181:                DEFAULTS.put(PROPERTY_LAYOUT_LEXER, "vqwiki.lex.LayoutLex");
0182:                DEFAULTS.put(PROPERTY_RECENT_CHANGES_DAYS, "5");
0183:                DEFAULTS.put(PROPERTY_MAXIMUM_BACKLINKS, "20");
0184:                DEFAULTS.put(PROPERTY_REPLY_ADDRESS, "vqwiki-admin@localhost");
0185:                DEFAULTS.put(PROPERTY_SMTP_HOST, "");
0186:                DEFAULTS.put(PROPERTY_NEW_LINE_BREAKS, "1");
0187:                DEFAULTS.put(PROPERTY_ALLOW_TEMPLATES, "true");
0188:                DEFAULTS.put(PROPERTY_USE_PREVIEW, "false");
0189:                DEFAULTS.put(PROPERTY_ATTACHMENT_TYPE, "inline");
0190:                DEFAULTS.put(PROPERTY_ATTACHMENT_TIMESTAMP, "true");
0191:                DEFAULTS.put(PROPERTY_COOKIE_EXPIRE, "31104000");
0192:                DEFAULTS.put(PROPERTY_CONVERT_TABS, "true");
0193:                DEFAULTS.put(PROPERTY_FIRST_USE, "true");
0194:                DEFAULTS.put(PROPERTY_CONVERT_ENTITIES, "false");
0195:                DEFAULTS.put(PROPERTY_DEFAULT_TOPIC, "StartingPoints");
0196:                DEFAULTS.put(PROPERTY_DATABASE_TYPE, "mysql");
0197:                DEFAULTS.put(PROPERTY_ALLOW_VWIKI_LIST, "true");
0198:                DEFAULTS.put(PROPERTY_DBCP_MAX_ACTIVE, "10");
0199:                DEFAULTS.put(PROPERTY_DBCP_MAX_IDLE, "3");
0200:                DEFAULTS.put(PROPERTY_DBCP_TEST_ON_BORROW, "true");
0201:                DEFAULTS.put(PROPERTY_DBCP_TEST_ON_RETURN, "true");
0202:                DEFAULTS.put(PROPERTY_DBCP_TEST_WHILE_IDLE, "true");
0203:                DEFAULTS.put(PROPERTY_DBCP_MIN_EVICTABLE_IDLE_TIME, "600");
0204:                DEFAULTS.put(PROPERTY_DBCP_TIME_BETWEEN_EVICTION_RUNS, "120");
0205:                DEFAULTS.put(PROPERTY_DBCP_NUM_TESTS_PER_EVICTION_RUN, "5");
0206:                DEFAULTS.put(PROPERTY_DBCP_WHEN_EXHAUSTED_ACTION, String
0207:                        .valueOf(GenericObjectPool.WHEN_EXHAUSTED_GROW));
0208:                DEFAULTS.put(PROPERTY_DBCP_VALIDATION_QUERY, "SELECT 1");
0209:                DEFAULTS.put(PROPERTY_DBCP_REMOVE_ABANDONED, "true");
0210:                DEFAULTS.put(PROPERTY_DBCP_REMOVE_ABANDONED_TIMEOUT, "120");
0211:                DEFAULTS.put(PROPERTY_DBCP_LOG_ABANDONED, "true");
0212:                DEFAULTS.put(PROPERTY_WIKI_SERVER_HOSTNAME, "");
0213:                DEFAULTS.put(PROPERTY_FILE_ENCODING, "utf-8");
0214:                DEFAULTS.put(PROPERTY_ATTACHMENT_INDEXING_ENABLED, "false");
0215:                DEFAULTS.put(PROPERTY_EXTLINKS_INDEXING_ENABLED, "false");
0216:                DEFAULTS.put(PROPERTY_RECENT_CHANGES_REFRESH_INTERVAL, "1");
0217:                DEFAULTS.put(PROPERTY_SEPARATE_WIKI_TITLE_WORDS, "false");
0218:                DEFAULTS.put(PROPERTY_SUPPRESS_NOTIFY_WITHIN_SAME_DAY, "false");
0219:                DEFAULTS.put(PROPERTY_USERGROUP_TYPE, "");
0220:                DEFAULTS.put(PROPERTY_USERGROUP_FACTORY,
0221:                        "com.sun.jndi.ldap.LdapCtxFactory");
0222:                DEFAULTS.put(PROPERTY_USERGROUP_URL, "ldap://localhost:389");
0223:                DEFAULTS.put(PROPERTY_USERGROUP_USERNAME, "");
0224:                DEFAULTS.put(PROPERTY_USERGROUP_PASSWORD, "");
0225:                DEFAULTS.put(PROPERTY_USERGROUP_BASIC_SEARCH,
0226:                        "ou=users,dc=mycompany,dc=com");
0227:                DEFAULTS.put(PROPERTY_USERGROUP_SEARCH_RESTRICTIONS,
0228:                        "objectClass=person");
0229:                DEFAULTS.put(PROPERTY_USERGROUP_USERID_FIELD, "uid");
0230:                DEFAULTS.put(PROPERTY_USERGROUP_MAIL_FIELD, "mail");
0231:                DEFAULTS.put(PROPERTY_USERGROUP_FULLNAME_FIELD, "cn");
0232:                DEFAULTS
0233:                        .put(
0234:                                PROPERTY_USERGROUP_DETAILVIEW,
0235:                                "@@cn@@</a><br/>@@title@@<br/>Telefon: @@telephoneNumber@@<br/>Mobil: @@mobile@@<br/>@@ou@@ / @@businessCategory@@<br/><a href=\"mailto:@@mail@@\">@@mail@@</a> <br/>");
0236:                // Tomcat assumes ISO-8859-1 in URI's. That's the reason why all Latin-1 languages can't handle special characters.
0237:                // However, even worse, there is no standard J2EE-way to handle this. We must set this here to ISO-8859-1.
0238:                // If someone needs UTF-8 URI's, he should configure URIEncoding="UTF-8" in Tomcats connector settings (server.xml)
0239:                // or have a look at the specific way of the user application server.
0240:                // also see http://weblogs.java.net/blog/joconner/archive/2005/07/charset_traps.html
0241:                // Note: according to RFC 3986, URL's should be encoded to UTF-8 by default. Unfortunatly, many systems don't comply
0242:                DEFAULTS.put(PROPERTY_FORCE_ENCODING, "ISO-8859-1");
0243:                DEFAULTS.put(PROPERTY_MAKE_TOC, "false");
0244:                DEFAULTS.put(PROPERTY_FRANZ_NEWTOPIC_STYLE, "false");
0245:                // FIXME - this should eventually be made true
0246:                DEFAULTS.put(PROPERTY_ENCODE_PASSWORDS, "false");
0247:                // FIXME (PARSER_TEMP) - temporary property until conversion is complete
0248:                DEFAULTS.put(PROPERTY_USE_NEW_PARSER, "false");
0249:                logger.info("Using properties file location: "
0250:                        + getPropertiesFileLocation());
0251:                refresh();
0252:            }
0253:
0254:            /**
0255:             *
0256:             */
0257:            public static String relativeDirIfNecessary(String path) {
0258:                if (path.length() <= 2) {
0259:                    return path;
0260:                }
0261:                if (!path.startsWith("/")
0262:                        && !(Character.isLetter(path.charAt(0)) && path
0263:                                .charAt(1) == ':')) {
0264:                    return new File(dir(), path).getAbsolutePath();
0265:                }
0266:                return path;
0267:            }
0268:
0269:            /**
0270:             * The directory to place attachments in. This is either an absolute path if the admin setting for "upload directory"
0271:             * starts with a "/" or a drive letter, or it is a relative path.
0272:             * @param virtualWiki
0273:             * @param name
0274:             * @return
0275:             */
0276:            public File uploadPath(String virtualWiki, String name) {
0277:                String dir = Environment.relativeDirIfNecessary(Environment
0278:                        .getInstance().getUploadDir());
0279:                if (virtualWiki == null || "".equals(virtualWiki)) {
0280:                    virtualWiki = WikiBase.DEFAULT_VWIKI;
0281:                }
0282:                File baseDir = new File(dir, virtualWiki);
0283:                baseDir.mkdirs();
0284:                dir = baseDir.getAbsolutePath();
0285:                File uploadedFile = new File(dir, name);
0286:                return uploadedFile;
0287:            }
0288:
0289:            /**
0290:             * Get a stream from a resource name using this classes class loader
0291:             * @param resourceName
0292:             * @return
0293:             */
0294:            public InputStream getResourceAsStream(String resourceName) {
0295:                return Environment.class.getResourceAsStream(resourceName);
0296:            }
0297:
0298:            /**
0299:             * Get default value for an admin property
0300:             * @param settingName
0301:             * @return
0302:             */
0303:            private String defaultValue(String settingName) {
0304:                return (String) DEFAULTS.get(settingName);
0305:            }
0306:
0307:            /**
0308:             * Return a location to store/retrieve the VQWiki properties file. This is in order of precedence:
0309:             * <ol>
0310:             *   <li>The path given by the context environment entry "propertiesFile"</li>
0311:             *   <li>The path found by looking for the resource named "/vqwiki.properties" using the class loader
0312:             * for this class. This will usually be located in WEB-INF/classes</li>
0313:             *   <li>A file called vqwiki.properties in the process owner's home directory</li>
0314:             * </ol>
0315:             * @return properties file location
0316:             */
0317:            private String getPropertiesFileLocation() {
0318:                String propertiesFilePath = null;
0319:                try {
0320:                    InitialContext ictx = new InitialContext();
0321:                    propertiesFilePath = (String) ictx
0322:                            .lookup("java:comp/env/propertiesFile");
0323:                    logger.debug("properties file from context: "
0324:                            + propertiesFilePath);
0325:                } catch (Exception e) {
0326:                    logger.debug("No entry for properties in context:\n"
0327:                            + e.toString());
0328:                }
0329:                if (propertiesFilePath == null) {
0330:                    URL resource = Environment.class
0331:                            .getResource("/vqwiki.properties");
0332:                    logger.debug("properties file as resource: " + resource);
0333:                    if (resource != null) {
0334:                        String defaultencoding = null;
0335:                        try {
0336:                            defaultencoding = System
0337:                                    .getProperty("file.encoding");
0338:                        } catch (AccessControlException ae) {
0339:                            logger
0340:                                    .warn("This application server doesn't allow to access "
0341:                                            + "file.encoding with System.getProperty. Set default "
0342:                                            + "encoding for filename-URL to UTF-8");
0343:                            defaultencoding = "UTF-8";
0344:                        }
0345:                        try {
0346:                            propertiesFilePath = URLDecoder.decode(resource
0347:                                    .getFile(), defaultencoding);
0348:                        } catch (UnsupportedEncodingException e) {
0349:                            logger
0350:                                    .error(
0351:                                            "The platform's default encoding is not supported in the JDK.",
0352:                                            e);
0353:                            try {
0354:                                propertiesFilePath = URLDecoder.decode(resource
0355:                                        .getFile(), "UTF-8");
0356:                            } catch (UnsupportedEncodingException e1) {
0357:                                logger
0358:                                        .fatal(
0359:                                                "Even UTF-8 is not supported by this JDK!",
0360:                                                e1);
0361:                            }
0362:                        }
0363:                        logger.debug("properties file as file from resource: "
0364:                                + propertiesFilePath);
0365:                    }
0366:                }
0367:                if (propertiesFilePath == null) {
0368:                    StringBuffer buffer = new StringBuffer();
0369:                    buffer.append(System.getProperty("user.home"));
0370:                    buffer.append(System.getProperty("file.separator"));
0371:                    buffer.append("wiki/vqwiki.properties");
0372:                }
0373:                return propertiesFilePath;
0374:            }
0375:
0376:            /**
0377:             *
0378:             */
0379:            private InputStream getPropertiesInputStream() throws Exception {
0380:                String propertiesFile = getPropertiesFileLocation();
0381:                if (propertiesFile == null) {
0382:                    return getResourceAsStream("/vqwiki.properties");
0383:                }
0384:                return new FileInputStream(propertiesFile);
0385:            }
0386:
0387:            /**
0388:             *
0389:             */
0390:            public String getStringSetting(String settingName) {
0391:                try {
0392:                    if (currentProperties == null) {
0393:                        currentProperties = new Properties();
0394:                        currentProperties.load(getPropertiesInputStream());
0395:                    }
0396:                } catch (Exception e) {
0397:                    logger.error(e);
0398:                    return defaultValue(settingName);
0399:                }
0400:                String value = currentProperties.getProperty(settingName);
0401:                if (value == null) {
0402:                    return defaultValue(settingName);
0403:                }
0404:                return value;
0405:            }
0406:
0407:            /**
0408:             *
0409:             */
0410:            public int getIntSetting(String settingName) {
0411:                String asString = getStringSetting(settingName);
0412:                logger.debug("Setting as string:" + asString);
0413:                return Integer.parseInt(asString);
0414:            }
0415:
0416:            /**
0417:             *
0418:             */
0419:            public boolean getBooleanSetting(String settingName) {
0420:                return Boolean.valueOf(getStringSetting(settingName))
0421:                        .booleanValue();
0422:            }
0423:
0424:            /**
0425:             *
0426:             */
0427:            public void setSetting(String settingName, String value) {
0428:                try {
0429:                    if (currentProperties == null) {
0430:                        currentProperties = new Properties();
0431:                        currentProperties.load(getPropertiesInputStream());
0432:                    }
0433:                } catch (Exception e) {
0434:                    logger.error("Error setting " + settingName, e);
0435:                    return;
0436:                }
0437:                currentProperties.setProperty(settingName, value);
0438:            }
0439:
0440:            /**
0441:             *
0442:             */
0443:            public void setSetting(String settingName, boolean value) {
0444:                setSetting(settingName, String.valueOf(value));
0445:            }
0446:
0447:            /**
0448:             *
0449:             */
0450:            public void setSetting(String settingName, int value) {
0451:                setSetting(settingName, String.valueOf(value));
0452:            }
0453:
0454:            /**
0455:             *
0456:             */
0457:            public boolean getForceUsername() {
0458:                return getBooleanSetting(PROPERTY_FORCE_USERNAME);
0459:            }
0460:
0461:            /**
0462:             * Re-read the properties file and sets the home directory. If no properties
0463:             * file is found it will be the user's home directory + "/wiki"
0464:             */
0465:            public void refresh() {
0466:                currentProperties = new Properties();
0467:                File f = null;
0468:                try {
0469:                    f = getPropsFile();
0470:                    logger.debug("Loading properties from " + f);
0471:                    currentProperties.load(new FileInputStream(f));
0472:                    //dir
0473:                    if (currentProperties.getProperty(PROPERTY_HOME_DIR) == null) {
0474:                        currentProperties
0475:                                .setProperty(PROPERTY_HOME_DIR, System
0476:                                        .getProperty("user.home")
0477:                                        + System.getProperty("file.separator")
0478:                                        + "wiki");
0479:                    }
0480:                    //allow back-tick
0481:                    if (currentProperties.getProperty("attachmentsToDatabase") == null) {
0482:                        setSetting(PROPERTY_ALLOW_BACK_TICK,
0483:                                DEFAULT_ATTACHMENTS_TO_DATABASE);
0484:                    } else {
0485:                        setSetting(PROPERTY_ALLOW_BACK_TICK, Boolean.valueOf(
0486:                                currentProperties.getProperty("allowBackTick"))
0487:                                .booleanValue());
0488:                    }
0489:                } catch (Exception e) {
0490:                    logger
0491:                            .debug("Couldn't access properrties file, using static defaults: "
0492:                                    + f);
0493:                    logger.debug("Handled exception: " + e);
0494:                    currentProperties = new Properties();
0495:                    currentProperties.setProperty(PROPERTY_HOME_DIR, System
0496:                            .getProperty("user.home")
0497:                            + System.getProperty("file.separator") + "wiki");
0498:                }
0499:                logger.debug("Properties: " + currentProperties);
0500:                logoImageName = lookupLogoImageName();
0501:                if (getPersistenceType() == WikiBase.DATABASE) {
0502:                    DatabaseConnection.setPoolInitialized(false);
0503:                }
0504:            }
0505:
0506:            /**
0507:             *
0508:             */
0509:            public void saveProperties() throws Exception {
0510:                File f = getPropsFile();
0511:                logger.debug("Writing to properties file: " + f);
0512:                if (currentProperties == null) {
0513:                    currentProperties = new Properties();
0514:                }
0515:                //FileOutputStream out = new FileOutputStream( f );
0516:                OutputStream out = getPropertiesOutputStream();
0517:                logger.debug(currentProperties);
0518:                currentProperties.store(out, "VQWiki");
0519:                out.close();
0520:            }
0521:
0522:            /**
0523:             * Singleton reinforcement
0524:             */
0525:            public static Environment getInstance() {
0526:                if (instance == null) {
0527:                    instance = new Environment();
0528:                }
0529:                return instance;
0530:            }
0531:
0532:            /**
0533:             *
0534:             */
0535:            private File getPropsFile() throws Exception {
0536:                return new File(getPropertiesFileLocation());
0537:            }
0538:
0539:            /**
0540:             * Returns the base directory for the Wiki file-system
0541:             */
0542:            public String getHomeDir() {
0543:                return getStringSetting(PROPERTY_HOME_DIR);
0544:            }
0545:
0546:            /**
0547:             *
0548:             */
0549:            public void setHomeDir(String dir) {
0550:                setSetting(PROPERTY_HOME_DIR, dir);
0551:            }
0552:
0553:            /**
0554:             * Returns the directory for uploading topic attachments to
0555:             */
0556:            public String getUploadDir() {
0557:                return getStringSetting(PROPERTY_UPLOAD_DIR);
0558:            }
0559:
0560:            /**
0561:             *
0562:             */
0563:            public int getIndexRefreshInterval() {
0564:                return getIntSetting(PROPERTY_INDEX_REFRESH_INTERVAL);
0565:            }
0566:
0567:            /**
0568:             *
0569:             */
0570:            public void setIndexRefreshInterval(int interval) {
0571:                setSetting(PROPERTY_INDEX_REFRESH_INTERVAL, interval);
0572:            }
0573:
0574:            /**
0575:             *
0576:             */
0577:            public int getRecentChangesRefreshInterval() {
0578:                return getIntSetting(PROPERTY_RECENT_CHANGES_REFRESH_INTERVAL);
0579:            }
0580:
0581:            /**
0582:             *
0583:             */
0584:            public void setRecentChangesRefreshInterval(int interval) {
0585:                setSetting(PROPERTY_RECENT_CHANGES_REFRESH_INTERVAL, interval);
0586:            }
0587:
0588:            /**
0589:             *
0590:             */
0591:            public boolean getAllowHTML() {
0592:                return getBooleanSetting(PROPERTY_ALLOW_HTML);
0593:            }
0594:
0595:            /**
0596:             *
0597:             */
0598:            public void setAllowHTML(boolean allow) {
0599:                setSetting(PROPERTY_ALLOW_HTML, allow);
0600:            }
0601:
0602:            /**
0603:             *
0604:             */
0605:            public boolean isVersioningOn() {
0606:                return getBooleanSetting(PROPERTY_VERSIONING_ON);
0607:            }
0608:
0609:            /**
0610:             *
0611:             */
0612:            public void setVersioningOn(boolean on) {
0613:                setSetting(PROPERTY_VERSIONING_ON, on);
0614:            }
0615:
0616:            /**
0617:             *
0618:             */
0619:            public int getPersistenceType() {
0620:                if (getStringSetting(PROPERTY_PERSISTENCE_TYPE).equals(
0621:                        "DATABASE")) {
0622:                    return WikiBase.DATABASE;
0623:                } else {
0624:                    return WikiBase.FILE;
0625:                }
0626:            }
0627:
0628:            /**
0629:             *
0630:             */
0631:            public void setPersistenceType(int persistenceType) {
0632:                if (persistenceType == WikiBase.FILE) {
0633:                    setSetting(PROPERTY_PERSISTENCE_TYPE, "FILE");
0634:                } else if (persistenceType == WikiBase.DATABASE) {
0635:                    setSetting(PROPERTY_PERSISTENCE_TYPE, "DATABASE");
0636:                }
0637:            }
0638:
0639:            /**
0640:             *
0641:             */
0642:            public int getEditTimeOut() {
0643:                return getIntSetting(PROPERTY_EDIT_TIME_OUT);
0644:            }
0645:
0646:            /**
0647:             *
0648:             */
0649:            public void setEditTimeOut(int timeout) {
0650:                setSetting(PROPERTY_EDIT_TIME_OUT, timeout);
0651:            }
0652:
0653:            /**
0654:             *
0655:             */
0656:            public void setUploadDir(String dir) {
0657:                setSetting(PROPERTY_UPLOAD_DIR, dir);
0658:            }
0659:
0660:            /**
0661:             *
0662:             */
0663:            public static String dir() {
0664:                return getInstance().getHomeDir()
0665:                        + System.getProperty("file.separator");
0666:            }
0667:
0668:            /**
0669:             *
0670:             */
0671:            public String getBaseContext() {
0672:                return getStringSetting(PROPERTY_BASE_CONTEXT);
0673:            }
0674:
0675:            /**
0676:             *
0677:             */
0678:            public void setBaseContext(String baseContext) {
0679:                setSetting(PROPERTY_BASE_CONTEXT, baseContext);
0680:            }
0681:
0682:            /**
0683:             *
0684:             */
0685:            public boolean isAllowBackTick() {
0686:                return getBooleanSetting(PROPERTY_ALLOW_BACK_TICK);
0687:            }
0688:
0689:            /**
0690:             *
0691:             */
0692:            public void setAllowBackTick(boolean allowBackTick) {
0693:                setSetting(PROPERTY_ALLOW_BACK_TICK, allowBackTick);
0694:            }
0695:
0696:            /**
0697:             *
0698:             */
0699:            public boolean isAttachmentsToDatabase() {
0700:                return attachmentsToDatabase;
0701:            }
0702:
0703:            /**
0704:             *
0705:             */
0706:            public void setAttachmentsToDatabase(boolean _attachmentsToDatabase) {
0707:                this .attachmentsToDatabase = _attachmentsToDatabase;
0708:            }
0709:
0710:            /**
0711:             *
0712:             */
0713:            public String getDriver() {
0714:                return getStringSetting(PROPERTY_DRIVER);
0715:            }
0716:
0717:            /**
0718:             *
0719:             */
0720:            public void setDriver(String driver) {
0721:                setSetting(PROPERTY_DRIVER, driver);
0722:            }
0723:
0724:            /**
0725:             *
0726:             */
0727:            public String getUrl() {
0728:                return getStringSetting(PROPERTY_URL);
0729:            }
0730:
0731:            /**
0732:             *
0733:             */
0734:            public void setUrl(String url) {
0735:                setSetting(PROPERTY_URL, url);
0736:            }
0737:
0738:            /**
0739:             *
0740:             */
0741:            public String getUserName() {
0742:                return getStringSetting(PROPERTY_USERNAME);
0743:            }
0744:
0745:            /**
0746:             *
0747:             */
0748:            public void setUserName(String userName) {
0749:                setSetting(PROPERTY_USERNAME, userName);
0750:            }
0751:
0752:            /**
0753:             *
0754:             */
0755:            public String getPassword() {
0756:                if (getBooleanSetting(PROPERTY_ENCODE_PASSWORDS)) {
0757:                    return Encryption
0758:                            .decrypt(getStringSetting(PROPERTY_PASSWORD));
0759:                }
0760:                return getStringSetting(PROPERTY_PASSWORD);
0761:            }
0762:
0763:            /**
0764:             *
0765:             */
0766:            public void setPassword(String password) throws Exception {
0767:                if (getBooleanSetting(PROPERTY_ENCODE_PASSWORDS)) {
0768:                    password = Encryption.encrypt(password);
0769:                }
0770:                setSetting(PROPERTY_PASSWORD, password);
0771:            }
0772:
0773:            /**
0774:             *
0775:             */
0776:            public boolean isForceUsername() {
0777:                return getBooleanSetting(PROPERTY_FORCE_USERNAME);
0778:            }
0779:
0780:            /**
0781:             *
0782:             */
0783:            public void setForceUsername(boolean forceUsername) {
0784:                setSetting(PROPERTY_FORCE_USERNAME, forceUsername);
0785:            }
0786:
0787:            /**
0788:             *
0789:             */
0790:            public String getLogoImageName() {
0791:                return this .logoImageName;
0792:            }
0793:
0794:            /**
0795:             *
0796:             */
0797:            public boolean isDefaultLogoImageName() {
0798:                return DEFAULT_LOGO_IMAGE_NAME.equals(logoImageName);
0799:            }
0800:
0801:            /**
0802:             *
0803:             */
0804:            public boolean isLogoImageAbsoluteUrl() {
0805:                return lookupLogoImageName().indexOf(':') >= 0;
0806:            }
0807:
0808:            /**
0809:             *
0810:             */
0811:            public boolean isEmailAvailable() {
0812:                String smtpHost = this .getStringSetting(PROPERTY_SMTP_HOST);
0813:                if (smtpHost != null) {
0814:                    return !"".equals(smtpHost);
0815:                }
0816:                return false;
0817:            }
0818:
0819:            /**
0820:             *
0821:             */
0822:            public boolean isAllowVirtualWikiList() {
0823:                return this .getBooleanSetting(PROPERTY_ALLOW_VWIKI_LIST);
0824:            }
0825:
0826:            /**
0827:             *
0828:             */
0829:            public boolean isTemplatesAvailable() {
0830:                return this .getBooleanSetting(PROPERTY_ALLOW_TEMPLATES);
0831:            }
0832:
0833:            /**
0834:             *
0835:             */
0836:            public boolean isPreviewAvailable() {
0837:                return this .getBooleanSetting(PROPERTY_USE_PREVIEW);
0838:            }
0839:
0840:            /**
0841:             *
0842:             */
0843:            public boolean isConvertTabs() {
0844:                return this .getBooleanSetting(PROPERTY_CONVERT_TABS);
0845:            }
0846:
0847:            /**
0848:             *
0849:             */
0850:            public String getDefaultTopic() {
0851:                return this .getStringSetting(PROPERTY_DEFAULT_TOPIC);
0852:            }
0853:
0854:            /**
0855:             *
0856:             */
0857:            public String getDefaultTopicEncoded() {
0858:                return JSPUtils.encodeURL(this 
0859:                        .getStringSetting(PROPERTY_DEFAULT_TOPIC));
0860:            }
0861:
0862:            /**
0863:             *
0864:             */
0865:            private String lookupLogoImageName() {
0866:                String _logoImageName = null;
0867:                try {
0868:                    InitialContext ictx = new InitialContext();
0869:                    _logoImageName = (String) ictx
0870:                            .lookup("java:comp/env/logoImageName");
0871:                    if (_logoImageName != null && !"".equals(logoImageName)) {
0872:                        return _logoImageName;
0873:                    }
0874:                } catch (Exception e) {
0875:                    logger.debug("Exception retrieving logoImageName:\n"
0876:                            + e.toString());
0877:                }
0878:                return DEFAULT_LOGO_IMAGE_NAME;
0879:            }
0880:
0881:            /**
0882:             *
0883:             */
0884:            private OutputStream getPropertiesOutputStream() throws Exception {
0885:                String propertiesFile = getPropertiesFileLocation();
0886:                return new FileOutputStream(propertiesFile, false);
0887:            }
0888:
0889:            /**
0890:             *
0891:             */
0892:            public boolean isFirstUse() {
0893:                if (getBooleanSetting(PROPERTY_FIRST_USE)) {
0894:                    logger.info("First use of VQWiki, creating admin password");
0895:                    try {
0896:                        setAdminPassword(generateNewAdminPassword());
0897:                        setSetting(PROPERTY_FIRST_USE, false);
0898:                        saveProperties();
0899:                    } catch (Exception e) {
0900:                        logger.error(e);
0901:                    }
0902:                    return true;
0903:                }
0904:                return false;
0905:            }
0906:
0907:            /**
0908:             *
0909:             */
0910:            public String getAdminPassword() {
0911:                if (getBooleanSetting(PROPERTY_ENCODE_PASSWORDS)) {
0912:                    return Encryption
0913:                            .decrypt(getStringSetting(PROPERTY_ADMIN_PASSWORD));
0914:                }
0915:                return getStringSetting(PROPERTY_ADMIN_PASSWORD);
0916:            }
0917:
0918:            /**
0919:             *
0920:             */
0921:            public void setAdminPassword(String password) throws Exception {
0922:                if (getBooleanSetting(PROPERTY_ENCODE_PASSWORDS)) {
0923:                    password = Encryption.encrypt(password);
0924:                }
0925:                setSetting(PROPERTY_ADMIN_PASSWORD, password);
0926:            }
0927:
0928:            /**
0929:             *
0930:             */
0931:            public String generateNewAdminPassword() {
0932:                StringBuffer buffer = new StringBuffer();
0933:                for (int i = 0; i < 5; i++) {
0934:                    int n = (int) (Math.random() * 26 + 65);
0935:                    buffer.append((char) n);
0936:                }
0937:                String value = buffer.toString();
0938:                return value;
0939:            }
0940:
0941:            /**
0942:             *
0943:             */
0944:            public String getSmtpPassword() {
0945:                if (getBooleanSetting(PROPERTY_ENCODE_PASSWORDS)) {
0946:                    return Encryption
0947:                            .decrypt(getStringSetting(PROPERTY_SMTP_PASSWORD));
0948:                }
0949:                return getStringSetting(PROPERTY_SMTP_PASSWORD);
0950:            }
0951:
0952:            /**
0953:             *
0954:             */
0955:            public void setSmtpPassword(String smtpPassword) throws Exception {
0956:                if (getBooleanSetting(PROPERTY_ENCODE_PASSWORDS)) {
0957:                    smtpPassword = Encryption.encrypt(smtpPassword);
0958:                }
0959:                setSetting(PROPERTY_SMTP_PASSWORD, smtpPassword);
0960:            }
0961:
0962:            /**
0963:             *
0964:             */
0965:            public String getUserGroupPassword() {
0966:                if (getBooleanSetting(PROPERTY_ENCODE_PASSWORDS)) {
0967:                    return Encryption
0968:                            .decrypt(getStringSetting(PROPERTY_USERGROUP_PASSWORD));
0969:                }
0970:                return getStringSetting(PROPERTY_USERGROUP_PASSWORD);
0971:            }
0972:
0973:            /**
0974:             *
0975:             */
0976:            public void setUserGroupPassword(String userGroupPassword)
0977:                    throws Exception {
0978:                if (getBooleanSetting(PROPERTY_ENCODE_PASSWORDS)) {
0979:                    userGroupPassword = Encryption.encrypt(userGroupPassword);
0980:                }
0981:                setSetting(PROPERTY_USERGROUP_PASSWORD, userGroupPassword);
0982:            }
0983:
0984:            /**
0985:             *
0986:             */
0987:            public boolean isMySQL() {
0988:                return ("mysql".equalsIgnoreCase(getDatabaseType()));
0989:            }
0990:
0991:            /**
0992:             *
0993:             */
0994:            public boolean isOracle() {
0995:                return ("oracle".equalsIgnoreCase(getDatabaseType()));
0996:            }
0997:
0998:            /**
0999:             *
1000:             */
1001:            public String getDatabaseType() {
1002:                return getStringSetting(PROPERTY_DATABASE_TYPE);
1003:            }
1004:
1005:            /**
1006:             *
1007:             */
1008:            public String getFileEncoding() {
1009:                return getStringSetting(PROPERTY_FILE_ENCODING);
1010:            }
1011:
1012:            /**
1013:             *
1014:             */
1015:            public String getForceEncoding() {
1016:                return getStringSetting(PROPERTY_FORCE_ENCODING);
1017:            }
1018:
1019:            /**
1020:             * Property for making automatic TOC on the right side.
1021:             * THIS HAS EXPERIMENTAL STATE.
1022:             * @return true if there shold be a table of content on every site, false otherwise.
1023:             */
1024:            public boolean isMakeToc() {
1025:                return getBooleanSetting(PROPERTY_MAKE_TOC);
1026:            }
1027:
1028:            /**
1029:             * Property for switching between Franz Newtopic style (a new topic has a question mark after the topic) or
1030:             * CSS newtopic style (the whole topic will be displayed with the css-class "newtopic").
1031:             * @return true if a new topic should have a clickable question mark after the word,
1032:             *         false if a new topic word should be displayed with the css class "newtopic".
1033:             */
1034:            public boolean isFranzNewTopicStyle() {
1035:                return getBooleanSetting(PROPERTY_FRANZ_NEWTOPIC_STYLE);
1036:            }
1037:
1038:            /**
1039:             *
1040:             */
1041:            public boolean doIgnoreWikiname(String name) {
1042:                if (wikinameIgnore == null) {
1043:                    wikinameIgnore = new ArrayList();
1044:                    InputStream in = getClass().getResourceAsStream(
1045:                            "/wikiname.ignore");
1046:                    if (in == null) {
1047:                        logger
1048:                                .debug("No wikinames to ignore, wikiname.ignore does not exist");
1049:                        return false;
1050:                    }
1051:                    try {
1052:                        BufferedReader reader = new BufferedReader(
1053:                                new InputStreamReader(in));
1054:                        while (true) {
1055:                            String line = reader.readLine();
1056:                            if (line == null) {
1057:                                break;
1058:                            }
1059:                            logger.debug("Adding " + line.toLowerCase()
1060:                                    + " to ignore list");
1061:                            wikinameIgnore.add(line.toLowerCase());
1062:                        }
1063:                        reader.close();
1064:                        in.close();
1065:                    } catch (IOException e) {
1066:                        logger.warn("Error reading wikiname.ignore", e);
1067:                    }
1068:                }
1069:                if (wikinameIgnore.isEmpty()) {
1070:                    return false;
1071:                }
1072:                boolean ignore = wikinameIgnore.contains(name.toLowerCase());
1073:                if (ignore) {
1074:                    logger.debug("Do ignore " + name);
1075:                }
1076:                return ignore;
1077:            }
1078:
1079:            /**
1080:             *
1081:             */
1082:            public boolean isAttachmentIndexingEnabled() {
1083:                return getBooleanSetting(PROPERTY_ATTACHMENT_INDEXING_ENABLED);
1084:            }
1085:
1086:            /**
1087:             *
1088:             */
1089:            public boolean isAttachmentTimestamp() {
1090:                return this .getBooleanSetting(PROPERTY_ATTACHMENT_TIMESTAMP);
1091:            }
1092:
1093:            /**
1094:             *
1095:             */
1096:            public boolean isExtLinksIndexingEnabled() {
1097:                return getBooleanSetting(PROPERTY_EXTLINKS_INDEXING_ENABLED);
1098:            }
1099:
1100:            /**
1101:             * Return true if titles are to be spaced between the humps in the CamelCaps, e.g "Camel Caps"
1102:             *
1103:             * @return true if separate title words is on
1104:             */
1105:            public boolean isSeparateWikiTitleWords() {
1106:                return this 
1107:                        .getBooleanSetting(PROPERTY_SEPARATE_WIKI_TITLE_WORDS);
1108:            }
1109:
1110:            /**
1111:             * This is set by the main controller servlet on every request
1112:             * @param realPath the actual local path that is the base of the context
1113:             */
1114:            public void setRealPath(String realPath) {
1115:                logger.debug("real path: " + realPath);
1116:                this .realPath = realPath;
1117:            }
1118:
1119:            /**
1120:             * the actual local path that is the base of the context
1121:             * @return path
1122:             */
1123:            public String getRealPath() {
1124:                return realPath;
1125:            }
1126:
1127:            /**
1128:             * @return Returns the usergroupType.
1129:             */
1130:            public int getUsergroupType() {
1131:                String persistenceType = getStringSetting(PROPERTY_USERGROUP_TYPE);
1132:                if (persistenceType.equals("LDAP")) {
1133:                    return WikiBase.LDAP;
1134:                } else if (persistenceType.equals("DATABASE")) {
1135:                    return WikiBase.DATABASE;
1136:                } else {
1137:                    return 0;
1138:                }
1139:            }
1140:
1141:            /**
1142:             * @param membershipType The usergroupType to set.
1143:             */
1144:            public void setUsergroupType(int membershipType) {
1145:                String usergroupType;
1146:                if (membershipType == WikiBase.LDAP) {
1147:                    usergroupType = "LDAP";
1148:                } else if (membershipType == WikiBase.DATABASE) {
1149:                    usergroupType = "DATABASE";
1150:                } else {
1151:                    usergroupType = "";
1152:                }
1153:                setSetting(PROPERTY_USERGROUP_TYPE, usergroupType);
1154:            }
1155:
1156:            /**
1157:             *
1158:             */
1159:            public boolean getEncodePasswords() {
1160:                return getBooleanSetting(PROPERTY_ENCODE_PASSWORDS);
1161:            }
1162:
1163:            /**
1164:             *
1165:             */
1166:            public void setEncodePasswords(boolean encode) throws Exception {
1167:                // get passwords prior to changing encryption
1168:                String adminPassword = this .getAdminPassword();
1169:                String dbPassword = this .getPassword();
1170:                String smtpPassword = this .getSmtpPassword();
1171:                String userGroupPassword = this .getUserGroupPassword();
1172:                // change encryption
1173:                setSetting(PROPERTY_ENCODE_PASSWORDS, encode);
1174:                // re-set passwords with changed encryption
1175:                setAdminPassword(adminPassword);
1176:                setPassword(dbPassword);
1177:                setSmtpPassword(smtpPassword);
1178:                setUserGroupPassword(userGroupPassword);
1179:            }
1180:
1181:            /**
1182:             * FIXME (PARSER_TEMP) - temporary property until conversion is complete
1183:             */
1184:            public boolean getUseNewParser() {
1185:                return getBooleanSetting(PROPERTY_USE_NEW_PARSER);
1186:            }
1187:
1188:            /**
1189:             * FIXME (PARSER_TEMP) - temporary property until conversion is complete
1190:             */
1191:            public void setUseNewParser(boolean encode) throws Exception {
1192:                setSetting(PROPERTY_USE_NEW_PARSER, encode);
1193:            }
1194:
1195:            /**
1196:             *
1197:             */
1198:            public String getActionAdmin() {
1199:                return WikiServlet.ACTION_ADMIN;
1200:            }
1201:
1202:            /**
1203:             *
1204:             */
1205:            public String getActionAllTopics() {
1206:                return WikiServlet.ACTION_ALL_TOPICS;
1207:            }
1208:
1209:            /**
1210:             *
1211:             */
1212:            public String getActionAppend() {
1213:                return WikiServlet.ACTION_APPEND;
1214:            }
1215:
1216:            /**
1217:             *
1218:             */
1219:            public String getActionAttach() {
1220:                return WikiServlet.ACTION_ATTACH;
1221:            }
1222:
1223:            /**
1224:             *
1225:             */
1226:            public String getActionCancel() {
1227:                return WikiServlet.ACTION_CANCEL;
1228:            }
1229:
1230:            /**
1231:             *
1232:             */
1233:            public String getActionDiff() {
1234:                return WikiServlet.ACTION_DIFF;
1235:            }
1236:
1237:            /**
1238:             *
1239:             */
1240:            public String getActionEdit() {
1241:                return WikiServlet.ACTION_EDIT;
1242:            }
1243:
1244:            /**
1245:             *
1246:             */
1247:            public String getActionEditUser() {
1248:                return WikiServlet.ACTION_EDIT_USER;
1249:            }
1250:
1251:            /**
1252:             *
1253:             */
1254:            public String getActionFirstUse() {
1255:                return WikiServlet.ACTION_FIRST_USE;
1256:            }
1257:
1258:            /**
1259:             *
1260:             */
1261:            public String getActionHistory() {
1262:                return WikiServlet.ACTION_HISTORY;
1263:            }
1264:
1265:            /**
1266:             *
1267:             */
1268:            public String getActionImport() {
1269:                return WikiServlet.ACTION_IMPORT;
1270:            }
1271:
1272:            /**
1273:             *
1274:             */
1275:            public String getActionLocklist() {
1276:                return WikiServlet.ACTION_LOCKLIST;
1277:            }
1278:
1279:            /**
1280:             *
1281:             */
1282:            public String getActionLogin() {
1283:                return WikiServlet.ACTION_LOGIN;
1284:            }
1285:
1286:            /**
1287:             *
1288:             */
1289:            public String getActionMember() {
1290:                return WikiServlet.ACTION_MEMBER;
1291:            }
1292:
1293:            /**
1294:             *
1295:             */
1296:            public String getActionMenuJump() {
1297:                return WikiServlet.ACTION_MENU_JUMP;
1298:            }
1299:
1300:            /**
1301:             *
1302:             */
1303:            public String getActionNotify() {
1304:                return WikiServlet.ACTION_NOTIFY;
1305:            }
1306:
1307:            /**
1308:             *
1309:             */
1310:            public String getActionOrphanedTopics() {
1311:                return WikiServlet.ACTION_ORPHANED_TOPICS;
1312:            }
1313:
1314:            /**
1315:             *
1316:             */
1317:            public String getActionPreview() {
1318:                return WikiServlet.ACTION_PREVIEW;
1319:            }
1320:
1321:            /**
1322:             *
1323:             */
1324:            public String getActionPrint() {
1325:                return WikiServlet.ACTION_PRINT;
1326:            }
1327:
1328:            /**
1329:             *
1330:             */
1331:            public String getActionRecentChanges() {
1332:                return WikiServlet.ACTION_RECENT_CHANGES;
1333:            }
1334:
1335:            /**
1336:             *
1337:             */
1338:            public String getActionRss() {
1339:                return WikiServlet.ACTION_RSS;
1340:            }
1341:
1342:            /**
1343:             *
1344:             */
1345:            public String getActionSave() {
1346:                return WikiServlet.ACTION_SAVE;
1347:            }
1348:
1349:            /**
1350:             *
1351:             */
1352:            public String getActionSaveTemplate() {
1353:                return WikiServlet.ACTION_SAVE_TEMPLATE;
1354:            }
1355:
1356:            /**
1357:             *
1358:             */
1359:            public String getActionSaveUser() {
1360:                return WikiServlet.ACTION_SAVE_USER;
1361:            }
1362:
1363:            /**
1364:             *
1365:             */
1366:            public String getActionSearch() {
1367:                return WikiServlet.ACTION_SEARCH;
1368:            }
1369:
1370:            /**
1371:             *
1372:             */
1373:            public String getActionSearchResults() {
1374:                return WikiServlet.ACTION_SEARCH_RESULTS;
1375:            }
1376:
1377:            /**
1378:             *
1379:             */
1380:            public String getActionTodoTopics() {
1381:                return WikiServlet.ACTION_TODO_TOPICS;
1382:            }
1383:
1384:            /**
1385:             *
1386:             */
1387:            public String getActionUnlock() {
1388:                return WikiServlet.ACTION_UNLOCK;
1389:            }
1390:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.