本文整理汇总了Java中com.github.sardine.DavResource类的典型用法代码示例。如果您正苦于以下问题:Java DavResource类的具体用法?Java DavResource怎么用?Java DavResource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DavResource类属于com.github.sardine包,在下文中一共展示了DavResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listFolderContent
import com.github.sardine.DavResource; //导入依赖的package包/类
/**
* List all file names and subfolders of the specified path traversing into subfolders to the given depth.
*
* @param path path of the folder
* @param depth depth of recursion while listing folder contents
* @return found file names and subfolders
*/
public List<String> listFolderContent(String path, int depth)
{
String url = (_serverConfig.isUseHTTPS() ? "https" : "http") +"://"+_serverConfig.getServerName()+"/"+WEB_DAV_BASE_PATH+path ;
List<String> retVal= new LinkedList<>();
Sardine sardine = SardineFactory.begin();
sardine.setCredentials(_serverConfig.getUserName(), _serverConfig.getPassword());
List<DavResource> resources;
try {
resources = sardine.list(url, depth);
} catch (IOException e) {
throw new NextcloudApiException(e);
}
for (DavResource res : resources)
{
retVal.add(res.getName());
}
return retVal;
}
示例2: getChildrenAttributes
import com.github.sardine.DavResource; //导入依赖的package包/类
@Override
protected List<ServerFileAttributes> getChildrenAttributes(ServerPath folder) throws IOException {
List<DavResource> resources = getSardine().list(folder.toUri().toString(), 1);
/*
* Older lighttpd servers seems NOT to include the parent as first element!
* We therefore check if the first resource matches the parent folder.
*/
if (resources.isEmpty()) {
return Collections.emptyList();
}
int start = 1; // collection includes parent folder
if (resources.get(0).isDirectory()) {
if (fileSystem.getPath(resources.get(0).getPath()).toRealPath().getNameCount() == folder.toRealPath().getNameCount() + 1) {
start = 0;
}
} else {
start = 0;
}
List<ServerFileAttributes> attributes = new ArrayList<>(resources.size() - start);
for (int i = start; i < resources.size(); i++) {
attributes.add(new DAVFileAttributes(resources.get(i)));
}
return attributes;
}
示例3: getAttributes
import com.github.sardine.DavResource; //导入依赖的package包/类
private PathAttributes getAttributes(Path path, DavResource p) {
PathAttributesImplementation attributes = new PathAttributesImplementation();
attributes.setPath(path);
attributes.setDirectory(p.isDirectory());
attributes.setRegular(!p.isDirectory());
attributes.setCreationTime(p.getCreation().getTime());
attributes.setLastModifiedTime(p.getModified().getTime());
attributes.setLastAccessTime(attributes.getLastModifiedTime());
attributes.setSize(p.getContentLength());
// Not sure if this is right ?
attributes.setReadable(true);
attributes.setWritable(false);
return attributes;
}
示例4: listDirectory
import com.github.sardine.DavResource; //导入依赖的package包/类
@Override
protected List<PathAttributes> listDirectory(Path path) throws XenonException {
List<DavResource> list = null;
try {
list = client.list(getDirectoryPath(path), 1);
} catch (Exception e) {
throw new XenonException(ADAPTOR_NAME, "Failed to list directory: " + path, e);
}
ArrayList<PathAttributes> result = new ArrayList<>(list.size());
String dirPath = path.toString() + "/";
for (DavResource d : list) {
// The list also returns the directory itself, so ensure we don't
// return it!
if (!dirPath.equals(d.getPath())) {
String filename = d.getName();
result.add(getAttributes(path.resolve(filename), d));
}
}
return result;
}
示例5: hasToProcessFile
import com.github.sardine.DavResource; //导入依赖的package包/类
/**
* Checks if the file has to be processed, verifying the content type
* (application/xml) and the date filter configured in the the Ingest.
*
* @param res WebDav resource.
* @return <code>true</code> is the file has to be processed,
* <code>false</code> otherwise.
*/
private boolean hasToProcessFile(DavResource res) {
if (res.isDirectory()) {
return false;
}
if (!res.getContentType().equalsIgnoreCase("application/xml")) {
return false;
}
IngestWebDav ingestWebdav = (IngestWebDav) ingest;
Date beginFilterDate = ingestWebdav.getDateFrom();
Date endFilterDate = ingestWebdav.getDateTo();
Date resourceDate = res.getModified();
if ((beginFilterDate != null) && (resourceDate.before(beginFilterDate))) {
return false;
}
return (endFilterDate == null) || (resourceDate.after(endFilterDate));
}
示例6: toAttributes
import com.github.sardine.DavResource; //导入依赖的package包/类
protected PathAttributes toAttributes(final DavResource resource) {
final PathAttributes attributes = new PathAttributes();
final Map<QName, String> properties = resource.getCustomPropsNS();
if(properties.containsKey(DAVTimestampFeature.LAST_MODIFIED)) {
final String value = properties.get(DAVTimestampFeature.LAST_MODIFIED);
try {
attributes.setModificationDate(
new RFC1123DateFormatter().parse(value).getTime());
}
catch(InvalidDateException e) {
log.warn(String.format("Failure parsing property %s", value));
if(resource.getModified() != null) {
attributes.setModificationDate(resource.getModified().getTime());
}
}
}
else if(resource.getModified() != null) {
attributes.setModificationDate(resource.getModified().getTime());
}
if(resource.getCreation() != null) {
attributes.setCreationDate(resource.getCreation().getTime());
}
if(resource.getContentLength() != null) {
attributes.setSize(resource.getContentLength());
}
if(StringUtils.isNotBlank(resource.getEtag())) {
attributes.setETag(resource.getEtag());
}
if(StringUtils.isNotBlank(resource.getDisplayName())) {
attributes.setDisplayname(resource.getDisplayName());
}
if(StringUtils.isNotBlank(resource.getDisplayName())) {
attributes.setDisplayname(resource.getDisplayName());
}
return attributes;
}
示例7: listFolder
import com.github.sardine.DavResource; //导入依赖的package包/类
private List<String> listFolder(String url) throws IOException {
List<String> files = new ArrayList<>();
List<DavResource> resources = getSardine().list(url);
for (DavResource res : resources) {
files.add(res.getName());
}
return files;
}
示例8: testNewFileIsInDir
import com.github.sardine.DavResource; //导入依赖的package包/类
@Test
public void testNewFileIsInDir() throws IOException {
sardine.put( getMethodUrl() + "newFile", content );
boolean found = false;
List<DavResource> resources = sardine.list( getMethodUrl() );
for( DavResource res : resources ) {
if( res.toString().endsWith( "newFile" ) ) {
found = true;
}
}
assertThat( found ).isEqualTo( true );
}
示例9: testSetLastModified
import com.github.sardine.DavResource; //导入依赖的package包/类
@Test
public void testSetLastModified() throws IOException {
DavResource dir = sardine.list( getMethodUrl() ).get( 0 );
long modi = dir.getModified().getTime() - 4000;
String theLastModified = IOUtil.getLastModified( modi );
HashMap<QName, String> patch = new HashMap<>();
patch.put( SardineUtil.createQNameWithDefaultNamespace( "getlastmodified" ), theLastModified );//format.format(now.getTime()));
DavResource resource = sardine.patch( getMethodUrl(), patch ).get( 0 );
assertThat( resource.getModified() ).isCloseTo( Date.from( Instant.ofEpochMilli( modi ) ), 1000 );
}
示例10: testCreationDate
import com.github.sardine.DavResource; //导入依赖的package包/类
@Test
public void testCreationDate() throws IOException {
List<DavResource> dir = sardine.list( getMethodUrl() );
Date created = dir.get( 0 ).getCreation();
assertThat( created ).isCloseTo( new Date(), 2000 );
}
示例11: putInputStream
import com.github.sardine.DavResource; //导入依赖的package包/类
@Override
public long putInputStream(InputStream sourceInputStream, ContentReference targetContentReference)
throws ContentIOException
{
if (!isContentReferenceSupported(targetContentReference))
{
throw new ContentIOException("ContentReference not supported");
}
try
{
String remoteFileUrl = getRemoteFileUrl(targetContentReference);
logger.debug("Putting input stream to " + remoteFileUrl);
sardine.put(remoteFileUrl, sourceInputStream);
List<DavResource> resources = sardine.list(remoteFileUrl);
if (resources == null || resources.size() > 1)
{
throw new ContentIOException("Unable to determine result of transfer");
}
DavResource davResource = resources.iterator().next();
return davResource.getContentLength();
}
catch (IOException e)
{
logger.error(e.getMessage(), e);
throw new ContentIOException("Failed to write content: " + e.getMessage(), e);
}
}
示例12: getFileAttributes
import com.github.sardine.DavResource; //导入依赖的package包/类
@Override
protected BasicFileAttributes getFileAttributes(ServerPath path) throws IOException {
List<DavResource> list = getSardine().list(path.toUri().toString(), 0);
if (list.size() != 1) {
throw new IOException("Could not get file attributes for path: " + path);
}
return new DAVFileAttributes(list.get(0));
}
示例13: processFile
import com.github.sardine.DavResource; //导入依赖的package包/类
/**
* Process the remote WebDav file, validating it and ingesting in the
* system.
*
* @param res WebDav resource.
* @param baseUrl Base url of the WebDav resource.
* @return count of invalid records processed.
*/
private long processFile(DavResource res, String baseUrl) {
long failedRecordsCount = 0;
Document document = null;
try {
// Retrieve file content
String absoluteHrefPath = getResourceAbsoluteUrl(res, baseUrl);
document = XmlUtil.load(absoluteHrefPath);
MetadataParser parser = parserProvider.getMetadataParser(document);
MetadataParserResponse parserResult = parser.parse(document);
Metadata metadata = parserResult.getMetadata();
metadata.setInstitution(ingest.getNameOgpRepository());
boolean valid = metadataValidator.validate(metadata, report);
if (valid) {
metadataIngester.ingest(ImmutableList.of(metadata),
getIngestReport());
} else {
failedRecordsCount++;
}
} catch (Exception e) {
failedRecordsCount++;
logger.error("Error in Webdav Ingest: " + this.ingest.getName()
+ " (processing file:" + baseUrl + ")", e);
saveException(e, IngestReportErrorType.SYSTEM_ERROR, document);
}
return failedRecordsCount;
}
示例14: DAVFileAttributes
import com.github.sardine.DavResource; //导入依赖的package包/类
DAVFileAttributes(DavResource res) {
this.resource = res;
}
示例15: init
import com.github.sardine.DavResource; //导入依赖的package包/类
/**
* Initialises the service: checks if default configuration is available.
*/
@PostConstruct
public void init() {
logger.debug("Initialising configuration service");
if (localConfiguration == null) {
logger.error("Failed to get local configuration, check 'application.properties' file is on classpath");
} else {
EccConfiguration eccConfiguration = localConfiguration.getConfiguration();
if (eccConfiguration == null) {
logger.error("Failed to get default ECC configuration from local configuration, check 'application.properties' file contains ecc.configuration.* entries");
} else {
// logger.debug("Found default ECC configuration:\n" + eccConfiguration.toJson().toString(2));
ProjectConfigAccessorConfiguration projectConfigAccessorConfiguration = localConfiguration.getProjectconfig();
if (projectConfigAccessorConfiguration == null) {
logger.error("Failed to get default ProjectConfigAccessorConfiguration from local configuration, check 'application.properties' file contains ecc.projectconfig.* entries");
} else {
logger.debug("Found default ProjectConfigAccessorConfiguration configuration:\n" + projectConfigAccessorConfiguration.toJson().toString(2));
// TODO: validate eccConfiguration, projectConfigAccessorConfiguration
localEccConfiguration = eccConfiguration;
configUsername = projectConfigAccessorConfiguration.getUsername();
configPassword = projectConfigAccessorConfiguration.getPassword();
initialised = true;
logger.debug("Configuration service initialised successfully, checking webdav service availability");
Sardine sardine = SardineFactory.begin(projectConfigAccessorConfiguration.getUsername(), projectConfigAccessorConfiguration.getPassword());
try {
List<DavResource> resources = sardine.getResources(projectConfigAccessorConfiguration.getEndpoint());
for (DavResource res : resources) {
if (projectConfigAccessorConfiguration.getSortedWhiteList().contains(res.getName())) {
logger.debug("Adding project '" + res.getName() + "' to the list of online configurations");
whiteListedOnlineProjects.add(res.getName());
}
}
if (whiteListedOnlineProjects.size() > 1) {
Collections.sort(whiteListedOnlineProjects);
}
webdavServiceOnline = true;
} catch (IOException ex) {
logger.error("Failed to connect to webdav service", ex.getMessage());
}
}
}
}
}