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

📄 pagemanager.java

📁 jspwiki source code,jspwiki source code
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }        m_provider.putPageText( page, content );    }    /**     *  Locks page for editing.  Note, however, that the PageManager     *  will in no way prevent you from actually editing this page;     *  the lock is just for information.     *     *  @param page WikiPage to lock     *  @param user Username to use for locking     *  @return null, if page could not be locked.     */    public PageLock lockPage( WikiPage page, String user )    {        PageLock lock = null;        if( m_reaper == null )        {            //            //  Start the lock reaper lazily.  We don't want to start it in            //  the constructor, because starting threads in constructors            //  is a bad idea when it comes to inheritance.  Besides,            //  laziness is a virtue.            //            m_reaper = new LockReaper( m_engine );            m_reaper.start();        }        synchronized( m_pageLocks )        {            fireEvent( WikiPageEvent.PAGE_LOCK, page.getName() ); // prior to or after actual lock?            lock = m_pageLocks.get( page.getName() );            if( lock == null )            {                //                //  Lock is available, so make a lock.                //                Date d = new Date();                lock = new PageLock( page, user, d,                                     new Date( d.getTime() + m_expiryTime*60*1000L ) );                m_pageLocks.put( page.getName(), lock );                log.debug( "Locked page "+page.getName()+" for "+user);            }            else            {                log.debug( "Page "+page.getName()+" already locked by "+lock.getLocker() );                lock = null; // Nothing to return            }        }        return lock;    }    /**     *  Marks a page free to be written again.  If there has not been a lock,     *  will fail quietly.     *     *  @param lock A lock acquired in lockPage().  Safe to be null.     */    public void unlockPage( PageLock lock )    {        if( lock == null ) return;        synchronized( m_pageLocks )        {            m_pageLocks.remove( lock.getPage() );            log.debug( "Unlocked page "+lock.getPage() );        }        fireEvent( WikiPageEvent.PAGE_UNLOCK, lock.getPage() );    }    /**     *  Returns the current lock owner of a page.  If the page is not     *  locked, will return null.     *     *  @param page The page to check the lock for     *  @return Current lock, or null, if there is no lock     */    public PageLock getCurrentLock( WikiPage page )    {        PageLock lock = null;        synchronized( m_pageLocks )        {            lock = m_pageLocks.get( page.getName() );        }        return lock;    }    /**     *  Returns a list of currently applicable locks.  Note that by the time you get the list,     *  the locks may have already expired, so use this only for informational purposes.     *     *  @return List of PageLock objects, detailing the locks.  If no locks exist, returns     *          an empty list.     *  @since 2.0.22.     */    public List getActiveLocks()    {        ArrayList<PageLock> result = new ArrayList<PageLock>();        synchronized( m_pageLocks )        {            for( PageLock lock : m_pageLocks.values() )            {                result.add( lock );            }        }        return result;    }    /**     *  Finds a WikiPage object describing a particular page and version.     *       *  @param pageName  The name of the page     *  @param version   A version number     *  @return          A WikiPage object, or null, if the page does not exist     *  @throws ProviderException If there is something wrong with the page      *                            name or the repository     */    public WikiPage getPageInfo( String pageName, int version )        throws ProviderException    {        if( pageName == null || pageName.length() == 0 )        {            throw new ProviderException("Illegal page name '"+pageName+"'");        }        WikiPage page = null;        try        {            page = m_provider.getPageInfo( pageName, version );        }        catch( RepositoryModifiedException e )        {            //            //  This only occurs with the latest version.            //            log.info("Repository has been modified externally while fetching info for "+pageName );            page = m_provider.getPageInfo( pageName, version );            if( page != null )            {                m_engine.updateReferences( page );            }            else            {                m_engine.getReferenceManager().pageRemoved( new WikiPage(m_engine,pageName) );            }        }        //        //  Should update the metadata.        //        /*        if( page != null && !page.hasMetadata() )        {            WikiContext ctx = new WikiContext(m_engine,page);            m_engine.textToHTML( ctx, getPageText(pageName,version) );        }        */        return page;    }    /**     *  Gets a version history of page.  Each element in the returned     *  List is a WikiPage.     *       *  @param pageName The name of the page to fetch history for     *  @return If the page does not exist, returns null, otherwise a List     *          of WikiPages.     *  @throws ProviderException If the repository fails.     */    public List getVersionHistory( String pageName )        throws ProviderException    {        if( pageExists( pageName ) )        {            return m_provider.getVersionHistory( pageName );        }        return null;    }    /**     *  Returns a human-readable description of the current provider.     *       *  @return A human-readable description.     */    public String getProviderDescription()    {        return m_provider.getProviderInfo();    }    /**     *  Returns the total count of all pages in the repository. This     *  method is equivalent of calling getAllPages().size(), but     *  it swallows the ProviderException and returns -1 instead of     *  any problems.     *       *  @return The number of pages, or -1, if there is an error.     */    public int getTotalPageCount()    {        try        {            return m_provider.getAllPages().size();        }        catch( ProviderException e )        {            log.error( "Unable to count pages: ",e );            return -1;        }    }    /**     *  Returns true, if the page exists (any version).     *       *  @param pageName  Name of the page.     *  @return A boolean value describing the existence of a page     *  @throws ProviderException If the backend fails or the name is illegal.     */    public boolean pageExists( String pageName )        throws ProviderException    {        if( pageName == null || pageName.length() == 0 )        {            throw new ProviderException("Illegal page name");        }        return m_provider.pageExists( pageName );    }    /**     *  Checks for existence of a specific page and version.     *       *  @since 2.3.29     *  @param pageName Name of the page     *  @param version The version to check     *  @return <code>true</code> if the page exists, <code>false</code> otherwise     *  @throws ProviderException If backend fails or name is illegal     */    public boolean pageExists( String pageName, int version )        throws ProviderException    {        if( pageName == null || pageName.length() == 0 )        {            throw new ProviderException("Illegal page name");        }        if( version == WikiProvider.LATEST_VERSION )            return pageExists( pageName );        if( m_provider instanceof CachingProvider )        {            return ((CachingProvider)m_provider).pageExists( pageName , version );        }        return m_provider.getPageInfo( pageName, version ) != null;    }    /**     *  Deletes only a specific version of a WikiPage.     *       *  @param page The page to delete.     *  @throws ProviderException if the page fails     */    public void deleteVersion( WikiPage page )        throws ProviderException    {        m_provider.deleteVersion( page.getName(), page.getVersion() );        // FIXME: If this was the latest, reindex Lucene        // FIXME: Update RefMgr    }    /**     *  Deletes an entire page, all versions, all traces.     *       *  @param page The WikiPage to delete     *  @throws ProviderException If the repository operation fails     */    public void deletePage( WikiPage page )        throws ProviderException    {        fireEvent( WikiPageEvent.PAGE_DELETE_REQUEST, page.getName() );        m_provider.deletePage( page.getName() );        fireEvent( WikiPageEvent.PAGE_DELETED, page.getName() );    }

⌨️ 快捷键说明

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