📄 commandresolver.java
字号:
if ( groupName != null && groupName.length() > 0 ) { GroupPrincipal group = new GroupPrincipal( groupName ); return command.targetedCommand( group ); } } // No page provided; return an "ordinary" command return command; } /** * <p> * Returns the correct page name, or <code>null</code>, if no such page can be found. * Aliases are considered. * </p> * <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> * <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. * </p> * @since 2.4.20 * @param page the page name. * @return The rewritten page name, or <code>null</code>, if the page does not exist. * @throws ProviderException if the underlyng page provider that locates pages * throws an exception */ public final String getFinalPageName( String page ) throws ProviderException { boolean isThere = simplePageExists( page ); String finalName = page; if ( !isThere && m_matchEnglishPlurals ) { if ( page.endsWith( "s" ) ) { finalName = page.substring( 0, page.length() - 1 ); } else { finalName += "s"; } isThere = simplePageExists( finalName ); } if( !isThere ) { finalName = MarkupParser.wikifyLink( page ); isThere = simplePageExists(finalName); if( !isThere && m_matchEnglishPlurals ) { if( finalName.endsWith( "s" ) ) { finalName = finalName.substring( 0, finalName.length() - 1 ); } else { finalName += "s"; } isThere = simplePageExists( finalName ); } } return isThere ? finalName : null; } /** * <p> * If the page is a special page, this method returns a direct URL to that * page; otherwise, it returns <code>null</code>. * </p> * <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". * </p> * @param page the page name ro search for * @return the URL of the special page, if the supplied page is one, or <code>null</code> */ public final String getSpecialPageReference( String page ) { Command command = m_specialPages.get( page ); if ( command != null ) { return m_engine.getURLConstructor() .makeURL( command.getRequestContext(), command.getURLPattern(), true, null ); } return null; } /** * Extracts a Command based on the JSP path of an HTTP request. * If the JSP requested matches a Command's <code>getJSP()</code> * value, that Command is returned. * @param request the HTTP request * @return the resolved Command, or <code>null</code> if not found */ protected final Command extractCommandFromPath( HttpServletRequest request ) { String jsp = request.getServletPath(); // Take everything to right of initial / and left of # or ? int hashMark = jsp.indexOf( '#' ); if ( hashMark != -1 ) { jsp = jsp.substring( 0, hashMark ); } int questionMark = jsp.indexOf( '?' ); if ( questionMark != -1 ) { jsp = jsp.substring( 0, questionMark ); } if ( jsp.startsWith( "/" ) ) { jsp = jsp.substring( 1 ); } // Find special page reference? for( Iterator i = m_specialPages.entrySet().iterator(); i.hasNext(); ) { Map.Entry entry = (Map.Entry) i.next(); Command specialCommand = (Command) entry.getValue(); if ( specialCommand.getJSP().equals( jsp ) ) { return specialCommand; } } // Still haven't found a matching command? // Ok, see if we match against our standard list of JSPs if ( jsp.length() > 0 && JSPS.containsKey( jsp ) ) { return JSPS.get( jsp ); } return null; } /** * Determines the correct wiki page based on a supplied request context and * HTTP request. This method attempts to determine the page requested by a * user, taking into acccount special pages. The resolution algorithm will: * <ul> * <li>Extract the page name from the URL according to the rules for the * current {@link URLConstructor}. If a page name was * passed in the request, return the correct name after taking into account * potential plural matches.</li> * <li>If the extracted page name is <code>null</code>, attempt to see * if a "special page" was intended by examining the servlet path. For * example, the request path "/UserPreferences.jsp" will resolve to * "UserPreferences."</li> * <li>If neither of these methods work, this method returns * <code>null</code></li> * </ul> * @param requestContext the request context * @param request the HTTP request * @return the resolved page name */ protected final String extractPageFromParameter( String requestContext, HttpServletRequest request ) { String page; // Extract the page name from the URL directly try { page = m_engine.getURLConstructor().parsePage( requestContext, request, m_engine.getContentEncoding() ); if ( page != null ) { try { // Look for singular/plural variants; if one // not found, take the one the user supplied String finalPage = getFinalPageName( page ); if ( finalPage != null ) { page = finalPage; } } catch( ProviderException e ) { // FIXME: Should not ignore! } return page; } } catch( IOException e ) { m_log.error( "Unable to create context", e ); throw new InternalWikiException( "Big internal booboo, please check logs." ); } // Didn't resolve; return null return null; } /** * Looks up and returns the correct, versioned WikiPage based on a supplied * page name and optional <code>version</code> parameter passed in an HTTP * request. If the <code>version</code> parameter does not exist in the * request, the latest version is returned. * @param request the HTTP request * @param page the name of the page to look up; this page <em>must</em> exist * @return the wiki page */ protected final WikiPage resolvePage( HttpServletRequest request, String page ) { // See if the user included a version parameter WikiPage wikipage; int version = WikiProvider.LATEST_VERSION; String rev = request.getParameter( "version" ); if ( rev != null ) { try { version = Integer.parseInt( rev ); } catch( NumberFormatException e ) { // This happens a lot with bots or other guys who are trying // to test if we are vulnerable to e.g. XSS attacks. We catch // it here so that the admin does not get tons of mail. } } wikipage = m_engine.getPage( page, version ); if ( wikipage == null ) { page = MarkupParser.cleanLink( page ); wikipage = new WikiPage( m_engine, page ); } return wikipage; } /** * Determines whether a "page" exists by examining the list of special pages * and querying the page manager. * @param page the page to seek * @return <code>true</code> if the page exists, <code>false</code> * otherwise * @throws ProviderException if the underlyng page provider that locates pages * throws an exception */ protected final boolean simplePageExists( String page ) throws ProviderException { if ( m_specialPages.containsKey( page ) ) { return true; } return m_engine.getPageManager().pageExists( page ); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -