📄 wikiengine.java
字号:
// 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("JSPWiki "+Release.VERSTR+" starting. Whee!"); log.debug("Configuring WikiEngine..."); // // Create and find the default working directory. // m_workDir = props.getProperty( PROP_WORKDIR ); 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( props.getProperty( PROP_ENCODING, "ISO-8859-1" ) ); m_baseURL = props.getProperty( PROP_BASEURL, "" ); m_beautifyTitle = TextUtil.getBooleanProperty( props, PROP_BEAUTIFYTITLE, m_beautifyTitle ); m_matchEnglishPlurals = TextUtil.getBooleanProperty( props, PROP_MATCHPLURALS, m_matchEnglishPlurals ); m_templateDir = props.getProperty( PROP_TEMPLATEDIR, "default" ); m_frontPage = props.getProperty( PROP_FRONTPAGE, "Main" ); // // Initialize the important modules. Any exception thrown by the // managers means that we will not start up. // try { Class urlclass = ClassUtil.findClass( "com.ecyrd.jspwiki.url", props.getProperty( PROP_URLCONSTRUCTOR, "DefaultURLConstructor" ) ); m_urlConstructor = (URLConstructor) urlclass.newInstance(); m_urlConstructor.initialize( this, props ); m_pageManager = new PageManager( this, props ); m_pluginManager = new PluginManager( props ); m_differenceManager = new DifferenceManager( this, props ); m_attachmentManager = new AttachmentManager( this, props ); m_variableManager = new VariableManager( props ); m_filterManager = new FilterManager( this, props ); m_searchManager = new SearchManager( this, props ); // // ReferenceManager has the side effect of loading all // pages. Therefore after this point, all page attributes // are available. // initReferenceManager(); m_templateManager = new TemplateManager( this, props ); m_userManager = new UserManager( this, props ); m_authorizationManager = new AuthorizationManager( this, props ); } catch( Exception 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() ); } // // Initialize the good-to-have-but-not-fatal modules. // try { if( TextUtil.getBooleanProperty( props, RSSGenerator.PROP_GENERATE_RSS, false ) ) { m_rssGenerator = new RSSGenerator( this, props ); } } catch( Exception e ) { log.error( "Unable to start RSS generator - JSPWiki will still work, "+ "but there will be no RSS feed.", e ); } // FIXME: I wonder if this should be somewhere else. if( m_rssGenerator != null ) { new RSSThread().start(); } 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. */ private void initReferenceManager() { m_pluginManager.setInitStage( true ); try { ArrayList pages = new ArrayList(); pages.addAll( m_pageManager.getAllPages() ); pages.addAll( m_attachmentManager.getAllAttachments() ); // Build a new manager with default key lists. if( m_referenceManager == null ) { m_referenceManager = new ReferenceManager( this ); m_referenceManager.initialize( pages ); } } catch( ProviderException e ) { log.fatal("PageProvider is unable to list pages: ", e); } m_pluginManager.setInitStage( false ); m_filterManager.addPageFilter( m_referenceManager, -1000 ); // FIXME: Magic number. } /** * 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 = props.getProperty(key); if( value == null ) { throw new NoRequiredPropertyException( "Required property not found", key ); } return value; } /** * Internal method for getting a property. This is used by the * TranslatorReader for example. */ public Properties getWikiProperties() { return m_properties; } /** * Returns the JSPWiki working directory. * @since 2.1.100 */ public String getWorkDir() { return m_workDir; } /** * Don't use. * @since 1.8.0 */ public String getPluginSearchPath() { // FIXME: This method should not be here, probably. return m_properties.getProperty( PluginManager.PROP_SEARCHPATH ); } /** * Returns the current template directory. * * @since 1.9.20 */ public String getTemplateDir() { return m_templateDir; } public TemplateManager getTemplateManager() { return m_templateManager; } /** * Returns the base URL. Always prepend this to any reference * you make. * * @since 1.6.1 */ public String getBaseURL() { return m_baseURL; } /** * Returns the moment when this engine was started. * * @since 2.0.15. */ public Date getStartTime() { return m_startTime; } /** * Returns the basic absolute URL to a page, without any modifications. * You may add any parameters to this. This is a convinience method. * * @since 2.0.3 */ public String getViewURL( String pageName ) { return m_urlConstructor.makeURL( WikiContext.VIEW, pageName, true, null ); } /** * Returns the basic URL to an editor. * @deprecated * * @since 2.0.3 */ public String getEditURL( String pageName ) { return m_urlConstructor.makeURL( WikiContext.EDIT, pageName, false, null ); } /** * Returns the basic attachment URL. * @since 2.0.42. * @deprecated */ public String getAttachmentURL( String attName ) { return m_urlConstructor.makeURL( WikiContext.ATTACH, attName, false, null ); } /** * Returns an URL if a WikiContext is not available. * @param context The WikiContext (VIEW, EDIT, etc...) * @param pageName Name of the page, as usual * @param params List of parameters. May be null, if no parameters. * @param absolute If true, will generate an absolute URL regardless of properties setting. */ public String getURL( String context, String pageName, String params, boolean absolute ) { return m_urlConstructor.makeURL( context, pageName, absolute, params ); } /** * Returns the default front page, if no page is used. */ public String getFrontPage() { return m_frontPage; } /** * Returns the ServletContext that this particular WikiEngine was * initialized with. <B>It may return null</B>, if the WikiEngine is not * running inside a servlet container! * * @since 1.7.10 * @return ServletContext of the WikiEngine, or null. */ public ServletContext getServletContext() { return m_servletContext; } /** * This is a safe version of the Servlet.Request.getParameter() routine. * Unfortunately, the default version always assumes that the incoming * character set is ISO-8859-1, even though it was something else. * This means that we need to make a new string using the correct * encoding. * <P> * For more information, see: * <A HREF="http://www.jguru.com/faq/view.jsp?EID=137049">JGuru FAQ</A>. * <P> * Incidentally, this is almost the same as encodeName(), below. * I am not yet entirely sure if it's safe to merge the code. * * @since 1.5.3 */ public String safeGetParameter( ServletRequest request, String name ) { try { String res = request.getParameter( name ); if( res != null ) { res = new String(res.getBytes("ISO-8859-1"), getContentEncoding() ); } return res; } catch( UnsupportedEncodingException e ) { log.fatal( "Unsupported encoding", e ); return ""; } } /** * Returns the query string (the portion after the question mark). * * @return The query string. If the query string is null, * returns an empty string. * * @since 2.1.3 */ public String safeGetQueryString( HttpServletRequest request ) { if (request == null) { return ""; } try { String res = request.getQueryString(); if( res != null ) { res = new String(res.getBytes("ISO-8859-1"), getContentEncoding() ); // // Ensure that the 'page=xyz' attribute is removed // FIXME: Is it really the mandate of this routine to // do that? // int pos1 = res.indexOf("page="); if (pos1 >= 0) { String tmpRes = res.substring(0, pos1); int pos2 = res.indexOf("&",pos1) + 1; if ( (pos2 > 0) && (pos2 < res.length()) ) { tmpRes = tmpRes + res.substring(pos2); } res = tmpRes; } } return res; } catch( UnsupportedEncodingException e ) { log.fatal( "Unsupported encoding", e ); return ""; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -