You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ja...@apache.org on 2009/04/05 17:11:33 UTC
svn commit: r762101 - in /incubator/jspwiki/trunk: ./
src/java/org/apache/wiki/ src/java/org/apache/wiki/action/
src/java/org/apache/wiki/api/ src/java/org/apache/wiki/content/
src/java/org/apache/wiki/parser/ src/java/org/apache/wiki/plugin/
src/java/...
Author: jalkanen
Date: Sun Apr 5 15:11:33 2009
New Revision: 762101
URL: http://svn.apache.org/viewvc?rev=762101&view=rev
Log:
* Got tired of the relative mess on page name resolving (as we were
doing this in quite a few places) and delegated the task to PageNameResolver class
(and its subclasses). The name resolving is managed by the WikiEngine.
* Moved a number of methods from WikiContextFactory to the respective
PageNameResolver classes.
* Added SpecialPageNameResolver (with some special handling) and
EnglishPluralPageNameResolver.
Added:
incubator/jspwiki/trunk/src/java/org/apache/wiki/content/EnglishPluralsPageNameResolver.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageNameResolver.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/content/SpecialPageNameResolver.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/EnglishPluralsPageNameResolverTest.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/SpecialPageNameResolverTest.java
Modified:
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/InsertPage.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/LinkTag.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/PageNameTag.java
incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiPageTypeConverter.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/action/WikiContextFactoryTest.java
incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/AllTests.java
Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sun Apr 5 15:11:33 2009
@@ -1,3 +1,17 @@
+2009-04-05 Janne Jalkanen <ja...@apache.org>
+
+ * 3.0.0-svn-94
+
+ * Got tired of the relative mess on page name resolving (as we were
+ doing this in quite a few places) and delegated the task to PageNameResolver class
+ (and its subclasses). The name resolving is managed by the WikiEngine.
+
+ * Moved a number of methods from WikiContextFactory to the respective
+ PageNameResolver classes.
+
+ * Added SpecialPageNameResolver (with some special handling) and
+ EnglishPluralPageNameResolver.
+
2009-04-05 Harry Metske <me...@apache.org>
* 3.0.0-svn-93
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/JCRWikiPage.java Sun Apr 5 15:11:33 2009
@@ -57,7 +57,12 @@
private static final String AUTHOR = "wiki:author";
- private static final String ACL = "wiki:acl";
+ private static final String ACL = "wiki:acl";
+
+ private static final String ATTR_CONTENT = "wiki:content";
+
+ private static final String CONTENTTYPE = "wiki:contentType";
+
public static final String REFERSTO = "wiki:refersTo";
@@ -66,15 +71,6 @@
private WikiEngine m_engine;
private String m_jcrPath = null;
- /**
- * Use {@link WikiEngine#createPage(String)} instead.
- * @deprecated
- */
- public JCRWikiPage( WikiEngine engine, String path )
- {
- this( engine, WikiName.valueOf( path ) );
- }
-
/**
* Use {@link WikiEngine#createPage(WikiName)} instead.
* @deprecated
@@ -452,10 +448,9 @@
return null;
}
- public String getContentType()
+ public String getContentType() throws ProviderException
{
- // TODO Auto-generated method stub
- return null;
+ return (String)getAttribute( CONTENTTYPE );
}
public Set<String> getReferrers()
@@ -500,8 +495,7 @@
public void setContentType( String contentType )
{
- // TODO Auto-generated method stub
-
+ setAttribute( CONTENTTYPE, contentType );
}
public void save() throws ProviderException
@@ -519,9 +513,7 @@
throw new ProviderException("Save failed",e);
}
}
-
- private static final String ATTR_CONTENT = "wiki:content";
-
+
public String getContentAsString() throws ProviderException
{
try
@@ -589,7 +581,7 @@
}
- public boolean isAttachment()
+ public boolean isAttachment() throws ProviderException
{
if( getContentType().equals( ContentManager.JSPWIKI_CONTENT_TYPE ) ) return false;
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/WikiEngine.java Sun Apr 5 15:11:33 2009
@@ -266,7 +266,10 @@
private boolean m_isConfigured = false; // Flag.
+ private List<PageNameResolver> m_nameResolvers = new ArrayList<PageNameResolver>();
+ private SpecialPageNameResolver m_specialPageResolver;
+
/** Each engine has its own workflow manager. */
private WorkflowManager m_workflowMgr = null;
@@ -533,6 +536,14 @@
// Initialize the WikiContextFactory -- this MUST be done after setting the baseURL
m_contextFactory = new WikiContextFactory( this, props );
+ /**
+ * We treat the specialPageResolver in a slightly different way
+ * than others.
+ */
+ m_specialPageResolver = new SpecialPageNameResolver(this);
+ m_nameResolvers.add( m_specialPageResolver );
+ m_nameResolvers.add( new EnglishPluralsPageNameResolver( this ) );
+
Class urlclass = ClassUtil.findClass( "org.apache.wiki.url",
TextUtil.getStringProperty( props, PROP_URLCONSTRUCTOR, "DefaultURLConstructor" ) );
m_urlConstructor = (URLConstructor) urlclass.newInstance();
@@ -903,7 +914,14 @@
// FIXME: This method should return the FQN of the defaultspace:frontpage page of the wiki.
public String getFrontPage()
{
- return m_frontPage;
+ try
+ {
+ return getFrontPage(null).getQualifiedName().toString();
+ }
+ catch( ProviderException e )
+ {
+ return "ErrorFrontPageCannotBeDetermined";
+ }
}
/**
@@ -919,15 +937,17 @@
public WikiPage getFrontPage( String space ) throws ProviderException
{
WikiPage p;
+ WikiName name = new WikiName( space, m_frontPage );
+
try
{
- p = getPage( m_frontPage );
+ p = m_contentManager.getPage( name );
}
catch( PageNotFoundException e )
{
try
{
- p = createPage( new WikiName(space,m_frontPage) );
+ p = createPage( name );
}
catch( PageAlreadyExistsException e1 )
{
@@ -1107,10 +1127,10 @@
* @param original The page to check
* @return A reference to the page, or null, if there's no special page.
*/
- public String getSpecialPageReference( String original )
+ public URI getSpecialPageReference( String original )
{
- URI uri = m_contextFactory.getSpecialPageURI( original );
- return uri == null ? null : uri.toString();
+ URI uri = m_specialPageResolver.getSpecialPageURI( original );
+ return uri;
}
/**
@@ -1203,23 +1223,20 @@
{
WikiPage att = null;
+ WikiName name = WikiName.valueOf(page);
try
{
- if( m_contextFactory.getSpecialPageURI(page) != null ) return true;
-
- if( getFinalPageName( page ) != null )
+ if( getFinalPageName( name ) != null )
{
return true;
}
-
- att = getAttachmentManager().getAttachmentInfo( (WikiContext)null, page );
}
catch( Exception e )
{
log.debug("pageExists() failed to find attachments",e);
}
- return att != null;
+ return false;
}
/**
@@ -1234,18 +1251,17 @@
public boolean pageExists( String page, int version )
throws ProviderException
{
- if( m_contextFactory.getSpecialPageURI(page) != null ) return true;
-
boolean isThere = false;
- String finalName;
+ WikiName finalName = WikiName.valueOf( page );
try
{
// Go and check if this particular version of this page exists
- finalName = getFinalPageName( page );
- isThere = m_contentManager.pageExists( WikiName.valueOf( finalName ), version );
+ finalName = getFinalPageName( finalName );
+ isThere = m_contentManager.pageExists( finalName, version );
}
- catch( PageNotFoundException e )
+ catch( Exception e )
{
+ // FIXME: probably not a good idea to catch everything.
// It's not there!
}
@@ -1271,21 +1287,6 @@
return false;
}
- /**
- * Returns the correct page name This
- * method simply delegates to
- * {@link org.apache.wiki.action.WikiContextFactory#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.
- * @throws PageNotFoundException if the page cannot be found
- */
- public String getFinalPageName( String page )
- throws PageNotFoundException, ProviderException
- {
- return m_contextFactory.getFinalPageName( page );
- }
/**
* Turns a WikiName into something that can be
@@ -1940,21 +1941,26 @@
}
/**
- * Finds the corresponding WikiPage object based on the page name. It always finds
- * the latest version of a page.
+ * Finds the corresponding WikiPage object based on the page name.
*
* @param pagereq The name of the page to look for.
* @return A WikiPage object, or null, if the page by the name could not be found.
- * @throws ProviderException
- * @throws PageNotFoundException
+ * @throws ProviderException
+ * @throws PageNotFoundException
*/
public WikiPage getPage( String pagereq )
throws PageNotFoundException, ProviderException
{
- return getPage( pagereq, WikiProvider.LATEST_VERSION );
+ return getPage( WikiName.valueOf( pagereq ) );
}
+ public WikiPage getPage( WikiName name )
+ throws PageNotFoundException, ProviderException
+ {
+ return m_contentManager.getPage( name );
+ }
+
/**
* Finds the corresponding WikiPage object base on the page name and version.
*
@@ -2552,4 +2558,22 @@
{
m_contentManager.release();
}
+
+ /**
+ * Resolves a page name as per the installed PageNameResolvers.
+ *
+ * @param page the page name.
+ * @return The rewritten page name. May also return null in case there
+ * were problems.
+ */
+ public final WikiName getFinalPageName( WikiName page ) throws ProviderException
+ {
+ for( PageNameResolver resolver : m_nameResolvers )
+ {
+ page = resolver.resolve( page );
+ }
+
+ return page;
+ }
+
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/ViewActionBean.java Sun Apr 5 15:11:33 2009
@@ -135,7 +135,7 @@
String pageName = pageParamError.getFieldValue();
// Is it a special page?
- URI uri = getContext().getEngine().getWikiContextFactory().getSpecialPageURI( pageName );
+ URI uri = getContext().getEngine().getSpecialPageReference( pageName );
if( uri != null )
{
return new RedirectResolution( uri.toString() );
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/action/WikiContextFactory.java Sun Apr 5 15:11:33 2009
@@ -98,10 +98,7 @@
private static final long serialVersionUID = 1L;
- /** Prefix in jspwiki.properties signifying special page keys. */
- private static final String PROP_SPECIALPAGE = "jspwiki.specialPage.";
-
- /**
+ /**
* This method can be used to find the WikiContext programmatically from a
* JSP PageContext. We check the request context. The wiki context, if it
* exists, is looked up using the key
@@ -152,17 +149,11 @@
request.setAttribute( WikiTagBase.ATTR_CONTEXT, context );
}
- /** Private map with JSPs as keys, URIs (for absolute or relative URLs) as values */
- private final Map<String, URI> m_specialRedirects;
-
private final WikiEngine m_engine;
private String m_mockContextPath;
- /** If true, we'll also consider english plurals (+s) a match. */
- private boolean m_matchEnglishPlurals;
-
- /** Maps (pre-3.0) request contexts map to WikiActionBeans. */
+ /** Maps (pre-3.0) request contexts map to WikiActionBeans. */
private final Map<String, HandlerInfo> m_contextMap = new HashMap<String, HandlerInfo>();
/**
@@ -177,13 +168,9 @@
{
super();
m_engine = engine;
- m_specialRedirects = new HashMap<String, URI>();
initRequestContextMap( properties );
- initSpecialPageRedirects( properties );
- // Do we match plurals?
- m_matchEnglishPlurals = TextUtil.getBooleanProperty( properties, WikiEngine.PROP_MATCHPLURALS, true );
// Set the path prefix for constructing synthetic Stripes mock requests;
// trailing slash is removed.
@@ -213,87 +200,6 @@
return handler;
}
- /**
- * <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
- * @throws PageNotFoundException if the page does not exist
- */
- public final String getFinalPageName( String page ) throws PageNotFoundException, 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 an
- * a String representing the relative or absolute URL to that page;
- * otherwise, it returns <code>null</code>.
- * </p>
- * <p>
- * Special pages are non-existent 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>
- */
- public final URI getSpecialPageURI( String page )
- {
- return m_specialRedirects.get( page );
- }
/**
* <p>
@@ -437,51 +343,6 @@
}
}
- /**
- * Skims through a supplied set of Properties and looks for anything with
- * the "special page" prefix, and creates Stripes
- * {@link net.sourceforge.stripes.action.RedirectResolution} objects for any
- * that are found.
- */
- private void initSpecialPageRedirects( Properties properties )
- {
- for( Map.Entry<Object,Object> entry : properties.entrySet() )
- {
- String key = (String) entry.getKey();
- if( key.startsWith( PROP_SPECIALPAGE ) )
- {
- String specialPage = key.substring( PROP_SPECIALPAGE.length() );
- String redirectUrl = (String) entry.getValue();
- if( specialPage != null && redirectUrl != null )
- {
- specialPage = specialPage.trim();
-
- // Parse the special page
- redirectUrl = redirectUrl.trim();
- try
- {
- URI uri = new URI( redirectUrl );
- if ( uri.getAuthority() == null )
- {
- // No http:// ftp:// or other authority, so it must be relative to webapp /
- if ( !redirectUrl.startsWith( "/" ) )
- {
- uri = new URI( "/" + redirectUrl );
- }
- }
-
- // Add the URI for the special page
- m_specialRedirects.put( specialPage, uri );
- }
- catch( URISyntaxException e )
- {
- // The user supplied a STRANGE reference
- log.error( "Strange special page reference: " + redirectUrl );
- }
- }
- }
- }
- }
/**
* Creates and returns a new WikiActionBean based on a supplied class, with
@@ -527,12 +388,12 @@
// Extract and set the WikiPage
if( page == null )
{
- String pageName = extractPageFromParameter( request );
+ WikiName pageName = extractPageFromParameter( request );
// For view action, default to front page
if( pageName == null && WikiContext.VIEW.equals( requestContext ) )
{
- pageName = m_engine.getFrontPage();
+ page = m_engine.getFrontPage(null);
}
// Make sure the page is resolved properly (taking into account
@@ -576,7 +437,7 @@
* @param request the HTTP request
* @return the resolved page name
*/
- protected final String extractPageFromParameter( HttpServletRequest request )
+ protected final WikiName extractPageFromParameter( HttpServletRequest request )
{
// Corner case when request == null
if( request == null )
@@ -586,29 +447,28 @@
// Extract the page name from the URL directly
String[] pages = request.getParameterValues( "page" );
- String page = null;
+ WikiName page = null;
if( pages != null && pages.length > 0 )
{
- page = pages[0];
+ page = WikiName.valueOf(pages[0]);
try
{
- // Look for singular/plural variants
- String finalPage = getFinalPageName( page );
+ // Look for variants
+ WikiName finalPage = m_engine.getFinalPageName( page );
+
+ // If no variant, use whatever the user supplied.
+ if( finalPage == null ) return page;
+
return finalPage;
}
- catch( PageNotFoundException e )
- {
- // No worries; use the one the user supplied
- }
catch( ProviderException e )
{
// FIXME: Should not ignore!
}
- return page;
}
// Didn't resolve; return null
- return page;
+ return null;
}
/**
@@ -622,7 +482,7 @@
* exist
* @return the wiki page
*/
- protected final WikiPage resolvePage( HttpServletRequest request, String page ) throws PageNotFoundException, ProviderException
+ protected final WikiPage resolvePage( HttpServletRequest request, WikiName page ) throws PageNotFoundException, ProviderException
{
// See if the user included a version parameter
int version = WikiProvider.LATEST_VERSION;
@@ -635,14 +495,14 @@
try
{
- return m_engine.getPage( page, version );
+ return m_engine.getContentManager().getPage( page, version );
}
catch( PageNotFoundException e )
{
- page = MarkupParser.cleanLink( page );
+ String pageName = MarkupParser.cleanLink( page.getPath() );
try
{
- return m_engine.createPage( WikiName.valueOf( page ) );
+ return m_engine.createPage( WikiName.valueOf( pageName ) );
}
catch( PageAlreadyExistsException e1 )
{
@@ -652,20 +512,4 @@
}
}
- /**
- * 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
- */
- protected final boolean simplePageExists( String page ) throws ProviderException
- {
- if( m_specialRedirects.containsKey( page ) )
- {
- return true;
- }
- return m_engine.getPageManager().pageExists( page );
- }
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/api/WikiPage.java Sun Apr 5 15:11:33 2009
@@ -26,7 +26,6 @@
import java.util.List;
import java.util.Map;
-import org.apache.wiki.JCRWikiPage;
import org.apache.wiki.auth.acl.Acl;
import org.apache.wiki.content.PageNotFoundException;
import org.apache.wiki.content.WikiName;
@@ -261,4 +260,17 @@
* @throws ProviderException If something goes wrong.
*/
public List<WikiPage> getChildren() throws ProviderException;
+
+ /**
+ * Returns true, if this page is an attachment (that is, does not
+ * contain wikimarkup and has a parent page).
+ * <p>
+ * As of 3.0, you should not do an instanceof Attachment test to
+ * test for attachmentness, since Attachment is now an interface.
+ * Use this method instead.
+ *
+ * @return True, if this is an attachment. False otherwise.
+ * @throws ProviderException If the attachmentness cannot be determined.
+ */
+ public boolean isAttachment() throws ProviderException;
}
Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/EnglishPluralsPageNameResolver.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/EnglishPluralsPageNameResolver.java?rev=762101&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/EnglishPluralsPageNameResolver.java (added)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/EnglishPluralsPageNameResolver.java Sun Apr 5 15:11:33 2009
@@ -0,0 +1,77 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.wiki.content;
+
+import org.apache.wiki.WikiEngine;
+import org.apache.wiki.providers.ProviderException;
+import org.apache.wiki.util.TextUtil;
+
+/**
+ * A resolver for English language plurals (matches "PageName" to "PageNames" and
+ * vice versa). If the page does not exist, returns the requested name.
+ */
+public class EnglishPluralsPageNameResolver extends PageNameResolver
+{
+ /** If true, we'll also consider english plurals (+s) a match. */
+ private boolean m_matchEnglishPlurals;
+
+
+ public EnglishPluralsPageNameResolver( WikiEngine engine )
+ {
+ super( engine );
+
+
+ // Do we match plurals?
+ m_matchEnglishPlurals = TextUtil.getBooleanProperty( engine.getWikiProperties(),
+ WikiEngine.PROP_MATCHPLURALS,
+ true );
+ }
+
+ @Override
+ public WikiName resolve( WikiName name ) throws ProviderException
+ {
+ ContentManager mgr = m_engine.getContentManager();
+
+ if( mgr.pageExists( name ) ) return name;
+
+ if( m_matchEnglishPlurals )
+ {
+ WikiName alternativeName;
+
+ if( name.getPath().endsWith( "s" ) )
+ {
+ alternativeName = new WikiName( name.getSpace(),
+ name.getPath().substring( 0, name.getPath().length()-1) );
+ }
+ else
+ {
+ alternativeName = new WikiName( name.getSpace(),
+ name.getPath()+"s" );
+ }
+
+ if( mgr.pageExists( alternativeName ) )
+ return alternativeName;
+ }
+
+ return name;
+ }
+
+}
Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageNameResolver.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageNameResolver.java?rev=762101&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageNameResolver.java (added)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/PageNameResolver.java Sun Apr 5 15:11:33 2009
@@ -0,0 +1,54 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.wiki.content;
+
+import org.apache.wiki.WikiEngine;
+import org.apache.wiki.providers.ProviderException;
+
+/**
+ * Resolves a given WikiName to a new WikiName. For example,
+ * a subclass could check for plural forms of the WikiName
+ * and return the corresponding version. It could also be
+ * used to sanitize a WikiName or whatever you feel is useful.
+ */
+public abstract class PageNameResolver
+{
+ protected WikiEngine m_engine;
+
+ /**
+ * Construct a PageNameResolver against a given WikiEngine.
+ *
+ * @param engine The Engine.
+ */
+ public PageNameResolver( WikiEngine engine )
+ {
+ m_engine = engine;
+ }
+
+ /**
+ * Resolves the page name to another page.
+ *
+ * @param name The name to check for
+ * @return A new name that you should getPage() on.
+ * @throws ProviderException If the resolution fails in any way.
+ */
+ public abstract WikiName resolve( WikiName name ) throws ProviderException;
+}
Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/SpecialPageNameResolver.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/SpecialPageNameResolver.java?rev=762101&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/SpecialPageNameResolver.java (added)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/SpecialPageNameResolver.java Sun Apr 5 15:11:33 2009
@@ -0,0 +1,154 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.wiki.content;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.wiki.WikiEngine;
+import org.apache.wiki.log.Logger;
+import org.apache.wiki.log.LoggerFactory;
+import org.apache.wiki.providers.ProviderException;
+
+/**
+ * This PageNameResolver initializes itself from the "jspwiki.specialPage" -properties
+ * and resolves the PageName to itself if the page exists.
+ */
+public class SpecialPageNameResolver extends PageNameResolver
+{
+ /** Prefix in jspwiki.properties signifying special page keys. */
+ private static final String PROP_SPECIALPAGE = "jspwiki.specialPage.";
+
+ private static Logger log = LoggerFactory.getLogger( SpecialPageNameResolver.class );
+
+ /** Private map with JSPs as keys, URIs (for absolute or relative URLs) as values */
+ private final Map<String, URI> m_specialRedirects;
+
+ /**
+ * Constructs a SpecialPageNameResolver using the engine properties.
+ *
+ * @param engine {@inheritDoc}
+ */
+ public SpecialPageNameResolver( WikiEngine engine )
+ {
+ super( engine );
+
+ m_specialRedirects = new HashMap<String, URI>();
+
+ initSpecialPageRedirects( engine.getWikiProperties() );
+ }
+
+ @Override
+ public WikiName resolve( WikiName name ) throws ProviderException
+ {
+ if( simplePageExists(name) ) return name;
+
+ return null;
+ }
+
+
+ /**
+ * 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
+ */
+ protected final boolean simplePageExists( WikiName page ) throws ProviderException
+ {
+ if( m_specialRedirects.containsKey( page ) )
+ {
+ return true;
+ }
+
+ return m_engine.getContentManager().pageExists( page );
+ }
+
+ /**
+ * Skims through a supplied set of Properties and looks for anything with
+ * the "special page" prefix, and creates Stripes
+ * {@link net.sourceforge.stripes.action.RedirectResolution} objects for any
+ * that are found.
+ */
+ private void initSpecialPageRedirects( Properties properties )
+ {
+ for( Map.Entry<Object,Object> entry : properties.entrySet() )
+ {
+ String key = (String) entry.getKey();
+ if( key.startsWith( PROP_SPECIALPAGE ) )
+ {
+ String specialPage = key.substring( PROP_SPECIALPAGE.length() );
+ String redirectUrl = (String) entry.getValue();
+ if( specialPage != null && redirectUrl != null )
+ {
+ specialPage = specialPage.trim();
+
+ // Parse the special page
+ redirectUrl = redirectUrl.trim();
+ try
+ {
+ URI uri = new URI( redirectUrl );
+ if ( uri.getAuthority() == null )
+ {
+ // No http:// ftp:// or other authority, so it must be relative to webapp /
+ if ( !redirectUrl.startsWith( "/" ) )
+ {
+ uri = new URI( "/" + redirectUrl );
+ }
+ }
+
+ // Add the URI for the special page
+ m_specialRedirects.put( specialPage, uri );
+ }
+ catch( URISyntaxException e )
+ {
+ // The user supplied a STRANGE reference
+ log.error( "Strange special page reference: " + redirectUrl );
+ }
+ }
+ }
+ }
+ }
+
+
+
+ /**
+ * <p>
+ * If the page is a special page, this method returns an
+ * a String representing the relative or absolute URL to that page;
+ * otherwise, it returns <code>null</code>.
+ * </p>
+ * <p>
+ * Special pages are non-existent 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>
+ */
+ public final URI getSpecialPageURI( String page )
+ {
+ return m_specialRedirects.get( page );
+ }
+}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/content/WikiName.java Sun Apr 5 15:11:33 2009
@@ -45,25 +45,28 @@
/**
* Create a WikiName from a space and a path.
*
- * @param space The space
+ * @param space The space. If space == null, then uses {@link ContentManager#DEFAULT_SPACE}
* @param path The path
*/
public WikiName(String space, String path)
{
- m_space = space;
+ m_space = (space != null) ? space : ContentManager.DEFAULT_SPACE;
m_path = path;
}
/**
* Parses a fully-qualified name (FQN) and turns it into a WikiName.
* If the space name is missing, uses {@link ContentManager#DEFAULT_SPACE}
- * for the space name.
+ * for the space name. If the path is null, throws an IllegalArgumentException.
*
* @param path Path to parse
* @return A WikiName
+ * @throws IllegalArgumentException If the path is null.
*/
- public static WikiName valueOf(String path)
+ public static WikiName valueOf(String path) throws IllegalArgumentException
{
+ if( path == null ) throw new IllegalArgumentException("null path given to WikiName.valueOf().");
+
WikiName name = new WikiName();
int colon = path.indexOf(':');
@@ -80,9 +83,6 @@
name.m_path = path;
return name;
-
- // FIXME: Should probably use this
- //throw new IllegalArgumentException("The path does not represent a fully qualified WikiName (space:path/path/path)");
}
/**
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/parser/JSPWikiMarkupParser.java Sun Apr 5 15:11:33 2009
@@ -42,6 +42,7 @@
import org.apache.wiki.auth.WikiSecurityException;
import org.apache.wiki.auth.acl.Acl;
import org.apache.wiki.content.PageNotFoundException;
+import org.apache.wiki.content.WikiName;
import org.apache.wiki.i18n.InternationalizationManager;
import org.apache.wiki.log.Logger;
import org.apache.wiki.log.LoggerFactory;
@@ -436,10 +437,11 @@
{
if( page == null || page.length() == 0 ) return null;
- return m_engine.getFinalPageName( page );
+ return m_engine.getFinalPageName( WikiName.valueOf( page ) ).toString();
}
catch( Exception e )
{
+ // FIXME: This should be completely different!
log.warn("TranslatorReader got a faulty page name!",e);
return page; // FIXME: What would be the correct way to go back?
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/InsertPage.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/InsertPage.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/InsertPage.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/plugin/InsertPage.java Sun Apr 5 15:11:33 2009
@@ -31,6 +31,7 @@
import org.apache.wiki.api.WikiPage;
import org.apache.wiki.auth.AuthorizationManager;
import org.apache.wiki.auth.permissions.PermissionFactory;
+import org.apache.wiki.content.WikiName;
import org.apache.wiki.util.TextUtil;
@@ -101,7 +102,7 @@
WikiPage page = null;
try
{
- String pageName = engine.getFinalPageName( includedPage );
+ WikiName pageName = engine.getFinalPageName( context.getPage().getQualifiedName().resolve( includedPage ) );
if( pageName != null )
{
page = engine.getPage( pageName );
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/LinkTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/LinkTag.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/LinkTag.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/LinkTag.java Sun Apr 5 15:11:33 2009
@@ -33,6 +33,7 @@
import org.apache.wiki.api.WikiPage;
import org.apache.wiki.attachment.Attachment;
import org.apache.wiki.content.PageNotFoundException;
+import org.apache.wiki.content.WikiName;
import org.apache.wiki.parser.JSPWikiMarkupParser;
import org.apache.wiki.parser.MarkupParser;
import org.apache.wiki.providers.ProviderException;
@@ -245,7 +246,7 @@
//
WikiPage p = engine.getPage( m_pageName );
- if( p instanceof Attachment )
+ if( p.isAttachment() )
{
url = m_wikiContext.getURL( WikiContext.ATTACH, m_pageName );
}
@@ -258,19 +259,19 @@
reallink = MarkupParser.cleanLink( reallink );
- String matchedLink;
+ WikiName matchedLink;
String sectref = "";
- if( (matchedLink = engine.getFinalPageName( reallink )) != null )
+ if( (matchedLink = engine.getFinalPageName( WikiName.valueOf(reallink) )) != null )
{
- sectref = "section-"+engine.encodeName(matchedLink)+"-"+namedSection;
+ sectref = "section-"+engine.encodeName(matchedLink.getPath())+"-"+namedSection;
sectref = "#"+sectref.replace('%', '_');
}
else
{
- matchedLink = reallink;
+ matchedLink = WikiName.valueOf(reallink);
}
- url = makeBasicURL( m_context, matchedLink, parms, m_absolute ) + sectref;
+ url = makeBasicURL( m_context, matchedLink.toString(), parms, m_absolute ) + sectref;
}
else
{
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/PageNameTag.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/PageNameTag.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/PageNameTag.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/tags/PageNameTag.java Sun Apr 5 15:11:33 2009
@@ -25,6 +25,7 @@
import org.apache.wiki.WikiEngine;
import org.apache.wiki.api.WikiPage;
import org.apache.wiki.attachment.Attachment;
+import org.apache.wiki.providers.ProviderException;
/**
@@ -38,14 +39,14 @@
private static final long serialVersionUID = 0L;
public final int doWikiStartTag()
- throws IOException
+ throws IOException, ProviderException
{
WikiEngine engine = m_wikiContext.getEngine();
WikiPage page = m_wikiContext.getPage();
if( page != null )
{
- if( page instanceof Attachment )
+ if( page.isAttachment() )
{
pageContext.getOut().print( ((Attachment)page).getFileName() );
}
Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiPageTypeConverter.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiPageTypeConverter.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiPageTypeConverter.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/ui/stripes/WikiPageTypeConverter.java Sun Apr 5 15:11:33 2009
@@ -1,16 +1,22 @@
-/* Copyright 2005-2006 Tim Fennell
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
*/
package org.apache.wiki.ui.stripes;
@@ -44,8 +50,7 @@
{
/**
* Converts a named wiki page into a valid WikiPage object by retrieving the
- * latest version via the WikiEngine. If the exact page is not found, plural
- * variations will be tried. If the page cannot be found (perhaps because it
+ * latest version via the WikiEngine. If the page cannot be found (perhaps because it
* does not exist), this method will add a validation error to the supplied
* Collection of errors and return <code>null</code>. The error will be
* of type {@link net.sourceforge.stripes.validation.LocalizableError} and
@@ -69,22 +74,7 @@
}
catch( PageNotFoundException e )
{
- try
- {
- try
- {
- String finalName = engine.getWikiContextFactory().getFinalPageName( pageName );
- return engine.getPage( finalName );
- }
- catch( PageNotFoundException e1 )
- {
- errors.add( new LocalizableError( "common.nopage", pageName ) );
- }
- }
- catch( ProviderException e2 )
- {
- errors.add( new SimpleError( e2.getMessage() ) );
- }
+ errors.add( new LocalizableError( "common.nopage", pageName ) );
}
catch( ProviderException e )
{
Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/WikiEngineTest.java Sun Apr 5 15:11:33 2009
@@ -121,10 +121,10 @@
m_engine.saveText( "Foobars", "2" );
assertEquals( "plural mistake", "Foobars",
- m_engine.getFinalPageName( "Foobars" ) );
+ m_engine.getFinalPageName( WikiName.valueOf("Foobars") ) );
assertEquals( "singular mistake", "Foobar",
- m_engine.getFinalPageName( "Foobar" ) );
+ m_engine.getFinalPageName( WikiName.valueOf("Foobar" )) );
}
public void testFinalPageNameSingular()
@@ -133,9 +133,9 @@
m_engine.saveText( "Foobar", "1" );
assertEquals( "plural mistake", "Foobar",
- m_engine.getFinalPageName( "Foobars" ) );
+ m_engine.getFinalPageName( WikiName.valueOf("Foobars") ) );
assertEquals( "singular mistake", "Foobar",
- m_engine.getFinalPageName( "Foobar" ) );
+ m_engine.getFinalPageName( WikiName.valueOf("Foobar") ) );
}
public void testFinalPageNamePlural()
@@ -144,9 +144,9 @@
m_engine.saveText( "Foobars", "1" );
assertEquals( "plural mistake", "Foobars",
- m_engine.getFinalPageName( "Foobars" ) );
+ m_engine.getFinalPageName( WikiName.valueOf("Foobars") ) );
assertEquals( "singular mistake", "Foobars",
- m_engine.getFinalPageName( "Foobar" ) );
+ m_engine.getFinalPageName( WikiName.valueOf("Foobar") ) );
}
public void testPutPage()
Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/action/WikiContextFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/action/WikiContextFactoryTest.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/action/WikiContextFactoryTest.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/action/WikiContextFactoryTest.java Sun Apr 5 15:11:33 2009
@@ -161,37 +161,6 @@
context = resolver.newContext( request, response, WikiContext.VIEW_GROUP );
assertEquals( WikiContext.VIEW_GROUP, context.getRequestContext() );
}
-
- public void testFinalPageName() throws Exception
- {
- String page;
- page = resolver.getFinalPageName( "SinglePage" );
- assertEquals( "SinglePage", page );
- page = resolver.getFinalPageName( "SinglePages" );
- assertEquals( "SinglePage", page );
-
- page = resolver.getFinalPageName( "PluralPages" );
- assertEquals( "PluralPages", page );
- page = resolver.getFinalPageName( "PluralPage" );
- assertEquals( "PluralPages", page );
-
- page = resolver.getFinalPageName( "NonExistentPage" );
- assertNull( page );
- }
-
- public void testSpecialPageReference()
- {
- URI uri;
- uri = resolver.getSpecialPageURI( "RecentChanges" );
- assertEquals( "/RecentChanges.jsp", uri.toString() );
-
- uri = resolver.getSpecialPageURI( "FindPage" );
- assertEquals( "/Search.jsp", uri.toString() );
-
- // UserPrefs doesn't exist in our test properties
- uri = resolver.getSpecialPageURI( "UserPrefs" );
- assertNull( uri );
- }
public static Test suite()
{
Modified: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/AllTests.java?rev=762101&r1=762100&r2=762101&view=diff
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/AllTests.java (original)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/AllTests.java Sun Apr 5 15:11:33 2009
@@ -39,6 +39,8 @@
suite.addTest( PageRenamerTest.suite() );
suite.addTest( WikiNameTest.suite() );
suite.addTest( ContentManagerTest.suite() );
+ suite.addTest( SpecialPageNameResolverTest.suite() );
+ suite.addTest( EnglishPluralsPageNameResolverTest.suite() );
return suite;
}
Added: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/EnglishPluralsPageNameResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/EnglishPluralsPageNameResolverTest.java?rev=762101&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/EnglishPluralsPageNameResolverTest.java (added)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/EnglishPluralsPageNameResolverTest.java Sun Apr 5 15:11:33 2009
@@ -0,0 +1,80 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+package org.apache.wiki.content;
+
+import java.util.Properties;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.wiki.TestEngine;
+import org.apache.wiki.WikiEngine;
+
+public class EnglishPluralsPageNameResolverTest extends TestCase
+{
+ private EnglishPluralsPageNameResolver resolver;
+ private TestEngine m_engine;
+
+ public void setUp() throws Exception
+ {
+ Properties props = new Properties();
+ props.load( TestEngine.findTestProperties() );
+ props.put( WikiEngine.PROP_MATCHPLURALS, "yes" );
+ m_engine = new TestEngine( props );
+
+ m_engine.saveText( "SinglePage", "This is a test." );
+ m_engine.saveText( "PluralPages", "This is a test." );
+
+ resolver = new EnglishPluralsPageNameResolver(m_engine);
+ }
+
+ public void tearDown() throws Exception
+ {
+ m_engine.deletePage( "SinglePage" );
+ m_engine.deletePage( "PluralPages" );
+ }
+
+ public void testFinalPageName() throws Exception
+ {
+ WikiName page;
+ page = resolver.resolve( WikiName.valueOf("SinglePage") );
+ assertEquals( "SinglePage", page );
+
+ page = resolver.resolve( WikiName.valueOf("SinglePages") );
+ assertEquals( "SinglePage", page );
+
+ page = resolver.resolve( WikiName.valueOf("PluralPages") );
+ assertEquals( "PluralPages", page );
+
+ page = resolver.resolve( WikiName.valueOf( "PluralPage" ) );
+ assertEquals( "PluralPages", page );
+
+ page = resolver.resolve( WikiName.valueOf("NonExistentPage") );
+ assertNull( page );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(EnglishPluralsPageNameResolverTest.class);
+ }
+
+}
Added: incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/SpecialPageNameResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/SpecialPageNameResolverTest.java?rev=762101&view=auto
==============================================================================
--- incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/SpecialPageNameResolverTest.java (added)
+++ incubator/jspwiki/trunk/tests/java/org/apache/wiki/content/SpecialPageNameResolverTest.java Sun Apr 5 15:11:33 2009
@@ -0,0 +1,45 @@
+package org.apache.wiki.content;
+
+import java.net.URI;
+import java.util.Properties;
+
+import org.apache.wiki.TestEngine;
+import org.apache.wiki.WikiEngine;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class SpecialPageNameResolverTest extends TestCase
+{
+ private SpecialPageNameResolver resolver;
+
+ public void setUp() throws Exception
+ {
+ Properties props = new Properties();
+ props.load( TestEngine.findTestProperties() );
+ WikiEngine engine = new TestEngine( props );
+
+ resolver = new SpecialPageNameResolver(engine);
+ }
+
+ public void testSpecialPageReference()
+ {
+ URI uri;
+ uri = resolver.getSpecialPageURI( "RecentChanges" );
+ assertEquals( "/RecentChanges.jsp", uri.toString() );
+
+ uri = resolver.getSpecialPageURI( "FindPage" );
+ assertEquals( "/Search.jsp", uri.toString() );
+
+ // UserPrefs doesn't exist in our test properties
+ uri = resolver.getSpecialPageURI( "UserPrefs" );
+ assertNull( uri );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(SpecialPageNameResolverTest.class);
+ }
+
+}