if (format == null) {
format = "application/pdf";
}
if (animalType == null) {
throw new PetClinicException("animal type must be specified.");
}
animalType = animalType.trim();
if (animalType.length() == 0) {
throw new PetClinicException("animal type must be specified.");
}
InputStream data = getClass().getResourceAsStream(animalType + "-brochure." + format);
if (data == null) {
throw new NotFoundException("A brochure for animal " + animalType + " in format " + format + " was not found.");
}
if ("text/html".equalsIgnoreCase(format)) {
data = getClass().getResourceAsStream("clinic-brochure.html");
}
else if ("text/plain".equalsIgnoreCase(format)) {
data = getClass().getResourceAsStream("clinic-brochure.txt");
}
else {
throw new PetClinicException("Unknown brochure format: " + format);
}
AnimalBrochure brochure = new AnimalBrochure();
brochure.setContentType(format);
brochure.setContent(data);