📄 wikiengine.java
字号:
} m_referenceManager.updateReferences( page.getName(), links ); } } } catch( ProviderException e ) { log.fatal("PageProvider is unable to list pages: ", e); } log.info( "Cross reference scan done (" + (System.currentTimeMillis()-start) + " ms)" ); m_pluginManager.enablePlugins( true ); } /** * Throws an exception if a property is not found. */ 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; } /** * @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; } /** * 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 URL to a page, without any modifications. * You may add any parameters to this. * * @since 2.0.3 */ public String getViewURL( String pageName ) {/* pageName = encodeName( pageName ); String srcString = "%uWiki.jsp?page=%p"; srcString = TextUtil.replaceString( srcString, "%u", m_baseURL ); srcString = TextUtil.replaceString( srcString, "%p", pageName ); return srcString; */ return m_baseURL+"Wiki.jsp?page="+encodeName(pageName); } /** * Returns the basic URL to an editor. * * @since 2.0.3 */ public String getEditURL( String pageName ) { return m_baseURL+"Edit.jsp?page="+encodeName(pageName); } /** * Returns the basic attachment URL. * @since 2.0.42. */ public String getAttachmentURL( String attName ) { return m_baseURL+"attach?page="+encodeName(attName); } /** * 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.0.40. */ 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 ""; } } /** * Returns an URL to some other Wiki that we know. * * @return null, if no such reference was found. */ public String getInterWikiURL( String wikiName ) { return m_properties.getProperty(PROP_INTERWIKIREF+wikiName); } /** * Returns a collection of all supported InterWiki links. */ public Collection getAllInterWikiLinks() { Vector v = new Vector(); for( Enumeration i = m_properties.propertyNames(); i.hasMoreElements(); ) { String prop = (String) i.nextElement(); if( prop.startsWith( PROP_INTERWIKIREF ) ) { v.add( prop.substring( prop.lastIndexOf(".")+1 ) ); } } return v; } /** * Returns a collection of all image types that get inlined. */ public Collection getAllInlinedImagePatterns() { return TranslatorReader.getImagePatterns( this ); } /** * If the page is a special page, then returns a direct URL * to that page. Otherwise returns null. * <P> * Special pages are non-existant references to other pages. * For example, you could define a special page reference * "RecentChanges" which would always be redirected to "RecentChanges.jsp" * instead of trying to find a Wiki page called "RecentChanges". */ public String getSpecialPageReference( String original ) { String propname = "jspwiki.specialPage."+original; String specialpage = m_properties.getProperty( propname ); return specialpage; } /** * Returns the name of the application. */ // FIXME: Should use servlet context as a default instead of a constant. public String getApplicationName() { String appName = m_properties.getProperty("jspwiki.applicationName"); if( appName == null ) return Release.APPNAME; return appName; } /** * Beautifies the title of the page by appending spaces in suitable * places. * * @since 1.7.11 */ public String beautifyTitle( 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. */ public boolean pageExists( String page ) { if( getSpecialPageReference(page) != null ) return true; if( getFinalPageName( page ) != null ) { return true; } Attachment att = null; try { 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 */ public boolean pageExists( String page, int version ) throws ProviderException { if( getSpecialPageReference(page) != null ) return true; String finalName = getFinalPageName( page ); WikiPage p = null; if( finalName != null ) { // // Go and check if this particular version of this page // exists. // p = m_pageManager.getPageInfo( finalName, version ); } if( p == null ) { try { p = getAttachmentManager().getAttachmentInfo( (WikiContext)null, page, version ); } catch( ProviderException e ) { log.debug("pageExists() failed to find attachments",e); } } return (p != null); } /** * Returns true, if the requested page (or an alias) exists, with the * specified version in the WikiPage. * * @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. * <P> * In some cases, page names can refer to other pages. For example, * when you have matchEnglishPlurals set, then a page name "Foobars" * will be transformed into "Foobar", should a page "Foobars" not exist, * but the page "Foobar" would. This method gives you the correct * page name to refer to. * <P> * This facility can also be used to rewrite any page name, for example, * by using aliases. It can also be used to check the existence of any * page. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -