Search in sources :

Example 1 with URLConstructor

use of org.apache.wiki.url.URLConstructor in project jspwiki by apache.

the class WikiEngine method initialize.

/**
 *  Does all the real initialization.
 */
private void initialize(final Properties props) throws WikiException {
    m_startTime = new Date();
    m_properties = props;
    LOG.info("*******************************************");
    LOG.info("{} {} starting. Whee!", Release.APPNAME, Release.getVersionString());
    // begin initialization
    fireEvent(WikiEngineEvent.INITIALIZING);
    LOG.debug("Java version: {}", System.getProperty("java.runtime.version"));
    LOG.debug("Java vendor: {}", System.getProperty("java.vm.vendor"));
    LOG.debug("OS: {} {} {}", System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"));
    LOG.debug("Default server locale: {}", Locale.getDefault());
    LOG.debug("Default server timezone: {}", TimeZone.getDefault().getDisplayName(true, TimeZone.LONG));
    if (m_servletContext != null) {
        LOG.info("Servlet container: {}", m_servletContext.getServerInfo());
        if (m_servletContext.getMajorVersion() < 3 || (m_servletContext.getMajorVersion() == 3 && m_servletContext.getMinorVersion() < 1)) {
            throw new InternalWikiException("JSPWiki requires a container which supports at least version 3.1 of Servlet specification");
        }
    }
    LOG.debug("Configuring WikiEngine...");
    // Create and find the default working directory.
    m_workDir = TextUtil.getStringProperty(props, PROP_WORKDIR, null);
    if (m_workDir == null) {
        m_workDir = System.getProperty("java.io.tmpdir", ".");
        m_workDir += File.separator + Release.APPNAME + "-" + m_appid;
    }
    try {
        final File f = new File(m_workDir);
        f.mkdirs();
        // 
        if (!f.exists()) {
            throw new WikiException("Work directory does not exist: " + m_workDir);
        }
        if (!f.canRead()) {
            throw new WikiException("No permission to read work directory: " + m_workDir);
        }
        if (!f.canWrite()) {
            throw new WikiException("No permission to write to work directory: " + m_workDir);
        }
        if (!f.isDirectory()) {
            throw new WikiException("jspwiki.workDir does not point to a directory: " + m_workDir);
        }
    } catch (final SecurityException e) {
        LOG.fatal("Unable to find or create the working directory: {}", m_workDir, e);
        throw new IllegalArgumentException("Unable to find or create the working dir: " + m_workDir, e);
    }
    LOG.info("JSPWiki working directory is '{}'", m_workDir);
    m_saveUserInfo = TextUtil.getBooleanProperty(props, PROP_STOREUSERNAME, m_saveUserInfo);
    m_useUTF8 = StandardCharsets.UTF_8.name().equals(TextUtil.getStringProperty(props, PROP_ENCODING, StandardCharsets.ISO_8859_1.name()));
    m_templateDir = TextUtil.getStringProperty(props, PROP_TEMPLATEDIR, "default");
    enforceValidTemplateDirectory();
    m_frontPage = TextUtil.getStringProperty(props, PROP_FRONTPAGE, "Main");
    // 
    try {
        final String aclClassName = m_properties.getProperty(PROP_ACL_MANAGER_IMPL, ClassUtil.getMappedClass(AclManager.class.getName()).getName());
        final String urlConstructorClassName = TextUtil.getStringProperty(props, PROP_URLCONSTRUCTOR, "DefaultURLConstructor");
        final Class<URLConstructor> urlclass = ClassUtil.findClass("org.apache.wiki.url", urlConstructorClassName);
        initComponent(CommandResolver.class, this, props);
        initComponent(urlclass.getName(), URLConstructor.class);
        initComponent(CachingManager.class, this, props);
        initComponent(PageManager.class, this, props);
        initComponent(PluginManager.class, this, props);
        initComponent(DifferenceManager.class, this, props);
        initComponent(AttachmentManager.class, this, props);
        initComponent(VariableManager.class, props);
        initComponent(SearchManager.class, this, props);
        initComponent(AuthenticationManager.class);
        initComponent(AuthorizationManager.class);
        initComponent(UserManager.class);
        initComponent(GroupManager.class);
        initComponent(EditorManager.class, this);
        initComponent(ProgressManager.class, this);
        initComponent(aclClassName, AclManager.class);
        initComponent(WorkflowManager.class);
        initComponent(TasksManager.class);
        initComponent(InternationalizationManager.class, this);
        initComponent(TemplateManager.class, this, props);
        initComponent(FilterManager.class, this, props);
        initComponent(AdminBeanManager.class, this);
        initComponent(PageRenamer.class, this, props);
        // RenderingManager depends on FilterManager events.
        initComponent(RenderingManager.class);
        // ReferenceManager has the side effect of loading all pages. Therefore, after this point, all page attributes are available.
        // initReferenceManager is indirectly using m_filterManager, so it has to be called after it was initialized.
        initReferenceManager();
        // Hook the different manager routines into the system.
        getManager(FilterManager.class).addPageFilter(getManager(ReferenceManager.class), -1001);
        getManager(FilterManager.class).addPageFilter(getManager(SearchManager.class), -1002);
    } catch (final RuntimeException e) {
        // RuntimeExceptions may occur here, even if they shouldn't.
        LOG.fatal("Failed to start managers.", e);
        throw new WikiException("Failed to start managers: " + e.getMessage(), e);
    } catch (final ClassNotFoundException e) {
        LOG.fatal("JSPWiki could not start, URLConstructor was not found: {}", e.getMessage(), e);
        throw new WikiException(e.getMessage(), e);
    } catch (final InstantiationException e) {
        LOG.fatal("JSPWiki could not start, URLConstructor could not be instantiated: {}", e.getMessage(), e);
        throw new WikiException(e.getMessage(), e);
    } catch (final IllegalAccessException e) {
        LOG.fatal("JSPWiki could not start, URLConstructor cannot be accessed: {}", e.getMessage(), e);
        throw new WikiException(e.getMessage(), e);
    } catch (final Exception e) {
        // Final catch-all for everything
        LOG.fatal("JSPWiki could not start, due to an unknown exception when starting.", e);
        throw new WikiException("Failed to start. Caused by: " + e.getMessage() + "; please check log files for better information.", e);
    }
    // Initialize the good-to-have-but-not-fatal modules.
    try {
        if (TextUtil.getBooleanProperty(props, RSSGenerator.PROP_GENERATE_RSS, false)) {
            initComponent(RSSGenerator.class, this, props);
        }
    } catch (final Exception e) {
        LOG.error("Unable to start RSS generator - JSPWiki will still work, but there will be no RSS feed.", e);
    }
    final Map<String, String> extraComponents = ClassUtil.getExtraClassMappings();
    initExtraComponents(extraComponents);
    // initialization complete
    fireEvent(WikiEngineEvent.INITIALIZED);
    LOG.info("WikiEngine configured.");
    m_isConfigured = true;
}
Also used : WikiException(org.apache.wiki.api.exceptions.WikiException) SearchManager(org.apache.wiki.search.SearchManager) Date(java.util.Date) WikiException(org.apache.wiki.api.exceptions.WikiException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) ProviderException(org.apache.wiki.api.exceptions.ProviderException) FilterManager(org.apache.wiki.filters.FilterManager) ReferenceManager(org.apache.wiki.references.ReferenceManager) File(java.io.File) AclManager(org.apache.wiki.auth.acl.AclManager) URLConstructor(org.apache.wiki.url.URLConstructor)

Aggregations

File (java.io.File)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 Date (java.util.Date)1 ProviderException (org.apache.wiki.api.exceptions.ProviderException)1 WikiException (org.apache.wiki.api.exceptions.WikiException)1 AclManager (org.apache.wiki.auth.acl.AclManager)1 FilterManager (org.apache.wiki.filters.FilterManager)1 ReferenceManager (org.apache.wiki.references.ReferenceManager)1 SearchManager (org.apache.wiki.search.SearchManager)1 URLConstructor (org.apache.wiki.url.URLConstructor)1