+ private String getBackupFilename(FileHeaderDTO file, String filename){
+ List<FileHeaderDTO> deletedFiles = new ArrayList<FileHeaderDTO>();
+ try{
+ deletedFiles = getService().getDeletedFiles(file.getOwner().getId());
+ }
+ catch(ObjectNotFoundException e){
+
+ } catch (RpcException e) {
+
+ }
+ List<FileHeaderDTO> filesInSameFolder = new ArrayList<FileHeaderDTO>();
+ for(FileHeaderDTO deleted : deletedFiles)
+ if(deleted.getFolder().getId().equals(file.getFolder().getId()))
+ filesInSameFolder.add(deleted);
+ int i=1;
+ String filenameToCheck = filename;
+ for(FileHeaderDTO same : filesInSameFolder)
+ if(same.getName().startsWith(filename)){
+ String toCheck=same.getName().substring(filename.length(),same.getName().length());
+ if(toCheck.startsWith(" ")){
+ int test =-1;
+ try{
+ test = Integer.valueOf(toCheck.replace(" ",""));
+ }
+ catch(NumberFormatException e){
+ //do nothing since string is not a number
+ }
+ if(test>=i)
+ i = test+1;
+ }
+ }
+
+ return filename+" "+i;
+ }
+