📄 wikiengine.java
字号:
* Returns the current PageManager. */ public PageManager getPageManager() { return m_pageManager; } /** * Returns the current AttachmentManager. * @since 1.9.31. */ public AttachmentManager getAttachmentManager() { return m_attachmentManager; } /** * Returns the currently used authorization manager. */ public AuthorizationManager getAuthorizationManager() { return m_authorizationManager; } /** * Returns the currently used user manager. */ public UserManager getUserManager() { return m_userManager; } /** * Returns the manager responsible for the filters. * @since 2.1.88 */ public FilterManager getFilterManager() { return m_filterManager; } /** * Returns the manager responsible for searching the Wiki. * @since 2.2.21 */ public SearchManager getSearchManager() { return m_searchManager; } /** * Parses the given path and attempts to match it against the list * of specialpages to see if this path exists. It is used to map things * like "UserPreferences.jsp" to page "User Preferences". * * @return WikiName, or null if a match could not be found. */ private String matchSpecialPagePath( String path ) { // // Remove servlet root marker. // if( path.startsWith("/") ) { path = path.substring(1); } for( Iterator i = m_properties.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry) i.next(); String key = (String)entry.getKey(); if( key.startsWith( PROP_SPECIALPAGE ) ) { String value = (String)entry.getValue(); if( value.equals( path ) ) { return key.substring( PROP_SPECIALPAGE.length() ); } } } return null; } /** * Figure out to which page we are really going to. Considers * special page names from the jspwiki.properties, and possible aliases. * * @param context The Wiki Context in which the request is being made. * @return A complete URL to the new page to redirect to * @since 2.2 */ public String getRedirectURL( WikiContext context ) { String pagename = context.getPage().getName(); String redirURL = null; redirURL = getSpecialPageReference( pagename ); if( redirURL == null ) { String alias = (String)context.getPage().getAttribute( WikiPage.ALIAS ); if( alias != null ) { redirURL = getViewURL( alias ); } else { redirURL = (String)context.getPage().getAttribute( WikiPage.REDIRECT ); } } return redirURL; } /** * Shortcut to create a WikiContext from the Wiki page. * * @since 2.1.15. */ // FIXME: We need to have a version which takes a fixed page // name as well, or check it elsewhere. public WikiContext createContext( HttpServletRequest request, String requestContext ) { String pagereq; if( !m_isConfigured ) { throw new InternalWikiException("WikiEngine has not been properly started. It is likely that the configuration is faulty. Please check all logs for the possible reason."); } try { pagereq = m_urlConstructor.parsePage( requestContext, request, getContentEncoding() ); } catch( IOException e ) { log.error("Unable to create context",e); throw new InternalWikiException("Big internal booboo, please check logs."); } String template = safeGetParameter( request, "skin" ); // // Figure out the page name. // We also check the list of special pages, which incidentally // allows us to localize them, too. // if( pagereq == null || pagereq.length() == 0 ) { String servlet = request.getServletPath(); log.debug("Servlet path is: "+servlet); pagereq = matchSpecialPagePath( servlet ); log.debug("Mapped to "+pagereq); if( pagereq == null ) { pagereq = getFrontPage(); } } int hashMark = pagereq.indexOf('#'); if( hashMark != -1 ) { pagereq = pagereq.substring( 0, hashMark ); } int version = WikiProvider.LATEST_VERSION; String rev = request.getParameter("version"); if( rev != null ) { version = Integer.parseInt( rev ); } // // Find the WikiPage object // String pagename = pagereq; WikiPage wikipage; try { pagename = getFinalPageName( pagereq ); } catch( ProviderException e ) {} // FIXME: Should not ignore! if( pagename != null ) { wikipage = getPage( pagename, version ); } else { wikipage = getPage( pagereq, version ); } if( wikipage == null ) { pagereq = TranslatorReader.cleanLink( pagereq ); wikipage = new WikiPage( pagereq ); } // // Figure out which template we should be using for this page. // if( template == null ) { template = (String)wikipage.getAttribute( PROP_TEMPLATEDIR ); // FIXME: Most definitely this should be checked for // existence, or else it is possible to create pages that // cannot be shown. if( template == null || template.length() == 0 ) { template = getTemplateDir(); } } WikiContext context = new WikiContext( this, wikipage ); context.setRequestContext( requestContext ); context.setHttpRequest( request ); context.setTemplate( template ); UserProfile user = getUserManager().getUserProfile( request ); context.setCurrentUser( user ); return context; } /** * Deletes a page or an attachment completely, including all versions. * * @param pageName * @throws ProviderException */ public void deletePage( String pageName ) throws ProviderException { WikiPage p = getPage( pageName ); if( p instanceof Attachment ) { m_attachmentManager.deleteAttachment( (Attachment) p ); } else { if (m_attachmentManager.hasAttachments( p )) { Collection attachments = m_attachmentManager.listAttachments( p ); for( Iterator atti = attachments.iterator(); atti.hasNext(); ) { m_attachmentManager.deleteAttachment( (Attachment)(atti.next()) ); } } m_pageManager.deletePage( p ); } } /** * Deletes a specific version of a page or an attachment. * * @param page * @throws ProviderException */ public void deleteVersion( WikiPage page ) throws ProviderException { if( page instanceof Attachment ) { m_attachmentManager.deleteVersion( (Attachment) page ); } else { m_pageManager.deleteVersion( page ); } } /** * Returns the URL of the global RSS file. May be null, if the * RSS file generation is not operational. * @since 1.7.10 */ public String getGlobalRSSURL() { if( m_rssURL != null ) { return getBaseURL()+m_rssURL; } return null; } /** * @since 2.2 */ public String getRootPath() { return m_rootPath; } /** * @since 2.2.6 * @return */ public URLConstructor getURLConstructor() { return m_urlConstructor; } /** * @since 2.1.165 * @return */ public RSSGenerator getRSSGenerator() { return m_rssGenerator; } /** * Runs the RSS generation thread. * FIXME: MUST be somewhere else, this is not a good place. */ private class RSSThread extends Thread { public void run() { try { String fileName = m_properties.getProperty( RSSGenerator.PROP_RSSFILE, "rss.rdf" ); int rssInterval = TextUtil.parseIntParameter( m_properties.getProperty( RSSGenerator.PROP_INTERVAL ), 3600 ); log.debug("RSS file will be at "+fileName); log.debug("RSS refresh interval (seconds): "+rssInterval); while(true) { Writer out = null; Reader in = null; try { // // Generate RSS file, output it to // default "rss.rdf". // log.debug("Regenerating RSS feed to "+fileName); String feed = m_rssGenerator.generate(); File file = new File( m_rootPath, fileName ); in = new StringReader(feed); out = new BufferedWriter( new OutputStreamWriter( new FileOutputStream(file), "UTF-8") ); FileUtil.copyContents( in, out ); m_rssURL = fileName; } catch( IOException e ) { log.error("Cannot generate RSS feed to "+fileName, e ); m_rssURL = null; } finally { try { if( in != null ) in.close(); if( out != null ) out.close(); } catch( IOException e ) { log.fatal("Could not close I/O for RSS", e ); break; } } Thread.sleep(rssInterval*1000L); } // while } catch(InterruptedException e) { log.error("RSS thread interrupted, no more RSS feeds", e); } // // Signal: no more RSS feeds. // m_rssURL = null; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -