You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ja...@apache.org on 2009/11/24 01:05:33 UTC

svn commit: r883556 - in /incubator/jspwiki/trunk: ChangeLog src/java/org/apache/wiki/Release.java src/java/org/apache/wiki/util/Import.java src/scripts/ src/scripts/import.sh

Author: jalkanen
Date: Tue Nov 24 00:05:32 2009
New Revision: 883556

URL: http://svn.apache.org/viewvc?rev=883556&view=rev
Log:
First iteration of import routines.

Added:
    incubator/jspwiki/trunk/src/java/org/apache/wiki/util/Import.java
    incubator/jspwiki/trunk/src/scripts/
    incubator/jspwiki/trunk/src/scripts/import.sh
Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=883556&r1=883555&r2=883556&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Tue Nov 24 00:05:32 2009
@@ -1,3 +1,13 @@
+2009-10-26 Janne Jalkanen <ja...@apache.org>
+
+        * 3.0.0-svn-181
+        
+        * Added first iteration of import code, which works with 2.8.4-svn-3. Known
+        problems: Attachments are not yet imported. Existence of ACLs breaks code.
+        
+        * WikiPath is now case-insensitive in equals() to support proper wikipage
+        case-insensitiveness.
+
 2009-11-21 Harry Metske <me...@apache.org>
 
         * 3.0.0-svn-180

Modified: incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java?rev=883556&r1=883555&r2=883556&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/Release.java Tue Nov 24 00:05:32 2009
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "180";
+    public static final String     BUILD         = "181";
 
     /**
      *  This is the generic version string you should use

Added: incubator/jspwiki/trunk/src/java/org/apache/wiki/util/Import.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/java/org/apache/wiki/util/Import.java?rev=883556&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/java/org/apache/wiki/util/Import.java (added)
+++ incubator/jspwiki/trunk/src/java/org/apache/wiki/util/Import.java Tue Nov 24 00:05:32 2009
@@ -0,0 +1,172 @@
+/* 
+    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 org.apache.wiki.util;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.jcr.LoginException;
+import javax.jcr.RepositoryException;
+
+import net.sourceforge.stripes.mock.MockServletContext;
+
+import org.apache.wiki.WikiEngine;
+import org.apache.wiki.api.WikiException;
+import org.apache.wiki.content.ContentManager;
+import org.apache.wiki.content.PageAlreadyExistsException;
+
+/**
+ *  Imports an XML file from the Export routines.
+ */
+// FIXME: Needs to be localized.
+public final class Import
+{
+    /**
+     *  Private constructor to prevent instantiation.
+     */
+    private Import()
+    {}
+    
+    private static void usage()
+    {
+        System.out.println("Usage: java "+Import.class.getName()+" -p <propertyfile> <xmlfile>");
+        System.exit( 1 );
+    }
+    
+    /**
+     *  Finds a parameter from given string array. Known formats:
+     *  [-<param> parameter] and [-<param>parameter].
+     *  
+     *  @param params
+     *  @param option Option switch string (e.g. "-p"). If null, finds a optionless parameter.
+     *  @return Parameter string, if it exists. Empty string, if there was the switch but no param. null, if there was no switch.
+     */
+    private static String getArg(String[] params, String option)
+    {
+        for( int i = 0; i < params.length; i++ )
+        {
+            if( option == null )
+            {
+                // Skip next.
+                if( params[i].startsWith("-") )
+                {
+                    ++i;
+                }
+                else
+                {
+                    return params[i];
+                }
+            }
+            else if( params[i].equals(option) )
+            {
+                if( i < params.length-1 )
+                {
+                    return params[i+1];
+                }
+                else if( params[i+1].startsWith("-") )
+                {
+                    return "";
+                }
+                else
+                {
+                    return "";
+                }
+            }
+            else if( params[i].startsWith(option) )
+            {
+                String opt = params[i].substring( option.length() );
+                
+                return opt;
+            }
+        }
+        
+        return null;
+    }
+    
+    /**
+     *  Main entry point.
+     *  
+     * @param argv
+     * @throws FileNotFoundException
+     * @throws IOException
+     * @throws WikiException
+     * @throws LoginException
+     * @throws RepositoryException
+     * @throws InterruptedException
+     * @throws PageAlreadyExistsException
+     */
+    // FIXME: Exception handling is vague at best.
+    public static void main(String[] argv) throws FileNotFoundException, IOException, WikiException, LoginException, RepositoryException, InterruptedException, PageAlreadyExistsException
+    {
+        if( argv.length < 2 )
+            usage();
+
+        String propfile = getArg(argv,"-p");
+        if( propfile == null ) usage();
+
+        System.out.println("Using propertyfile '"+propfile+"' to configure JSPWiki");
+
+        String xmlfile = getArg(argv,null);
+        if( xmlfile == null ) usage();
+        
+        System.out.println("Reading contents of repository from '"+xmlfile+"'");
+        
+        Properties props = new CommentedProperties();
+        try
+        {
+            props.load( new FileInputStream(propfile) );
+        }
+        catch( IOException e) 
+        {
+            System.err.println("Could not open property file "+e.getMessage());
+            System.exit(5);
+        }
+        
+        WikiEngine engine = null;
+        try
+        {
+            engine = WikiEngine.getInstance( new MockServletContext("JSPWiki"), props );
+        }
+        catch( Exception e )
+        {
+            System.err.println("Error starting JSPWiki: "+e.getMessage());
+            e.printStackTrace( System.err );
+            System.exit(5);
+        }
+
+        Thread.sleep(10); // Workaround for JSPWIKI-610 for now.
+        
+        try
+        {
+            ContentManager mgr = engine.getContentManager();
+    
+            mgr.importXML( xmlfile );
+        }
+        finally
+        {
+            engine.shutdown();
+        }
+        
+        System.out.println("Importing completed.");
+    }
+}

Added: incubator/jspwiki/trunk/src/scripts/import.sh
URL: http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/scripts/import.sh?rev=883556&view=auto
==============================================================================
--- incubator/jspwiki/trunk/src/scripts/import.sh (added)
+++ incubator/jspwiki/trunk/src/scripts/import.sh Tue Nov 24 00:05:32 2009
@@ -0,0 +1,61 @@
+#!/bin/sh
+#
+#
+#    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.  
+#
+####################################################################################
+#
+#  This script imports a JSPWiki repository exported with the export.sh command
+#  into the given WikiSpace.
+#
+#  Currently tested only on OSX, but should run well on Linux/BSD/Solaris. Windows
+#  counterpart needed!
+#
+
+# FIXME: This should use some sort of an algorithm to figure out the home
+JSPWIKI_HOME=${PWD}
+
+# First one is for a source installation, the latter is for binary installation
+# One of these should work, but not both.
+LIBSRC=${JSPWIKI_HOME}/src/WebContent/
+LIBBIN=${JSPWIKI_HOME}/
+LIBCMP=${JSPWIKI_HOME}/build/classes/
+CLASSESSRC=${JSPWIKI_HOME}/src/WebContent/WEB-INF/classes/
+ETC=${JSPWIKI_HOME}/etc
+
+CLASSPATH="${LIBCMP}:${LIBSRC}:${LIBBIN}:${LIBSRC}/WEB-INF/classes:${ETC}"
+
+for i in ${LIBSRC}/WEB-INF/lib/*.jar
+do
+	CLASSPATH=${CLASSPATH}:$i
+done
+
+for i in ${LIBBIN}/WEB-INF/lib/*.jar
+do
+	CLASSPATH=${CLASSPATH}:$i
+done
+
+#echo $CLASSPATH
+
+#
+#  OK, now run JSPWiki.
+#
+java -classpath ${CLASSPATH} org.apache.wiki.util.Import $@
+