Interface Folder

All Superinterfaces:
HierarchyItem
All Known Subinterfaces:
Search, SynchronizationCollection

public interface Folder extends HierarchyItem
Represents a folder in the WebDAV repository.

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.

  • Method Details

    • getChildren

      PageResults getChildren(List<Property> propNames, Long offset, Long nResults, List<OrderProperty> orderProps) throws ServerException
      Gets the array of this folder's children.
      Parameters:
      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.
      Returns:
      Instance of PageResults class that contains items on a requested page and total number of items in a folder.
      Throws:
      ServerException - In case of an error.

      The code below is part of Collection Synchronization sample provided with the SDK.
          @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;
              DirectoryStream.Filter<Path> notHiddenFilter = entry -> !isHidden(entry);
              try (DirectoryStream<Path> ds = Files.newDirectoryStream(fullFolderPath, notHiddenFilter)) {
                  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);
          }
      
      
    • createFile

      File createFile(String name) throws LockedException, ServerException
      Creates new WebDAV file with the specified name in this folder.
      Parameters:
      name - Name of the file to create.
      Returns:
      Reference to created File.
      Throws:
      LockedException - This folder was locked. Client did not provide the lock token.
      ServerException - In case of an error.

      The code below is part of Collection Synchronization sample provided with the SDK.
          @Override
          public FileImpl createFile(String name) throws LockedException, ServerException {
              ensureHasToken();
      
              Path fullPath = deleteIfHidden(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;
          }
      
      
    • createFolder

      Folder createFolder(String name) throws LockedException, ServerException
      Creates new WebDAV folder with the specified name in this folder.
      Parameters:
      name - Name of the folder to create.
      Returns:
      Instance of newly created Folder.
      Throws:
      LockedException - This folder was locked. Client did not provide the lock token.
      ServerException - In case of an error.

      The code below is part of Collection Synchronization sample provided with the SDK.
          @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 = deleteIfHidden(name);
              if (!Files.exists(fullPath)) {
                  try {
                      Files.createDirectory(fullPath);
                  } catch (IOException e) {
                      throw new ServerException(e);
                  }
              }
          }