Search in sources :

Example 1 with AttachmentDAO

use of net.jforum.dao.AttachmentDAO in project jforum2 by rafaelsteil.

the class AttachmentsAction method extensionsUpdate.

public void extensionsUpdate() {
    AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
    // Check for records to delete
    String[] delete = this.request.getParameterValues("delete");
    List deleteList = new ArrayList();
    if (delete != null) {
        deleteList = Arrays.asList(delete);
        am.removeExtensions(delete);
    }
    int total = this.request.getIntParameter("total_records");
    for (int i = 0; i < total; i++) {
        if (deleteList.contains(this.request.getParameter("id_" + i))) {
            continue;
        }
        AttachmentExtension e = new AttachmentExtension();
        e.setAllow(this.request.getParameter("allow_" + i) != null);
        e.setComment(this.request.getParameter("comment_" + i));
        e.setExtension(this.request.getParameter("extension_" + i));
        e.setExtensionGroupId(this.request.getIntParameter("extension_group_" + i));
        e.setId(this.request.getIntParameter("id_" + i));
        e.setUploadIcon(this.request.getParameter("upload_icon_" + i));
        am.updateExtension(e);
    }
    this.extensions();
}
Also used : AttachmentDAO(net.jforum.dao.AttachmentDAO) AttachmentExtension(net.jforum.entities.AttachmentExtension) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with AttachmentDAO

use of net.jforum.dao.AttachmentDAO in project jforum2 by rafaelsteil.

the class AttachmentsAction method quotaLimitUpdate.

public void quotaLimitUpdate() {
    AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
    // First check if we should delete some entry
    String[] delete = this.request.getParameterValues("delete");
    List deleteList = new ArrayList();
    if (delete != null) {
        deleteList = Arrays.asList(delete);
        am.removeQuotaLimit(delete);
    }
    // Now update the remaining
    int total = this.request.getIntParameter("total_records");
    for (int i = 0; i < total; i++) {
        if (deleteList.contains(this.request.getParameter("id_" + i))) {
            continue;
        }
        QuotaLimit ql = new QuotaLimit();
        ql.setId(this.request.getIntParameter("id_" + i));
        ql.setDescription(this.request.getParameter("quota_desc_" + i));
        ql.setSize(this.request.getIntParameter("max_filesize_" + i));
        ql.setType(this.request.getIntParameter("type_" + i));
        am.updateQuotaLimit(ql);
    }
    this.quotaLimit();
}
Also used : AttachmentDAO(net.jforum.dao.AttachmentDAO) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) QuotaLimit(net.jforum.entities.QuotaLimit)

Example 3 with AttachmentDAO

use of net.jforum.dao.AttachmentDAO in project jforum2 by rafaelsteil.

the class AttachmentsAction method quotaLimit.

public void quotaLimit() {
    AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
    this.context.put("quotas", am.selectQuotaLimit());
    this.setTemplateName(TemplateKeys.ATTACHMENTS_QUOTA_LIMIT);
    this.context.put("groups", new TreeGroup().getNodes());
    this.context.put("selectedList", new ArrayList());
    this.context.put("groupQuotas", am.selectGroupsQuotaLimits());
}
Also used : AttachmentDAO(net.jforum.dao.AttachmentDAO) TreeGroup(net.jforum.util.TreeGroup) ArrayList(java.util.ArrayList)

Example 4 with AttachmentDAO

use of net.jforum.dao.AttachmentDAO in project jforum2 by rafaelsteil.

the class PostAction method downloadAttach.

public void downloadAttach() {
    int id = this.request.getIntParameter("attach_id");
    if (!SessionFacade.isLogged() && !SystemGlobals.getBoolValue(ConfigKeys.ATTACHMENTS_ANONYMOUS)) {
        String referer = this.request.getHeader("Referer");
        if (referer != null) {
            this.setTemplateName(ViewCommon.contextToLogin(referer));
        } else {
            this.setTemplateName(ViewCommon.contextToLogin());
        }
        return;
    }
    AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
    Attachment a = am.selectAttachmentById(id);
    PostDAO postDao = DataAccessDriver.getInstance().newPostDAO();
    Post post = postDao.selectById(a.getPostId());
    String forumId = Integer.toString(post.getForumId());
    boolean attachmentsEnabled = SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, forumId);
    boolean attachmentsDownload = SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD, forumId);
    if (!attachmentsEnabled && !attachmentsDownload) {
        this.setTemplateName(TemplateKeys.POSTS_CANNOT_DOWNLOAD);
        this.context.put("message", I18n.getMessage("Attachments.featureDisabled"));
        return;
    }
    String filename = SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_STORE_DIR) + "/" + a.getInfo().getPhysicalFilename();
    if (!new File(filename).exists()) {
        this.setTemplateName(TemplateKeys.POSTS_ATTACH_NOTFOUND);
        this.context.put("message", I18n.getMessage("Attachments.notFound"));
        return;
    }
    FileInputStream fis = null;
    OutputStream os = null;
    try {
        a.getInfo().setDownloadCount(a.getInfo().getDownloadCount() + 1);
        am.updateAttachment(a);
        fis = new FileInputStream(filename);
        os = response.getOutputStream();
        if (am.isPhysicalDownloadMode(a.getInfo().getExtension().getExtensionGroupId())) {
            this.response.setContentType("application/octet-stream");
        } else {
            this.response.setContentType(a.getInfo().getMimetype());
        }
        if (this.request.getHeader("User-Agent").indexOf("Firefox") != -1) {
            this.response.setHeader("Content-Disposition", "attachment; filename=\"" + new String(a.getInfo().getRealFilename().getBytes(SystemGlobals.getValue(ConfigKeys.ENCODING)), SystemGlobals.getValue(ConfigKeys.DEFAULT_CONTAINER_ENCODING)) + "\";");
        } else {
            this.response.setHeader("Content-Disposition", "attachment; filename=\"" + ViewCommon.toUtf8String(a.getInfo().getRealFilename()) + "\";");
        }
        this.response.setContentLength((int) a.getInfo().getFilesize());
        int c;
        byte[] b = new byte[4096];
        while ((c = fis.read(b)) != -1) {
            os.write(b, 0, c);
        }
        JForumExecutionContext.enableCustomContent(true);
    } catch (IOException e) {
        throw new ForumException(e);
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (Exception e) {
            }
        }
        if (os != null) {
            try {
                os.close();
            } catch (Exception e) {
            }
        }
    }
}
Also used : AttachmentDAO(net.jforum.dao.AttachmentDAO) Post(net.jforum.entities.Post) OutputStream(java.io.OutputStream) Attachment(net.jforum.entities.Attachment) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AttachmentException(net.jforum.exceptions.AttachmentException) ForumException(net.jforum.exceptions.ForumException) IOException(java.io.IOException) ForumException(net.jforum.exceptions.ForumException) PostDAO(net.jforum.dao.PostDAO) File(java.io.File)

Example 5 with AttachmentDAO

use of net.jforum.dao.AttachmentDAO in project jforum2 by rafaelsteil.

the class AttachmentCommon method editAttachments.

public void editAttachments(int postId, int forumId) {
    // Allow removing the attachments at least
    AttachmentDAO am = DataAccessDriver.getInstance().newAttachmentDAO();
    // Check for attachments to remove
    List deleteList = new ArrayList();
    String[] delete = null;
    String s = this.request.getParameter("delete_attach");
    if (s != null) {
        delete = s.split(",");
    }
    if (delete != null) {
        for (int i = 0; i < delete.length; i++) {
            if (delete[i] != null && !delete[i].equals("")) {
                int id = Integer.parseInt(delete[i]);
                Attachment a = am.selectAttachmentById(id);
                am.removeAttachment(id, postId);
                String filename = SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_STORE_DIR) + "/" + a.getInfo().getPhysicalFilename();
                File f = new File(filename);
                if (f.exists()) {
                    f.delete();
                }
                // Check if we have a thumb to delete
                f = new File(filename + "_thumb");
                if (f.exists()) {
                    f.delete();
                }
            }
        }
        deleteList = Arrays.asList(delete);
    }
    if (!SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_ENABLED, Integer.toString(forumId)) && !SecurityRepository.canAccess(SecurityConstants.PERM_ATTACHMENTS_DOWNLOAD)) {
        return;
    }
    // Update
    String[] attachIds = null;
    s = this.request.getParameter("edit_attach_ids");
    if (s != null) {
        attachIds = s.split(",");
    }
    if (attachIds != null) {
        for (int i = 0; i < attachIds.length; i++) {
            if (deleteList.contains(attachIds[i]) || attachIds[i] == null || attachIds[i].equals("")) {
                continue;
            }
            int id = Integer.parseInt(attachIds[i]);
            Attachment a = am.selectAttachmentById(id);
            a.getInfo().setComment(this.request.getParameter("edit_comment_" + id));
            am.updateAttachment(a);
        }
    }
}
Also used : AttachmentDAO(net.jforum.dao.AttachmentDAO) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Attachment(net.jforum.entities.Attachment) File(java.io.File)

Aggregations

AttachmentDAO (net.jforum.dao.AttachmentDAO)8 ArrayList (java.util.ArrayList)5 List (java.util.List)4 File (java.io.File)2 Attachment (net.jforum.entities.Attachment)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 PostDAO (net.jforum.dao.PostDAO)1 AttachmentExtension (net.jforum.entities.AttachmentExtension)1 AttachmentExtensionGroup (net.jforum.entities.AttachmentExtensionGroup)1 Post (net.jforum.entities.Post)1 QuotaLimit (net.jforum.entities.QuotaLimit)1 AttachmentException (net.jforum.exceptions.AttachmentException)1 ForumException (net.jforum.exceptions.ForumException)1 TreeGroup (net.jforum.util.TreeGroup)1