com.ecyrd.jspwiki
Class WikiEngine

java.lang.Object
  |
  +--com.ecyrd.jspwiki.WikiEngine

public class WikiEngine
extends java.lang.Object

Provides Wiki services to the JSP page.

This is the main interface through which everything should go.

Using this class: Always get yourself an instance from JSP page by using the WikiEngine.getInstance() method. Never create a new WikiEngine() from scratch, unless you're writing tests.

Author:
Janne Jalkanen

Field Summary
static java.lang.String PREFS_COOKIE_NAME
          The name of the cookie that gets stored to the user browser.
static java.lang.String PROP_BASEURL
          The name for the base URL to use in all references.
static java.lang.String PROP_BEAUTIFYTITLE
          Property name for the "spaces in titles" -hack.
static java.lang.String PROP_ENCODING
          Define the used encoding.
static java.lang.String PROP_FRONTPAGE
          Property name for the default front page.
static java.lang.String PROP_INTERWIKIREF
           
static java.lang.String PROP_MATCHPLURALS
          Property name for the "match english plurals" -hack.
static java.lang.String PROP_STOREIPADDRESS
          If true, logs the IP address of the editor on saving.
static java.lang.String PROP_STOREUSERNAME
          If true, then the user name will be stored with the page data.
static java.lang.String PROP_TEMPLATEDIR
          Property name for the template that is used.
 
Constructor Summary
  WikiEngine(java.util.Properties properties)
          Instantiate the WikiEngine using a given set of properties.
protected WikiEngine(javax.servlet.ServletContext context)
          Instantiate using this method when you're running as a servlet and WikiEngine will figure out where to look for the property file.
 
Method Summary
 java.lang.String beautifyTitle(java.lang.String title)
          Beautifies the title of the page by appending spaces in suitable places.
 java.lang.String decodeName(java.lang.String pagerequest)
           
 java.lang.String encodeName(java.lang.String pagename)
          Turns a WikiName into something that can be called through using an URL.
 java.util.Collection findPages(java.lang.String query)
          Parses an incoming search request, then does a search.
static java.lang.Class findWikiClass(java.lang.String className, java.lang.String defaultPackage)
          Attempts to locate a Wiki class, defaulting to the defaultPackage in case the actual class could not be located.
 java.util.Collection getAllInlinedImagePatterns()
          Returns a collection of all image types that get inlined.
 java.util.Collection getAllInterWikiLinks()
          Returns a collection of all supported InterWiki links.
 java.lang.String getApplicationName()
          Returns the name of the application.
 AttachmentManager getAttachmentManager()
          Returns the current AttachmentManager.
 java.lang.String getAttachmentURL(java.lang.String attName)
          Returns the basic attachment URL.
 java.lang.String getBaseURL()
          Returns the base URL.
 java.lang.String getContentEncoding()
          Returns the IANA name of the character set encoding we're supposed to be using right now.
 java.lang.String getCurrentProvider()
          Returns the provider name
 java.lang.String getCurrentProviderInfo()
          return information about current provider.
 java.lang.String getDiff(java.lang.String page, int version1, int version2)
          Returns a diff of two versions of a page.
 java.lang.String getEditURL(java.lang.String pageName)
          Returns the basic URL to an editor.
 java.lang.String getFinalPageName(java.lang.String page)
          Returns the correct page name, or null, if no such page can be found.
 java.lang.String getFrontPage()
          Returns the default front page, if no page is used.
 java.lang.String getGlobalRSSURL()
          Returns the URL of the global RSS file.
 java.lang.String getHTML(java.lang.String page)
          Returns the converted HTML of the page.
 java.lang.String getHTML(java.lang.String pagename, int version)
          Returns the converted HTML of the page's specific version.
 java.lang.String getHTML(WikiContext context, WikiPage page)
          Returns the converted HTML of the page using a different context than the default context.
static WikiEngine getInstance(javax.servlet.ServletConfig config)
          Gets a WikiEngine related to this servlet.
 java.lang.String getInterWikiURL(java.lang.String wikiName)
          Returns an URL to some other Wiki that we know.
 WikiPage getPage(java.lang.String pagereq)
          Return a bunch of information from the web page.
 WikiPage getPage(java.lang.String pagereq, int version)
          Returns specific information about a Wiki page.
 int getPageCount()
          Returns the number of pages in this Wiki
 PageManager getPageManager()
          Returns the current PageManager.
 PluginManager getPluginManager()
          Returns the current plugin manager.
 java.lang.String getPluginSearchPath()
           
 java.lang.String getPureText(java.lang.String page, int version)
          Returns the pure text of a page, no conversions.
 java.util.Collection getRecentChanges()
          Returns a Collection of WikiPages, sorted in time order of last change.
 ReferenceManager getReferenceManager()
          Returns this object's ReferenceManager.
static java.lang.String getRequiredProperty(java.util.Properties props, java.lang.String key)
          Throws an exception if a property is not found.
 javax.servlet.ServletContext getServletContext()
          Returns the ServletContext that this particular WikiEngine was initialized with.
 java.lang.String getSpecialPageReference(java.lang.String original)
          If the page is a special page, then returns a direct URL to that page.
 java.util.Date getStartTime()
          Returns the moment when this engine was started.
 java.lang.String getTemplateDir()
          Returns the current template directory.
 java.lang.String getText(java.lang.String page)
          Returns the unconverted text of a page.
 java.lang.String getText(java.lang.String page, int version)
          Returns the unconverted text of the given version of a page, if it exists.
 java.lang.String getText(WikiContext context, WikiPage page)
          Returns plain text (with HTML entities replaced).
 java.lang.String getUserName(javax.servlet.http.HttpServletRequest request)
          Retrieves the user name.
 java.lang.String getValidUserName(javax.servlet.http.HttpServletRequest request)
          If no author name has been set, then use the IP address, if allowed.
 VariableManager getVariableManager()
           
 java.util.List getVersionHistory(java.lang.String page)
          Returns a Collection of WikiPages containing the version history of a page.
 java.lang.String getViewURL(java.lang.String pageName)
          Returns the basic URL to a page, without any modifications.
 java.util.Properties getWikiProperties()
          Internal method for getting a property.
 boolean pageExists(java.lang.String page)
          Returns true, if the requested page (or an alias) exists.
 boolean pageExists(java.lang.String page, int version)
          Returns true, if the requested page (or an alias) exists with the requested version.
 boolean pageExists(WikiPage page)
          Returns true, if the requested page (or an alias) exists, with the specified version in the WikiPage.
 java.lang.String safeGetParameter(javax.servlet.ServletRequest request, java.lang.String name)
          This is a safe version of the Servlet.Request.getParameter() routine.
 java.lang.String safeGetQueryString(javax.servlet.http.HttpServletRequest request)
          Returns the query string (the portion after the question mark).
 void saveText(java.lang.String page, java.lang.String text)
          Writes the WikiText of a page into the page repository.
 void saveText(java.lang.String page, java.lang.String text, javax.servlet.http.HttpServletRequest request)
           
protected  java.util.Collection scanWikiLinks(java.lang.String pagedata)
          Reads a WikiPageful of data from a String and returns all links internal to this Wiki in a Collection.
 java.lang.String textToHTML(WikiContext context, java.lang.String pagedata)
          Converts raw page data to HTML.
 java.lang.String textToHTML(WikiContext context, java.lang.String pagedata, StringTransmutator localLinkHook, StringTransmutator extLinkHook)
          Just convert WikiText to HTML.
 void updateReferences(java.lang.String pageName)
          Updates all references for the given page.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_INTERWIKIREF

public static final java.lang.String PROP_INTERWIKIREF
See Also:
Constant Field Values

PROP_STOREUSERNAME

public static final java.lang.String PROP_STOREUSERNAME
If true, then the user name will be stored with the page data.

See Also:
Constant Field Values

PROP_STOREIPADDRESS

public static final java.lang.String PROP_STOREIPADDRESS
If true, logs the IP address of the editor on saving.

See Also:
Constant Field Values

PROP_ENCODING

public static final java.lang.String PROP_ENCODING
Define the used encoding. Currently supported are ISO-8859-1 and UTF-8

See Also:
Constant Field Values

PROP_BASEURL

public static final java.lang.String PROP_BASEURL
The name for the base URL to use in all references.

See Also:
Constant Field Values

PROP_BEAUTIFYTITLE

public static final java.lang.String PROP_BEAUTIFYTITLE
Property name for the "spaces in titles" -hack.

See Also:
Constant Field Values

PREFS_COOKIE_NAME

public static final java.lang.String PREFS_COOKIE_NAME
The name of the cookie that gets stored to the user browser.

See Also:
Constant Field Values

PROP_MATCHPLURALS

public static final java.lang.String PROP_MATCHPLURALS
Property name for the "match english plurals" -hack.

See Also:
Constant Field Values

PROP_TEMPLATEDIR

public static final java.lang.String PROP_TEMPLATEDIR
Property name for the template that is used.

See Also:
Constant Field Values

PROP_FRONTPAGE

public static final java.lang.String PROP_FRONTPAGE
Property name for the default front page.

See Also:
Constant Field Values
Constructor Detail

WikiEngine

public WikiEngine(java.util.Properties properties)
           throws WikiException
Instantiate the WikiEngine using a given set of properties. Use this constructor for testing purposes only.


WikiEngine

protected WikiEngine(javax.servlet.ServletContext context)
              throws WikiException
Instantiate using this method when you're running as a servlet and WikiEngine will figure out where to look for the property file. Do not use this method - use WikiEngine.getInstance() instead.

Method Detail

getInstance

public static WikiEngine getInstance(javax.servlet.ServletConfig config)
                              throws InternalWikiException
Gets a WikiEngine related to this servlet. Since this method is only called from JSP pages (and JspInit()) to be specific, we throw a RuntimeException if things don't work.

Throws:
InternalWikiException - in case something fails. This is a RuntimeException, so be prepared for it.

getRequiredProperty

public static java.lang.String getRequiredProperty(java.util.Properties props,
                                                   java.lang.String key)
                                            throws NoRequiredPropertyException
Throws an exception if a property is not found.

NoRequiredPropertyException

getWikiProperties

public java.util.Properties getWikiProperties()
Internal method for getting a property. This is used by the TranslatorReader for example.


getPluginSearchPath

public java.lang.String getPluginSearchPath()
Since:
1.8.0

getTemplateDir

public java.lang.String getTemplateDir()
Returns the current template directory.

Since:
1.9.20

getBaseURL

public java.lang.String getBaseURL()
Returns the base URL. Always prepend this to any reference you make.

Since:
1.6.1

getStartTime

public java.util.Date getStartTime()
Returns the moment when this engine was started.

Since:
2.0.15.

getViewURL

public java.lang.String getViewURL(java.lang.String pageName)
Returns the basic URL to a page, without any modifications. You may add any parameters to this.

Since:
2.0.3

getEditURL

public java.lang.String getEditURL(java.lang.String pageName)
Returns the basic URL to an editor.

Since:
2.0.3

getAttachmentURL

public java.lang.String getAttachmentURL(java.lang.String attName)
Returns the basic attachment URL.

Since:
2.0.42.

getFrontPage

public java.lang.String getFrontPage()
Returns the default front page, if no page is used.


getServletContext

public javax.servlet.ServletContext getServletContext()
Returns the ServletContext that this particular WikiEngine was initialized with. It may return null, if the WikiEngine is not running inside a servlet container!

Returns:
ServletContext of the WikiEngine, or null.
Since:
1.7.10

safeGetParameter

public java.lang.String safeGetParameter(javax.servlet.ServletRequest request,
                                         java.lang.String name)
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.

For more information, see: JGuru FAQ.

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

safeGetQueryString

public java.lang.String safeGetQueryString(javax.servlet.http.HttpServletRequest request)
Returns the query string (the portion after the question mark).

Returns:
The query string. If the query string is null, returns an empty string.
Since:
2.0.40.

getInterWikiURL

public java.lang.String getInterWikiURL(java.lang.String wikiName)
Returns an URL to some other Wiki that we know.

Returns:
null, if no such reference was found.

getAllInterWikiLinks

public java.util.Collection getAllInterWikiLinks()
Returns a collection of all supported InterWiki links.


getAllInlinedImagePatterns

public java.util.Collection getAllInlinedImagePatterns()
Returns a collection of all image types that get inlined.


getSpecialPageReference

public java.lang.String getSpecialPageReference(java.lang.String original)
If the page is a special page, then returns a direct URL to that page. Otherwise returns null.

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".


getApplicationName

public java.lang.String getApplicationName()
Returns the name of the application.


beautifyTitle

public java.lang.String beautifyTitle(java.lang.String title)
Beautifies the title of the page by appending spaces in suitable places.

Since:
1.7.11

pageExists

public boolean pageExists(java.lang.String page)
Returns true, if the requested page (or an alias) exists. Will consider any version as existing. Will also consider attachments.

Parameters:
page - WikiName of the page.

pageExists

public boolean pageExists(java.lang.String page,
                          int version)
                   throws ProviderException
Returns true, if the requested page (or an alias) exists with the requested version.

Parameters:
page - Page name
ProviderException

pageExists

public boolean pageExists(WikiPage page)
                   throws ProviderException
Returns true, if the requested page (or an alias) exists, with the specified version in the WikiPage.

ProviderException
Since:
2.0

getFinalPageName

public java.lang.String getFinalPageName(java.lang.String page)
Returns the correct page name, or null, if no such page can be found. Aliases are considered.

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.

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.

Parameters:
page - Page name.
Returns:
The rewritten page name, or null, if the page does not exist.
Since:
2.0

encodeName

public java.lang.String encodeName(java.lang.String pagename)
Turns a WikiName into something that can be called through using an URL.

Since:
1.4.1

decodeName

public java.lang.String decodeName(java.lang.String pagerequest)

getContentEncoding

public java.lang.String getContentEncoding()
Returns the IANA name of the character set encoding we're supposed to be using right now.

Since:
1.5.3

getText

public java.lang.String getText(java.lang.String page)
Returns the unconverted text of a page.

Parameters:
page - WikiName of the page to fetch.

getText

public java.lang.String getText(java.lang.String page,
                                int version)
Returns the unconverted text of the given version of a page, if it exists. This method also replaces the HTML entities.

Parameters:
page - WikiName of the page to fetch
version - Version of the page to fetch

getPureText

public java.lang.String getPureText(java.lang.String page,
                                    int version)
Returns the pure text of a page, no conversions.

Parameters:
version - If WikiPageProvider.LATEST_VERSION, then uses the latest version.

getText

public java.lang.String getText(WikiContext context,
                                WikiPage page)
Returns plain text (with HTML entities replaced). This should be the main entry point for getText().

Since:
1.9.15.

getHTML

public java.lang.String getHTML(WikiContext context,
                                WikiPage page)
Returns the converted HTML of the page using a different context than the default context.


getHTML

public java.lang.String getHTML(java.lang.String page)
Returns the converted HTML of the page.

Parameters:
page - WikiName of the page to convert.

getHTML

public java.lang.String getHTML(java.lang.String pagename,
                                int version)
Returns the converted HTML of the page's specific version. The version must be a positive integer, otherwise the current version is returned.

Parameters:
pagename - WikiName of the page to convert.
version - Version number to fetch

textToHTML

public java.lang.String textToHTML(WikiContext context,
                                   java.lang.String pagedata)
Converts raw page data to HTML.

Parameters:
pagedata - Raw page data to convert to HTML

scanWikiLinks

protected java.util.Collection scanWikiLinks(java.lang.String pagedata)
Reads a WikiPageful of data from a String and returns all links internal to this Wiki in a Collection.


textToHTML

public java.lang.String textToHTML(WikiContext context,
                                   java.lang.String pagedata,
                                   StringTransmutator localLinkHook,
                                   StringTransmutator extLinkHook)
Just convert WikiText to HTML.


updateReferences

public void updateReferences(java.lang.String pageName)
Updates all references for the given page.


saveText

public void saveText(java.lang.String page,
                     java.lang.String text)
Writes the WikiText of a page into the page repository.

Parameters:
page - Page name
text - The Wiki markup for the page.

getUserName

public java.lang.String getUserName(javax.servlet.http.HttpServletRequest request)
Retrieves the user name. It will check if user has been authenticated, or he has a cookie with his username set. The cookie takes precedence, which allows the wiki master to set up a site with a single master password. Note that this behaviour will be changed in 2.1 or thereabouts. Earlier versions than 1.9.42 preferred the authenticated name over the cookie name.

Parameters:
request - HttpServletRequest that was called.
Returns:
The WikiName of the user, or null, if no username was set.

getValidUserName

public java.lang.String getValidUserName(javax.servlet.http.HttpServletRequest request)
If no author name has been set, then use the IP address, if allowed. If no IP address is allowed, then returns a default.

Returns:
Returns any sort of user name. Never returns null.

saveText

public void saveText(java.lang.String page,
                     java.lang.String text,
                     javax.servlet.http.HttpServletRequest request)
Parameters:
request - The HTTP Servlet request associated with this transaction.
Since:
1.5.1

getPageCount

public int getPageCount()
Returns the number of pages in this Wiki


getCurrentProvider

public java.lang.String getCurrentProvider()
Returns the provider name


getCurrentProviderInfo

public java.lang.String getCurrentProviderInfo()
return information about current provider.

Since:
1.6.4

getRecentChanges

public java.util.Collection getRecentChanges()
Returns a Collection of WikiPages, sorted in time order of last change.


findPages

public java.util.Collection findPages(java.lang.String query)
Parses an incoming search request, then does a search.

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.


getPage

public WikiPage getPage(java.lang.String pagereq)
Return a bunch of information from the web page.


getPage

public WikiPage getPage(java.lang.String pagereq,
                        int version)
Returns specific information about a Wiki page.

Since:
1.6.7.

getVersionHistory

public java.util.List getVersionHistory(java.lang.String page)
Returns a Collection of WikiPages containing the version history of a page.


getDiff

public java.lang.String getDiff(java.lang.String page,
                                int version1,
                                int version2)
Returns a diff of two versions of a page.

Parameters:
page - Page to return
version1 - Version number of the old page. If WikiPageProvider.LATEST_VERSION (-1), then uses current page.
version2 - Version number of the new page. If WikiPageProvider.LATEST_VERSION (-1), then uses current page.
Returns:
A HTML-ized difference between two pages. If there is no difference, returns an empty string.

findWikiClass

public static java.lang.Class findWikiClass(java.lang.String className,
                                            java.lang.String defaultPackage)
                                     throws java.lang.ClassNotFoundException
Attempts to locate a Wiki class, defaulting to the defaultPackage in case the actual class could not be located.

Parameters:
className - Class to search for.
defaultPackage - A default package to try if the class cannot be directly located. May be null.
Throws:
java.lang.ClassNotFoundException - if the class could not be located.

getReferenceManager

public ReferenceManager getReferenceManager()
Returns this object's ReferenceManager.

Since:
1.6.1

getPluginManager

public PluginManager getPluginManager()
Returns the current plugin manager.

Since:
1.6.1

getVariableManager

public VariableManager getVariableManager()

getPageManager

public PageManager getPageManager()
Returns the current PageManager.


getAttachmentManager

public AttachmentManager getAttachmentManager()
Returns the current AttachmentManager.

Since:
1.9.31.

getGlobalRSSURL

public java.lang.String getGlobalRSSURL()
Returns the URL of the global RSS file. May be null, if the RSS file generation is not operational.

Since:
1.7.10