Subversion Repositories XServices

Rev

Rev 156 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 177
Line 71... Line 71...
71
  /* (non-Javadoc)
71
  /* (non-Javadoc)
72
   * @see net.brutex.xservices.ws.rs.FileInfo#getFiles(javax.ws.rs.core.HttpHeaders, java.lang.String, boolean, boolean, int, java.lang.String, int, int)
72
   * @see net.brutex.xservices.ws.rs.FileInfo#getFiles(javax.ws.rs.core.HttpHeaders, java.lang.String, boolean, boolean, int, java.lang.String, int, int)
73
   */
73
   */
74
  public Response getFiles(HttpHeaders h, UriInfo uriInfo, String dir, boolean withDir, boolean withFiles, int level, String search, int count, int page, boolean useCache)
74
  public Response getFiles(HttpHeaders h, UriInfo uriInfo, String dir, boolean withDir, boolean withFiles, int level, String search, int count, int page, boolean useCache)
75
  {
75
  {
-
 
76
	if(dir==null) {
-
 
77
		dir = "c:/"; 
-
 
78
		logger.warn("No directory specified. Default is 'c:/'.");
76
	
79
		}
77
	isPermitted(dir);
80
	isPermitted(dir);
Line 78... Line 81...
78
	
81
	
Line 79... Line -...
79
    URI baseuri = URI.create(uriInfo.getBaseUri()+FileInfo.BASE_PATH+"getFile?file=");
-
 
80
    
82
    URI baseuri = URI.create(uriInfo.getBaseUri()+FileInfo.BASE_PATH+"getFile?file=");
81
    if(dir==null) {dir = "c:/"; System.out.println("No directory specified.");}
83
    
Line 82... Line 84...
82
    logger.info(String.format("Listing directory '%s'.", dir));
84
    logger.info(String.format("Listing directory '%s'.", dir));
83
    if (level <= 0) level = 1;
85
    if (level <= 0) level = 1;
Line 107... Line 109...
107
      if (fromIndex > toIndex) fromIndex = toIndex;
109
      if (fromIndex > toIndex) fromIndex = toIndex;
108
      GenericEntity<List<FileInfoType>> sublist = new GenericEntity<List<FileInfoType>>(list.subList(fromIndex, toIndex)) {};
110
      GenericEntity<List<FileInfoType>> sublist = new GenericEntity<List<FileInfoType>>(list.subList(fromIndex, toIndex)) {};
109
      logger.info(String.format("Returning items %s to %s from total of %s items in the list.", fromIndex, toIndex, list.size()));
111
      logger.info(String.format("Returning items %s to %s from total of %s items in the list.", fromIndex, toIndex, list.size()));
110
      return Response.ok(sublist).build();
112
      return Response.ok(sublist).build();
111
    } catch (CacheException e) {
113
    } catch (CacheException e) {
112
      Response.serverError().build();
114
      return Response.serverError().build();
113
    }
115
    }
114
    return null;
-
 
115
  }
116
  }
Line 116... Line 117...
116
 
117
 
117
  /**
118
  /**
118
   * Sets the directory.
119
   * Sets the directory.
Line 252... Line 253...
252
		logger.warn(String.format("User '%s' does not have permission to access '%s'.",SecurityUtils.getSubject().getPrincipal(), dir ));
253
		logger.warn(String.format("User '%s' does not have permission to access '%s'.",SecurityUtils.getSubject().getPrincipal(), dir ));
253
		throw new NotAuthorizedException(new UnauthorizedException("User does not have permission to access "+ dir));
254
		throw new NotAuthorizedException(new UnauthorizedException("User does not have permission to access "+ dir));
254
	}
255
	}
255
	return true;
256
	return true;
256
}
257
}
-
 
258
 
-
 
259
//http://stackoverflow.com/questions/3758606/how-to-convert-byte-size-into-human-readable-format-in-java
-
 
260
private static String humanReadableByteCount(long bytes, boolean si) {
-
 
261
    int unit = si ? 1000 : 1024;
-
 
262
    if (bytes < unit) return bytes + " B";
-
 
263
    int exp = (int) (Math.log(bytes) / Math.log(unit));
-
 
264
    String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i");
-
 
265
    return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre);
-
 
266
}
-
 
267
 
257
}
268
}
258
 
269