|
jforum example source code file (Rename.jsp)
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 |
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.