Class WikiEngine

  • All Implemented Interfaces:
    Engine

    public class WikiEngine
    extends java.lang.Object
    implements Engine
    Main implementation for Engine.

    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.

    • Field Detail

      • managers

        protected final java.util.Map<java.lang.Class<?>,​java.lang.Object> managers
        Stores WikiEngine's associated managers.
    • 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.
        Parameters:
        properties - A set of properties to use to initialize this WikiEngine.
        Throws:
        WikiException - If the initialization fails.
      • WikiEngine

        protected WikiEngine​(javax.servlet.ServletContext context,
                             java.lang.String appid,
                             java.util.Properties props)
                      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.
        Parameters:
        context - A ServletContext.
        appid - An Application ID. This application is a unique random string which is used to recognize this WikiEngine.
        props - The WikiEngine configuration.
        Throws:
        WikiException - If the WikiEngine construction fails.
    • 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.
        Parameters:
        config - The ServletConfig object for this servlet.
        Returns:
        A WikiEngine instance.
        Throws:
        InternalWikiException - in case something fails. This is a RuntimeException, so be prepared for it.
      • getInstance

        public static WikiEngine getInstance​(javax.servlet.ServletConfig config,
                                             java.util.Properties props)
        Gets a WikiEngine related to the servlet. Works like getInstance(ServletConfig), but does not force the Properties object. This method is just an optional way of initializing a WikiEngine for embedded JSPWiki applications; normally, you should use getInstance(ServletConfig).
        Parameters:
        config - The ServletConfig of the webapp servlet/JSP calling this method.
        props - A set of properties, or null, if we are to load JSPWiki's default jspwiki.properties (this is the usual case).
        Returns:
        One well-behaving WikiEngine instance.
      • getInstance

        public static WikiEngine getInstance​(javax.servlet.ServletContext context,
                                             java.util.Properties props)
                                      throws InternalWikiException
        Gets a WikiEngine related to the servlet. Works just like getInstance( ServletConfig )
        Parameters:
        context - The ServletContext of the webapp servlet/JSP calling this method.
        props - A set of properties, or null, if we are to load JSPWiki's default jspwiki.properties (this is the usual case).
        Returns:
        One fully functional, properly behaving WikiEngine.
        Throws:
        InternalWikiException - If the WikiEngine instantiation fails.
      • getManager

        public <T> T getManager​(java.lang.Class<T> manager)
        Retrieves the object instantiated by the Engine matching the requested type.
        Specified by:
        getManager in interface Engine
        Type Parameters:
        T - type of the requested object.
        Parameters:
        manager - requested object instantiated by the Engine.
        Returns:
        requested object instantiated by the Engine, null if not available.
      • getManagers

        public <T> java.util.List<T> getManagers​(java.lang.Class<T> manager)
        Retrieves the objects instantiated by the Engine that can be assigned to the requested type.
        Specified by:
        getManagers in interface Engine
        Type Parameters:
        T - type of the requested object.
        Parameters:
        manager - requested objectx instantiated by the Engine.
        Returns:
        collection of requested objects instantiated by the Engine, empty list if none available.
      • isConfigured

        public boolean isConfigured()
        check if the Engine has been configured.
        Specified by:
        isConfigured in interface Engine
        Returns:
        true if it has, false otherwise.
      • initReferenceManager

        public void initReferenceManager()
                                  throws WikiException
        Initializes the reference manager. Scans all existing WikiPages for internal links and adds them to the ReferenceManager object.
        Throws:
        WikiException - If the reference manager initialization fails.
      • getWikiProperties

        public java.util.Properties getWikiProperties()
        Returns the set of properties that the Engine was initialized with. Note that this method returns a direct reference, so it's possible to manipulate the properties. However, this is not advised unless you really know what you're doing.
        Specified by:
        getWikiProperties in interface Engine
        Returns:
        The wiki properties
      • getWorkDir

        public java.lang.String getWorkDir()
        Returns the JSPWiki working directory set with "jspwiki.workDir".
        Specified by:
        getWorkDir in interface Engine
        Returns:
        The working directory.
      • getTemplateDir

        public java.lang.String getTemplateDir()
        Returns the current template directory.
        Specified by:
        getTemplateDir in interface Engine
        Returns:
        The template directory as initialized by the engine.
      • getStartTime

        public java.util.Date getStartTime()
        Returns the moment when this engine was started.
        Specified by:
        getStartTime in interface Engine
        Returns:
        The start time of this wiki.
      • getBaseURL

        public java.lang.String getBaseURL()
        Returns the base URL, telling where this Wiki actually lives.
        Specified by:
        getBaseURL in interface Engine
        Returns:
        The Base URL.
      • 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.
        Specified by:
        getGlobalRSSURL in interface Engine
        Returns:
        The global RSS url
      • getInterWikiURL

        public java.lang.String getInterWikiURL​(java.lang.String wikiName)
        Returns an URL to some other Wiki that we know.
        Specified by:
        getInterWikiURL in interface Engine
        Parameters:
        wikiName - The name of the other wiki.
        Returns:
        null, if no such reference was found.
      • getURL

        public java.lang.String getURL​(java.lang.String context,
                                       java.lang.String pageName,
                                       java.lang.String params)
        Returns an URL if a WikiContext is not available.
        Specified by:
        getURL in interface Engine
        Parameters:
        context - The WikiContext (VIEW, EDIT, etc...)
        pageName - Name of the page, as usual
        params - List of parameters. May be null, if no parameters.
        Returns:
        An URL (absolute or relative).
      • getFrontPage

        public java.lang.String getFrontPage()
        Returns the default front page, if no page is used.
        Specified by:
        getFrontPage in interface Engine
        Returns:
        The front page name.
      • getServletContext

        public javax.servlet.ServletContext getServletContext()
        Returns the ServletContext that this particular Engine was initialized with. It may return null, if the Engine is not running inside a servlet container!
        Specified by:
        getServletContext in interface Engine
        Returns:
        ServletContext of the Engine, or null.
      • getAllInterWikiLinks

        public java.util.Collection<java.lang.String> getAllInterWikiLinks()
        Returns a collection of all supported InterWiki links.
        Specified by:
        getAllInterWikiLinks in interface Engine
        Returns:
        A Collection of Strings.
      • 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. This method delegates requests to CommandResolver.getSpecialPageReference(String).

        Special pages are defined in jspwiki.properties using the jspwiki.specialPage setting. They're typically used to give Wiki page names to e.g. custom JSP pages.

        Specified by:
        getSpecialPageReference in interface Engine
        Parameters:
        original - The page to check
        Returns:
        A reference to the page, or null, if there's no special page.
      • getApplicationName

        public java.lang.String getApplicationName()
        Returns the name of the application.
        Specified by:
        getApplicationName in interface Engine
        Returns:
        A string describing the name of this application.
      • encodeName

        public java.lang.String encodeName​(java.lang.String pagename)
        Turns a WikiName into something that can be called through using an URL.
        Specified by:
        encodeName in interface Engine
        Parameters:
        pagename - A name. Can be actually any string.
        Returns:
        A properly encoded name.
        See Also:
        Engine.decodeName(String)
      • decodeName

        public java.lang.String decodeName​(java.lang.String pagerequest)
        Decodes a URL-encoded request back to regular life. This properly heeds the encoding as defined in the settings file.
        Specified by:
        decodeName in interface Engine
        Parameters:
        pagerequest - The URL-encoded string to decode
        Returns:
        A decoded string.
        See Also:
        Engine.encodeName(String)
      • getContentEncoding

        public java.nio.charset.Charset getContentEncoding()
        Returns the IANA name of the character set encoding we're supposed to be using right now.
        Specified by:
        getContentEncoding in interface Engine
        Returns:
        The content encoding (either UTF-8 or ISO-8859-1).
      • shutdown

        public void shutdown()
        Signals that the Engine will be shut down by the servlet container.

        It is called by WikiServlet.destroy(). When this method is called, it fires a "shutdown" WikiEngineEvent to all registered listeners.

        Specified by:
        shutdown in interface Engine
      • getTemplateManager

        @Deprecated
        public TemplateManager getTemplateManager()
        Deprecated.
        use getManager( TemplateManager.class ) instead.
        Returns the current TemplateManager.
        Returns:
        A TemplateManager instance.
      • getWorkflowManager

        @Deprecated
        public WorkflowManager getWorkflowManager()
        Deprecated.
        use getManager( WorkflowManager.class ) instead.
        Returns the WorkflowManager associated with this WikiEngine. If the WikiEngine has not been initialized, this method will return null.
        Returns:
        the task queue
      • getReferenceManager

        @Deprecated
        public ReferenceManager getReferenceManager()
        Deprecated.
        use getManager( ReferenceManager.class ) instead.
        Returns this object's ReferenceManager.
        Returns:
        The current ReferenceManager instance.
        Since:
        1.6.1
      • getRenderingManager

        @Deprecated
        public RenderingManager getRenderingManager()
        Deprecated.
        use getManager( RenderingManager.class ) instead.
        Returns the current rendering manager for this wiki application.
        Returns:
        A RenderingManager object.
        Since:
        2.3.27
      • getPluginManager

        @Deprecated
        public PluginManager getPluginManager()
        Deprecated.
        use getManager( PluginManager.class ) instead.
        Returns the current plugin manager.
        Returns:
        The current PluginManager instance
        Since:
        1.6.1
      • getVariableManager

        @Deprecated
        public VariableManager getVariableManager()
        Deprecated.
        use getManager( VariableManager.class ) instead.
        Returns the current variable manager.
        Returns:
        The current VariableManager.
      • getPageManager

        @Deprecated
        public PageManager getPageManager()
        Deprecated.
        use getManager( PageManager.class ) instead.
        Returns the current PageManager which is responsible for storing and managing WikiPages.
        Returns:
        The current PageManager instance.
      • getCommandResolver

        @Deprecated
        public CommandResolver getCommandResolver()
        Deprecated.
        use getManager( CommandResolver.class ) instead.
        Returns the CommandResolver for this wiki engine.
        Returns:
        the resolver
      • getAttachmentManager

        @Deprecated
        public AttachmentManager getAttachmentManager()
        Deprecated.
        use getManager( AttachmentManager.class ) instead.
        Returns the current AttachmentManager, which is responsible for storing and managing attachments.
        Returns:
        The current AttachmentManager instance
        Since:
        1.9.31.
      • getAuthorizationManager

        @Deprecated
        public AuthorizationManager getAuthorizationManager()
        Deprecated.
        use getManager( AuthorizationManager.class ) instead.
        Returns the currently used authorization manager.
        Returns:
        The current AuthorizationManager instance.
      • getAuthenticationManager

        @Deprecated
        public AuthenticationManager getAuthenticationManager()
        Deprecated.
        use getManager( AuthenticationManager.class ) instead.
        Returns the currently used authentication manager.
        Returns:
        The current AuthenticationManager instance.
      • getFilterManager

        @Deprecated
        public FilterManager getFilterManager()
        Deprecated.
        use getManager( FilterManager.class ) instead.
        Returns the manager responsible for the filters.
        Returns:
        The current FilterManager instance.
        Since:
        2.1.88
      • getSearchManager

        @Deprecated
        public SearchManager getSearchManager()
        Deprecated.
        use getManager( SearchManager.class ) instead.
        Returns the manager responsible for searching the Wiki.
        Returns:
        The current SearchManager instance.
        Since:
        2.2.21
      • getProgressManager

        @Deprecated
        public ProgressManager getProgressManager()
        Deprecated.
        use getManager( ProgressManager.class ) instead.
        Returns the progress manager we're using
        Returns:
        A ProgressManager.
        Since:
        2.6
      • getRootPath

        public java.lang.String getRootPath()
        Returns the root path. The root path is where the Engine is located in the file system.
        Specified by:
        getRootPath in interface Engine
        Returns:
        A path to where the Wiki is installed in the local filesystem.
      • getURLConstructor

        @Deprecated
        public URLConstructor getURLConstructor()
        Deprecated.
        use getManager( URLConstructor.class ) instead.
        Returns:
        the URL constructor.
        Since:
        2.2.6
      • getRSSGenerator

        @Deprecated
        public RSSGenerator getRSSGenerator()
        Deprecated.
        use getManager( RSSGenerator.class ) instead.
        Returns the RSSGenerator. If the property jspwiki.rss.generate has not been set to true, this method will return null, and callers should check for this value.
        Returns:
        the RSS generator
        Since:
        2.1.165
      • getPageRenamer

        @Deprecated
        public PageRenamer getPageRenamer()
        Deprecated.
        use getManager( PageRenamer.class ) instead.
        Returns the PageRenamer employed by this WikiEngine.
        Returns:
        The current PageRenamer instance.
        Since:
        2.5.141
      • getUserManager

        @Deprecated
        public UserManager getUserManager()
        Deprecated.
        use getManager( UserManager.class ) instead.
        Returns the UserManager employed by this WikiEngine.
        Returns:
        The current UserManager instance.
        Since:
        2.3
      • getTasksManager

        @Deprecated
        public TasksManager getTasksManager()
        Deprecated.
        use getManager( TaskManager.class ) instead.
        Returns the TasksManager employed by this WikiEngine.
        Returns:
        The current TasksManager instance.
      • getGroupManager

        @Deprecated
        public GroupManager getGroupManager()
        Deprecated.
        use getManager( GroupManager.class ) instead.
        Returns the GroupManager employed by this WikiEngine.
        Returns:
        The current GroupManager instance.
        Since:
        2.3
      • getAclManager

        @Deprecated
        public AclManager getAclManager()
        Deprecated.
        use getManager( AclManager.class ) instead.
        Returns the AclManager employed by this WikiEngine. The AclManager is lazily initialized.

        The AclManager implementing class may be set by the System property Engine.PROP_ACL_MANAGER_IMPL.

        Returns:
        The current AclManager.
        Since:
        2.3
      • getDifferenceManager

        @Deprecated
        public DifferenceManager getDifferenceManager()
        Deprecated.
        use getManager( DifferenceManager.class ) instead.
        Returns the DifferenceManager so that texts can be compared.
        Returns:
        the difference manager.
      • getEditorManager

        @Deprecated
        public EditorManager getEditorManager()
        Deprecated.
        use getManager( EditorManager.class ) instead.
        Returns the current EditorManager instance.
        Returns:
        The current EditorManager.
      • getInternationalizationManager

        @Deprecated
        public InternationalizationManager getInternationalizationManager()
        Deprecated.
        use getManager( InternationalizationManager.class ) instead.
        Returns the current i18n manager.
        Returns:
        The current Intertan... Interante... Internatatializ... Whatever.
      • fireEvent

        protected final void fireEvent​(int type)
        Fires a WikiEngineEvent to all registered listeners.
        Parameters:
        type - the event type
      • firePageEvent

        protected final void firePageEvent​(int type,
                                           java.lang.String pageName)
        Fires a WikiPageEvent to all registered listeners.
        Parameters:
        type - the event type
      • setAttribute

        public void setAttribute​(java.lang.String key,
                                 java.lang.Object value)
        Adds an attribute to the engine for the duration of this engine. The value is not persisted.
        Specified by:
        setAttribute in interface Engine
        Parameters:
        key - the attribute name
        value - the value
      • getAttribute

        public <T> T getAttribute​(java.lang.String key)
        Gets an attribute from the engine.
        Specified by:
        getAttribute in interface Engine
        Parameters:
        key - the attribute name
        Returns:
        the value
      • removeAttribute

        public <T> T removeAttribute​(java.lang.String key)
        Removes an attribute.
        Specified by:
        removeAttribute in interface Engine
        Parameters:
        key - The key of the attribute to remove.
        Returns:
        The previous attribute, if it existed.