Search in sources :

Example 1 with FilePlugin

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);
}
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)

Aggregations

Engine (com.ramussoft.common.Engine)1 IEngine (com.ramussoft.common.IEngine)1 FilePersistent (com.ramussoft.core.attribute.simple.FilePersistent)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