String fileServiceName = null;
try {
Endpoint provider = findEndpointBean();
IFileType fileService = findService();
if (fileService == null) {
throw new FacesExceptionEx(null, "The file service type is not assigned (null)");
}
// Compose the URL to the service
// (delegate to the service type)
Map<String, String> params = getParameters(fileService, index, blockSize);
ClientService svc;
String serviceUrl = getServiceUrl();
if(StringUtil.isEmpty(serviceUrl)){
//TODO we need to tidy this up - the fileServiceData should not have a serviceUrl attribute - that should only be associated with the FileType
serviceUrl = fileService.getServiceUrl();
}
urlForLog = serviceUrl;
fileServiceName = fileService.getType();
// Check if rootFolder param is being used
if (getRootFolder() == null || getRootFolder().length() < 1) {
// Create the service and and read the file entries
if(StringUtil.isNotEmpty(serviceUrl)){
serviceUrl = ExtLibUtil.concatPath(serviceUrl, getCurrentDirectory(), '/');
}
svc = createService(provider, fileService, serviceUrl);
}
else {
if (getRootFolder().charAt(0) != '/') {
setRootFolder("/" + getRootFolder());
}
String root = getRootFolder();
String curr = getCurrentDirectory();
String path = "";
if (curr.length() > root.length()) {
path = curr.substring(root.length(), curr.length());
}
// Create the service and and read the file entries
svc = createService(provider, fileService, serviceUrl + root + path);
}
List<FileEntry> entries = fileService.readFileEntries(svc, this, params, serviceUrl);
FileEntry[] data = entries.toArray(new FileEntry[entries.size()]);
return new ArrayBlock(index, data);
} catch (Exception ex) {
throw new FacesExceptionEx(ex, "Error while calling the file service: {0}. Failed to access URL: {1}", fileServiceName, urlForLog);
}
}