jspwiki-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jalka...@apache.org
Subject svn commit: r724543 - in /incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki: WikiPage.java content/ContentManager.java content/WikiName.java providers/ProviderException.java
Date Mon, 08 Dec 2008 22:57:51 GMT
Author: jalkanen
Date: Mon Dec  8 14:57:51 2008
New Revision: 724543

URL: http://svn.apache.org/viewvc?rev=724543&view=rev
Log:
Added WikiName and made WikiPage use it.

Added:
    incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/content/WikiName.java
Modified:
    incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/WikiPage.java
    incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/content/ContentManager.java
    incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/providers/ProviderException.java

Modified: incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/WikiPage.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/WikiPage.java?rev=724543&r1=724542&r2=724543&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/WikiPage.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/WikiPage.java Mon
Dec  8 14:57:51 2008
@@ -35,6 +35,8 @@
 import com.ecyrd.jspwiki.auth.acl.Acl;
 import com.ecyrd.jspwiki.auth.acl.AclEntry;
 import com.ecyrd.jspwiki.auth.acl.AclImpl;
+import com.ecyrd.jspwiki.content.ContentManager;
+import com.ecyrd.jspwiki.content.WikiName;
 import com.ecyrd.jspwiki.providers.WikiPageProvider;
 
 /**
@@ -52,9 +54,8 @@
 {
     private static final long serialVersionUID = 1L;
 
-    private       String     m_name;
+    private       WikiName   m_name;
     private       WikiEngine m_engine;
-    private       String     m_wiki;
     private Date             m_lastModified;
     private long             m_fileSize = -1;
     private int              m_version = WikiPageProvider.LATEST_VERSION;
@@ -83,15 +84,26 @@
      *  Create a new WikiPage using a given engine and name.
      *  
      *  @param engine The WikiEngine that owns this page.
-     *  @param name   The name of the page.
+     *  @param name   The path of the page.
      */
-    public WikiPage( WikiEngine engine, String name )
+    public WikiPage( WikiEngine engine, String path )
     {
         m_engine = engine;
-        m_name = name;
-        m_wiki = engine.getApplicationName();
+        m_name   = WikiName.valueOf( path );
     }
 
+    public WikiPage( WikiEngine engine, WikiName name )
+    {
+        m_engine = engine;
+        m_name   = name;
+    }
+    
+    public WikiPage( WikiEngine engine, Node nd ) throws WikiException, RepositoryException
+    {
+        m_engine = engine;
+        m_name   = ContentManager.getWikiPath( nd.getPath() );
+    }
+    
     // FIXME: This should be a part of the constructor
     public void setJCRNode(Node nd)
     {
@@ -110,7 +122,7 @@
      */
     public String getName()
     {
-        return m_name;
+        return m_name.getPath();
     }
     
     /**
@@ -121,7 +133,7 @@
      */
     public String getQualifiedName()
     {
-        return m_wiki + ":" + m_name;
+        return m_name.toString();
     }
 
     /**
@@ -290,9 +302,10 @@
      *  
      *  @return The name of the wiki.
      */
+    // FIXME: Should we rename this method?
     public String getWiki()
     {
-        return m_wiki;
+        return m_name.getSpace();
     }
 
     /**
@@ -334,7 +347,7 @@
      */
     public String toString()
     {
-        return "WikiPage ["+m_wiki+":"+m_name+",ver="+m_version+",mod="+m_lastModified+"]";
+        return "WikiPage ["+m_name+",ver="+m_version+",mod="+m_lastModified+"]";
     }
 
     /**
@@ -348,9 +361,8 @@
     public Object clone()
     {
         WikiPage p = new WikiPage( m_engine, m_name );
-       
-        p.m_wiki         = m_wiki;
             
+        p.m_node         = m_node;
         p.m_author       = m_author;
         p.m_version      = m_version;
         p.m_lastModified = m_lastModified != null ? (Date)m_lastModified.clone() : null;

Modified: incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/content/ContentManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/content/ContentManager.java?rev=724543&r1=724542&r2=724543&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/content/ContentManager.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/content/ContentManager.java
Mon Dec  8 14:57:51 2008
@@ -23,6 +23,9 @@
 import java.util.*;
 
 import javax.jcr.*;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryManager;
+import javax.jcr.query.QueryResult;
 import javax.jcr.version.Version;
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.VersionIterator;
@@ -48,6 +51,12 @@
  */
 public class ContentManager
 {
+    protected static final String DEFAULT_SPACE = "Main";
+    
+    private static final String JCR_DEFAULT_SPACE = "pages/"+DEFAULT_SPACE;
+
+    private static final String JCR_PAGES_NODE = "pages";
+
     private static final long serialVersionUID = 2L;
     
     /** The property value for setting the amount of time before the page locks expire. 
@@ -110,9 +119,6 @@
     
     private String m_workspaceName = DEFAULT_WORKSPACE; // FIXME: Make settable
     
-    /** This is the name of the default wikispace. */
-    
-    private static final String DEFAULT_SPACE = "Main";
     /**
      *  Creates a new PageManager.
      *  
@@ -201,18 +207,18 @@
             //
             // Create main page directory
             //
-            if( !root.hasNode( "pages" ) )
+            if( !root.hasNode( JCR_PAGES_NODE ) )
             {
-                root.addNode( "pages" );
+                root.addNode( JCR_PAGES_NODE );
             }
         
             //
             //  Make sure at least the default "Main" wikispace exists.
             //
             
-            if( !root.hasNode( "pages/Main" ) )
+            if( !root.hasNode( JCR_DEFAULT_SPACE ) )
             {
-                root.addNode( "pages/Main" );
+                root.addNode( JCR_DEFAULT_SPACE );
             }
             
             session.save();
@@ -228,16 +234,44 @@
      *  please see {@link ReferenceManager#findCreated()}, which is probably a lot
      *  faster.  This method may cause repository access.
      *  
+     *  @param space Name of the Wiki space.  May be null, in which case gets all spaces
      *  @return A Collection of WikiPage objects.
      *  @throws ProviderException If the backend has problems.
      */
-    /*
-    public Collection getAllPages()
+   
+    public Collection<WikiPage> getAllPages( WikiContext ctx, String space )
         throws ProviderException
     {
-        return m_provider.getAllPages();
+        ArrayList<WikiPage> result = new ArrayList<WikiPage>();
+        try
+        {
+            Session session = getJCRSession( ctx );
+        
+            QueryManager mgr = session.getWorkspace().getQueryManager();
+            
+            Query q = mgr.createQuery( "/"+JCR_PAGES_NODE+"/"+((space != null) ? space :
"")+"/*", Query.XPATH );
+            
+            QueryResult qr = q.execute();
+            
+            for( NodeIterator ni = qr.getNodes(); ni.hasNext(); )
+            {
+                Node n = ni.nextNode();
+                
+                result.add( new WikiPage(ctx.getEngine(), n ) );
+            }
+        }
+        catch( RepositoryException e )
+        {
+            throw new ProviderException("getAllPages()",e);
+        }
+        catch( WikiException e )
+        {
+            throw new ProviderException("getAllPages()",e);
+        }
+        
+        return result;
     }
-*/
+
     /**
      *  
      *  @param pageName The name of the page to fetch.
@@ -804,55 +838,65 @@
         return session;
     }
     
-    protected static String getJCRPath( WikiContext ctx, String wikipath ) throws WikiException
+    /**
+     *  Evaluates a WikiName in the context of the current page request.
+     *  
+     *  @param ctx The current WikiContext.  May be null, in which case the wikiName must
be a FQN.
+     *  @param wikiName The WikiName.
+     *  @return A full JCR path
+     *  @throws WikiException If the conversion could not be done.
+     */
+    protected static String getJCRPath( WikiContext ctx, String wikiName ) throws WikiException
     {
         String spaceName;
         String spacePath;
         
-        int colon = wikipath.indexOf(':');
+        int colon = wikiName.indexOf(':');
         
         if( colon != -1 )
         {
             // This is a FQN
-            spaceName = wikipath.substring( 0, colon );
-            spacePath = wikipath.substring( colon+1 );
+            spaceName = wikiName.substring( 0, colon );
+            spacePath = wikiName.substring( colon+1 );
         }
-        else if( ctx != null && ctx instanceof WikiContext )
+        else if( ctx != null )
         {
-            WikiPage contextPage = ((WikiContext)ctx).getPage();
+            WikiPage contextPage = ctx.getPage();
             
             // Not an FQN, the wiki name is missing, so we'll use the context to figure it
out
             spaceName = contextPage.getWiki();
             
             // If the wikipath starts with "/", we assume it is an absolute path within this
             // wiki space.  Otherwise, it must be relative to the current path.
-            if( wikipath.startsWith( "/" ) )
+            if( wikiName.startsWith( "/" ) )
             {
-                spacePath = wikipath;
+                spacePath = wikiName;
             }
             else
             {
-                spacePath = contextPage.getName()+"/"+wikipath;
+                spacePath = contextPage.getName()+"/"+wikiName;
             }
         }
         else
         {
             spaceName = DEFAULT_SPACE;
-            spacePath = wikipath;
+            spacePath = wikiName;
         }
         
         return "/pages/"+spaceName+"/"+spacePath;
     }
 
-    protected static String getWikiPath( String jcrpath ) throws WikiException
+    // FIXME: Should be protected - fix once WikiPage moves to content-package
+    public static WikiName getWikiPath( String jcrpath ) throws WikiException
     {
-        if( jcrpath.startsWith("/pages/") )
+        if( jcrpath.startsWith("/"+JCR_PAGES_NODE+"/") )
         {
-            String wikiPath = jcrpath.substring( "/pages/".length() );
+            String wikiPath = jcrpath.substring( ("/"+JCR_PAGES_NODE+"/").length() );
 
             int firstSlash = wikiPath.indexOf( '/' );
             
-            return wikiPath.substring( 0, firstSlash )+":"+wikiPath.substring( firstSlash+1
);
+            return new WikiName(wikiPath.substring( 0, firstSlash ), 
+                                wikiPath.substring( firstSlash+1 ) );
         }
         
         throw new WikiException("This is not a valid JCR path: "+jcrpath);

Added: incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/content/WikiName.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/content/WikiName.java?rev=724543&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/content/WikiName.java
(added)
+++ incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/content/WikiName.java
Mon Dec  8 14:57:51 2008
@@ -0,0 +1,136 @@
+/* 
+    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 java.io.Serializable;
+
+/**
+ *  A WikiName represents a combination of a WikiSpace as well as a
+ *  path within that space.  For example, in "MyWiki:MainPage/foo.jpg",
+ *  "MyWiki" is the space, and "MainPage/foo.jpg" is the path within that space.
+ *  
+ *  @since 3.0
+ */
+public class WikiName implements Serializable, Comparable
+{
+    private static final long serialVersionUID = 1L;
+    private String m_space;
+    private String m_path;
+    
+    private WikiName()
+    {}
+    
+    /**
+     *  Create a WikiName from a space and a path.
+     *  
+     *  @param space The space
+     *  @param path The path
+     */
+    public WikiName(String space, String path)
+    {
+        m_space = space;
+        m_path  = path;
+    }
+    
+    /**
+     *  Parses a fully-qualified name (FQN) and turns it into a WikiName.
+     *  If the space name is missing, uses {@link ContentManager#DEFAULT_SPACE}
+     *  for the space name.
+     *  
+     *  @param path Path to parse
+     *  @return A WikiName
+     */
+    public static WikiName valueOf(String path)
+    {
+        WikiName name = new WikiName();
+        int colon = path.indexOf(':');
+        
+        if( colon != -1 )
+        {
+            // This is a FQN
+            name.m_space = path.substring( 0, colon );
+            name.m_path  = path.substring( colon+1 );
+            
+            return name;
+        }
+        else
+        {
+            name.m_space = ContentManager.DEFAULT_SPACE;
+            name.m_path = path;
+            
+            return name;
+        }
+        
+        // FIXME: Should probably use this
+        //throw new IllegalArgumentException("The path does not represent a fully qualified
WikiName (space:path/path/path)");
+    }
+    
+    /**
+     *  Return the space part of the WikiName
+     *  
+     *  @return Just the space name.
+     */
+    public String getSpace()
+    {
+        return m_space;
+    }
+    
+    /**
+     *  Return the path part of the WikiName.
+     *  
+     *  @return Just the path.
+     */
+    public String getPath()
+    {
+        return m_path;
+    }
+    
+    /**
+     *  Returns the FQN format (space:path) of the name.
+     *  
+     *  @return The name in FQN format.
+     */
+    public String toString()
+    {
+        return m_space+":"+m_path;
+    }
+
+    public int hashCode()
+    {
+        return m_space.hashCode() ^ m_path.hashCode();
+    }
+    
+    public int compareTo( Object o ) throws ClassCastException
+    {
+        return toString().compareTo( ((WikiName)o).toString() );
+    }
+    
+    public boolean equals( Object o )
+    {
+        if( o instanceof WikiName )
+        {
+            WikiName n = (WikiName) o;
+            
+            return m_space.equals( n.m_space ) && m_path.equals( n.m_path );
+        }
+        return false;
+    }
+}

Modified: incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/providers/ProviderException.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/providers/ProviderException.java?rev=724543&r1=724542&r2=724543&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/providers/ProviderException.java
(original)
+++ incubator/jspwiki/branches/JSPWIKI_JCR_BRANCH/src/com/ecyrd/jspwiki/providers/ProviderException.java
Mon Dec  8 14:57:51 2008
@@ -42,4 +42,9 @@
     {
         super( msg );
     }
+
+    public ProviderException( String string, Throwable rootCause )
+    {
+        super( string, rootCause );
+    }
 }



Mime
View raw message