@Override
public void doEncodeEnd(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException {
if (!(component instanceof AbstractOutputFile)) {
return;
}
AbstractOutputFile outputFile = (AbstractOutputFile) component;
String contents = null;
Object value = outputFile.getValue();
if (value instanceof File) {
contents = getContents((File) value);
} else if (value instanceof InputStream) {
contents = getContents((InputStream) value);
} else if (value != null) {
String resourcePath = value.toString();
URL resource = context.getExternalContext().getResource(resourcePath);
if (resource == null) {
throw new FileNotFoundException(resourcePath);
}
contents = getContents(resource.openStream());
}
if (contents != null) {
if (outputFile.isEscape()) {
writer.writeText(contents, null);
} else {
writer.write(contents);
}
}