public interface Folder extends HierarchyItem
Defines methods that WebDAV server folder items must implement.
In addition to methods provided by HierarchyItem
this interface also provides
methods for creating folders and files and enumerating folder children.
Modifier and Type | Method and Description |
---|---|
File |
createFile(String name)
Creates new WebDAV file with the specified name in this folder.
|
Folder |
createFolder(String name)
Creates new WebDAV folder with the specified name in this folder.
|
PageResults |
getChildren(List<Property> propNames,
Long offset,
Long nResults,
List<OrderProperty> orderProps)
Gets the array of this folder's children.
|
copyTo, delete, getCreated, getModified, getName, getPath, getProperties, getPropertyNames, moveTo, updateProperties
PageResults getChildren(List<Property> propNames, Long offset, Long nResults, List<OrderProperty> orderProps) throws ServerException
propNames
- List of properties to retrieve with the children. They will be queried by the engine later.offset
- The number of items to skip before returning the remaining items.nResults
- The number of items to return.orderProps
- List of order properties requested by the client.PageResults
class that contains items on a requested page and total number of items in a folder.ServerException
- In case of an error.
@Override public PageResults getChildren(List<Property> propNames, Long offset, Long nResults, List<OrderProperty> orderProps) throws ServerException { String decodedPath = HierarchyItemImpl.decodeAndConvertToPath(getPath()); Path fullFolderPath = Paths.get(getRootFolder() + decodedPath); List<HierarchyItemImpl> children = new ArrayList<>(); Long total = null; try (DirectoryStream<Path> ds = Files.newDirectoryStream(fullFolderPath)) { List<Path> paths = StreamSupport.stream(ds.spliterator(), false).collect(Collectors.toList()); paths = sortChildren(paths, orderProps); for (Path p : paths) { String childPath = getPath() + encode(p.getFileName().toString()); HierarchyItemImpl item = (HierarchyItemImpl) getEngine().getHierarchyItem(childPath); children.add(item); } total = (long) paths.size(); if (offset != null && nResults != null) { children = children.stream().skip(offset).limit(nResults).collect(Collectors.toList()); } } catch (IOException e) { getEngine().getLogger().logError(e.getMessage(), e); } return new PageResults(children, total); }
File createFile(String name) throws LockedException, ServerException
name
- Name of the file to create.File
.LockedException
- This folder was locked. Client did not provide the lock token.ServerException
- In case of an error.
@Override public FileImpl createFile(String name) throws LockedException, ServerException { ensureHasToken(); Path fullPath = Paths.get(this.getFullPath().toString(), name); if (!Files.exists(fullPath)) { try { Files.createFile(fullPath); } catch (IOException e) { throw new ServerException(e); } final String itemPath = getPath() + encode(name); getEngine().getWebSocketServer().notifyCreated(itemPath, getWebSocketID()); return FileImpl.getFile(itemPath, getEngine()); } return null; }
Folder createFolder(String name) throws LockedException, ServerException
name
- Name of the folder to create.LockedException
- This folder was locked. Client did not provide the lock token.ServerException
- In case of an error.
@Override public Folder createFolder(String name) throws LockedException, ServerException { createFolderInternal(name); getEngine().getWebSocketServer().notifyCreated(getPath() + encode(name), getWebSocketID()); return FolderImpl.getFolder(getPath() + encode(name), getEngine()); } private void createFolderInternal(String name) throws LockedException, ServerException { ensureHasToken(); Path fullPath = Paths.get(this.getFullPath().toString(), name); if (!Files.exists(fullPath)) { try { Files.createDirectory(fullPath); } catch (IOException e) { throw new ServerException(e); } } }
Copyright © ITHit. All Rights Reserved.