⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wikiengine.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     *  Do not use this method - use WikiEngine.getInstance() instead.     *     *  @param context A ServletContext.     *  @param appid   An Application ID.  This application is an unique random string which     *                 is used to recognize this WikiEngine.     *  @param props   The WikiEngine configuration.     *  @throws WikiException If the WikiEngine construction fails.     */    protected WikiEngine( ServletContext context, String appid, Properties props )        throws WikiException    {        super();        m_servletContext = context;        m_appid          = appid;        // Stash the WikiEngine in the servlet context        if ( context != null )        {            context.setAttribute( ATTR_WIKIENGINE,  this );            m_rootPath = context.getRealPath("/");        }                try        {            //            //  Note: May be null, if JSPWiki has been deployed in a WAR file.            //            initialize( props );            log.info("Root path for this Wiki is: '"+m_rootPath+"'");        }        catch( Exception e )        {            String msg = Release.APPNAME+": Unable to load and setup properties from jspwiki.properties. "+e.getMessage();            if ( context != null )            {                context.log( msg );            }            throw new WikiException( msg );        }    }    /**     *  Does all the real initialization.     */    private void initialize( Properties props )        throws WikiException    {        m_startTime  = new Date();        m_properties = props;        //        //  Initialized log4j.  However, make sure that        //  we don't initialize it multiple times.  Also, if        //  all of the log4j statements have been removed from        //  the property file, we do not do any property setting        //  either.q        //        if( !c_configured )        {            if( props.getProperty("log4j.rootCategory") != null )            {                PropertyConfigurator.configure( props );            }            c_configured = true;        }        log.info("*******************************************");        log.info(Release.APPNAME+" "+Release.getVersionString()+" starting. Whee!");        fireEvent( WikiEngineEvent.INITIALIZING ); // begin initialization        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() < 2 ||                (m_servletContext.getMajorVersion() == 2 && m_servletContext.getMinorVersion() < 4) )            {                throw new InternalWikiException("I require a container which supports at least version 2.4 of Servlet specification");            }        }        log.debug("Configuring WikiEngine...");        //  Initializes the CommandResolver        m_commandResolver  = new CommandResolver( this, props );        //        //  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        {            File f = new File( m_workDir );            f.mkdirs();            //            //  A bunch of sanity checks            //            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( 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);        }        log.info("JSPWiki working directory is '"+m_workDir+"'");        m_saveUserInfo   = TextUtil.getBooleanProperty( props,                                                        PROP_STOREUSERNAME,                                                        m_saveUserInfo );        m_useUTF8        = "UTF-8".equals( TextUtil.getStringProperty( props, PROP_ENCODING, "ISO-8859-1" ) );        m_baseURL        = TextUtil.getStringProperty( props, PROP_BASEURL, "" );        m_beautifyTitle  = TextUtil.getBooleanProperty( props,                                                        PROP_BEAUTIFYTITLE,                                                        m_beautifyTitle );        m_templateDir    = TextUtil.getStringProperty( props, PROP_TEMPLATEDIR, "default" );        m_frontPage      = TextUtil.getStringProperty( props, PROP_FRONTPAGE,   "Main" );        //        //  Initialize the important modules.  Any exception thrown by the        //  managers means that we will not start up.        //        // FIXME: This part of the code is getting unwieldy.  We must think        //        of a better way to do the startup-sequence.        try        {            Class urlclass = ClassUtil.findClass( "com.ecyrd.jspwiki.url",                    TextUtil.getStringProperty( props, PROP_URLCONSTRUCTOR, "DefaultURLConstructor" ) );            m_urlConstructor = (URLConstructor) urlclass.newInstance();            m_urlConstructor.initialize( this, props );            m_pageManager       = (PageManager)ClassUtil.getMappedObject(PageManager.class.getName(), this, props );            m_pluginManager     = (PluginManager)ClassUtil.getMappedObject(PluginManager.class.getName(), this, props );            m_differenceManager = (DifferenceManager)ClassUtil.getMappedObject(DifferenceManager.class.getName(), this, props );            m_attachmentManager = (AttachmentManager)ClassUtil.getMappedObject(AttachmentManager.class.getName(), this, props );            m_variableManager   = (VariableManager)ClassUtil.getMappedObject(VariableManager.class.getName(), props );            // m_filterManager     = (FilterManager)ClassUtil.getMappedObject(FilterManager.class.getName(), this, props );            m_renderingManager  = (RenderingManager) ClassUtil.getMappedObject(RenderingManager.class.getName());            m_searchManager     = (SearchManager)ClassUtil.getMappedObject(SearchManager.class.getName(), this, props );            m_authenticationManager = (AuthenticationManager) ClassUtil.getMappedObject(AuthenticationManager.class.getName());            m_authorizationManager  = (AuthorizationManager) ClassUtil.getMappedObject( AuthorizationManager.class.getName());            m_userManager           = (UserManager) ClassUtil.getMappedObject(UserManager.class.getName());            m_groupManager          = (GroupManager) ClassUtil.getMappedObject(GroupManager.class.getName());            m_editorManager     = (EditorManager)ClassUtil.getMappedObject(EditorManager.class.getName(), this );            m_editorManager.initialize( props );            m_progressManager   = new ProgressManager();            // Initialize the authentication, authorization, user and acl managers            m_authenticationManager.initialize( this, props );            m_authorizationManager.initialize( this, props );            m_userManager.initialize( this, props );            m_groupManager.initialize( this, props );            m_aclManager = getAclManager();            // Start the Workflow manager            m_workflowMgr = (WorkflowManager)ClassUtil.getMappedObject(WorkflowManager.class.getName());            m_workflowMgr.initialize(this, props);            m_internationalizationManager = (InternationalizationManager)                ClassUtil.getMappedObject(InternationalizationManager.class.getName(),this);            m_templateManager   = (TemplateManager)                ClassUtil.getMappedObject(TemplateManager.class.getName(), this, props );            m_adminBeanManager = (AdminBeanManager)                ClassUtil.getMappedObject(AdminBeanManager.class.getName(),this);            // Since we want to use a page filters initilize() method            // as a engine startup listener where we can initialize global event listeners,            // it must be called lastly, so that all object references in the engine            // are availabe to the initialize() method            m_filterManager     = (FilterManager)                ClassUtil.getMappedObject(FilterManager.class.getName(), this, props );            // RenderingManager depends on FilterManager events.            m_renderingManager.initialize( this, props );            //            //  ReferenceManager has the side effect of loading all            //  pages.  Therefore after this point, all page attributes            //  are available.            //            //  initReferenceManager is indirectly using m_filterManager, therefore            //  it has to be called after it was initialized.            //            initReferenceManager();            //            //  Hook the different manager routines into the system.            //            getFilterManager().addPageFilter(m_referenceManager, -1001 );            getFilterManager().addPageFilter(m_searchManager, -1002 );        }        catch( 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() );        }        catch (ClassNotFoundException e)        {            log.fatal( "JSPWiki could not start, URLConstructor was not found: ",e );            throw new WikiException(e.getMessage());        }        catch (InstantiationException e)        {            log.fatal( "JSPWiki could not start, URLConstructor could not be instantiated: ",e );            throw new WikiException(e.getMessage());        }        catch (IllegalAccessException e)        {            log.fatal( "JSPWiki could not start, URLConstructor cannot be accessed: ",e );            throw new WikiException(e.getMessage());        }        catch( 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; please check log files for better information.");        }                //        //  Initialize the good-to-have-but-not-fatal modules.        //        try        {            if( TextUtil.getBooleanProperty( props,                                             RSSGenerator.PROP_GENERATE_RSS,                                             false ) )            {                m_rssGenerator = (RSSGenerator)ClassUtil.getMappedObject(RSSGenerator.class.getName(), this, props );            }            m_pageRenamer = (PageRenamer)ClassUtil.getMappedObject(PageRenamer.class.getName(), this, props );        }        catch( Exception e )        {            log.error( "Unable to start RSS generator - JSPWiki will still work, "+                       "but there will be no RSS feed.", e );        }        // Start the RSS generator & generator thread        if( m_rssGenerator != null )        {            m_rssFile = TextUtil.getStringProperty( props,                    RSSGenerator.PROP_RSSFILE, "rss.rdf" );            File rssFile=null;            if (m_rssFile.startsWith(File.separator))            {                // honor absolute pathnames:                rssFile = new File(m_rssFile );            }            else            {                // relative path names are anchored from the webapp root path:                rssFile = new File( getRootPath(), m_rssFile );            }            int rssInterval = TextUtil.getIntegerProperty( props,                    RSSGenerator.PROP_INTERVAL, 3600 );            RSSThread rssThread = new RSSThread( this, rssFile, rssInterval );            rssThread.start();        }        fireEvent( WikiEngineEvent.INITIALIZED ); // initialization complete        log.info("WikiEngine configured.");        m_isConfigured = true;    }    /**     *  Initializes the reference manager. Scans all existing WikiPages for     *  internal links and adds them to the ReferenceManager object.     *     *  @throws WikiException If the reference manager initialization fails.     */    @SuppressWarnings("unchecked")    public void initReferenceManager() throws WikiException    {        try        {            ArrayList<WikiPage> pages = new ArrayList<WikiPage>();            pages.addAll( m_pageManager.getAllPages() );            pages.addAll( m_attachmentManager.getAllAttachments() );            // Build a new manager with default key lists.            if( m_referenceManager == null )            {                m_referenceManager =                    (ReferenceManager) ClassUtil.getMappedObject(ReferenceManager.class.getName(), this );                m_referenceManager.initialize( pages );            }        }        catch( ProviderException e )        {            log.fatal("PageProvider is unable to list pages: ", e);        }    }    /**     *  Throws an exception if a property is not found.     *     *  @param props A set of properties to search the key in.     *  @param key   The key to look for.     *  @return The required property     *     *  @throws NoRequiredPropertyException If the search key is not     *          in the property set.     */    // FIXME: Should really be in some util file.    public static String getRequiredProperty( Properties props, String key )        throws NoRequiredPropertyException    {        String value = TextUtil.getStringProperty( props, key, null );        if( value == null )        {            throw new NoRequiredPropertyException( "Required property not found",                                                   key );        }        return value;    }    /**     *  Returns the set of properties that the WikiEngine was initialized     *  with.  Note that this method returns a direct reference, so it's possible     *  to manipulate the properties.  However, this is not advised unless you     *  really know what you're doing.     *     *  @return The wiki properties     */    public Properties getWikiProperties()    {        return m_properties;    }    /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -