Skip to content

Commit e4dc905

Browse files
committed
Refactored the source code of DirectoryServerResource
1 parent f796e0b commit e4dc905

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

Diff for: modules/org.restlet/src/org/restlet/engine/local/DirectoryServerResource.java

+20-21
Original file line numberDiff line numberDiff line change
@@ -381,37 +381,36 @@ public void preventUpperDirectoryAccess() {
381381
protected Representation get() throws ResourceException {
382382
// Content negotiation has been disabled
383383
// The variant that may need to meet the request conditions
384-
Representation result = null;
385384

386385
List<Variant> variants = getVariants(Method.GET);
387386
if ((variants == null) || (variants.isEmpty())) {
388387
// Resource not found
389-
getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
390-
} else if (variants.size() == 1) {
391-
result = (Representation) variants.get(0);
392-
} else {
393-
ReferenceList variantRefs = new ReferenceList();
388+
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
389+
}
394390

395-
for (Variant variant : variants) {
396-
if (variant.getLocationRef() != null) {
397-
variantRefs.add(variant.getLocationRef());
398-
} else {
399-
getLogger()
400-
.warning(
401-
"A resource with multiple variants should provide a location for each variant when content negotiation is turned off");
402-
}
403-
}
391+
if (variants.size() == 1) {
392+
return (Representation) variants.get(0);
393+
}
394+
395+
ReferenceList variantRefs = new ReferenceList();
404396

405-
if (!variantRefs.isEmpty()) {
406-
// Return the list of variants
407-
setStatus(Status.REDIRECTION_MULTIPLE_CHOICES);
408-
result = variantRefs.getTextRepresentation();
397+
for (Variant variant : variants) {
398+
if (variant.getLocationRef() != null) {
399+
variantRefs.add(variant.getLocationRef());
409400
} else {
410-
setStatus(Status.CLIENT_ERROR_NOT_FOUND);
401+
getLogger()
402+
.warning(
403+
"A resource with multiple variants should provide a location for each variant when content negotiation is turned off");
411404
}
412405
}
413406

414-
return result;
407+
if (!variantRefs.isEmpty()) {
408+
// Return the list of variants
409+
setStatus(Status.REDIRECTION_MULTIPLE_CHOICES);
410+
return variantRefs.getTextRepresentation();
411+
}
412+
413+
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND);
415414
}
416415

417416
/**

0 commit comments

Comments
 (0)