📄 wikiengine.java
字号:
/** * Beautifies the title of the page by appending non-breaking spaces * in suitable places. This is really suitable only for HTML output, * as it uses the &nbsp; -character. * * @param title The title to beautify * @return A beautified title. * @since 2.1.127 */ public String beautifyTitleNoBreak( String title ) { if( m_beautifyTitle ) { return TextUtil.beautifyString( title, " " ); } return title; } /** * Returns true, if the requested page (or an alias) exists. Will consider * any version as existing. Will also consider attachments. * * @param page WikiName of the page. * @return true, if page (or attachment) exists. */ public boolean pageExists( String page ) { Attachment att = null; try { if( m_commandResolver.getSpecialPageReference(page) != null ) return true; if( getFinalPageName( page ) != null ) { return true; } att = getAttachmentManager().getAttachmentInfo( (WikiContext)null, page ); } catch( ProviderException e ) { log.debug("pageExists() failed to find attachments",e); } return att != null; } /** * Returns true, if the requested page (or an alias) exists with the * requested version. * * @param page Page name * @param version Page version * @return True, if page (or alias, or attachment) exists * @throws ProviderException If the provider fails. */ public boolean pageExists( String page, int version ) throws ProviderException { if( m_commandResolver.getSpecialPageReference(page) != null ) return true; String finalName = getFinalPageName( page ); boolean isThere = false; if( finalName != null ) { // // Go and check if this particular version of this page // exists. // isThere = m_pageManager.pageExists( finalName, version ); } if( isThere == false ) { // // Go check if such an attachment exists. // try { isThere = getAttachmentManager().getAttachmentInfo( (WikiContext)null, page, version ) != null; } catch( ProviderException e ) { log.debug("pageExists() failed to find attachments",e); } } return isThere; } /** * Returns true, if the requested page (or an alias) exists, with the * specified version in the WikiPage. * * @param page A WikiPage object describing the name and version. * @return true, if the page (or alias, or attachment) exists. * @throws ProviderException If something goes badly wrong. * @since 2.0 */ public boolean pageExists( WikiPage page ) throws ProviderException { if( page != null ) { return pageExists( page.getName(), page.getVersion() ); } return false; } /** * Returns the correct page name, or null, if no such * page can be found. Aliases are considered. This * method simply delegates to * {@link com.ecyrd.jspwiki.ui.CommandResolver#getFinalPageName(String)}. * @since 2.0 * @param page Page name. * @return The rewritten page name, or null, if the page does not exist. * @throws ProviderException If something goes wrong in the backend. */ public String getFinalPageName( String page ) throws ProviderException { return m_commandResolver.getFinalPageName( page ); } /** * Turns a WikiName into something that can be * called through using an URL. * * @since 1.4.1 * @param pagename A name. Can be actually any string. * @return A properly encoded name. * @see #decodeName(String) */ public String encodeName( String pagename ) { try { return URLEncoder.encode( pagename, m_useUTF8 ? "UTF-8" : "ISO-8859-1" ); } catch( UnsupportedEncodingException e ) { throw new InternalWikiException("ISO-8859-1 not a supported encoding!?! Your platform is borked."); } } /** * Decodes a URL-encoded request back to regular life. This properly heeds * the encoding as defined in the settings file. * * @param pagerequest The URL-encoded string to decode * @return A decoded string. * @see #encodeName(String) */ public String decodeName( String pagerequest ) { try { return URLDecoder.decode( pagerequest, m_useUTF8 ? "UTF-8" : "ISO-8859-1" ); } catch( UnsupportedEncodingException e ) { throw new InternalWikiException("ISO-8859-1 not a supported encoding!?! Your platform is borked."); } } /** * Returns the IANA name of the character set encoding we're * supposed to be using right now. * * @since 1.5.3 * @return The content encoding (either UTF-8 or ISO-8859-1). */ public String getContentEncoding() { if( m_useUTF8 ) return "UTF-8"; return "ISO-8859-1"; } /** * Returns the {@link com.ecyrd.jspwiki.workflow.WorkflowManager} associated with this * WikiEngine. If the WIkiEngine has not been initialized, this method will return * <code>null</code>. * @return the task queue */ public WorkflowManager getWorkflowManager() { return m_workflowMgr; } /** * Returns the un-HTMLized text of the latest version of a page. * This method also replaces the < and & -characters with * their respective HTML entities, thus making it suitable * for inclusion on an HTML page. If you want to have the * page text without any conversions, use getPureText(). * * @param page WikiName of the page to fetch. * @return WikiText. */ public String getText( String page ) { return getText( page, WikiPageProvider.LATEST_VERSION ); } /** * Returns the un-HTMLized text of the given version of a page. * This method also replaces the < and & -characters with * their respective HTML entities, thus making it suitable * for inclusion on an HTML page. If you want to have the * page text without any conversions, use getPureText(). * * * @param page WikiName of the page to fetch * @param version Version of the page to fetch * @return WikiText. */ public String getText( String page, int version ) { String result = getPureText( page, version ); // // Replace ampersand first, or else all quotes and stuff // get replaced as well with " etc. // /* result = TextUtil.replaceString( result, "&", "&" ); */ result = TextUtil.replaceEntities( result ); return result; } /** * Returns the un-HTMLized text of the given version of a page in * the given context. USE THIS METHOD if you don't know what * doing. * <p> * This method also replaces the < and & -characters with * their respective HTML entities, thus making it suitable * for inclusion on an HTML page. If you want to have the * page text without any conversions, use getPureText(). * * @since 1.9.15. * @param context The WikiContext * @param page A page reference (not an attachment) * @return The page content as HTMLized String. * @see #getPureText(WikiPage) */ public String getText( WikiContext context, WikiPage page ) { return getText( page.getName(), page.getVersion() ); } /** * Returns the pure text of a page, no conversions. Use this * if you are writing something that depends on the parsing * of the page. Note that you should always check for page * existence through pageExists() before attempting to fetch * the page contents. * * @param page The name of the page to fetch. * @param version If WikiPageProvider.LATEST_VERSION, then uses the * latest version. * @return The page contents. If the page does not exist, * returns an empty string. */ // FIXME: Should throw an exception on unknown page/version? public String getPureText( String page, int version ) { String result = null; try { result = m_pageManager.getPageText( page, version ); } catch( ProviderException e ) { // FIXME } finally { if( result == null ) result = ""; } return result; } /** * Returns the pure text of a page, no conversions. Use this * if you are writing something that depends on the parsing * the page. Note that you should always check for page * existence through pageExists() before attempting to fetch * the page contents. * * @param page A handle to the WikiPage * @return String of WikiText. * @since 2.1.13. */ public String getPureText( WikiPage page ) { return getPureText( page.getName(), page.getVersion() ); } /** * Returns the converted HTML of the page using a different * context than the default context. * * @param context A WikiContext in which you wish to render this page in. * @param page WikiPage reference. * @return HTML-rendered version of the page. */ public String getHTML( WikiContext context, WikiPage page ) { String pagedata = null; pagedata = getPureText( page.getName(), page.getVersion() ); String res = textToHTML( context, pagedata ); return res; } /** * Returns the converted HTML of the page. * * @param page WikiName of the page to convert. * @return HTML-rendered version of the page. */ public String getHTML( String page ) { return getHTML( page, WikiPageProvider.LATEST_VERSION ); } /** * Returns the converted HTML of the page's specific version. * The version must be a positive integer, otherwise the current * version is returned. * * @param pagename WikiName of the page to convert. * @param version Version number to fetch * @return HTML-rendered page text. */ public String getHTML( String pagename, int version ) { WikiPage page = getPage( pagename, version ); WikiContext context = new WikiContext( this, page ); context.setRequestContext( WikiContext.NONE ); String res = getHTML( context, page ); return res; } /** * Converts raw page data to HTML. * * @param pagedata Raw page data to convert to HTML
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -