com.github.sardine.SardineFactory Java Examples
The following examples show how to use
com.github.sardine.SardineFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AWebdavHandler.java From nextcloud-java-api with GNU General Public License v3.0 | 6 votes |
/** * Create a authenticate sardine connector * * @return sardine connector to server including authentication */ protected Sardine buildAuthSardine() { Sardine sardine = SardineFactory.begin(); sardine.setCredentials(_serverConfig.getUserName(), _serverConfig.getPassword()); sardine.enablePreemptiveAuthentication(_serverConfig.getServerName()); return sardine; }
Example #2
Source File: WebDavServiceImpl.java From studio with GNU General Public License v3.0 | 4 votes |
/** * {@inheritDoc} */ @Override public String upload(@ValidateStringParam(name = "site_id") final String site, @ValidateStringParam(name = "profile") final String profileId, @ValidateStringParam(name = "path") final String path, @ValidateStringParam(name = "filename") final String filename, final InputStream content) throws WebDavException { WebDavProfile profile = getProfile(site, profileId); String uploadUrl = StringUtils.appendIfMissing(profile.getBaseUrl(), "/"); try { Sardine sardine = SardineFactory.begin(profile.getUsername(), profile.getPassword()); if(StringUtils.isNotEmpty(path)) { String[] folders = StringUtils.split(path, "/"); for(String folder : folders) { uploadUrl += StringUtils.appendIfMissing(folder, "/"); logger.debug("Checking folder {0}", uploadUrl); if(!sardine.exists(uploadUrl)) { logger.debug("Creating folder {0}", uploadUrl); sardine.createDirectory(uploadUrl); logger.debug("Folder {0} created", uploadUrl); } else { logger.debug("Folder {0} already exists", uploadUrl); } } } uploadUrl = StringUtils.appendIfMissing(uploadUrl, "/"); String fileUrl = uploadUrl + UriUtils.encode(filename, charset.name()); logger.debug("Starting upload of file {0}", filename); logger.debug("Uploading file to {0}", fileUrl); sardine.put(fileUrl, content); logger.debug("Upload complete for file {0}", fileUrl); if(StringUtils.isNotEmpty(profile.getDeliveryBaseUrl())) { fileUrl = StringUtils.replaceFirst(fileUrl, profile.getBaseUrl(), profile.getDeliveryBaseUrl()); } return fileUrl; } catch (Exception e ) { throw new WebDavException("Error uploading file", e); } }