⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagemanager.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*    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 com.ecyrd.jspwiki;import java.io.IOException;import java.security.Permission;import java.security.Principal;import java.util.*;import org.apache.commons.lang.ArrayUtils;import org.apache.log4j.Logger;import com.ecyrd.jspwiki.auth.WikiPrincipal;import com.ecyrd.jspwiki.auth.WikiSecurityException;import com.ecyrd.jspwiki.auth.acl.Acl;import com.ecyrd.jspwiki.auth.acl.AclEntry;import com.ecyrd.jspwiki.auth.acl.AclEntryImpl;import com.ecyrd.jspwiki.auth.user.UserProfile;import com.ecyrd.jspwiki.event.*;import com.ecyrd.jspwiki.filters.FilterException;import com.ecyrd.jspwiki.modules.ModuleManager;import com.ecyrd.jspwiki.providers.CachingProvider;import com.ecyrd.jspwiki.providers.ProviderException;import com.ecyrd.jspwiki.providers.RepositoryModifiedException;import com.ecyrd.jspwiki.providers.WikiPageProvider;import com.ecyrd.jspwiki.util.ClassUtil;import com.ecyrd.jspwiki.util.WikiBackgroundThread;import com.ecyrd.jspwiki.workflow.Outcome;import com.ecyrd.jspwiki.workflow.Task;import com.ecyrd.jspwiki.workflow.Workflow;/** *  Manages the WikiPages.  This class functions as an unified interface towards *  the page providers.  It handles initialization and management of the providers, *  and provides utility methods for accessing the contents. *  <p> *  Saving a page is a two-stage Task; first the pre-save operations and then the *  actual save.  See the descriptions of the tasks for further information. * *  @since 2.0 */// FIXME: This class currently only functions just as an extra layer over providers,//        complicating things.  We need to move more provider-specific functionality//        from WikiEngine (which is too big now) into this class.public class PageManager extends ModuleManager implements WikiEventListener{    private static final long serialVersionUID = 1L;    /** The property value for setting the current page provider.  Value is {@value}. */    public static final String PROP_PAGEPROVIDER = "jspwiki.pageProvider";        /** The property value for setting the cache on/off.  Value is {@value}. */    public static final String PROP_USECACHE     = "jspwiki.usePageCache";        /** The property value for setting the amount of time before the page locks expire.      *  Value is {@value}.     */    public static final String PROP_LOCKEXPIRY   = "jspwiki.lockExpiryTime";        /** The message key for storing the text for the presave task.  Value is <tt>{@value}</tt>*/    public static final String PRESAVE_TASK_MESSAGE_KEY = "task.preSaveWikiPage";        /** The workflow attribute which stores the wikiContext. */    public static final String PRESAVE_WIKI_CONTEXT = "wikiContext";        /** The name of the key from jspwiki.properties which defines who shall approve     *  the workflow of storing a wikipage.  Value is <tt>{@value}</tt>*/    public static final String SAVE_APPROVER             = "workflow.saveWikiPage";        /** The message key for storing the Decision text for saving a page.  Value is {@value}. */    public static final String SAVE_DECISION_MESSAGE_KEY = "decision.saveWikiPage";        /** The message key for rejecting the decision to save the page.  Value is {@value}. */    public static final String SAVE_REJECT_MESSAGE_KEY   = "notification.saveWikiPage.reject";        /** The message key of the text to finally approve a page save.  Value is {@value}. */    public static final String SAVE_TASK_MESSAGE_KEY     = "task.saveWikiPage";        /** Fact name for storing the page name.  Value is {@value}. */    public static final String FACT_PAGE_NAME = "fact.pageName";        /** Fact name for storing a diff text. Value is {@value}. */    public static final String FACT_DIFF_TEXT = "fact.diffText";        /** Fact name for storing the current text.  Value is {@value}. */    public static final String FACT_CURRENT_TEXT = "fact.currentText";        /** Fact name for storing the proposed (edited) text.  Value is {@value}. */    public static final String FACT_PROPOSED_TEXT = "fact.proposedText";        /** Fact name for storing whether the user is authenticated or not.  Value is {@value}. */    public static final String FACT_IS_AUTHENTICATED = "fact.isAuthenticated";    static Logger log = Logger.getLogger( PageManager.class );    private WikiPageProvider m_provider;    protected HashMap<String,PageLock> m_pageLocks = new HashMap<String,PageLock>();    private WikiEngine m_engine;    private int m_expiryTime = 60;    private LockReaper m_reaper = null;    /**     *  Creates a new PageManager.     *       *  @param engine WikiEngine instance     *  @param props Properties to use for initialization     *  @throws WikiException If anything goes wrong, you get this.     */    public PageManager( WikiEngine engine, Properties props )        throws WikiException    {        super( engine );        String classname;        m_engine = engine;        boolean useCache = "true".equals(props.getProperty( PROP_USECACHE ));        m_expiryTime = TextUtil.parseIntParameter( props.getProperty( PROP_LOCKEXPIRY ), 60 );        //        //  If user wants to use a cache, then we'll use the CachingProvider.        //        if( useCache )        {            classname = "com.ecyrd.jspwiki.providers.CachingProvider";        }        else        {            classname = WikiEngine.getRequiredProperty( props, PROP_PAGEPROVIDER );        }        try        {            log.debug("Page provider class: '"+classname+"'");            Class providerclass = ClassUtil.findClass( "com.ecyrd.jspwiki.providers",                                                       classname );            m_provider = (WikiPageProvider)providerclass.newInstance();            log.debug("Initializing page provider class "+m_provider);            m_provider.initialize( m_engine, props );        }        catch( ClassNotFoundException e )        {            log.error("Unable to locate provider class '"+classname+"'",e);            throw new WikiException("no provider class");        }        catch( InstantiationException e )        {            log.error("Unable to create provider class '"+classname+"'",e);            throw new WikiException("faulty provider class");        }        catch( IllegalAccessException e )        {            log.error("Illegal access to provider class '"+classname+"'",e);            throw new WikiException("illegal provider class");        }        catch( NoRequiredPropertyException e )        {            log.error("Provider did not found a property it was looking for: "+e.getMessage(),                      e);            throw e;  // Same exception works.        }        catch( IOException e )        {            log.error("An I/O exception occurred while trying to create a new page provider: "+classname, e );            throw new WikiException("Unable to start page provider: "+e.getMessage());        }    }    /**     *  Returns the page provider currently in use.     *       *  @return A WikiPageProvider instance.     */    public WikiPageProvider getProvider()    {        return m_provider;    }    /**     *  Returns all pages in some random order.  If you need just the page names,      *  please see {@link ReferenceManager#findCreated()}, which is probably a lot     *  faster.  This method may cause repository access.     *       *  @return A Collection of WikiPage objects.     *  @throws ProviderException If the backend has problems.     */    public Collection getAllPages()        throws ProviderException    {        return m_provider.getAllPages();    }    /**     *  Fetches the page text from the repository.  This method also does some sanity checks,     *  like checking for the pageName validity, etc.  Also, if the page repository has been     *  modified externally, it is smart enough to handle such occurrences.     *       *  @param pageName The name of the page to fetch.     *  @param version The version to find     *  @return The page content as a raw string     *  @throws ProviderException If the backend has issues.     */    public String getPageText( String pageName, int version )        throws ProviderException    {        if( pageName == null || pageName.length() == 0 )        {            throw new ProviderException("Illegal page name");        }        String text = null;        try        {            text = m_provider.getPageText( pageName, version );        }        catch( RepositoryModifiedException e )        {            //            //  This only occurs with the latest version.            //            log.info("Repository has been modified externally while fetching page "+pageName );            //            //  Empty the references and yay, it shall be recalculated            //            //WikiPage p = new WikiPage( pageName );            WikiPage p = m_provider.getPageInfo( pageName, version );            m_engine.updateReferences( p );            if( p != null )            {                m_engine.getSearchManager().reindexPage( p );                text = m_provider.getPageText( pageName, version );            }            else            {                //                //  Make sure that it no longer exists in internal data structures either.                //                WikiPage dummy = new WikiPage(m_engine,pageName);                m_engine.getSearchManager().pageRemoved(dummy);                m_engine.getReferenceManager().pageRemoved(dummy);            }        }        return text;    }    /**     *  Returns the WikiEngine to which this PageManager belongs to.     *       *  @return The WikiEngine object.     */    public WikiEngine getEngine()    {        return m_engine;    }    /**     *  Puts the page text into the repository.  Note that this method does NOT update     *  JSPWiki internal data structures, and therefore you should always use WikiEngine.saveText()     *     * @param page Page to save     * @param content Wikimarkup to save     * @throws ProviderException If something goes wrong in the saving phase     */    public void putPageText( WikiPage page, String content )        throws ProviderException    {        if( page == null || page.getName() == null || page.getName().length() == 0 )        {            throw new ProviderException("Illegal page name");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -