Upgrading to WebDAV Server Library for Java v4
IT Hit WebDAV Server Library for Java v4 provides methods for requesting a specified range of items when listing folder content and searching. You can also specify specify sort conditions when listing folder content.
Interfaces Changes
The Folder.getChildren() and Search.search() methods now provide new parameters for specifying number of items to skip before returning the rest of the items (offset) and a number of items to return (page size). The getChildren() method also provides a parameter to pass sorting conditions (sort columns). It also has a different return type: PageResults class which contains items that correspond to the requested range and sorting and a total number of items in a folder.
Upgrading Your Code
To upgrade your server follow these steps:
-
Update the com.ithit.webdav.webdav-server artifact. Reference a new artifact from Maven.
After upgrade your server DAV header will advertise paging support:
DAV: 1,2,3,resumable-upload,paging
Now the WebDAV Ajax Library v5.8 or later can detect paging support. You can use the WebDAV Ajax Library to make paging requests and build paging UI. See Implementing Paging Through Folder Children Items and Search Results article for more details.
-
Update your getChildren() method. Replace your getChildren() method:
public List<? extends HierarchyItemImpl> getChildren(List<Property> propNames) throws ServerException { List<HierarchyItemImpl> children = new ArrayList<>(); ..... return children; }
with a new method:
public PageResults getChildren(List<Property> propNames, Long offset, Long nResults, List<OrderProperty> orderProps) throws ServerException { List<HierarchyItemImpl> children = new ArrayList<>(); // Populate your page list here according to offset, nResults and orderProps. ... // Get total number of items in the folder. Long total = ...; return new PageResults(children, total); }
You need to add 3 new parameters and change the return type.
See how to implement paging in the Implementing Paging Through Folder Children Items and Search Results article.
Note that if you do not need the paging support you can just ignore new parameters and leave your existing implementation. The only change you need to make is to modify the return object to be PageResults type. Pass list of items that you previously were returning from getChildren to PageResults constructor:
List<HierarchyItemImpl> children = new ArrayList<>(); // Populate your page list here. ... return new PageResults(children, (long) children.size());
-
Update your search method. Replace search() method:
public List<HierarchyItem> search( String searchString, SearchOptions options, List<Property> propNames) { List<HierarchyItem> results = new LinkedList<>(); ... return results; }
with:
public PageResults search(String searchString, SearchOptions options, List<Property> propNames, Long offset, Long nResults) { List<HierarchyItem> results = new ArrayList<>(); // Populate search results page according to offset and nResults. ... // Get total number of items in search results. long totalItems = ... return new PageResults(results, totalItems); }
You need to add 2 new parameters and change the return type. As with getChildren() method, if you do not need paging, you can ignore new parameters and pass the list of search results and total number of items in results directly to PageResults object constructor:
List<HierarchyItem> results = new ArrayList<>(); ... return new PageResults(results, (long) results.size());