You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-user@jakarta.apache.org by Stuart MacPherson <ap...@dsl.pipex.com> on 2003/08/29 09:49:20 UTC

RE: Implementing a search facility SERVLET!

Hmm

It did it again... definitely not me!

Here it is copied in...

import java.io.*;
import java.net.URL;
import java.security.Principal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import org.apache.slide.authenticate.SecurityToken;
import org.apache.slide.common.*;
import org.apache.slide.content.Content;
import org.apache.slide.content.NodeRevisionDescriptor;
import org.apache.slide.content.NodeRevisionDescriptors;
import org.apache.slide.lock.Lock;
import org.apache.slide.lock.NodeLock;
import org.apache.slide.security.AccessDeniedException;
import org.apache.slide.security.NodePermission;
import org.apache.slide.security.Security;
import org.apache.slide.structure.LinkedObjectNotFoundException;
import org.apache.slide.structure.ObjectNode;
import org.apache.slide.structure.ObjectNotFoundException;
import org.apache.slide.structure.Structure;
import org.apache.slide.util.conf.*;
import org.apache.slide.util.Messages;
import org.apache.slide.util.logger.Logger;
import org.apache.slide.webdav.*;
import org.apache.slide.webdav.method.*;
import org.apache.util.WebdavStatus;

public class SimpleWebdavServlet extends
org.apache.slide.webdav.WebdavServlet {


    private static final DateFormat formatter =
        new SimpleDateFormat(DATE_FORMAT);
    
    /**
     * Handle a GET request on a collection resource.
     */
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        
        if (directoryBrowsing) {
            Writer writer = resp.getWriter();
            resp.setContentType("text/html");
            try {
                displayDirectoryBrowsing(req, writer);
            } catch (AccessDeniedException e) {
                resp.sendError(WebdavStatus.SC_FORBIDDEN);
            } catch (ObjectNotFoundException e) {
                resp.sendError(WebdavStatus.SC_NOT_FOUND);
            } catch (LinkedObjectNotFoundException e) {
                resp.sendError(WebdavStatus.SC_NOT_FOUND);
            } catch (SlideException e) {
                resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ERROR);
            }
        } else {
            resp.sendError(WebdavStatus.SC_FORBIDDEN);
        }
    }
    
    /**
     * Display a directory browsing page.
     */
    protected void displayDirectoryBrowsing(HttpServletRequest req,
                                            Writer servletWriter)
        throws IOException, SlideException {
        
        String contextPath = req.getContextPath();
        if (contextPath == null)
            contextPath = "";
        
        // get the helpers
        Content content = token.getContentHelper();
        Lock lock = token.getLockHelper();
        Security security = token.getSecurityHelper();
        Structure structure = token.getStructureHelper();

        SlideToken slideToken = WebdavUtils.getSlideToken(req);
        String resourcePath =
            WebdavUtils.getRelativePath(
                req, (WebdavServletConfig)getServletConfig());
        ObjectNode object = structure.retrieve(slideToken, resourcePath);
        String name = object.getUri();
        
        ////////////////////////CUSTOM CODE//////////////////////////
        String slideHomeURL = req.getRequestURL().toString();
        
        HttpSession session = req.getSession();
        session.setAttribute("slideFileDest", name);
        session.setAttribute("slideHomeURL", slideHomeURL);
        ////////////////////////CUSTOM CODE/////////////////////////
        
        // Number of characters to trim from the beginnings of filenames
        int trim = name.length();
        if (!name.endsWith("/"))
            trim += 1;
        if (name.equals("/"))
            trim = 1;
        
        PrintWriter writer = new PrintWriter(servletWriter);
        
        // Render the page header
        writer.print("<html>\r\n");
        writer.print("<head>\r\n");
        writer.print("<title>");
        writer.print
            (Messages.format
                 ("org.apache.slide.webdav.GetMethod.directorylistingfor",
name));
        writer.print("</title>\r\n</head>\r\n");
        writer.print("<body bgcolor=\"white\">\r\n");

/////////////////////////////
        writer.print("<H1> docEDGE </H1>\r\n");
/////////////////////////////


        writer.print("<table width=\"90%\" cellspacing=\"0\"" +
                         " cellpadding=\"5\" align=\"center\">\r\n");
        
        // Render the in-page title
        writer.print("<tr><td colspan=\"3\"><font
size=\"+2\">\r\n<strong>");
        writer.print
            (Messages.format
                 ("org.apache.slide.webdav.GetMethod.directorylistingfor",
name));
        writer.print("</strong>\r\n</font></td></tr>\r\n");
        
        // Render the link to our parent (if required)
        String parentDirectory = name;
        if (parentDirectory.endsWith("/")) {
            parentDirectory =
                parentDirectory.substring(0, parentDirectory.length() - 1);
        }
        int slash = parentDirectory.lastIndexOf("/");
        if (slash >= 0) {
            String parent = name.substring(0, slash);
            writer.print("<tr><td colspan=\"5\" bgcolor=\"#ffffff\">\r\n");
            writer.print("<a href=\"");
            writer.print(WebdavUtils.encodeURL(contextPath));
            if (parent.equals(""))
                parent = "/";
            writer.print(parent);
            writer.print("\">");
            writer.print(Messages.format
                             ("org.apache.slide.webdav.GetMethod.parent",
parent));
            writer.print("</a>\r\n");
            writer.print("</td></tr>\r\n");
        }
        
        Enumeration permissionsList = null;
        Enumeration locksList = null;
        
        try {
            
            permissionsList =
                security.enumeratePermissions(slideToken, object.getUri());
            locksList = lock.enumerateLocks(slideToken, object.getUri(),
false);
            
        } catch (SlideException e) {
            
            // Any security based exception will be trapped here
            
            // Any locking based exception will be trapped here
            
        }
        
        // Displaying ACL info
        if( org.apache.slide.util.Configuration.useIntegratedSecurity() )
            displayPermissions(permissionsList, writer, false);
        
        // Displaying lock info
        displayLocks(locksList, writer, false);
        
        writer.print("<tr><td colspan=\"5\" bgcolor=\"#ffffff\">");
        writer.print("&nbsp;");
        writer.print("</td></tr>\r\n");
        
        // Render the column headings
        writer.print("<tr bgcolor=\"#cccccc\">\r\n");
        writer.print("<td align=\"left\" colspan=\"3\">");
        writer.print("<font size=\"+1\"><strong>");
        writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.filename"));
        writer.print("</strong></font></td>\r\n");
        writer.print("<td align=\"center\"><font size=\"+1\"><strong>");
        writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.size"));
        writer.print("</strong></font></td>\r\n");
        writer.print("<td align=\"right\"><font size=\"+1\"><strong>");
        writer.print(Messages.message
 
("org.apache.slide.webdav.GetMethod.lastModified"));
        writer.print("</strong></font></td>\r\n");
        writer.print("</tr>\r\n");
        
        Enumeration resources = object.enumerateChildren();
        boolean shade = false;
        
        while (resources.hasMoreElements()) {
            
            String currentResource = (String) resources.nextElement();
            
            NodeRevisionDescriptor currentDescriptor = null;
            
            permissionsList = null;
            locksList = null;
            
            try {
                
                NodeRevisionDescriptors revisionDescriptors =
                    content.retrieve(slideToken, currentResource);
                // Retrieve latest revision descriptor
                currentDescriptor =
                    content.retrieve(slideToken, revisionDescriptors);
                
            } catch (SlideException e) {
                
                // Silent exception : Objects without any revision are
                // considered collections, and do not have any attributes
                
                // Any security based exception will be trapped here
                
                // Any locking based exception will be trapped here
                
            }
            
            try {
                
                permissionsList =
                    security.enumeratePermissions(slideToken,
currentResource);
                locksList = lock.enumerateLocks(slideToken, currentResource,
false);
                
            } catch (SlideException e) {
                
                // Any security based exception will be trapped here
                
                // Any locking based exception will be trapped here
                
            }
            
            String trimmed = currentResource.substring(trim);
            if (trimmed.equalsIgnoreCase("WEB-INF") ||
                trimmed.equalsIgnoreCase("META-INF"))
                continue;
            
            writer.print("<tr");
            if (shade) {
                writer.print(" bgcolor=\"dddddd\"");
            } else {
                writer.print(" bgcolor=\"eeeeee\"");
            }
            writer.print(">\r\n");
            shade = !shade;
            
            writer.print("<td align=\"left\"
colspan=\"3\">&nbsp;&nbsp;\r\n");
            writer.print("<a href=\"");
            writer.print(WebdavUtils.encodeURL(contextPath +
currentResource));
            writer.print("\"><tt>");
            writer.print(trimmed);
            if (WebdavUtils.isCollection(currentDescriptor)) {
                writer.print("/");
            }
            writer.print("</tt></a></td>\r\n");
            
            writer.print("<td align=\"right\"><tt>");
            if (WebdavUtils.isCollection(currentDescriptor))
                writer.print("&nbsp;");
            else
 
writer.print(renderSize(currentDescriptor.getContentLength()));
            writer.print("</tt></td>\r\n");
            
            writer.print("<td align=\"right\"><tt>");
            if (currentDescriptor != null) {
                writer.print(currentDescriptor.getLastModified());
            } else {
                writer.print("&nbsp;");
            }
            writer.print("</tt></td>\r\n");
            
            writer.print("</tr>\r\n");
            
            // Displaying ACL info
            if( org.apache.slide.util.Configuration.useIntegratedSecurity()
)
                displayPermissions(permissionsList, writer, shade);
            
            // Displaying lock info
            displayLocks(locksList, writer, shade);
            
        }
        
        // Render the page footer
        writer.print("<a href=\"/slide/fileUpload.jsp\"
target=\"_blank\"><font face=\"Arial, Helvetica, sans-serif\">Upload a
document to this folder</font></a>\r\n");
        writer.print("<tr><td colspan=\"5\">&nbsp;</td></tr>\r\n");
        writer.print("<tr><td colspan=\"3\" bgcolor=\"#cccccc\">");
        writer.print("<font size=\"-1\">");
        writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.version"));
        writer.print("</font></td>\r\n");
        writer.print("<td colspan=\"2\" align=\"right\"
bgcolor=\"#cccccc\">");
        writer.print("<font size=\"-1\">");
        writer.print(formatter.format(new Date()));
        writer.print("</font></td></tr>\r\n");
        writer.print("</table>\r\n");
        writer.print("<a href=\"/slide/portal.jsp\" target=\"_blank\"><font
face=\"Arial, Helvetica, sans-serif\">kiss my hairy buttcheeks</font></a>");
        writer.print("</body>\r\n");
        writer.print("</html>\r\n");
        
        // Return an input stream to the underlying bytes
        writer.flush();
        
    }
    
    
    public void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
        	
		for(int i =0; i<5;i++){
			System.out.println("RECEIVED THE POST!!!");
		}
		
	}
    
    
    /**
     * Display an ACL list.
     *
     * @param permissionsList List of NodePermission objects
     * @param shade
     * @param writer The output will be appended to this writer
     */
    private void displayPermissions(Enumeration permissionsList,
                                    PrintWriter writer,
                                    boolean shade)
        throws IOException {
        
        if ((permissionsList != null) &&
(permissionsList.hasMoreElements())) {
            
            writer.print("<tr" + (shade ? " bgcolor=\"eeeeee\"" 
                                        : " bgcolor=\"dddddd\"") + 
                         ">\r\n");
            writer.print("<td align=\"left\" colspan=\"5\"><tt><b>");
            writer.print(Messages.message
                             ("org.apache.slide.webdav.GetMethod.aclinfo"));
            writer.print("</b></tt></td>\r\n");
            writer.print("</tr>\r\n");
            
            writer.print("<tr" + (shade ? " bgcolor=\"eeeeee\"" 
                                        : " bgcolor=\"dddddd\"") + 
                         ">\r\n");
            
            writer.print("<td align=\"left\" colspan=\"2\"><tt><b>");
            writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.subject"));
            writer.print("</b></tt></td>\r\n");
            
            writer.print("<td align=\"left\"><tt><b>");
            writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.action"));
            writer.print("</b></tt></td>\r\n");
            
            writer.print("<td align=\"right\"><tt><b>");
            writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.inheritable"));
            writer.print("</b></tt></td>\r\n");
            
            writer.print("<td align=\"right\"><tt><b>");
            writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.deny"));
            writer.print("</b></tt></td>\r\n");
            
            writer.print("</tr>\r\n");
            
            while (permissionsList.hasMoreElements()) {
                
                writer.print("<tr" + (shade ? " bgcolor=\"eeeeee\"" 
                                            : " bgcolor=\"dddddd\"") + 
                             ">\r\n");
                
                NodePermission currentPermission =
                    (NodePermission) permissionsList.nextElement();
                
                writer.print("<td align=\"left\" colspan=\"2\"><tt>");
                writer.print(currentPermission.getSubjectUri());
                writer.print("</tt></td>\r\n");
                
                writer.print("<td align=\"left\"><tt>");
                writer.print(currentPermission.getActionUri());
                writer.print("</tt></td>\r\n");
                
                writer.print("<td align=\"right\"><tt>");
                writer.print(currentPermission.isInheritable());
                writer.print("</tt></td>\r\n");
                
                writer.print("<td align=\"right\"><tt>");
                writer.print(currentPermission.isNegative());
                writer.print("</tt></td>\r\n");
                
                writer.print("</tr>\r\n");
            }
            
        }
        
    }
    
    
    /**
     * Display a lock list.
     *
     * @param locksList List of NodeLock objects
     * @param shade
     * @param writer The output will be appended to this writer
     */
    private void displayLocks(Enumeration locksList, PrintWriter writer,
                              boolean shade)
        throws IOException {
        
        if ((locksList != null) && (locksList.hasMoreElements())) {
            
            writer.print("<tr" + (shade ? " bgcolor=\"eeeeee\"" 
                                        : " bgcolor=\"dddddd\"") + 
                         ">\r\n");
            writer.print("<td align=\"left\" colspan=\"5\"><tt><b>");
            writer.print(Messages.message
 
("org.apache.slide.webdav.GetMethod.locksinfo"));
            writer.print("</b></tt></td>\r\n");
            writer.print("</tr>\r\n");
            
            writer.print("<tr");
            if (!shade) {
                writer.print(" bgcolor=\"dddddd\"");
            } else {
                writer.print(" bgcolor=\"eeeeee\"");
            }
            writer.print(">\r\n");
            
            writer.print("<td align=\"left\"><tt><b>");
            writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.subject"));
            writer.print("</b></tt></td>\r\n");
            
            writer.print("<td align=\"left\"><tt><b>");
            writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.type"));
            writer.print("</b></tt></td>\r\n");
            
            writer.print("<td align=\"right\"><tt><b>");
            writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.expiration"));
            writer.print("</b></tt></td>\r\n");
            
            writer.print("<td align=\"right\"><tt><b>");
            writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.inheritable"));
            writer.print("</b></tt></td>\r\n");
            
            writer.print("<td align=\"right\"><tt><b>");
            writer.print(Messages.message
                         ("org.apache.slide.webdav.GetMethod.exclusive"));
            writer.print("</b></tt></td>\r\n");
            
            writer.print("</tr>\r\n");
            
            while (locksList.hasMoreElements()) {
                
                writer.print("<tr" + (shade ? " bgcolor=\"eeeeee\"" 
                                            : " bgcolor=\"dddddd\"") + 
                             ">\r\n");
                
                NodeLock currentLock = (NodeLock) locksList.nextElement();
                
                writer.print("<td align=\"left\"><tt>");
                writer.print(currentLock.getSubjectUri());
                writer.print("</tt></td>\r\n");
                
                writer.print("<td align=\"left\"><tt>");
                writer.print(currentLock.getTypeUri());
                writer.print("</tt></td>\r\n");
                
                writer.print("<td align=\"right\"><tt>");
                writer.print
                    (formatter.format(currentLock.getExpirationDate()));
                writer.print("</tt></td>\r\n");
                
                writer.print("<td align=\"right\"><tt>");
                writer.print(currentLock.isInheritable());
                writer.print("</tt></td>\r\n");
                
                writer.print("<td align=\"right\"><tt>");
                writer.print(currentLock.isExclusive());
                writer.print("</tt></td>\r\n");
                
            }
            
        }
        
    }
    
    
    // -------------------------------------------------------- Private
Methods
    
    
    /**
     * Render the specified file size (in bytes).
     *
     * @param size File size (in bytes)
     */
    private String renderSize(long size) {
        
        long leftSide = size / 1024;
        long rightSide = (size % 1024) / 103;   // Makes 1 digit
        if ((leftSide == 0) && (rightSide == 0) && (size > 0))
            rightSide = 1;
        
        return ("" + leftSide + "." + rightSide + " kb");
    }


}

-----Original Message-----
From: Stuart MacPherson [mailto:aprw00@dsl.pipex.com] 
Sent: 29 August 2003 08:40
To: 'Slide Users Mailing List'
Subject: RE: Implementing a search facility

Err

I definitely did it that time!  Here it is again...

Stu


-----Original Message-----
From: Andreas Probst [mailto:andpro77@gmx.net] 
Sent: 29 August 2003 06:12
To: Slide Users Mailing List
Subject: RE: Implementing a search facility

Still not attached.

On 29 Aug 2003 at 0:46, Stuart MacPherson wrote:

> Umm... here's the Servlet this time ;oS
> 
> 
> -----Original Message-----
> From: Stuart MacPherson [mailto:aprw00@dsl.pipex.com] 
> Sent: 29 August 2003 00:46
> To: 'Slide Users Mailing List'
> Subject: Implementing a search facility
> 
> I have successfully extended SimpleWebdavServlet, and now it
> handles the GET requests as well as the standard WevdavServlet.  
> 
> I want to implement a search system (that searches document
> properties) and then spits out a listing in a similar way to GET
> requests on single collections... except obviously this time it
> might not be just one collection, and could be many (depending on
> the docs that match the query). I have written search.jsp, which
> POSTs the search query form to my WebdavServlet (is this a good
> idea?), in which I have implemented a doPost() method which will
> handle searches and nothing else...
> 
> Only problem is that is doesn't seem to be getting that far (I
> have some debug println's that aren't being written).  In fact,
> when I do a directory listing it seems to taking the request, and
> (now this is weird) writing it as a text file to the root
> directory of slide!  It even shows in the directory listing!  I
> can click it, and open it in notepad... and it is basically the
> multipart/form-data request that should be getting processed by
> the Servlet.  The Servlet doesn't actually do anything with the
> request yet apart from the println's, but this other stuff deffo
> shouldn't be happening!
> 
> I have attached my SimpleWebdavServlet file, but it's basically
> stock apart from a few things between custom code markers, and
> some links that the writer prints as part of the directory
> listing response... nothing that should bust it up.
> 
> I pretty much guarantee you that I won't solve this one by myself
> (as seems to be my trademark)...  so I hope someone can help!
> 
> Regards
> Stu
> 
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: slide-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: slide-user-help@jakarta.apache.org





RE: Implementing a search facility SERVLET!

Posted by Andreas Probst <an...@gmx.net>.
Hi Stuart, 

the original WebdavServlet does only call doPost(), if the 
request is for a collection. Otherwise it creates a PostMethod 
and your doPost() will never be called.

See in WebdavServlet.service():

if ((methodName.equalsIgnoreCase("GET") ||
     methodName.equalsIgnoreCase("POST")) &&
    WebdavUtils.isCollection(token, req, config)) {
    // let the standard doGet() / doPost() methods handle
    // GET/POST requests on collections (to display a directory
    // index pag or something similar)
    super.service(req, resp);
} else {
    WebdavMethod method = 
methodFactory.createMethod(methodName);
    if (method == null) {
        throw new 
WebdavException(WebdavStatus.SC_METHOD_NOT_ALLOWED);
    } else {
        method.run(req, resp);
    }
}

Could it be this is the cause of the problem you observed?

Andreas



On 29 Aug 2003 at 8:49, Stuart MacPherson wrote:

> Hmm
> 
> It did it again... definitely not me!
> 
> Here it is copied in...
> 
> import java.io.*;
> import java.net.URL;
> import java.security.Principal;
> import java.text.DateFormat;
> import java.text.SimpleDateFormat;
> import java.util.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> 
> import org.apache.slide.authenticate.SecurityToken;
> import org.apache.slide.common.*;
> import org.apache.slide.content.Content;
> import org.apache.slide.content.NodeRevisionDescriptor;
> import org.apache.slide.content.NodeRevisionDescriptors;
> import org.apache.slide.lock.Lock;
> import org.apache.slide.lock.NodeLock;
> import org.apache.slide.security.AccessDeniedException;
> import org.apache.slide.security.NodePermission;
> import org.apache.slide.security.Security;
> import org.apache.slide.structure.LinkedObjectNotFoundException;
> import org.apache.slide.structure.ObjectNode; import
> org.apache.slide.structure.ObjectNotFoundException; import
> org.apache.slide.structure.Structure; import
> org.apache.slide.util.conf.*; import
> org.apache.slide.util.Messages; import
> org.apache.slide.util.logger.Logger; import
> org.apache.slide.webdav.*; import
> org.apache.slide.webdav.method.*; import
> org.apache.util.WebdavStatus;
> 
> public class SimpleWebdavServlet extends
> org.apache.slide.webdav.WebdavServlet {
> 
> 
>     private static final DateFormat formatter =
>         new SimpleDateFormat(DATE_FORMAT);
> 
>     /**
>      * Handle a GET request on a collection resource.
>      */
>     protected void doGet(HttpServletRequest req,
>     HttpServletResponse resp)
>         throws ServletException, IOException {
> 
>         if (directoryBrowsing) {
>             Writer writer = resp.getWriter();
>             resp.setContentType("text/html");
>             try {
>                 displayDirectoryBrowsing(req, writer);
>             } catch (AccessDeniedException e) {
>                 resp.sendError(WebdavStatus.SC_FORBIDDEN);
>             } catch (ObjectNotFoundException e) {
>                 resp.sendError(WebdavStatus.SC_NOT_FOUND);
>             } catch (LinkedObjectNotFoundException e) {
>                 resp.sendError(WebdavStatus.SC_NOT_FOUND);
>             } catch (SlideException e) {
>                 resp.setStatus(WebdavStatus.SC_INTERNAL_SERVER_ER
>                 ROR);
>             }
>         } else {
>             resp.sendError(WebdavStatus.SC_FORBIDDEN);
>         }
>     }
> 
>     /**
>      * Display a directory browsing page.
>      */
>     protected void displayDirectoryBrowsing(HttpServletRequest
>     req,
>                                 Writer servletWriter)
>         throws IOException, SlideException {
> 
>         String contextPath = req.getContextPath();
>         if (contextPath == null)
>             contextPath = "";
> 
>         // get the helpers
>         Content content = token.getContentHelper();
>         Lock lock = token.getLockHelper();
>         Security security = token.getSecurityHelper();
>         Structure structure = token.getStructureHelper();
> 
>         SlideToken slideToken = WebdavUtils.getSlideToken(req);
>         String resourcePath =
>             WebdavUtils.getRelativePath(
>                 req, (WebdavServletConfig)getServletConfig());
>         ObjectNode object = structure.retrieve(slideToken,
>         resourcePath); String name = object.getUri();
> 
>         ////////////////////////CUSTOM
>         CODE////////////////////////// String slideHomeURL =
>         req.getRequestURL().toString();
> 
>         HttpSession session = req.getSession();
>         session.setAttribute("slideFileDest", name);
>         session.setAttribute("slideHomeURL", slideHomeURL);
>         ////////////////////////CUSTOM
>         CODE/////////////////////////
> 
>         // Number of characters to trim from the beginnings of
>         filenames int trim = name.length(); if
>         (!name.endsWith("/"))
>             trim += 1;
>         if (name.equals("/"))
>             trim = 1;
> 
>         PrintWriter writer = new PrintWriter(servletWriter);
> 
>         // Render the page header
>         writer.print("<html>\r\n");
>         writer.print("<head>\r\n");
>         writer.print("<title>");
>         writer.print
>             (Messages.format
>                  ("org.apache.slide.webdav.GetMethod.directorylis
>                  tingfor",
> name));
>         writer.print("</title>\r\n</head>\r\n");
>         writer.print("<body bgcolor=\"white\">\r\n");
> 
> /////////////////////////////
>         writer.print("<H1> docEDGE </H1>\r\n");
> /////////////////////////////
> 
> 
>         writer.print("<table width=\"90%\" cellspacing=\"0\"" +
>                          " cellpadding=\"5\"
>                          align=\"center\">\r\n");
> 
>         // Render the in-page title
>         writer.print("<tr><td colspan=\"3\"><font
> size=\"+2\">\r\n<strong>");
>         writer.print
>             (Messages.format
>                  ("org.apache.slide.webdav.GetMethod.directorylis
>                  tingfor",
> name));
>         writer.print("</strong>\r\n</font></td></tr>\r\n");
> 
>         // Render the link to our parent (if required)
>         String parentDirectory = name;
>         if (parentDirectory.endsWith("/")) {
>             parentDirectory =
>                 parentDirectory.substring(0,
>                 parentDirectory.length() - 1);
>         }
>         int slash = parentDirectory.lastIndexOf("/");
>         if (slash >= 0) {
>             String parent = name.substring(0, slash);
>             writer.print("<tr><td colspan=\"5\"
>             bgcolor=\"#ffffff\">\r\n"); writer.print("<a
>             href=\"");
>             writer.print(WebdavUtils.encodeURL(contextPath)); if
>             (parent.equals(""))
>                 parent = "/";
>             writer.print(parent);
>             writer.print("\">");
>             writer.print(Messages.format
>                              ("org.apache.slide.webdav.GetMethod.
>                              parent",
> parent));
>             writer.print("</a>\r\n");
>             writer.print("</td></tr>\r\n");
>         }
> 
>         Enumeration permissionsList = null;
>         Enumeration locksList = null;
> 
>         try {
> 
>             permissionsList =
>                 security.enumeratePermissions(slideToken,
>                 object.getUri());
>             locksList = lock.enumerateLocks(slideToken,
>             object.getUri(),
> false);
> 
>         } catch (SlideException e) {
> 
>             // Any security based exception will be trapped here
> 
>             // Any locking based exception will be trapped here
> 
>         }
> 
>         // Displaying ACL info
>         if(
>         org.apache.slide.util.Configuration.useIntegratedSecurity
>         () )
>             displayPermissions(permissionsList, writer, false);
> 
>         // Displaying lock info
>         displayLocks(locksList, writer, false);
> 
>         writer.print("<tr><td colspan=\"5\"
>         bgcolor=\"#ffffff\">"); writer.print("&nbsp;");
>         writer.print("</td></tr>\r\n");
> 
>         // Render the column headings
>         writer.print("<tr bgcolor=\"#cccccc\">\r\n");
>         writer.print("<td align=\"left\" colspan=\"3\">");
>         writer.print("<font size=\"+1\"><strong>");
>         writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.file
>                          name"));
>         writer.print("</strong></font></td>\r\n");
>         writer.print("<td align=\"center\"><font
>         size=\"+1\"><strong>"); writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.size
>                          "));
>         writer.print("</strong></font></td>\r\n");
>         writer.print("<td align=\"right\"><font
>         size=\"+1\"><strong>"); writer.print(Messages.message
> 
> ("org.apache.slide.webdav.GetMethod.lastModified"));
>         writer.print("</strong></font></td>\r\n");
>         writer.print("</tr>\r\n");
> 
>         Enumeration resources = object.enumerateChildren();
>         boolean shade = false;
> 
>         while (resources.hasMoreElements()) {
> 
>             String currentResource = (String)
>             resources.nextElement();
> 
>             NodeRevisionDescriptor currentDescriptor = null;
> 
>             permissionsList = null;
>             locksList = null;
> 
>             try {
> 
>                 NodeRevisionDescriptors revisionDescriptors =
>                     content.retrieve(slideToken,
>                     currentResource);
>                 // Retrieve latest revision descriptor
>                 currentDescriptor =
>                     content.retrieve(slideToken,
>                     revisionDescriptors);
> 
>             } catch (SlideException e) {
> 
>                 // Silent exception : Objects without any
>                 revision are // considered collections, and do
>                 not have any attributes
> 
>                 // Any security based exception will be trapped
>                 here
> 
>                 // Any locking based exception will be trapped
>                 here
> 
>             }
> 
>             try {
> 
>                 permissionsList =
>                     security.enumeratePermissions(slideToken,
> currentResource);
>                 locksList = lock.enumerateLocks(slideToken,
>                 currentResource,
> false);
> 
>             } catch (SlideException e) {
> 
>                 // Any security based exception will be trapped
>                 here
> 
>                 // Any locking based exception will be trapped
>                 here
> 
>             }
> 
>             String trimmed = currentResource.substring(trim); if
>             (trimmed.equalsIgnoreCase("WEB-INF") ||
>                 trimmed.equalsIgnoreCase("META-INF"))
>                 continue;
> 
>             writer.print("<tr");
>             if (shade) {
>                 writer.print(" bgcolor=\"dddddd\"");
>             } else {
>                 writer.print(" bgcolor=\"eeeeee\"");
>             }
>             writer.print(">\r\n");
>             shade = !shade;
> 
>             writer.print("<td align=\"left\"
> colspan=\"3\">&nbsp;&nbsp;\r\n");
>             writer.print("<a href=\"");
>             writer.print(WebdavUtils.encodeURL(contextPath +
> currentResource));
>             writer.print("\"><tt>");
>             writer.print(trimmed);
>             if (WebdavUtils.isCollection(currentDescriptor)) {
>                 writer.print("/");
>             }
>             writer.print("</tt></a></td>\r\n");
> 
>             writer.print("<td align=\"right\"><tt>");
>             if (WebdavUtils.isCollection(currentDescriptor))
>                 writer.print("&nbsp;");
>             else
> 
> writer.print(renderSize(currentDescriptor.getContentLength()));
>             writer.print("</tt></td>\r\n");
> 
>             writer.print("<td align=\"right\"><tt>");
>             if (currentDescriptor != null) {
>                 writer.print(currentDescriptor.getLastModified())
>                 ;
>             } else {
>                 writer.print("&nbsp;");
>             }
>             writer.print("</tt></td>\r\n");
> 
>             writer.print("</tr>\r\n");
> 
>             // Displaying ACL info
>             if(
>             org.apache.slide.util.Configuration.useIntegratedSecu
>             rity()
> )
>                 displayPermissions(permissionsList, writer,
>                 shade);
> 
>             // Displaying lock info
>             displayLocks(locksList, writer, shade);
> 
>         }
> 
>         // Render the page footer
>         writer.print("<a href=\"/slide/fileUpload.jsp\"
> target=\"_blank\"><font face=\"Arial, Helvetica,
> sans-serif\">Upload a document to this folder</font></a>\r\n");
>         writer.print("<tr><td
>         colspan=\"5\">&nbsp;</td></tr>\r\n");
>         writer.print("<tr><td colspan=\"3\"
>         bgcolor=\"#cccccc\">"); writer.print("<font
>         size=\"-1\">"); writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.vers
>                          ion"));
>         writer.print("</font></td>\r\n");
>         writer.print("<td colspan=\"2\" align=\"right\"
> bgcolor=\"#cccccc\">");
>         writer.print("<font size=\"-1\">");
>         writer.print(formatter.format(new Date()));
>         writer.print("</font></td></tr>\r\n");
>         writer.print("</table>\r\n");
>         writer.print("<a href=\"/slide/portal.jsp\"
>         target=\"_blank\"><font
> face=\"Arial, Helvetica, sans-serif\">kiss my hairy
> buttcheeks</font></a>");
>         writer.print("</body>\r\n");
>         writer.print("</html>\r\n");
> 
>         // Return an input stream to the underlying bytes
>         writer.flush();
> 
>     }
> 
> 
>     public void doPost(HttpServletRequest req,
>     HttpServletResponse resp)
>         throws ServletException, IOException {
> 
>   for(int i =0; i<5;i++){
>    System.out.println("RECEIVED THE POST!!!");
>   }
> 
>  }
> 
> 
>     /**
>      * Display an ACL list.
>      *
>      * @param permissionsList List of NodePermission objects *
>      @param shade * @param writer The output will be appended to
>      this writer */
>     private void displayPermissions(Enumeration permissionsList,
>                                 PrintWriter writer,
>                                 boolean shade)
>         throws IOException {
> 
>         if ((permissionsList != null) &&
> (permissionsList.hasMoreElements())) {
> 
>             writer.print("<tr" + (shade ? " bgcolor=\"eeeeee\"" 
>                                 : " bgcolor=\"dddddd\"") + 
>                          ">\r\n");
>             writer.print("<td align=\"left\"
>             colspan=\"5\"><tt><b>");
>             writer.print(Messages.message
>                              ("org.apache.slide.webdav.GetMethod.
>                              aclinfo"));
>             writer.print("</b></tt></td>\r\n");
>             writer.print("</tr>\r\n");
> 
>             writer.print("<tr" + (shade ? " bgcolor=\"eeeeee\"" 
>                                 : " bgcolor=\"dddddd\"") + 
>                          ">\r\n");
> 
>             writer.print("<td align=\"left\"
>             colspan=\"2\"><tt><b>");
>             writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.subj
>                          ect"));
>             writer.print("</b></tt></td>\r\n");
> 
>             writer.print("<td align=\"left\"><tt><b>");
>             writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.acti
>                          on"));
>             writer.print("</b></tt></td>\r\n");
> 
>             writer.print("<td align=\"right\"><tt><b>");
>             writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.inhe
>                          ritable"));
>             writer.print("</b></tt></td>\r\n");
> 
>             writer.print("<td align=\"right\"><tt><b>");
>             writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.deny
>                          "));
>             writer.print("</b></tt></td>\r\n");
> 
>             writer.print("</tr>\r\n");
> 
>             while (permissionsList.hasMoreElements()) {
> 
>                 writer.print("<tr" + (shade ? "
>                 bgcolor=\"eeeeee\"" 
>                                 : " bgcolor=\"dddddd\"") + 
>                              ">\r\n");
> 
>                 NodePermission currentPermission =
>                     (NodePermission)
>                     permissionsList.nextElement();
> 
>                 writer.print("<td align=\"left\"
>                 colspan=\"2\"><tt>");
>                 writer.print(currentPermission.getSubjectUri());
>                 writer.print("</tt></td>\r\n");
> 
>                 writer.print("<td align=\"left\"><tt>");
>                 writer.print(currentPermission.getActionUri());
>                 writer.print("</tt></td>\r\n");
> 
>                 writer.print("<td align=\"right\"><tt>");
>                 writer.print(currentPermission.isInheritable());
>                 writer.print("</tt></td>\r\n");
> 
>                 writer.print("<td align=\"right\"><tt>");
>                 writer.print(currentPermission.isNegative());
>                 writer.print("</tt></td>\r\n");
> 
>                 writer.print("</tr>\r\n");
>             }
> 
>         }
> 
>     }
> 
> 
>     /**
>      * Display a lock list.
>      *
>      * @param locksList List of NodeLock objects
>      * @param shade
>      * @param writer The output will be appended to this writer
>      */
>     private void displayLocks(Enumeration locksList, PrintWriter
>     writer,
>                               boolean shade)
>         throws IOException {
> 
>         if ((locksList != null) && (locksList.hasMoreElements()))
>         {
> 
>             writer.print("<tr" + (shade ? " bgcolor=\"eeeeee\"" 
>                                 : " bgcolor=\"dddddd\"") + 
>                          ">\r\n");
>             writer.print("<td align=\"left\"
>             colspan=\"5\"><tt><b>");
>             writer.print(Messages.message
> 
> ("org.apache.slide.webdav.GetMethod.locksinfo"));
>             writer.print("</b></tt></td>\r\n");
>             writer.print("</tr>\r\n");
> 
>             writer.print("<tr");
>             if (!shade) {
>                 writer.print(" bgcolor=\"dddddd\"");
>             } else {
>                 writer.print(" bgcolor=\"eeeeee\"");
>             }
>             writer.print(">\r\n");
> 
>             writer.print("<td align=\"left\"><tt><b>");
>             writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.subj
>                          ect"));
>             writer.print("</b></tt></td>\r\n");
> 
>             writer.print("<td align=\"left\"><tt><b>");
>             writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.type
>                          "));
>             writer.print("</b></tt></td>\r\n");
> 
>             writer.print("<td align=\"right\"><tt><b>");
>             writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.expi
>                          ration"));
>             writer.print("</b></tt></td>\r\n");
> 
>             writer.print("<td align=\"right\"><tt><b>");
>             writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.inhe
>                          ritable"));
>             writer.print("</b></tt></td>\r\n");
> 
>             writer.print("<td align=\"right\"><tt><b>");
>             writer.print(Messages.message
>                          ("org.apache.slide.webdav.GetMethod.excl
>                          usive"));
>             writer.print("</b></tt></td>\r\n");
> 
>             writer.print("</tr>\r\n");
> 
>             while (locksList.hasMoreElements()) {
> 
>                 writer.print("<tr" + (shade ? "
>                 bgcolor=\"eeeeee\"" 
>                                 : " bgcolor=\"dddddd\"") + 
>                              ">\r\n");
> 
>                 NodeLock currentLock = (NodeLock)
>                 locksList.nextElement();
> 
>                 writer.print("<td align=\"left\"><tt>");
>                 writer.print(currentLock.getSubjectUri());
>                 writer.print("</tt></td>\r\n");
> 
>                 writer.print("<td align=\"left\"><tt>");
>                 writer.print(currentLock.getTypeUri());
>                 writer.print("</tt></td>\r\n");
> 
>                 writer.print("<td align=\"right\"><tt>");
>                 writer.print
>                     (formatter.format(currentLock.getExpirationDa
>                     te()));
>                 writer.print("</tt></td>\r\n");
> 
>                 writer.print("<td align=\"right\"><tt>");
>                 writer.print(currentLock.isInheritable());
>                 writer.print("</tt></td>\r\n");
> 
>                 writer.print("<td align=\"right\"><tt>");
>                 writer.print(currentLock.isExclusive());
>                 writer.print("</tt></td>\r\n");
> 
>             }
> 
>         }
> 
>     }
> 
> 
>     // --------------------------------------------------------
>     Private
> Methods
> 
> 
>     /**
>      * Render the specified file size (in bytes).
>      *
>      * @param size File size (in bytes)
>      */
>     private String renderSize(long size) {
> 
>         long leftSide = size / 1024;
>         long rightSide = (size % 1024) / 103;   // Makes 1 digit
>         if ((leftSide == 0) && (rightSide == 0) && (size > 0))
>             rightSide = 1;
> 
>         return ("" + leftSide + "." + rightSide + " kb");
>     }
> 
> 
> }
> 
> -----Original Message-----
> From: Stuart MacPherson [mailto:aprw00@dsl.pipex.com] 
> Sent: 29 August 2003 08:40
> To: 'Slide Users Mailing List'
> Subject: RE: Implementing a search facility
> 
> Err
> 
> I definitely did it that time!  Here it is again...
> 
> Stu
> 
> 
> -----Original Message-----
> From: Andreas Probst [mailto:andpro77@gmx.net] 
> Sent: 29 August 2003 06:12
> To: Slide Users Mailing List
> Subject: RE: Implementing a search facility
> 
> Still not attached.
> 
> On 29 Aug 2003 at 0:46, Stuart MacPherson wrote:
> 
> > Umm... here's the Servlet this time ;oS
> > 
> > 
> > -----Original Message-----
> > From: Stuart MacPherson [mailto:aprw00@dsl.pipex.com] 
> > Sent: 29 August 2003 00:46
> > To: 'Slide Users Mailing List'
> > Subject: Implementing a search facility
> > 
> > I have successfully extended SimpleWebdavServlet, and now it
> > handles the GET requests as well as the standard WevdavServlet.
> >  
> > 
> > I want to implement a search system (that searches document
> > properties) and then spits out a listing in a similar way to
> > GET requests on single collections... except obviously this
> > time it might not be just one collection, and could be many
> > (depending on the docs that match the query). I have written
> > search.jsp, which POSTs the search query form to my
> > WebdavServlet (is this a good idea?), in which I have
> > implemented a doPost() method which will handle searches and
> > nothing else...
> > 
> > Only problem is that is doesn't seem to be getting that far (I
> > have some debug println's that aren't being written).  In fact,
> > when I do a directory listing it seems to taking the request,
> > and (now this is weird) writing it as a text file to the root
> > directory of slide!  It even shows in the directory listing!  I
> > can click it, and open it in notepad... and it is basically the
> > multipart/form-data request that should be getting processed by
> > the Servlet.  The Servlet doesn't actually do anything with the
> > request yet apart from the println's, but this other stuff
> > deffo shouldn't be happening!
> > 
> > I have attached my SimpleWebdavServlet file, but it's basically
> > stock apart from a few things between custom code markers, and
> > some links that the writer prints as part of the directory
> > listing response... nothing that should bust it up.
> > 
> > I pretty much guarantee you that I won't solve this one by
> > myself (as seems to be my trademark)...  so I hope someone can
> > help!
> > 
> > Regards
> > Stu
> > 
> > 
> > 
> 
> 
> 
> -----------------------------------------------------------------
> ---- To unsubscribe, e-mail:
> slide-user-unsubscribe@jakarta.apache.org For additional
> commands, e-mail: slide-user-help@jakarta.apache.org
> 
> 
> 
> 
> 
> -----------------------------------------------------------------
> ---- To unsubscribe, e-mail:
> slide-user-unsubscribe@jakarta.apache.org For additional
> commands, e-mail: slide-user-help@jakarta.apache.org
>