You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2008/02/13 06:54:24 UTC
svn commit: r627255 [18/41] - in
/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src: ./ com/ com/ecyrd/
com/ecyrd/jspwiki/ com/ecyrd/jspwiki/action/ com/ecyrd/jspwiki/attachment/
com/ecyrd/jspwiki/auth/ com/ecyrd/jspwiki/auth/acl/ com/ecyrd/jspwiki...
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavPath.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavPath.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavPath.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavPath.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,272 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav;
+
+import java.util.ArrayList;
+import java.util.StringTokenizer;
+
+/**
+ * The DavPath represents an abstract path to any resource within the WebDav
+ * system. Since the file tree displayed by the DAV storage may be different
+ * from the actual representation, this component is needed.
+ * <p>
+ * You instantiate a new DavPath simply by saying
+ * <code>DavPath dp = new DavPath("/path/to/my/object");</code>
+ * <p>
+ * If the path ends in a slash, it is understood to be a directory. If not,
+ * it represents a file.
+ *
+ * @author jalkanen
+ *
+ */
+public class DavPath
+{
+ private ArrayList m_parts = new ArrayList();
+
+ private boolean m_isAbsolute = false;
+ private boolean m_isDirectory = false;
+
+ /**
+ * Creates a new, empty path.
+ *
+ */
+ private DavPath()
+ {
+ }
+
+ /**
+ * Creates a new DavPath from an old one.
+ * @param dp the dav path
+ */
+ public DavPath( DavPath dp )
+ {
+ m_parts.addAll( dp.m_parts );
+ m_isAbsolute = dp.m_isAbsolute;
+ m_isDirectory = dp.m_isDirectory;
+ }
+
+ /**
+ * Creates a new DavPath object. The path parameter should be
+ * an arbitrary string with components separated with slashes.
+ * @param path
+ */
+ public DavPath( String path )
+ {
+ if( path == null )
+ {
+ m_isDirectory = true;
+ m_isAbsolute = true;
+ return;
+ }
+
+ StringTokenizer st = new StringTokenizer( path, "/" );
+
+ while( st.hasMoreTokens() )
+ {
+ String part = st.nextToken();
+
+ //
+ // Skip empty components so that // gets transformed to a single /
+ //
+ if( part.length() > 0 )
+ m_parts.add( part );
+ }
+
+ //
+ // Figure out path attributes
+ //
+ if( path.endsWith("/") )
+ m_isDirectory = true;
+
+ m_isAbsolute = path.startsWith("/");
+ }
+
+ /**
+ * Adds another path to the end of this path.
+ *
+ * @param dp the current dav path
+ */
+ public void append( DavPath dp )
+ {
+ m_parts.addAll( dp.m_parts );
+ m_isDirectory = dp.m_isDirectory;
+ }
+
+ /**
+ * Adds another path to the end of this path. The "path" parameter
+ * may contain a slash-separated path (e.g. "foo/bar/blog.txt").
+ *
+ * @param path the current dav path
+ */
+ public void append( String path )
+ {
+ DavPath dp = new DavPath( path );
+
+ append( dp );
+ }
+
+ /**
+ * Returns true, if the path represents the top-level entity. This is true,
+ * if the path is "/" or it is empty.
+ *
+ * @return True or false.
+ */
+ public boolean isRoot()
+ {
+ return m_parts.size() == 0 || m_parts.get(0).equals("");
+ }
+
+ /**
+ * Returns true, if the path represents a directory.
+ *
+ * @return <code>true</code> if the path is a directory; <code>false</code> otherwise
+ */
+ public boolean isDirectory()
+ {
+ return isRoot() || m_isDirectory;
+ }
+
+ /**
+ * Returns the directory part of the DavPath.
+ *
+ * @return the directory portion of the path
+ */
+ public String pathPart()
+ {
+ StringBuffer result = new StringBuffer( m_isAbsolute ? "/" : "" );
+
+ for( int i = 0; i < m_parts.size()-(m_isDirectory ? 0 : 1); i++ )
+ {
+ result.append( (String)m_parts.get(i) );
+ result.append( "/" );
+ }
+
+ return result.toString();
+ }
+
+ /**
+ * Returns the file part of the DavPath. The method returns the last component
+ * of the path, unless the path is a directory, in which case it returns an
+ * empty string.
+ *
+ * @return the file name, or an empty string
+ */
+ public String filePart()
+ {
+ if( m_parts.size() > 0 && !m_isDirectory )
+ return (String) m_parts.get( m_parts.size()-1 );
+
+ return "";
+ }
+
+ /**
+ * Returns the name of the last component of the DavPath. This is either
+ * the name of a directory, or the name of a file.
+ *
+ * @return the name of the right-most portion of the dav path
+ */
+ public String getName()
+ {
+ if( isRoot() ) return "/";
+ if( !isDirectory() ) return filePart();
+
+ return (String) m_parts.get( m_parts.size()-1 );
+ }
+
+ /**
+ * Returns the entire path as a String.
+ * @return the entire dav path
+ */
+ public String getPath()
+ {
+ return pathPart()+filePart();
+ }
+
+ /**
+ * Returns a new DavPath object that is a sub-path of this path. E.g. if
+ * the path is "/foo/bar/blog.txt", subPath(1) would return "bar/blog.txt".
+ * Notice that the resulting path is not absolute in this case.
+ *
+ * @param idx Start from this part.
+ * @return A sub-path of this path.
+ */
+ public DavPath subPath( int idx )
+ {
+ DavPath dp = new DavPath();
+
+ for( int i = idx; i < m_parts.size(); i++ )
+ {
+ dp.m_parts.add( m_parts.get(i) );
+ }
+
+ // Only full copies are absolute paths
+ dp.m_isAbsolute = idx == 0;
+ dp.m_isDirectory = m_isDirectory;
+
+ return dp;
+ }
+
+ /**
+ * Returns the 'idx' component of the path, zero being the first component.
+ * If there is no such component,
+ * it will simply return null.
+ *
+ * @param idx The component to return. Zero is the first element.
+ * @return A part of the path.
+ */
+ public String get( int idx )
+ {
+ if( idx > size() )
+ return null;
+
+ return (String)m_parts.get(idx);
+ }
+
+ /**
+ * Exactly equivalent to length().
+ *
+ * @return The length of the path.
+ */
+ public int size()
+ {
+ return m_parts.size();
+ }
+
+ /**
+ * Exactly equivalent to size(). I'm too lazy to remember whether it's length() or size(),
+ * so I'll provide both...
+ *
+ * @return the size of the path
+ */
+ public int length()
+ {
+ return m_parts.size();
+ }
+
+ /**
+ * Returns a human-readable version of the path. Please use getPath() instead
+ * of toString(), as this method is only good for debugging purposes.
+ * @return the String representation of the path
+ */
+ public String toString()
+ {
+ return "DavPath ["+getPath()+"]";
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavProvider.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavProvider.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavProvider.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,32 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav;
+
+import com.ecyrd.jspwiki.dav.items.DavItem;
+
+public interface DavProvider
+{
+
+ public DavItem getItem( DavPath path );
+
+ public void setItem( DavPath path, DavItem item );
+
+ public String getURL( DavPath path );
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavUtil.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavUtil.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavUtil.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/DavUtil.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,96 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.ecs.XhtmlDocument;
+import org.apache.ecs.xhtml.li;
+import org.apache.ecs.xhtml.ul;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiPage;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public class DavUtil
+{
+ public static String getCollectionInHTML( WikiContext context, Collection coll )
+ {
+ XhtmlDocument doc = new XhtmlDocument("UTF-8");
+
+ ul content = new ul();
+
+ for( Iterator i = coll.iterator(); i.hasNext(); )
+ {
+ Object o = i.next();
+
+ if( o instanceof WikiPage )
+ {
+ WikiPage p = (WikiPage)o;
+ content.addElement( new li().addElement( p.getName() ) );
+ }
+ else if( o instanceof String )
+ {
+ content.addElement( new li().addElement( o.toString() ));
+ }
+ }
+
+ doc.appendBody( content );
+
+ return doc.toString();
+ }
+
+ public static void sendHTMLResponse( HttpServletResponse res, String txt )
+ throws IOException
+ {
+ res.setContentType( "text/html; charset=UTF-8" );
+ res.setContentLength( txt.length() );
+
+ res.getWriter().print( txt );
+ }
+
+ public static String combineURL( String part1, String part2 )
+ {
+ if( part1.endsWith("/") )
+ {
+ if( part2.startsWith("/") )
+ {
+ part2 = part2.substring(1);
+ }
+ }
+ else
+ {
+ if( !part2.startsWith("/") )
+ {
+ return part1+"/"+part2;
+ }
+ }
+
+ return part1+part2;
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/HTMLPagesDavProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/HTMLPagesDavProvider.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/HTMLPagesDavProvider.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/HTMLPagesDavProvider.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,127 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.action.NoneActionBean;
+import com.ecyrd.jspwiki.dav.items.DavItem;
+import com.ecyrd.jspwiki.dav.items.DirectoryItem;
+import com.ecyrd.jspwiki.dav.items.HTMLPageDavItem;
+import com.ecyrd.jspwiki.providers.ProviderException;
+
+public class HTMLPagesDavProvider extends RawPagesDavProvider
+{
+ public HTMLPagesDavProvider( WikiEngine engine )
+ {
+ super(engine);
+ }
+
+ private Collection listDirContents( DavPath path )
+ {
+ String st = path.getName();
+
+ log.info("Listing contents for dir "+st);
+ ArrayList davItems = new ArrayList();
+
+ try
+ {
+ Collection allPages = m_engine.getPageManager().getAllPages();
+
+ for( Iterator i = allPages.iterator(); i.hasNext(); )
+ {
+ WikiPage p = (WikiPage)i.next();
+
+ if( p.getName().toLowerCase().startsWith(st) )
+ {
+ DavPath dp = new DavPath( path );
+ dp.append( p.getName()+".html" );
+
+ DavItem di = new HTMLPageDavItem( this, dp, p );
+
+ davItems.add( di );
+ }
+ }
+ }
+ catch( ProviderException e )
+ {
+ log.error("Unable to fetch a list of all pages",e);
+ // FIXME
+ }
+ return davItems;
+ }
+
+ protected DavItem getItemNoCache( DavPath path )
+ {
+ String pname = path.filePart();
+
+ //
+ // Lists top-level elements
+ //
+ if( path.isRoot() )
+ {
+ log.info("Adding DAV items from path "+path);
+ DirectoryItem di = new DirectoryItem( this, path );
+
+ di.addDavItems( listAlphabeticals(path) );
+
+ return di;
+ }
+
+ //
+ // Lists each item in each subdir
+ //
+ if( path.isDirectory() )
+ {
+ log.info("Listing pages in path "+path);
+
+ DirectoryItem di = new DirectoryItem( this, path );
+
+ di.addDavItems( listDirContents(path) );
+
+ return di;
+ }
+
+ if( pname.endsWith(".html") && pname.length() > 5 )
+ {
+ pname = pname.substring(0,pname.length()-5);
+ }
+
+ WikiPage page = m_engine.getPage( pname );
+
+ if( page != null )
+ {
+ return new HTMLPageDavItem( this, path, page );
+ }
+
+ return null;
+ }
+
+ public String getURL( DavPath path )
+ {
+ String url = DavUtil.combineURL( DavUtil.combineURL( m_engine.getBaseURL() , "dav/html"), path.getPath() );
+ return url;
+ }
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/RawPagesDavProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/RawPagesDavProvider.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/RawPagesDavProvider.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/RawPagesDavProvider.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,265 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.dav.items.DavItem;
+import com.ecyrd.jspwiki.dav.items.DirectoryItem;
+import com.ecyrd.jspwiki.dav.items.PageDavItem;
+import com.ecyrd.jspwiki.providers.ProviderException;
+import com.opensymphony.oscache.base.Cache;
+import com.opensymphony.oscache.base.NeedsRefreshException;
+
+/**
+ * Implements something for the pages.
+ *
+ * @author jalkanen
+ *
+ * @since
+ */
+public class RawPagesDavProvider extends WikiDavProvider
+{
+ protected static final Logger log = Logger.getLogger( RawPagesDavProvider.class );
+
+ private Cache m_davItemCache = new Cache(true,false,false);
+
+ private int m_refreshPeriod = 30*1000; // In millisseconds
+
+
+ public RawPagesDavProvider( WikiEngine engine )
+ {
+ super(engine);
+ }
+
+ protected Collection listAlphabeticals( DavPath path )
+ {
+ ArrayList charList = new ArrayList();
+
+ try
+ {
+ Collection allPages = m_engine.getPageManager().getAllPages();
+
+ for( Iterator i = allPages.iterator(); i.hasNext(); )
+ {
+ String pageName = ((WikiPage)i.next()).getName();
+
+ Character firstChar = new Character(Character.toLowerCase(pageName.charAt(0)));
+
+ if( !charList.contains( firstChar ) )
+ {
+ charList.add( firstChar );
+ }
+ }
+ }
+ catch( ProviderException e )
+ {
+ log.error("Could not fetch a list of all pages:",e);
+ }
+
+ Collections.sort( charList );
+
+ ArrayList result = new ArrayList();
+
+ for( Iterator i = charList.iterator(); i.hasNext(); )
+ {
+ Character c = (Character)i.next();
+
+ result.add( new DirectoryItem(this, new DavPath(c.toString())) );
+ }
+
+ return result;
+ }
+
+ // FIXME: This is wasteful; this should really keep a structure of its
+ // own in memory
+
+ private Collection listDirContents( DavPath path )
+ {
+ String st = path.getName();
+
+ log.info("Listing contents for dir "+st);
+ ArrayList davItems = new ArrayList();
+
+ try
+ {
+ Collection allPages = m_engine.getPageManager().getAllPages();
+
+ for( Iterator i = allPages.iterator(); i.hasNext(); )
+ {
+ WikiPage p = (WikiPage)i.next();
+
+ if( p.getName().toLowerCase().startsWith(st) )
+ {
+ DavPath np = new DavPath( path );
+ np.append( p.getName()+".txt" );
+
+ DavItem di = new PageDavItem( this, np, p );
+
+ davItems.add( di );
+ }
+ }
+ }
+ catch( ProviderException e )
+ {
+ log.error("Unable to fetch a list of all pages",e);
+ // FIXME
+ }
+ return davItems;
+ }
+
+ public Collection listItems( DavPath path )
+ {
+ log.info("Listing dav path "+path+", size="+path.size());
+
+ switch( path.size() )
+ {
+ case 1:
+ return listAlphabeticals(path);
+
+ case 2:
+ return listDirContents( path );
+
+ default:
+ return null;
+ }
+ }
+
+ protected String getRelativePath( String path )
+ {
+ if( path.length() > 0 )
+ {
+ char c = Character.toLowerCase( path.charAt(0) );
+
+ return Character.toString(c);
+ }
+
+ return "";
+ }
+
+ public String getURL( DavPath path )
+ {
+ String url = DavUtil.combineURL( DavUtil.combineURL( m_engine.getBaseURL() , "dav/raw"), path.getPath() );
+ return url;
+ }
+
+ public DavItem getItem( DavPath dp )
+ {
+ DavItem di = null;
+
+ try
+ {
+ di = (DavItem)m_davItemCache.getFromCache( dp.toString(),
+ m_refreshPeriod );
+
+ if( di == null )
+ {
+ di = getItemNoCache( dp );
+ }
+ }
+ catch( NeedsRefreshException e )
+ {
+ DavItem old = (DavItem)e.getCacheContent();
+
+ if( old != null && old instanceof PageDavItem )
+ {
+ WikiPage cached = ((PageDavItem)old).getPage();
+
+ if( cached != null )
+ {
+ WikiPage current = m_engine.getPage( cached.getName() );
+
+ if( cached.getLastModified().equals( current.getLastModified() ) )
+ {
+ di = old;
+ }
+ }
+ }
+ else
+ {
+ di = getItemNoCache( dp );
+ }
+ }
+
+ m_davItemCache.putInCache( dp.toString(), di );
+
+ return di;
+ }
+
+ protected DavItem getItemNoCache( DavPath path )
+ {
+ String pname = path.filePart();
+
+ //
+ // Lists top-level elements
+ //
+ if( path.isRoot() )
+ {
+ log.info("Adding DAV items from path "+path);
+ DirectoryItem di = new DirectoryItem( this, path );
+
+ di.addDavItems( listAlphabeticals(path) );
+
+ return di;
+ }
+
+ //
+ // Lists each item in each subdir
+ //
+ if( path.isDirectory() )
+ {
+ log.info("Listing pages in path "+path);
+
+ DirectoryItem di = new DirectoryItem( this, path );
+
+ di.addDavItems( listDirContents(path) );
+
+ return di;
+ }
+
+ if( pname.endsWith(".txt") && pname.length() > 4 )
+ {
+ pname = pname.substring(0,pname.length()-4);
+ }
+
+ WikiPage page = m_engine.getPage( pname );
+
+ if( page != null )
+ {
+ return new PageDavItem( this, path, page );
+ }
+
+ return null;
+ }
+
+ public void setItem( DavPath path, DavItem item )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WebdavServlet.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WebdavServlet.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WebdavServlet.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WebdavServlet.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,177 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public class WebdavServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ private static final String METHOD_PROPPATCH = "PROPPATCH";
+ private static final String METHOD_PROPFIND = "PROPFIND";
+ private static final String METHOD_MKCOL = "MKCOL";
+ private static final String METHOD_COPY = "COPY";
+ private static final String METHOD_MOVE = "MOVE";
+ private static final String METHOD_LOCK = "LOCK";
+ private static final String METHOD_UNLOCK = "UNLOCK";
+
+ public static final int SC_PROCESSING = 102;
+ public static final int SC_MULTISTATUS = 207;
+ public static final int SC_UNPROCESSABLE = 422;
+ public static final int SC_LOCKED = 423;
+ public static final int SC_FAILED_DEPENDENCY = 424;
+ public static final int SC_INSUFFICIENT_STORAGE = 507;
+
+ /**
+ *
+ */
+ public WebdavServlet()
+ {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ public void doPropFind( HttpServletRequest request, HttpServletResponse response )
+ throws ServletException, IOException
+ {
+
+ }
+
+ public void doPropPatch( HttpServletRequest request, HttpServletResponse response )
+ throws ServletException, IOException
+ {
+
+ }
+
+ public void doMkCol( HttpServletRequest request, HttpServletResponse response )
+ throws ServletException, IOException
+ {
+
+ }
+
+ public void doCopy( HttpServletRequest request, HttpServletResponse response )
+ throws ServletException, IOException
+ {
+
+ }
+
+ public void doMove( HttpServletRequest request, HttpServletResponse response )
+ throws ServletException, IOException
+ {
+
+ }
+
+ /**
+ * The default implementation of this class just returns an error code.
+ *
+ * @param request
+ * @param response
+ */
+ public void doLock( HttpServletRequest request, HttpServletResponse response )
+ throws ServletException, IOException
+ {
+ try
+ {
+ response.sendError( HttpServletResponse.SC_NOT_IMPLEMENTED, "Sorry" );
+ }
+ catch( IOException e ) {}
+ }
+
+ /**
+ * The default implementation of this class just returns an error code.
+ *
+ * @param request
+ * @param response
+ */
+
+ public void doUnlock( HttpServletRequest request, HttpServletResponse response )
+ throws ServletException, IOException
+ {
+ try
+ {
+ response.sendError( HttpServletResponse.SC_NOT_IMPLEMENTED, "Sorry" );
+ }
+ catch( IOException e ) {}
+ }
+
+ protected void service( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
+ {
+ String method = request.getMethod();
+
+ // System.out.println("METHOD="+method+"; request="+request.getPathInfo() );
+
+ try
+ {
+ if( METHOD_PROPPATCH.equals(method) )
+ {
+ doPropPatch( request, response );
+ }
+ else if( METHOD_PROPFIND.equals(method) )
+ {
+ doPropFind( request, response );
+ }
+ else if( METHOD_MKCOL.equals(method) )
+ {
+ doMkCol( request, response );
+ }
+ else if( METHOD_COPY.equals(method) )
+ {
+ doCopy( request, response );
+ }
+ else if( METHOD_MOVE.equals(method) )
+ {
+ doMove( request, response );
+ }
+ else if( METHOD_LOCK.equals(method) )
+ {
+ doLock( request, response );
+ }
+ else if( METHOD_UNLOCK.equals(method) )
+ {
+ doUnlock( request, response );
+ }
+ else if( "OPTIONS".equals(method) )
+ {
+ doOptions( request, response );
+ }
+ else
+ {
+ super.service( request, response );
+ }
+ }
+ catch( Throwable t )
+ {
+ t.printStackTrace( System.out );
+
+ throw new ServletException( t );
+ }
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiDavProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiDavProvider.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiDavProvider.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiDavProvider.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,38 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav;
+
+
+import com.ecyrd.jspwiki.WikiEngine;
+
+public abstract class WikiDavProvider implements DavProvider
+{
+ protected WikiEngine m_engine;
+
+ public WikiDavProvider( WikiEngine engine )
+ {
+ m_engine = engine;
+ }
+
+ public WikiEngine getEngine()
+ {
+ return m_engine;
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiDavServlet.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiDavServlet.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiDavServlet.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiDavServlet.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,187 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav;
+
+import java.io.IOException;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.time.StopWatch;
+import org.apache.log4j.Logger;
+
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.dav.methods.DavMethod;
+import com.ecyrd.jspwiki.dav.methods.GetMethod;
+import com.ecyrd.jspwiki.dav.methods.PropFindMethod;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public class WikiDavServlet extends WebdavServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ private WikiEngine m_engine;
+ Logger log = Logger.getLogger(this.getClass().getName());
+ private DavProvider m_rawProvider;
+ private DavProvider m_rootProvider;
+ private DavProvider m_htmlProvider;
+
+ public void init( ServletConfig config )
+ throws ServletException
+ {
+ super.init( config );
+
+ m_engine = WikiEngine.getInstance( config );
+
+ m_rawProvider = new RawPagesDavProvider( m_engine );
+ m_rootProvider = new WikiRootProvider( m_engine );
+ m_htmlProvider = new HTMLPagesDavProvider( m_engine );
+ }
+
+ private DavProvider pickProvider( String context )
+ {
+ if( context.equals("raw") ) return m_rawProvider;
+ else if( context.equals("html") ) return m_htmlProvider;
+
+ return m_rootProvider;
+ }
+
+ public void doPropFind( HttpServletRequest req, HttpServletResponse res )
+ throws IOException,ServletException
+ {
+ StopWatch sw = new StopWatch();
+ sw.start();
+
+ // Do the "sanitize url" trick
+ String p = new String(req.getPathInfo().getBytes("ISO-8859-1"), "UTF-8");
+
+ DavPath path = new DavPath( p );
+ if( path.isRoot() )
+ {
+ DavMethod dm = new PropFindMethod( m_rootProvider );
+ dm.execute( req, res, path );
+ }
+ else
+ {
+ String context = path.get(0);
+
+ PropFindMethod m = new PropFindMethod( pickProvider(context) );
+ m.execute( req, res, path.subPath(1) );
+ }
+
+ sw.stop();
+
+ log.debug("Propfind done for path "+path+", took "+sw);
+ }
+
+ protected void doOptions( HttpServletRequest req, HttpServletResponse res )
+ {
+ log.debug("DAV doOptions for path "+req.getPathInfo());
+
+ res.setHeader( "DAV", "1" ); // We support only Class 1
+ res.setHeader( "Allow", "GET, PUT, POST, OPTIONS, PROPFIND, PROPPATCH, MOVE, COPY, DELETE");
+ res.setStatus( HttpServletResponse.SC_OK );
+ }
+
+
+ public void doMkCol( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
+ {
+ if( request.getContentLength() > 0 )
+ {
+ response.sendError( HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Message may contain no body" );
+ }
+ else
+ {
+ response.sendError( HttpServletResponse.SC_UNAUTHORIZED, "JSPWiki is read-only." );
+ }
+ }
+
+
+
+ public void doPropPatch( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
+ {
+ //DavMethod dm = new PropPatchMethod( m_rawProvider );
+
+ //dm.execute( request, response );
+ }
+
+ public void doCopy( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
+ {
+ response.sendError( HttpServletResponse.SC_UNAUTHORIZED, "JSPWiki is read-only." );
+ }
+
+ public void doMove( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
+ {
+ response.sendError( HttpServletResponse.SC_UNAUTHORIZED, "JSPWiki is read-only." );
+
+ }
+
+ protected void doDelete( HttpServletRequest arg0, HttpServletResponse response ) throws ServletException, IOException
+ {
+ response.sendError( HttpServletResponse.SC_UNAUTHORIZED, "JSPWiki is read-only." );
+ }
+
+ protected void doPost( HttpServletRequest arg0, HttpServletResponse response ) throws ServletException, IOException
+ {
+ response.sendError( HttpServletResponse.SC_UNAUTHORIZED, "JSPWiki is read-only." );
+ }
+
+ protected void doPut( HttpServletRequest arg0, HttpServletResponse response ) throws ServletException, IOException
+ {
+ response.sendError( HttpServletResponse.SC_UNAUTHORIZED, "JSPWiki is read-only." );
+ }
+
+ /*
+ * GET /dav/raw/WikiPage.txt
+ * GET /dav/html/WikiPage.html
+ * GET /dav/pdf/WikiPage.pdf
+ * GET /dav/raw/WikiPage/attachment1.png
+ *
+ */
+ protected void doGet( HttpServletRequest req, HttpServletResponse res )
+ throws ServletException, IOException
+ {
+ // Do the "sanitize url" trick
+ // String p = new String(req.getPathInfo().getBytes("ISO-8859-1"), "UTF-8");
+
+ req.setCharacterEncoding( m_engine.getContentEncoding() );
+ String p = req.getPathInfo();
+
+ DavPath path = new DavPath( p );
+
+ if( path.isRoot() )
+ {
+ DavMethod dm = new GetMethod( m_rootProvider );
+ dm.execute( req, res, path );
+ }
+ else
+ {
+ DavMethod dm = new GetMethod( pickProvider(path.get(0)) );
+
+ dm.execute( req, res, path.subPath(1) );
+ }
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiRootProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiRootProvider.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiRootProvider.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/WikiRootProvider.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,67 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.dav.items.DavItem;
+import com.ecyrd.jspwiki.dav.items.TopLevelDavItem;
+
+public class WikiRootProvider extends WikiDavProvider
+{
+ public WikiRootProvider( WikiEngine engine )
+ {
+ super( engine );
+ }
+
+ public Collection listItems( DavPath path )
+ {
+ ArrayList list = new ArrayList();
+
+ list.add( new TopLevelDavItem(this) );
+
+ return list;
+ }
+
+ public DavItem getItem( DavPath path )
+ {
+ return new TopLevelDavItem(this);
+ }
+
+ public DavItem refreshItem( DavItem old, DavPath path )
+ {
+ return new TopLevelDavItem(this);
+ }
+
+ public void setItem( DavPath path, DavItem item )
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public String getURL( DavPath path )
+ {
+ String url = DavUtil.combineURL( DavUtil.combineURL( m_engine.getBaseURL() , "dav/"), path.getPath() );
+ return url;
+ }
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/AttachmentDirectoryItem.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/AttachmentDirectoryItem.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/AttachmentDirectoryItem.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/AttachmentDirectoryItem.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,47 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.items;
+
+import java.util.Collection;
+
+import com.ecyrd.jspwiki.dav.DavPath;
+import com.ecyrd.jspwiki.dav.DavProvider;
+
+public class AttachmentDirectoryItem extends DirectoryItem
+{
+ public AttachmentDirectoryItem( DavProvider provider, DavPath parentpage )
+ {
+ super( provider, parentpage );
+ }
+
+ public String getHref()
+ {
+ return "";
+ // return m_provider.getEngine().getURL( WikiContext.ATTACH, "", null, true );
+ }
+
+ public Collection getPropertySet()
+ {
+ // TODO Auto-generated method stub
+ return super.getPropertySet();
+ }
+
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/AttachmentItem.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/AttachmentItem.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/AttachmentItem.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/AttachmentItem.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,101 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.items;
+
+import java.util.Collection;
+
+import javax.servlet.ServletContext;
+
+import org.jdom.Element;
+
+import com.ecyrd.jspwiki.attachment.Attachment;
+import com.ecyrd.jspwiki.dav.AttachmentDavProvider;
+import com.ecyrd.jspwiki.dav.DavPath;
+
+/**
+ * Represents a DAV attachment.
+ * @author jalkanen
+ *
+ * @since
+ */
+public class AttachmentItem extends PageDavItem
+{
+
+ /**
+ * Constructs a new DAV attachment.
+ * @param provider the dav provider
+ * @param path the current dav path
+ * @param att the attachment
+ */
+ public AttachmentItem( AttachmentDavProvider provider, DavPath path, Attachment att )
+ {
+ super( provider, path, att );
+ }
+
+
+ /**
+ * Returns a collection of properties for this attachment.
+ * @return the attachment properties
+ * @see com.ecyrd.jspwiki.dav.items.DavItem#getPropertySet()
+ */
+ public Collection getPropertySet()
+ {
+ Collection set = getCommonProperties();
+
+ set.add( new Element("getcontentlength",m_davns).setText( Long.toString(getLength())) );
+ set.add( new Element("getcontenttype",m_davns).setText( getContentType() ));
+
+ return set;
+ }
+
+ public String getHref()
+ {
+ return m_provider.getURL( m_path );
+ }
+
+ /**
+ * Returns the content type as defined by the servlet container;
+ * or if the container cannot be found, returns "application/octet-stream".
+ * @return the content type
+ */
+ public String getContentType()
+ {
+ ServletContext ctx = ((AttachmentDavProvider)m_provider).getEngine().getServletContext();
+
+ if( ctx != null )
+ {
+ String mimetype = ctx.getMimeType( m_page.getName() );
+
+ if( mimetype != null ) return mimetype;
+ }
+
+ return "application/octet-stream"; // FIXME: This is not correct
+ }
+
+ /**
+ * Returns the length of the attachment.
+ * @return the length
+ * @see com.ecyrd.jspwiki.dav.items.DavItem#getLength()
+ */
+ public long getLength()
+ {
+ return m_page.getSize();
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/DavItem.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/DavItem.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/DavItem.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/DavItem.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,92 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.items;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+import com.ecyrd.jspwiki.dav.DavPath;
+import com.ecyrd.jspwiki.dav.DavProvider;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public abstract class DavItem
+{
+ protected DavProvider m_provider;
+ protected ArrayList m_items = new ArrayList();
+ protected DavPath m_path;
+
+ protected DavItem( DavProvider provider, DavPath path )
+ {
+ m_provider = provider;
+ m_path = path;
+ }
+
+ public DavPath getPath()
+ {
+ return m_path;
+ }
+
+ public abstract Collection getPropertySet();
+
+ public abstract String getHref();
+
+ public abstract InputStream getInputStream();
+
+ public abstract long getLength();
+
+ public abstract String getContentType();
+
+ public Iterator iterator( int depth )
+ {
+ ArrayList list = new ArrayList();
+
+ if( depth == 0 )
+ {
+ list.add( this );
+ }
+ else if( depth == 1 )
+ {
+ list.add( this );
+ list.addAll( m_items );
+ }
+ else if( depth == -1 )
+ {
+ list.add( this );
+
+ for( Iterator i = m_items.iterator(); i.hasNext(); )
+ {
+ DavItem di = (DavItem)i.next();
+
+ for( Iterator j = di.iterator(-1); i.hasNext(); )
+ {
+ list.add( j.next() );
+ }
+ }
+ }
+
+ return list.iterator();
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/DirectoryItem.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/DirectoryItem.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/DirectoryItem.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/DirectoryItem.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,97 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.items;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+import com.ecyrd.jspwiki.dav.DavPath;
+import com.ecyrd.jspwiki.dav.DavProvider;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public class DirectoryItem extends DavItem
+{
+ public DirectoryItem( DavProvider provider, DavPath path )
+ {
+ super( provider, path );
+ }
+
+ public String getContentType()
+ {
+ return "text/plain; charset=UTF-8";
+ }
+
+ public long getLength()
+ {
+ return -1;
+ }
+
+ public Collection getPropertySet()
+ {
+ ArrayList ts = new ArrayList();
+ Namespace davns = Namespace.getNamespace( "DAV:" );
+
+ ts.add( new Element("resourcetype",davns).addContent(new Element("collection",davns)) );
+
+ Element txt = new Element("displayname",davns);
+ txt.setText( m_path.getName() );
+ ts.add( txt );
+
+ ts.add( new Element("getcontentlength",davns).setText("0") );
+ ts.add( new Element("getlastmodified", davns).setText(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(new Date())));
+
+
+ return ts;
+ }
+
+ public String getHref()
+ {
+ return m_provider.getURL( m_path );
+ }
+
+ public void addDavItem( DavItem di )
+ {
+ m_items.add( di );
+ }
+
+ public void addDavItems( Collection c )
+ {
+ m_items.addAll( c );
+ }
+
+ /* (non-Javadoc)
+ * @see com.ecyrd.jspwiki.dav.items.DavItem#getInputStream()
+ */
+ public InputStream getInputStream()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/HTMLPageDavItem.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/HTMLPageDavItem.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/HTMLPageDavItem.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/HTMLPageDavItem.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,130 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.items;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Collection;
+
+import org.jdom.Element;
+
+import com.ecyrd.jspwiki.WikiContext;
+import com.ecyrd.jspwiki.WikiEngine;
+import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.dav.DavPath;
+import com.ecyrd.jspwiki.dav.DavProvider;
+import com.ecyrd.jspwiki.dav.WikiDavProvider;
+import com.ecyrd.jspwiki.parser.MarkupParser;
+
+/**
+ * Represents a DAV HTML page item.
+ * @author jalkanen
+ *
+ * @since
+ */
+public class HTMLPageDavItem extends PageDavItem
+{
+ private long m_cachedLength = -1;
+
+ /**
+ * @param provider the DAV provider
+ * @param path the DAV path
+ * @param page the wiki page
+ */
+ public HTMLPageDavItem( DavProvider provider, DavPath path, WikiPage page )
+ {
+ super( provider, path, page );
+ }
+
+ /**
+ * @see com.ecyrd.jspwiki.dav.items.DavItem#getHref()
+ */
+ public String getHref()
+ {
+ return m_provider.getURL( m_path );
+ }
+
+ /**
+ * Returns the content type for the item. Always returns
+ * <code>text/html; charset=UTF-8</code>.
+ * @see com.ecyrd.jspwiki.dav.items.DavItem#getContentType()
+ */
+ public String getContentType()
+ {
+ return "text/html; charset=UTF-8";
+ }
+
+ private byte[] getText()
+ {
+ WikiEngine engine = ((WikiDavProvider)m_provider).getEngine();
+
+ WikiContext context = engine.getWikiActionBeanFactory().newViewActionBean( m_page );
+
+ context.setVariable( MarkupParser.PROP_RUNPLUGINS, "false" );
+ context.setVariable( WikiEngine.PROP_RUNFILTERS, "false" );
+
+ String text = engine.getHTML( context, m_page );
+
+ try
+ {
+ return text.getBytes("UTF-8");
+ }
+ catch( UnsupportedEncodingException e )
+ {
+ return null; // Should never happen
+ }
+ }
+
+ public InputStream getInputStream()
+ {
+ byte[] text = getText();
+
+ ByteArrayInputStream in = new ByteArrayInputStream( text );
+
+ return in;
+ }
+
+ public long getLength()
+ {
+ if( m_cachedLength == -1 )
+ {
+ byte[] text = getText();
+
+ m_cachedLength = text.length;
+ }
+
+ return m_cachedLength;
+ }
+
+ public Collection getPropertySet()
+ {
+ Collection set = getCommonProperties();
+
+ //
+ // Rendering the page for every single time is not really a very good idea.
+ //
+
+ set.add( new Element("getcontentlength",m_davns).setText( Long.toString(getLength()) ) );
+ set.add( new Element("getcontenttype",m_davns).setText("text/html; charset=\"UTF-8\""));
+
+ return set;
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/PageDavItem.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/PageDavItem.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/PageDavItem.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/PageDavItem.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,124 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.items;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.jdom.Element;
+import org.jdom.Namespace;
+
+import com.ecyrd.jspwiki.WikiPage;
+import com.ecyrd.jspwiki.dav.DavPath;
+import com.ecyrd.jspwiki.dav.DavProvider;
+import com.ecyrd.jspwiki.dav.WikiDavProvider;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public class PageDavItem extends DavItem
+{
+ protected WikiPage m_page;
+ protected Namespace m_dcns = Namespace.getNamespace( "dc", "http://purl.org/dc/elements/1.1/" );
+ protected Namespace m_davns = Namespace.getNamespace( "DAV:" );
+
+ /**
+ *
+ */
+ public PageDavItem( DavProvider provider, DavPath path, WikiPage page )
+ {
+ super( provider, path );
+ m_page = page;
+ }
+
+ public WikiPage getPage()
+ {
+ return m_page;
+ }
+
+ protected Collection getCommonProperties()
+ {
+ ArrayList set = new ArrayList();
+
+ set.add( new Element("resourcetype",m_davns) );
+ set.add( new Element("creator",m_dcns).setText(m_page.getAuthor()) );
+ set.add( new Element("getlastmodified",m_davns).setText(DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(m_page.getLastModified())));
+ set.add( new Element("displayname",m_davns).setText(m_page.getName()) );
+
+ return set;
+ }
+
+ /* (non-Javadoc)
+ * @see com.ecyrd.jspwiki.dav.DavItem#getPropertySet(int)
+ */
+ public Collection getPropertySet()
+ {
+ Collection set = getCommonProperties();
+
+ set.add( new Element("getcontentlength",m_davns).setText( Long.toString(getLength())) );
+ set.add( new Element("getcontenttype",m_davns).setText( getContentType() ));
+
+ return set;
+ }
+
+ public String getHref()
+ {
+ return m_provider.getURL( m_path );
+ }
+
+ /* (non-Javadoc)
+ * @see com.ecyrd.jspwiki.dav.items.DavItem#getContentType()
+ */
+ public String getContentType()
+ {
+ return "text/plain; charset=UTF-8";
+ }
+
+ /* (non-Javadoc)
+ * @see com.ecyrd.jspwiki.dav.items.DavItem#getInputStream()
+ */
+ public InputStream getInputStream()
+ {
+ String text = ((WikiDavProvider)m_provider).getEngine().getPureText( m_page );
+
+ try
+ {
+ ByteArrayInputStream in = new ByteArrayInputStream( text.getBytes("UTF-8") );
+
+ return in;
+ }
+ catch( UnsupportedEncodingException e ) {}
+
+ return null;
+ }
+
+ public long getLength()
+ {
+ // FIXME: Use getBytes()
+ String text = ((WikiDavProvider)m_provider).getEngine().getPureText( m_page );
+ return text.length();
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/TopLevelDavItem.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/TopLevelDavItem.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/TopLevelDavItem.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/items/TopLevelDavItem.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,38 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.items;
+
+import com.ecyrd.jspwiki.dav.DavPath;
+import com.ecyrd.jspwiki.dav.DavProvider;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public class TopLevelDavItem extends DirectoryItem
+{
+ public TopLevelDavItem( DavProvider provider )
+ {
+ super( provider, new DavPath("/") );
+ addDavItem( new DirectoryItem( provider, new DavPath("raw") ) );
+ addDavItem( new DirectoryItem( provider, new DavPath("html") ) );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/DavMethod.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/DavMethod.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/DavMethod.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/DavMethod.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,50 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.methods;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.ecyrd.jspwiki.dav.DavPath;
+import com.ecyrd.jspwiki.dav.DavProvider;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public abstract class DavMethod
+{
+ protected DavProvider m_provider;
+
+ /**
+ *
+ */
+ public DavMethod( DavProvider provider )
+ {
+ m_provider = provider;
+ }
+
+ public abstract void execute( HttpServletRequest req, HttpServletResponse res, DavPath path )
+ throws ServletException, IOException;
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/GetMethod.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/GetMethod.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/GetMethod.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/GetMethod.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,85 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.methods;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.ecyrd.jspwiki.FileUtil;
+import com.ecyrd.jspwiki.dav.DavPath;
+import com.ecyrd.jspwiki.dav.DavProvider;
+import com.ecyrd.jspwiki.dav.items.DavItem;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public class GetMethod extends DavMethod
+{
+
+ /**
+ *
+ */
+ public GetMethod( DavProvider provider )
+ {
+ super( provider );
+ }
+
+ public void execute( HttpServletRequest req, HttpServletResponse res, DavPath dp )
+ throws IOException
+ {
+ DavItem di = m_provider.getItem( dp );
+
+ if( di != null )
+ {
+ String mime = di.getContentType();
+ res.setContentType( mime );
+
+ long length = di.getLength();
+
+ if( length >= 0 )
+ {
+ res.setContentLength( (int)di.getLength() );
+ }
+
+ InputStream in = di.getInputStream();
+
+ if( in != null )
+ {
+ FileUtil.copyContents( in, res.getOutputStream() );
+
+ in.close();
+ }
+ else
+ {
+ res.sendError( HttpServletResponse.SC_NO_CONTENT ); // FIXME: probably not correct
+ }
+
+ }
+ else
+ {
+ res.sendError( HttpServletResponse.SC_NOT_FOUND );
+ }
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/PropFindMethod.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/PropFindMethod.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/PropFindMethod.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/PropFindMethod.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,293 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.methods;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.Format;
+import org.jdom.output.XMLOutputter;
+import org.jdom.xpath.XPath;
+
+import com.ecyrd.jspwiki.dav.DavContext;
+import com.ecyrd.jspwiki.dav.DavPath;
+import com.ecyrd.jspwiki.dav.DavProvider;
+import com.ecyrd.jspwiki.dav.WebdavServlet;
+import com.ecyrd.jspwiki.dav.items.DavItem;
+import com.ecyrd.jspwiki.providers.ProviderException;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public class PropFindMethod
+ extends DavMethod
+{
+ private static Logger log = Logger.getLogger( PropFindMethod.class );
+
+ /**
+ *
+ */
+ public PropFindMethod( DavProvider provider )
+ {
+ super( provider );
+ }
+
+ public void sendMultiResponse( HttpServletResponse res, Element response )
+ throws IOException
+ {
+ res.setContentType("application/xml; charset=\"UTF-8\"");
+ res.setStatus( WebdavServlet.SC_MULTISTATUS );
+
+ Document doc = new Document();
+
+ doc.setRootElement( response );
+
+ XMLOutputter output = new XMLOutputter();
+
+ // System.out.println("Returning");
+ output.setFormat( Format.getPrettyFormat() );
+ // output.output( doc, System.out );
+ output.output( doc, res.getWriter() );
+ }
+
+ private Element getPropertyNames( DavContext dc )
+ {
+ log.debug("Retrieving all property names for context "+dc);
+
+ Namespace davns = Namespace.getNamespace( "DAV:" );
+ Element root = new Element("multistatus", davns);
+
+ DavItem di = m_provider.getItem( dc.getPath() );
+
+ for( Iterator i = di.iterator(dc.getDepth()); i.hasNext(); )
+ {
+ di = (DavItem) i.next();
+
+ Element response = new Element("response", davns);
+
+ response.addContent( new Element("href",davns).setText( di.getHref() ) );
+
+ Element propstat = new Element("propstat", davns);
+
+ //
+ // Wiki specifics.
+ //
+ Collection c = di.getPropertySet();
+
+ Element prop = new Element("prop",davns);
+
+ for( Iterator j = c.iterator(); j.hasNext(); )
+ {
+ Element el = (Element)j.next();
+ el.removeContent();
+ prop.addContent( el );
+ }
+
+ propstat.addContent( prop );
+ propstat.addContent( new Element("status",davns).setText("HTTP/1.1 200 OK"));
+
+ response.addContent( propstat );
+
+ root.addContent( response );
+ }
+
+ return root;
+ }
+
+ private Element getProperties( DavContext dc, List askedprops )
+ throws IOException
+ {
+ Namespace davns = Namespace.getNamespace( "DAV:" );
+
+ Element root = new Element("multistatus", davns);
+
+ DavItem di = m_provider.getItem( dc.getPath() );
+
+ if( di == null )
+ {
+ throw new FileNotFoundException( dc.getPath().toString() );
+ }
+
+ for( Iterator i = di.iterator(dc.getDepth()); i.hasNext(); )
+ {
+ di = (DavItem) i.next();
+
+ Element response = new Element("response", davns);
+
+ response.addContent( new Element("href",davns).setText( di.getHref() ) );
+
+ Element props = new Element("prop", davns);
+ Element failedprops = new Element("prop", davns );
+
+ //
+ // Get the matching property set
+ //
+ Collection c = di.getPropertySet();
+
+ if( askedprops == null )
+ {
+ for( Iterator j = c.iterator(); j.hasNext(); )
+ {
+ Element el = (Element)j.next();
+
+ props.addContent( el );
+ }
+ }
+ else
+ {
+ for( Iterator x = askedprops.iterator(); x.hasNext(); )
+ {
+ Element askedElement = (Element)x.next();
+
+ boolean found = false;
+
+ for( Iterator j = c.iterator(); j.hasNext(); )
+ {
+ Element el = (Element)j.next();
+
+ if( askedElement.getNamespaceURI().equals( el.getNamespaceURI() ) &&
+ askedElement.getName().equals( el.getName() ) )
+ {
+ //
+ // This protects in case there are multiple elements
+ // in the request.
+ //
+ if( props.indexOf(el) == -1 )
+ {
+ props.addContent( el );
+ }
+ found = true;
+ break;
+ }
+ }
+
+ if( !found )
+ {
+ Element el = (Element)askedElement.clone();
+ failedprops.addContent( el );
+ }
+ }
+
+ }
+
+ if( props.getContentSize() > 0 )
+ {
+ Element ps = new Element("propstat",davns);
+ ps.addContent( props );
+ ps.addContent( new Element("status",davns).setText("HTTP/1.1 200 OK"));
+ response.addContent( ps );
+ }
+
+ if( failedprops.getContentSize() > 0 )
+ {
+ Element ps = new Element("propstat",davns);
+ ps.addContent( failedprops );
+ ps.addContent( new Element("status",davns).setText("HTTP/1.1 404 Not found"));
+ response.addContent( ps );
+ }
+
+ root.addContent( response );
+ }
+
+ return root;
+ }
+
+ private Element getAllProps( DavContext dc )
+ throws ProviderException, IOException
+ {
+ log.debug("Retrieving all properties for context "+dc.getPath());
+
+ return getProperties( dc, null );
+ }
+
+
+ public void execute( HttpServletRequest req, HttpServletResponse res, DavPath dp )
+ throws ServletException, IOException
+ {
+ DavContext dc = new DavContext( req, dp );
+
+ try
+ {
+ Document doc = new SAXBuilder().build( req.getInputStream() );
+
+ XPath xpath = XPath.newInstance("/D:propfind/*");
+ xpath.addNamespace( "D", "DAV:" );
+
+ Element firstnode = (Element)xpath.selectSingleNode( doc );
+
+ Element davresponse = null;
+
+ System.out.println("Request="+dc.getPath()+" depth="+dc.getDepth());
+
+ if( firstnode == null || firstnode.getName().equals("allprop") )
+ {
+ davresponse = getAllProps( dc );
+ }
+ else if( firstnode.getName().equals("propname") )
+ {
+ davresponse = getPropertyNames( dc );
+ }
+ else if( firstnode.getName().equals("prop") )
+ {
+ XPath ndxp = XPath.newInstance("/D:propfind/D:prop/*");
+ ndxp.addNamespace( "D", "DAV:" );
+
+ List nodes = ndxp.selectNodes( doc );
+
+ davresponse = getProperties( dc, nodes );
+ }
+
+ sendMultiResponse( res, davresponse );
+ }
+ catch( JDOMException e )
+ {
+ // This is probably someone trying to poke at us
+ log.info( "Broken XML received", e );
+
+ res.sendError( HttpServletResponse.SC_BAD_REQUEST, "Parse error" );
+ }
+ catch( ProviderException e )
+ {
+ log.error( "Provider failed", e );
+
+ res.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage() );
+ }
+ catch( FileNotFoundException e )
+ {
+ res.sendError( HttpServletResponse.SC_NOT_FOUND, e.getMessage() );
+ }
+ }
+
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/PropPatchMethod.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/PropPatchMethod.java?rev=627255&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/PropPatchMethod.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/src/com/ecyrd/jspwiki/dav/methods/PropPatchMethod.java Tue Feb 12 21:53:55 2008
@@ -0,0 +1,54 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2002 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.ecyrd.jspwiki.dav.methods;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.ecyrd.jspwiki.dav.DavPath;
+import com.ecyrd.jspwiki.dav.DavProvider;
+
+/**
+ * @author jalkanen
+ *
+ * @since
+ */
+public class PropPatchMethod
+ extends DavMethod
+{
+
+ /**
+ * Constructs a new DAV PropPatchMethod.
+ * @param provider the DAV provider
+ */
+ public PropPatchMethod( DavProvider provider )
+ {
+ super( provider );
+ }
+
+ public void execute( HttpServletRequest req, HttpServletResponse res, DavPath dp ) throws ServletException, IOException
+ {
+ res.sendError( HttpServletResponse.SC_UNAUTHORIZED, "JSPWiki is read-only" );
+ }
+
+}