📄 wikiengine.java
字号:
WikiPage p = new WikiPage( page ); String author = getValidUserName( request ); p.setAuthor( author ); try { m_pageManager.putPageText( p, text ); } catch( ProviderException e ) { log.error("Unable to put page: ", e); } } } /** * Returns the number of pages in this Wiki */ public int getPageCount() { return m_pageManager.getTotalPageCount(); } /** * Returns the provider name */ public String getCurrentProvider() { return m_pageManager.getProvider().getClass().getName(); } /** * return information about current provider. * @since 1.6.4 */ public String getCurrentProviderInfo() { return m_pageManager.getProviderDescription(); } /** * Returns a Collection of WikiPages, sorted in time * order of last change. */ // FIXME: Should really get a Date object and do proper comparisons. // This is terribly wasteful. public Collection getRecentChanges() { try { Collection pages = m_pageManager.getAllPages(); Collection atts = m_attachmentManager.getAllAttachments(); TreeSet sortedPages = new TreeSet( new PageTimeComparator() ); sortedPages.addAll( pages ); sortedPages.addAll( atts ); return sortedPages; } catch( ProviderException e ) { log.error( "Unable to fetch all pages: ",e); return null; } } /** * Parses an incoming search request, then * does a search. * <P> * Search language is simple: prepend a word * with a + to force a word to be included (all files * not containing that word are automatically rejected), * '-' to cause the rejection of all those files that contain * that word. */ // FIXME: does not support phrase searches yet, but for them // we need a version which reads the whole page into the memory // once. // // FIXME: Should also have attributes attached. // public Collection findPages( String query ) { StringTokenizer st = new StringTokenizer( query, " \t," ); QueryItem[] items = new QueryItem[st.countTokens()]; int word = 0; log.debug("Expecting "+items.length+" items"); // // Parse incoming search string // while( st.hasMoreTokens() ) { log.debug("Item "+word); String token = st.nextToken().toLowerCase(); items[word] = new QueryItem(); switch( token.charAt(0) ) { case '+': items[word].type = QueryItem.REQUIRED; token = token.substring(1); log.debug("Required word: "+token); break; case '-': items[word].type = QueryItem.FORBIDDEN; token = token.substring(1); log.debug("Forbidden word: "+token); break; default: items[word].type = QueryItem.REQUESTED; log.debug("Requested word: "+token); break; } items[word++].word = token; } Collection results = m_pageManager.findPages( items ); return results; } /** * Return a bunch of information from the web page. */ public WikiPage getPage( String pagereq ) { return getPage( pagereq, WikiProvider.LATEST_VERSION ); } /** * Returns specific information about a Wiki page. * @since 1.6.7. */ public WikiPage getPage( String pagereq, int version ) { try { WikiPage p = m_pageManager.getPageInfo( pagereq, version ); if( p == null ) { p = m_attachmentManager.getAttachmentInfo( (WikiContext)null, pagereq ); } return p; } catch( ProviderException e ) { log.error( "Unable to fetch page info",e); return null; } } /** * Returns a Collection of WikiPages containing the * version history of a page. */ public List getVersionHistory( String page ) { List c = null; try { c = m_pageManager.getVersionHistory( page ); if( c == null ) { c = m_attachmentManager.getVersionHistory( page ); } } catch( ProviderException e ) { log.error("FIXME"); } return c; } /** * Returns a diff of two versions of a page. * * @param page Page to return * @param version1 Version number of the old page. If * WikiPageProvider.LATEST_VERSION (-1), then uses current page. * @param version2 Version number of the new page. If * WikiPageProvider.LATEST_VERSION (-1), then uses current page. * * @return A HTML-ized difference between two pages. If there is no difference, * returns an empty string. */ public String getDiff( String page, int version1, int version2 ) { String page1 = getPureText( page, version1 ); String page2 = getPureText( page, version2 ); // Kludge to make diffs for new pages to work this way. if( version1 == WikiPageProvider.LATEST_VERSION ) { page1 = ""; } String diff = m_differenceEngine.makeDiff( page1, page2 ); diff = TextUtil.replaceEntities( diff ); try { if( diff.length() > 0 ) { diff = m_differenceEngine.colorizeDiff( diff ); } } catch( IOException e ) { log.error("Failed to colorize diff result.", e); } return diff; } /** * Attempts to locate a Wiki class, defaulting to the defaultPackage * in case the actual class could not be located. * * @param className Class to search for. * @param defaultPackage A default package to try if the class * cannot be directly located. May be null. * @throws ClassNotFoundException if the class could not be located. */ public static Class findWikiClass( String className, String defaultPackage ) throws ClassNotFoundException { Class tryClass; if( className == null ) { throw new ClassNotFoundException("Null className!"); } // // Attempt to use a shortcut, if possible. // try { tryClass = Class.forName( className ); } catch( ClassNotFoundException e ) { // FIXME: This causes "null" names to be searched for twice, which // is a performance penalty and not very nice. if( defaultPackage == null ) defaultPackage = ""; if( !defaultPackage.endsWith(".") ) defaultPackage += "."; tryClass = Class.forName( defaultPackage+className ); } return tryClass; } /** * Returns this object's ReferenceManager. * @since 1.6.1 */ // (FIXME: We may want to protect this, though...) public ReferenceManager getReferenceManager() { return m_referenceManager; } /** * Returns the current plugin manager. * @since 1.6.1 */ public PluginManager getPluginManager() { return m_pluginManager; } public VariableManager getVariableManager() { return m_variableManager; } /** * 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 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; } /** * 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.info("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 + -