Author: jalkanen
Date: Fri May 9 13:39:20 2008
New Revision: 654933
URL: http://svn.apache.org/viewvc?rev=654933&view=rev
Log:
[JSPWIKI-251]: New, Apache-licensed version of PageRenamer. Unfortunately, is
still lacking a lot of features.
Added:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/PageRenamer.java
Removed:
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/PageRenamer.java
Modified:
incubator/jspwiki/trunk/ChangeLog
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/WikiEngine.java
Modified: incubator/jspwiki/trunk/ChangeLog
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=654933&r1=654932&r2=654933&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Fri May 9 13:39:20 2008
@@ -1,3 +1,16 @@
+2008-05-09 Janne Jalkanen <[EMAIL PROTECTED]>
+
+ * 2.7.0-svn-20
+
+ * [JSPWIKI-251]: Removed the old com.ecyrd.jspwiki.PageRenamer
+ and replaced it with com.ecyrd.jspwiki.content.PageRenamer, which
+ is fully Apache-licensed.
+
+ Unfortunately, the new PageRenamer does not support changing
+ referring pages yet, error messages are not localized properly,
+ etc. So this is a considerable functionality downgrade until
+ we can get a better version made. Patches gladly accepted!
+
2008-05-06 Janne Jalkanen <[EMAIL PROTECTED]>
* 2.7.0-svn-19
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=654933&r1=654932&r2=654933&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Fri May 9
13:39:20 2008
@@ -77,7 +77,7 @@
* <p>
* If the build identifier is empty, it is not added.
*/
- public static final String BUILD = "19";
+ public static final String BUILD = "20";
/**
* This is the generic version string you should use
Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/WikiEngine.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/WikiEngine.java?rev=654933&r1=654932&r2=654933&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/WikiEngine.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/WikiEngine.java Fri May 9
13:39:20 2008
@@ -45,6 +45,7 @@
import com.ecyrd.jspwiki.auth.acl.AclManager;
import com.ecyrd.jspwiki.auth.acl.DefaultAclManager;
import com.ecyrd.jspwiki.auth.authorize.GroupManager;
+import com.ecyrd.jspwiki.content.PageRenamer;
import com.ecyrd.jspwiki.diff.DifferenceManager;
import com.ecyrd.jspwiki.event.WikiEngineEvent;
import com.ecyrd.jspwiki.event.WikiEventListener;
@@ -1502,7 +1503,7 @@
* @param pagedata The page contents
* @return a Collection of Strings
*/
- protected Collection scanWikiLinks( WikiPage page, String pagedata )
+ public Collection scanWikiLinks( WikiPage page, String pagedata )
{
LinkCollector localCollector = new LinkCollector();
Added: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/PageRenamer.java
URL:
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/PageRenamer.java?rev=654933&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/PageRenamer.java
(added)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/content/PageRenamer.java Fri
May 9 13:39:20 2008
@@ -0,0 +1,118 @@
+/*
+ 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.content;
+
+import com.ecyrd.jspwiki.*;
+import com.ecyrd.jspwiki.parser.MarkupParser;
+
+/**
+ * Provides page renaming functionality. Note that there used to be
+ * a similarly named class in 2.6, but due to unclear copyright, the
+ * class was completely rewritten from scratch for 2.8.
+ *
+ * @since 2.8
+ */
+public class PageRenamer
+{
+
+ /**
+ * Renames a page.
+ *
+ * @param context The current context.
+ * @param renameFrom The name from which to rename.
+ * @param renameTo The new name.
+ * @param changeReferrers If true, also changes all the referrers.
+ * @return The final new name (in case it had to be modified)
+ * @throws WikiException If the page cannot be renamed.
+ */
+ public String renamePage( WikiContext context,
+ String renameFrom,
+ String renameTo,
+ boolean changeReferrers )
+ throws WikiException
+ {
+ //
+ // Sanity checks first
+ //
+ if( renameFrom == null || renameFrom.length() == 0 )
+ {
+ throw new WikiException( "From name may not be null or empty" );
+ }
+ if( renameTo == null || renameTo.length() == 0 )
+ {
+ throw new WikiException( "To name may not be null or empty" );
+ }
+
+ if( renameTo.equals(renameFrom) )
+ {
+ throw new WikiException( "You cannot rename the page to itself" );
+ }
+
+ //
+ // Clean up the "to" -name so that it does not contain anything
illegal
+ //
+
+ renameTo = MarkupParser.cleanLink( renameTo.trim() );
+
+ //
+ // Preconditions: "from" page must exist, and "to" page must not yet
exist.
+ //
+ WikiEngine engine = context.getEngine();
+ WikiPage fromPage = engine.getPage( renameFrom );
+
+ if( fromPage == null )
+ {
+ throw new WikiException("No such page "+renameFrom);
+ }
+
+ WikiPage toPage = engine.getPage( renameTo );
+
+ if( toPage != null )
+ {
+ throw new WikiException("Page already exists "+renameTo);
+ }
+
+ // FIXME: Temporary
+ if( changeReferrers ) throw new WikiException("Referrer change not yet
supported.");
+
+ //
+ // Do the actual rename by changing from the frompage to the topage
+ //
+
+ engine.getPageManager().getProvider().movePage( renameFrom, renameTo );
+
+
engine.getAttachmentManager().getCurrentProvider().moveAttachmentsForPage(
renameFrom, renameTo );
+
+ toPage = engine.getPage( renameTo );
+
+ if( toPage == null ) throw new InternalWikiException("Rename seems to
have failed for some strange reason - please check logs!");
+
+ engine.getReferenceManager().pageRemoved( fromPage );
+ engine.getReferenceManager().updateReferences( renameTo,
+ engine.scanWikiLinks(
toPage, engine.getPureText( toPage )) );
+
+ //
+ // Done, return the new name.
+ //
+ return renameTo;
+ }
+
+}