if ((dynamicContentId != null)
&& (library != null)
&& (library.equals("primefaces"))) {
Map session = context.getExternalContext().getSessionMap();
StreamedContent streamedContent = null;
try {
String dynamicContentEL = (String) session.get(dynamicContentId);
ExternalContext externalContext = context.getExternalContext();
if (dynamicContentEL != null) {
ELContext eLContext = context.getELContext();
ValueExpression ve =
context.getApplication()
.getExpressionFactory()
.createValueExpression(context.getELContext(), dynamicContentEL, StreamedContent.class);
streamedContent = (StreamedContent) ve.getValue(eLContext);
externalContext.setResponseStatus(200);
externalContext.setResponseContentType(streamedContent.getContentType());
if (streamedContent.getContentEncoding() != null) {
externalContext.setResponseHeader("Content-Encoding", streamedContent.getContentEncoding());
}
byte[] buffer = new byte[2048];
InputStream inputStream = streamedContent.getStream();
int length = 0;
while ((length = inputStream.read(buffer)) >= 0) {
externalContext.getResponseOutputStream().write(buffer, 0, length);
}
}
externalContext.responseFlushBuffer();
context.responseComplete();
} catch (Exception e) {
logger.log(Level.SEVERE, "Error in streaming dynamic resource. {0}", new Object[] { e.getMessage() });
e.printStackTrace();
} finally {
session.remove(dynamicContentId);
if (streamedContent != null)
streamedContent.getStream().close();
}
} else {
super.handleResourceRequest(context);
}
}