use of com.ramussoft.core.attribute.simple.FilePersistent 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);
}
use of com.ramussoft.core.attribute.simple.FilePersistent in project ramus by Vitaliy-Yakovchuk.
the class FileAttributeViewer method printAttribute.
@Override
public void printAttribute(PrintStream printStream, DataPlugin dataPlugin, Element element, Attribute attribute, HTTPParser parser, AttributeViewerCallback callback) throws IOException {
FilePersistent value = (FilePersistent) dataPlugin.getEngine().getAttribute(element, attribute);
if (value != null) {
callback.beforePrint(printStream);
String href = "files/file_getter.html?id=" + element.getId() + "&attr=" + attribute.getId();
parser.printStartATeg(href);
printStream.print(value.getName());
parser.printEndATeg();
if (isImage(value.getName())) {
printStream.println("<br>");
parser.printStartATeg(href + "&prev=true");
printStream.println("<img class=\"faimage\" src=\"" + parser.getFromLink() + href + "\">");
parser.printEndATeg();
}
callback.afterPrint(printStream);
}
}
Aggregations