alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

jforum example source code file (Rename.jsp)

This example jforum source code file (Rename.jsp) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - jforum tags/keywords

an, jspwiki, logger, new, page, page, string, string, unknown, wikicontext, wikiengine, wikiexception, wikiexception, wikisession

The jforum Rename.jsp source code

<%@ page import="org.apache.log4j.*" %>
<%@ page import="com.ecyrd.jspwiki.*" %>
<%@ page errorPage="/Error.jsp" %>
<%@ taglib uri="/WEB-INF/jspwiki.tld" prefix="wiki" %>
<%! 
    public void jspInit()
    {
        wiki = WikiEngine.getInstance( getServletConfig() );
    }

    Logger log = Logger.getLogger("JSPWiki");
    WikiEngine wiki;
%>

<%
    // Create wiki context and check for authorization
	WikiContext wikiContext = wiki.createContext( request, WikiContext.RENAME );
    if(!wikiContext.hasAccess( response )) return;
	
    String renameFrom = wikiContext.getName();
    String renameTo = request.getParameter( "renameto");
    
    boolean changeReferences = false;

    if (request.getParameter("references") != null) 
    {
        changeReferences = true;
    }

    // Set the content type and include the response content
    response.setContentType("text/html; charset="+wiki.getContentEncoding() );
    
    log.info("Page rename request for page '"+renameFrom+ "' to new name '"+renameTo+"' from "+request.getRemoteAddr()+" by "+request.getRemoteUser() );
    
    WikiSession wikiSession = wikiContext.getWikiSession();
    try 
    {
        if (renameTo.length() > 0)
        {
            String renamedTo = wiki.renamePage(wikiContext, renameFrom, renameTo, changeReferences);

            log.info("Page successfully renamed to '"+renamedTo+"'");

            response.sendRedirect( wikiContext.getURL( WikiContext.VIEW, renamedTo ) );
            return;
        }
        else
        {
            wikiSession.addMessage( "New page name empty.<br/>\nClick back on your browser and fill in the new name.");

            log.info("Page rename request failed because new page name was left blank");
        
%>
            <h3>Unable to rename page

            <dl>
               <dt>Reason:
               <dd>
                  <wiki:Messages div="error" />
               </dd>      
            </dl>
<%
        }

    } 
    catch (WikiException e) 
    {
        if (e.getMessage().equals("Page exists")) 
        {
            if (renameTo.equals( renameFrom ))
            {
                log.info("Page rename request failed because page names are identical");
                wikiSession.addMessage( "Page names identical.<br/>\nClick back on your browser and change the new name." );
            }
            else
            {
                log.info("Page rename request failed because new page name is already in use");
                wikiSession.addMessage( "Page \"" + renameTo + "\" already exists.<br/>\nClick back on your browser and change the new name or delete the page \"" + renameTo + "\" first." );
            }
        } 
        else 
        {
            wikiSession.addMessage( "An Unknown error occurred (" + e.toString() + ")" );
        }

%>
       <h3>Unable to rename page

       <dl>
          <dt>Reason:
          <dd>
             <wiki:Messages div="error" />
          </dd>      
       </dl>
<%
    }
%>

Other jforum examples (source code examples)

Here is a short list of links related to this jforum Rename.jsp source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.