*/
public List<DirectoryEntry> listDirectory(ObjectPath path,
ListOptions options ) {
if (!path.isDirectory()) {
throw new EsuException(
"listDirectory must be called with a directory path");
}
byte[] data = null;
// Read out the directory's contents
try {
String resource = getResourcePath(context, path);
URL u = buildUrl(resource, null);
HttpURLConnection con = (HttpURLConnection) u.openConnection();
// Build headers
Map<String, String> headers = new HashMap<String, String>();
headers.put("x-emc-uid", uid);
if(unicodeEnabled) {
headers.put("x-emc-utf8", "true");
}
// Process options
if( options != null ) {
if( options.isIncludeMetadata() ) {
headers.put( "x-emc-include-meta", "1" );
if( options.getSystemMetadata() != null ) {
headers.put( "x-emc-system-tags",
join( options.getSystemMetadata(), "," ) );
}
if( options.getUserMetadata() != null ) {
headers.put( "x-emc-user-tags",
join( options.getUserMetadata(), "," ) );
}
}
if( options.getLimit() > 0 ) {
headers.put( "x-emc-limit", ""+options.getLimit() );
}
if( options.getToken() != null ) {
headers.put( "x-emc-token", options.getToken() );
}
}
// Add date
headers.put("Date", getDateHeader());
// Sign request
signRequest("GET", resource, null, headers);
configureRequest( con, "GET", headers );
con.connect();
// Check response
if (con.getResponseCode() > 299) {
handleError(con);
}
if( options != null ) {
// Update the token for listing more results. If there are no
// more results, the header will not be set and the token will
// be cleared in the options object.
options.setToken( con.getHeaderField("x-emc-token") );
} else {
if( con.getHeaderField( "x-emc-token" ) != null ) {
l4j.warn( "Result set truncated. Use ListOptions to " +
"retrieve token for next page of results." );
}
}
// The requested content is in the response body.
data = readResponse(con, null);
} catch (MalformedURLException e) {
throw new EsuException("Invalid URL", e);
} catch (IOException e) {
throw new EsuException("Error connecting to server", e);
} catch (GeneralSecurityException e) {
throw new EsuException("Error computing request signature", e);
} catch (URISyntaxException e) {
throw new EsuException("Invalid URL", e);
}
return parseDirectoryListing( data, path );
}