*/
public void setRequest(String basePath, String requested)
throws DiffableException {
if(requested == null){
throw new DiffableException("Error creating resource request for '"+requested+"'.");
}
try {
this.basePath = basePath;
// The Javascript client must end all requests for diffs with
// '.diff'.
if (requested.endsWith(".diff")) {
this.isDiff = true;
}
// Diff requests are formed by listing the resource hash followed by
// an underscore followed by the old version hash followed by an
// underscore followed by the new version hash followed by '.diff.'
// For instance, assumed js/fake.js gets hashed as aa, the old
// version is bb and the new version is cc, the diff request will
// look like: aa_bb_cc.diff
if (this.isDiff) {
// Take the part of the string before the '.diff' and split out
// the component hashes.
String[] parts = requested.split("\\.")[0].split("_");
this.resourceHash = parts[0];
this.oldVersion = parts[1];
this.newVersion = parts[2];
} else {
// If this is not a request for a delta then the request should
// simply take the form of the resource hash. For instance, if
// fake.js hashes to aa, then the request should look like:
// aa.js.
this.resourceHash = requested;
}
// The printer and the provider are not available in the Constructor at that time
} catch (Exception exc) {
printer.print(exc);
DiffableException newExc = new DiffableException(
provider.error("resourcerequest.error", requested));
newExc.setStackTrace(exc.getStackTrace());
throw newExc;
}
}