Package org.guvnor.tools.utils.webdav

Examples of org.guvnor.tools.utils.webdav.IWebDavClient


        }
    }

    private String getResourceContents(TreeObject node) throws Exception {
        GuvnorRepository rep = node.getGuvnorRepository();
        IWebDavClient webdav = WebDavServerCache.getWebDavClient(rep.getLocation());
        if (webdav == null) {
            webdav = WebDavClientFactory.createClient(new URL(rep.getLocation()));
            WebDavServerCache.cacheWebDavClient(rep.getLocation(), webdav);
        }
        String res = webdav.getResourceContents(node.getFullPath());
        return res;
    }
View Full Code Here


                                    String password, boolean saveInfo) throws Exception {
        Map<String, String> info = new HashMap<String, String>();
        info.put("username", username); //$NON-NLS-1$
        info.put("password", password); //$NON-NLS-1$
        URL serverUrl = new URL(server);
        IWebDavClient client = WebDavServerCache.getWebDavClient(server);
        if (client == null) {
            client = WebDavClientFactory.createClient(serverUrl);
            WebDavServerCache.cacheWebDavClient(server, client);
        }
        if (saveInfo) {
            Platform.flushAuthorizationInfo(serverUrl, "", "basic"); //$NON-NLS-1$ //$NON-NLS-2$
            Platform.addAuthorizationInfo(serverUrl, "", "basic", info); //$NON-NLS-1$ //$NON-NLS-2$
        } else {
            WebDavSessionAuthenticator authen = new WebDavSessionAuthenticator();
            authen.addAuthenticationInfo(new URL(server), "", "basic", info); //$NON-NLS-1$ //$NON-NLS-2$
            client.setSessionAuthenticator(authen);
        }
    }
View Full Code Here

        ISelection selection = viewer.getSelection();
        Object obj = ((IStructuredSelection)selection).getFirstElement();
        if (obj instanceof ResourceHistoryEntry) {
            ResourceHistoryEntry theEntry = (ResourceHistoryEntry)obj;
            try {
                IWebDavClient client = WebDavServerCache.getWebDavClient(repository);
                if (client == null) {
                    client = WebDavClientFactory.createClient(new URL(repository));
                    WebDavServerCache.cacheWebDavClient(repository, client);
                }
                String contents = null;
                try {
                    contents = client.getResourceVersionContents(fullPath, theEntry.getRevision());
                } 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(repository, client);
                    if (retry) {
                        contents = client.getResourceVersionContents(fullPath, theEntry.getRevision());
                    }
                }
                if (contents != null) {
                    String editorTitle = null;
                    int pos = fullPath.lastIndexOf("/"); //$NON-NLS-1$
View Full Code Here

                                             String targetLoc,
                                             IFile selectedFile) {
        boolean res = false;
        try {
            String fullPath = targetLoc + selectedFile.getName();
            IWebDavClient client = WebDavServerCache.getWebDavClient(repLoc);
            if (client == null) {
                client = WebDavClientFactory.createClient(new URL(repLoc));
                WebDavServerCache.cacheWebDavClient(repLoc, client);
            }
            try {
//                res = client.createResource(fullPath, selectedFile.getContents(), false);
                // Hack: When creating a file, if the actual contents are passed first,
                // the client hangs for about 20 seconds when closing the InputStream.
                // Don't know why...
                // But, if the file is created with empty contents, and then the contents
                // set, the operation is fast (less than a couple of seconds)
                res = client.createResource(fullPath, new ByteArrayInputStream(new byte[0]), false);
                if (res) {
                    client.putResource(fullPath, selectedFile.getContents());
                }
            } 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(repLoc, client);
                if (retry) {
//                    res = client.createResource(fullPath, selectedFile.getContents(), false);
                    // See Hack note immediately above...
                    res = client.createResource(fullPath, new ByteArrayInputStream(new byte[0]), false);
                    if (res) {
                        client.putResource(fullPath, selectedFile.getContents());
                    }
                }
            }
            if (res) {
                GuvnorMetadataUtils.markCurrentGuvnorResource(selectedFile);
                ResourceProperties resProps = client.queryProperties(fullPath);
                GuvnorMetadataProps mdProps =
                        new GuvnorMetadataProps(selectedFile.getName(),
                                               repLoc,
                                               fullPath, resProps.getLastModifiedDate(),
                                               resProps.getRevision());
View Full Code Here

     * @param selectedFile The Guvnor controlled file with pending changes
     */
    public static void commitFileChanges(IFile selectedFile) {
        try {
            GuvnorMetadataProps props = GuvnorMetadataUtils.getGuvnorMetadata(selectedFile);
            IWebDavClient client = WebDavServerCache.getWebDavClient(props.getRepository());
            if (client == null) {
                client = WebDavClientFactory.createClient(new URL(props.getRepository()));
                WebDavServerCache.cacheWebDavClient(props.getRepository(), client);
            }
            ResourceProperties remoteProps = null;
            try {
                remoteProps = client.queryProperties(props.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(props.getRepository(), client);
                if (retry) {
                    remoteProps = client.queryProperties(props.getFullpath());
                }
            }
            if (remoteProps == null) {
                throw new Exception("Could not retrieve server version of " + props.getFullpath()); //$NON-NLS-1$
            }
            // Check to make sure that the version in the repository is the same as the base
            // version for the local copy
            boolean proceed = true;
            if (!props.getRevision().equals(remoteProps.getRevision())) {
                String msg = MessageFormat.format(Messages.getString("overwrite.confirmation"), //$NON-NLS-1$
                                                 new Object[] { selectedFile.getName(),
                                                                remoteProps.getRevision(),
                                                                props.getRevision() });
                Display display = PlatformUI.getWorkbench().getDisplay();
                proceed = MessageDialog.openQuestion(display.getActiveShell(),
                                                    Messages.getString("overwrite.confirmation.caption"), msg); //$NON-NLS-1$

            }
            if (proceed) {
                client.putResource(props.getFullpath(), selectedFile.getContents());
                GuvnorMetadataUtils.markCurrentGuvnorResource(selectedFile);
                ResourceProperties resProps = client.queryProperties(props.getFullpath());
                GuvnorMetadataProps mdProps = GuvnorMetadataUtils.getGuvnorMetadata(selectedFile);
                mdProps.setVersion(resProps.getLastModifiedDate());
                mdProps.setRevision(resProps.getRevision());
                GuvnorMetadataUtils.setGuvnorMetadataProps(selectedFile.getFullPath(), mdProps);
            }
View Full Code Here

            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);
View Full Code Here

TOP

Related Classes of org.guvnor.tools.utils.webdav.IWebDavClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.