drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/model/TreeParent.java
public void listDirectory(TreeParent node,
                                  IElementCollector collector,
                                 IProgressMonitor monitor) {
            monitor.beginTask(Messages.getString("pending"), 1); //$NON-NLS-1$

            monitor.worked(1);
            GuvnorRepository rep = node.getGuvnorRepository();
            try {
                IWebDavClient webdav = WebDavServerCache.getWebDavClient(rep.getLocation());
                if (webdav == null) {
                    webdav = WebDavClientFactory.createClient(new URL(rep.getLocation()));
                    WebDavServerCache.cacheWebDavClient(rep.getLocation(), webdav);
                }
                Map<String, ResourceProperties> listing = null;
                try {
                    listing = webdav.listDirectory(node.getFullPath());
                } catch (WebDavException wde) {
                    if (wde.getErrorCode() != IResponse.SC_UNAUTHORIZED) {
                        // If not an authentication failure, we don't know what to do with it
                        throw wde;
                    }
                    boolean retry = PlatformUtils.getInstance().authenticateForServer(
                                                node.getGuvnorRepository().getLocation(), webdav);
                    if (retry) {
                        listing = webdav.listDirectory(node.getFullPath());
                    }
                }
                if (listing != null) {
                    for (String s: listing.keySet()) {
                        ResourceProperties resProps = listing.get(s);
                        TreeObject o = null;
                        if (resProps.isDirectory()) {
                            Type childType;
                            switch (getNodeType()) {
                            case REPOSITORY:
                                if (s.startsWith("snapshot")) {
                                    childType = Type.SNAPSHOTS;
                                } else if (s.startsWith("packages")) {
                                    childType = Type.PACKAGES;
                                } else if (s.startsWith("globalarea")) {
                                    childType = Type.GLOBALS;
                                } else {
                                    childType = Type.PACKAGE;
                                }
                                break;
                            case SNAPSHOTS:
                                childType = Type.SNAPSHOT_PACKAGE;
                                break;
                            case SNAPSHOT_PACKAGE:
                                childType = Type.SNAPSHOT;
                                break;
                            default:
                                childType = Type.PACKAGE;
                            }
                            o = new TreeParent(s, childType);
                        } else {
                            o = new TreeObject(s, Type.RESOURCE);
                        }
                        o.setGuvnorRepository(rep);
                        o.setResourceProps(resProps);
                        node.addChild(o);
                        collector.add(o, monitor);
                    }
                }
                monitor.worked(1);
            } catch (WebDavException e) {
                if (e.getErrorCode() == IResponse.SC_UNAUTHORIZED) {
                    PlatformUtils.reportAuthenticationFailure();
                } else {
                    if (e.getErrorCode() == IResponse.SC_NOT_IMPLEMENTED) {
                        Activator.getDefault().displayMessage(IStatus.ERROR,
                                                           Messages.getString("rep.connect.fail")); //$NON-NLS-1$
                    } else {
                        Activator.getDefault().displayError(IStatus.ERROR, e.getMessage(), e, true);
                    }
                }
            } catch (ConnectException ce) {
                Activator.getDefault().
                    displayMessage(IStatus.ERROR,
                                  Messages.getString("rep.connect.fail")); //$NON-NLS-1$
            } catch (Exception e) {
                Activator.getDefault().displayError(IStatus.ERROR, e.getMessage(), e, true);
            }
        }
public void listDirectory(TreeParent node,
                                  IElementCollector collector,
                                 IProgressMonitor monitor) {
            monitor.beginTask(Messages.getString("pending"), 1); //$NON-NLS-1$

            monitor.worked(1);
            GuvnorRepository rep = node.getGuvnorRepository();
            try {
                IWebDavClient webdav = WebDavServerCache.getWebDavClient(rep.getLocation());
                if (webdav == null) {
                    webdav = WebDavClientFactory.createClient(new URL(rep.getLocation()));
                    WebDavServerCache.cacheWebDavClient(rep.getLocation(), webdav);
                }
                Map<String, ResourceProperties> listing = null;
                try {
                    listing = webdav.listDirectory(node.getFullPath());
                } catch (WebDavException wde) {
                    if (wde.getErrorCode() != IResponse.SC_UNAUTHORIZED) {
                        // If not an authentication failure, we don't know what to do with it
                        throw wde;
                    }
                    boolean retry = PlatformUtils.getInstance().authenticateForServer(
                                                node.getGuvnorRepository().getLocation(), webdav);
                    if (retry) {
                        listing = webdav.listDirectory(node.getFullPath());
                    }
                }
                if (listing != null) {
                    for (String s: listing.keySet()) {
                        ResourceProperties resProps = listing.get(s);
                        TreeObject o = null;
                        if (resProps.isDirectory()) {
                            Type childType;
                            switch (getNodeType()) {
                            case REPOSITORY:
                                if (s.startsWith("snapshot")) {
                                    childType = Type.SNAPSHOTS;
                                } else if (s.startsWith("packages")) {
                                    childType = Type.PACKAGES;
                                } else if (s.startsWith("globalarea")) {
                                    childType = Type.GLOBALS;
                                } else {
                                    childType = Type.PACKAGE;
                                }
                                break;
                            case SNAPSHOTS:
                                childType = Type.SNAPSHOT_PACKAGE;
                                break;
                            case SNAPSHOT_PACKAGE:
                                childType = Type.SNAPSHOT;
                                break;
                            default:
                                childType = Type.PACKAGE;
                            }
                            o = new TreeParent(s, childType);
                        } else {
                            o = new TreeObject(s, Type.RESOURCE);
                        }
                        o.setGuvnorRepository(rep);
                        o.setResourceProps(resProps);
                        node.addChild(o);
                        collector.add(o, monitor);
                    }
                }
                monitor.worked(1);
            } catch (WebDavException e) {
                if (e.getErrorCode() == IResponse.SC_UNAUTHORIZED) {
                    PlatformUtils.reportAuthenticationFailure();
                } else {
                    if (e.getErrorCode() == IResponse.SC_NOT_IMPLEMENTED) {
                        Activator.getDefault().displayMessage(IStatus.ERROR,
                                                           Messages.getString("rep.connect.fail")); //$NON-NLS-1$
                    } else {
                        Activator.getDefault().displayError(IStatus.ERROR, e.getMessage(), e, true);
                    }
                }
            } catch (ConnectException ce) {
                Activator.getDefault().
                    displayMessage(IStatus.ERROR,
                                  Messages.getString("rep.connect.fail")); //$NON-NLS-1$
            } catch (Exception e) {
                Activator.getDefault().displayError(IStatus.ERROR, e.getMessage(), e, true);
            }
        }
Creates a directory listing.
@param node The directory to list.
@param collector The collector for the elements listed.
@param monitor Progress monitor for the operation.