use of com.ramussoft.core.attribute.simple.FilePlugin in project ramus by Vitaliy-Yakovchuk.
the class HTTPParser method printFile.
private void printFile() throws IOException {
long elementId = Long.parseLong(params.get("id"));
long attributeId = Long.parseLong(params.get("attr"));
Engine engine = dataPlugin.getEngine();
FilePlugin plugin = (FilePlugin) engine.getPluginProperty("Core", FilePlugin.PLUGIN_NAME);
String string = plugin.getFilePath(elementId, attributeId);
List<Persistent>[] lists = engine.getBinaryAttribute(elementId, attributeId);
if (lists[0].size() > 0) {
FilePersistent fp = (FilePersistent) lists[0].get(0);
String userAgent = request.getUserAgent();
String encodedFileName = null;
if ((userAgent != null) && (userAgent.contains("MSIE") || userAgent.contains("Opera"))) {
encodedFileName = URLEncoder.encode(fp.getName(), "UTF-8");
} else {
byte[] bytes = fp.getName().getBytes("UTF-8");
try {
encodedFileName = "=?UTF-8?B?" + new String(Base64.encode(bytes), "UTF-8") + "?=";
} catch (Exception e) {
e.printStackTrace();
}
}
if (params.get("prev") == null) {
response.setContentDisposition("attachment; filename=" + encodedFileName);
response.setRamusContentDisposition(toUtf8(fp.getName()));
}
}
byte[] bytes = engine.getStream(string);
response.writeHead();
if (bytes != null)
stream.write(bytes);
}
Aggregations