/** * This method causes all existing data to be deleted from the Wiki. Use only when totally * re-initializing a system. To reiterate: CALLING THIS METHOD WILL DELETE ALL WIKI DATA! */ protected static void purgeData(Connection conn) throws Exception { // BOOM! Everything gone... WikiDatabase.queryHandler().dropTables(conn); try { // re-create empty tables WikiDatabase.queryHandler().createTables(conn); } catch (Exception e) { // creation failure, don't leave tables half-committed WikiDatabase.queryHandler().dropTables(conn); } }
protected static void initialize() { try { WikiDatabase.CONNECTION_VALIDATION_QUERY = WikiDatabase.queryHandler().connectionValidationQuery(); WikiDatabase.EXISTENCE_VALIDATION_QUERY = WikiDatabase.queryHandler().existenceValidationQuery(); // initialize connection pool in its own try-catch to avoid an error // causing property values not to be saved. DatabaseConnection.setPoolInitialized(false); } catch (Exception e) { logger.severe("Unable to initialize database", e); } }
private void setProperties(HttpServletRequest request, ModelAndView next) throws Exception { Environment.setValue( Environment.PROP_BASE_FILE_DIR, request.getParameter(Environment.PROP_BASE_FILE_DIR)); Environment.setValue( Environment.PROP_FILE_DIR_FULL_PATH, request.getParameter(Environment.PROP_FILE_DIR_FULL_PATH)); Environment.setValue( Environment.PROP_FILE_DIR_RELATIVE_PATH, request.getParameter(Environment.PROP_FILE_DIR_RELATIVE_PATH)); Environment.setValue( Environment.PROP_BASE_PERSISTENCE_TYPE, request.getParameter(Environment.PROP_BASE_PERSISTENCE_TYPE)); if (Environment.getValue(Environment.PROP_BASE_PERSISTENCE_TYPE) .equals(WikiBase.PERSISTENCE_EXTERNAL)) { Environment.setValue( Environment.PROP_DB_DRIVER, request.getParameter(Environment.PROP_DB_DRIVER)); Environment.setValue( Environment.PROP_DB_TYPE, request.getParameter(Environment.PROP_DB_TYPE)); Environment.setValue(Environment.PROP_DB_URL, request.getParameter(Environment.PROP_DB_URL)); Environment.setValue( Environment.PROP_DB_USERNAME, request.getParameter(Environment.PROP_DB_USERNAME)); Encryption.setEncryptedProperty( Environment.PROP_DB_PASSWORD, request.getParameter(Environment.PROP_DB_PASSWORD), null); next.addObject("dbPassword", request.getParameter(Environment.PROP_DB_PASSWORD)); } else { WikiDatabase.setupDefaultDatabase(Environment.getInstance()); } Environment.setValue(Environment.PROP_FILE_SERVER_URL, Utilities.getServerUrl(request)); Environment.setValue(Environment.PROP_SERVER_URL, Utilities.getServerUrl(request)); }
protected static void releaseConnection(Connection conn, Object transactionObject) throws Exception { if (transactionObject instanceof Connection) { // transaction objects will be released elsewhere return; } WikiDatabase.releaseConnection(conn); }
protected static void setup(Locale locale, WikiUser user) throws Exception { Connection conn = null; try { try { conn = WikiDatabase.getConnection(); // set up tables WikiDatabase.queryHandler().createTables(conn); } catch (Exception e) { logger.severe("Unable to set up database tables", e); // clean up anything that might have been created WikiDatabase.queryHandler().dropTables(conn); throw e; } try { WikiDatabase.setupDefaultVirtualWiki(conn); WikiDatabase.setupAdminUser(user, conn); WikiDatabase.setupSpecialPages(locale, user, conn); } catch (Exception e) { DatabaseConnection.handleErrors(conn); throw e; } } finally { WikiDatabase.releaseConnection(conn); } }
/** * Initialize a test HSQL database for JAMWiki including two virtual wikis and a default user * account. */ private void setupDatabase() throws Exception { WikiDatabase.setupDefaultDatabase(Environment.getInstance()); Locale locale = new Locale("en-US"); String username = "******"; String password = "******"; WikiUser wikiUser = new WikiUser(username); WikiBase.reset(locale, wikiUser, username, password); // set up a second "test" virtual wiki VirtualWiki virtualWiki = new VirtualWiki("test"); virtualWiki.setRootTopicName("StartingPoints"); WikiBase.getDataHandler().writeVirtualWiki(virtualWiki); WikiBase.getDataHandler().setupSpecialPages(locale, wikiUser, virtualWiki); }
protected static Connection getConnection(Object transactionObject) throws Exception { if (transactionObject instanceof Connection) { return (Connection) transactionObject; } return WikiDatabase.getConnection(); }
static { WikiDatabase.initialize(); }
private void properties(HttpServletRequest request, ModelAndView next, WikiPageInfo pageInfo) throws Exception { Properties props = new Properties(); try { setProperty(props, request, Environment.PROP_BASE_DEFAULT_TOPIC); setProperty(props, request, Environment.PROP_BASE_LOGO_IMAGE); setProperty(props, request, Environment.PROP_BASE_META_DESCRIPTION); setBooleanProperty(props, request, Environment.PROP_TOPIC_NON_ADMIN_TOPIC_MOVE); setBooleanProperty(props, request, Environment.PROP_TOPIC_FORCE_USERNAME); setBooleanProperty(props, request, Environment.PROP_TOPIC_WYSIWYG); setProperty(props, request, Environment.PROP_IMAGE_RESIZE_INCREMENT); setProperty(props, request, Environment.PROP_RECENT_CHANGES_NUM); setBooleanProperty(props, request, Environment.PROP_TOPIC_SPAM_FILTER); setBooleanProperty(props, request, Environment.PROP_TOPIC_USE_PREVIEW); setBooleanProperty(props, request, Environment.PROP_PRINT_NEW_WINDOW); setProperty(props, request, Environment.PROP_PARSER_CLASS); setBooleanProperty(props, request, Environment.PROP_PARSER_TOC); setProperty(props, request, Environment.PROP_PARSER_TOC_DEPTH); setBooleanProperty(props, request, Environment.PROP_PARSER_ALLOW_HTML); setBooleanProperty(props, request, Environment.PROP_PARSER_ALLOW_JAVASCRIPT); setBooleanProperty(props, request, Environment.PROP_PARSER_ALLOW_TEMPLATES); setProperty(props, request, Environment.PROP_PARSER_SIGNATURE_USER_PATTERN); setProperty(props, request, Environment.PROP_PARSER_SIGNATURE_DATE_PATTERN); setProperty(props, request, Environment.PROP_BASE_FILE_DIR); setProperty(props, request, Environment.PROP_BASE_PERSISTENCE_TYPE); if (props .getProperty(Environment.PROP_BASE_PERSISTENCE_TYPE) .equals(WikiBase.PERSISTENCE_EXTERNAL)) { setProperty(props, request, Environment.PROP_DB_DRIVER); setProperty(props, request, Environment.PROP_DB_TYPE); setProperty(props, request, Environment.PROP_DB_URL); setProperty(props, request, Environment.PROP_DB_USERNAME); setPassword(props, request, next, Environment.PROP_DB_PASSWORD, "dbPassword"); } else { WikiDatabase.setupDefaultDatabase(props); } setProperty(props, request, Environment.PROP_DBCP_MAX_ACTIVE); setProperty(props, request, Environment.PROP_DBCP_MAX_IDLE); setBooleanProperty(props, request, Environment.PROP_DBCP_TEST_ON_BORROW); setBooleanProperty(props, request, Environment.PROP_DBCP_TEST_ON_RETURN); setBooleanProperty(props, request, Environment.PROP_DBCP_TEST_WHILE_IDLE); setProperty(props, request, Environment.PROP_DBCP_MIN_EVICTABLE_IDLE_TIME); setProperty(props, request, Environment.PROP_DBCP_TIME_BETWEEN_EVICTION_RUNS); setProperty(props, request, Environment.PROP_DBCP_NUM_TESTS_PER_EVICTION_RUN); setProperty(props, request, Environment.PROP_DBCP_WHEN_EXHAUSTED_ACTION); setBooleanProperty(props, request, Environment.PROP_DBCP_REMOVE_ABANDONED); setProperty(props, request, Environment.PROP_DBCP_REMOVE_ABANDONED_TIMEOUT); int maxFileSizeInKB = Integer.parseInt(request.getParameter(Environment.PROP_FILE_MAX_FILE_SIZE)); props.setProperty( Environment.PROP_FILE_MAX_FILE_SIZE, Integer.toString(maxFileSizeInKB * 1000)); setProperty(props, request, Environment.PROP_FILE_DIR_FULL_PATH); setProperty(props, request, Environment.PROP_FILE_DIR_RELATIVE_PATH); /* setProperty(props, request, Environment.PROP_EMAIL_SMTP_HOST); setProperty(props, request, Environment.PROP_EMAIL_SMTP_USERNAME); setPassword(props, request, next, Environment.PROP_EMAIL_SMTP_PASSWORD, "smtpPassword"); setProperty(props, request, Environment.PROP_EMAIL_REPLY_ADDRESS); */ setProperty(props, request, Environment.PROP_LDAP_CONTEXT); setProperty(props, request, Environment.PROP_LDAP_FACTORY_CLASS); setProperty(props, request, Environment.PROP_LDAP_FIELD_EMAIL); setProperty(props, request, Environment.PROP_LDAP_FIELD_FIRST_NAME); setProperty(props, request, Environment.PROP_LDAP_FIELD_LAST_NAME); setProperty(props, request, Environment.PROP_LDAP_FIELD_USERID); setProperty(props, request, Environment.PROP_BASE_USER_HANDLER); setProperty(props, request, Environment.PROP_LDAP_LOGIN); setPassword(props, request, next, Environment.PROP_LDAP_PASSWORD, "ldapPassword"); setProperty(props, request, Environment.PROP_LDAP_SECURITY_AUTHENTICATION); setProperty(props, request, Environment.PROP_LDAP_URL); setProperty(props, request, Environment.PROP_CACHE_INDIVIDUAL_SIZE); setProperty(props, request, Environment.PROP_CACHE_MAX_AGE); setProperty(props, request, Environment.PROP_CACHE_MAX_IDLE_AGE); setProperty(props, request, Environment.PROP_CACHE_TOTAL_SIZE); setBooleanProperty(props, request, Environment.PROP_RSS_ALLOWED); setProperty(props, request, Environment.PROP_RSS_TITLE); Vector errors = Utilities.validateSystemSettings(props); if (errors.size() > 0) { next.addObject("errors", errors); next.addObject("message", new WikiMessage("admin.message.changesnotsaved")); } else { // all is well, save the properties Iterator iterator = props.keySet().iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); String value = props.getProperty(key); Environment.setValue(key, value); } Environment.saveProperties(); // re-initialize to reset database settings (if needed) WikiBase.reset(request.getLocale(), Utilities.currentUser(request)); next.addObject("message", new WikiMessage("admin.message.changessaved")); } } catch (Exception e) { logger.severe("Failure while processing property values", e); next.addObject("message", new WikiMessage("admin.message.propertyfailure", e.getMessage())); } view(request, next, pageInfo, props); }