    001/*
    002    Licensed to the Apache Software Foundation (ASF) under one
    003    or more contributor license agreements.  See the NOTICE file
    004    distributed with this work for additional information
    005    regarding copyright ownership.  The ASF licenses this file
    006    to you under the Apache License, Version 2.0 (the
    007    "License"); you may not use this file except in compliance
    008    with the License.  You may obtain a copy of the License at
    009
    010       http://www.apache.org/licenses/LICENSE-2.0
    011
    012    Unless required by applicable law or agreed to in writing,
    013    software distributed under the License is distributed on an
    014    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    015    KIND, either express or implied.  See the License for the
    016    specific language governing permissions and limitations
    017    under the License.
    018 */
    019
    020package org.apache.wiki.event;
    021
    022/**
    023 *  WikiPageRenameEvent extends WikiPageEvent to indicate a change in the name of a WikiPage.
    024 *  <p>
    025 *  This reuses {@link #getPageName()} to return the new name of the page, with {@link #getOldPageName()} returning the old name.
    026 *
    027 * @see     org.apache.wiki.event.WikiPageEvent
    028 * @since   2.5.108
    029 */
    030public class WikiPageRenameEvent extends WikiPageEvent {
    031
    032    private static final long serialVersionUID = 1L;
    033
    034    /** Indicates a page rename event. This is based on events generated by {@link org.apache.wiki.content.PageRenamer}. */
    035    public static final int PAGE_RENAMED         = 28;
    036
    037    private final String m_oldpagename;
    038
    039    // ............
    040
    041    /**
    042     *  Constructs an instance of this event.
    043     *
    044     * @param src    the Object that is the source of the event.
    045     * @param oldname   the old name of the WikiPage being acted upon.
    046     * @param newname   the new name of the WikiPage being acted upon.
    047     */
    048    public WikiPageRenameEvent( final Object src, final String oldname, final String newname ) {
    049        super( src, PAGE_RENAMED, newname );
    050        m_oldpagename = oldname;
    051    }
    052
    053    /**
    054     * Returns the old Wiki page name associated with this event. This may be null if unavailable.
    055     *
    056     * @return     the old Wiki page name associated with this WikiEvent, or null.
    057     */
    058    public String getOldPageName() {
    059        return m_oldpagename;
    060    }
    061
    062    /**
    063     * Returns the new Wiki page name associated with this event. This returns the same value as the superclass' {@link #getPageName()}.
    064     * This may be null if unavailable.
    065     *
    066     * @return     the new Wiki page name associated with this WikiEvent, or null.
    067     */
    068    public String getNewPageName() {
    069        return super.getPageName();
    070    }
    071
    072    /**
    073     * Returns true if the int value is a WikiPageRenameEvent type.
    074     */
    075    public static boolean isValidType( final int type ) {
    076        return type == PAGE_RENAMED;
    077    }
    078
    079    /**
    080     * Returns a textual representation of the event type.
    081     *
    082     * @return a String representation of the type
    083     */
    084    @Override
    085    public String eventName() {
    086        return "PAGE_RENAMED";
    087    //  switch ( getType() )
    088    //  {
    089    //      case PAGE_RENAMED:         return "PAGE_RENAMED";
    090    //      default:                   return super.eventName();
    091    //  }
    092    }
    093
    094
    095    /** Returns a human-readable description of the event type.
    096     * @return a String description of the type
    097     */
    098    @Override
    099    public String getTypeDescription() {
    100        return "page renamed event";
    101    //  switch ( getType() )
    102    //  {
    103    //      case PAGE_RENAMED:         return "page renamed event";
    104    //      default:                   return super.getTypeDescription();
    105    //  }
    106    }
    107
    108}