Search in sources :

Example 1 with FilePersistent

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);
}
Also used : FilePlugin(com.ramussoft.core.attribute.simple.FilePlugin) List(java.util.List) ArrayList(java.util.ArrayList) IEngine(com.ramussoft.common.IEngine) Engine(com.ramussoft.common.Engine) DataException(com.ramussoft.report.data.DataException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SQLException(java.sql.SQLException) IOException(java.io.IOException) FilePersistent(com.ramussoft.core.attribute.simple.FilePersistent)

Example 2 with FilePersistent

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);
    }
}
Also used : FilePersistent(com.ramussoft.core.attribute.simple.FilePersistent)

Aggregations

FilePersistent (com.ramussoft.core.attribute.simple.FilePersistent)2 Engine (com.ramussoft.common.Engine)1 IEngine (com.ramussoft.common.IEngine)1 FilePlugin (com.ramussoft.core.attribute.simple.FilePlugin)1 DataException (com.ramussoft.report.data.DataException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1