Package org.fenixedu.academic.domain

Examples of org.fenixedu.academic.domain.File


    @Override
    public ActionForward execute(final ActionMapping mapping, final ActionForm actionForm, final HttpServletRequest request,
            final HttpServletResponse response) throws Exception {
        final String oid = request.getParameter("oid");
        final File file = FenixFramework.getDomainObject(oid);
        if (file == null) {
            response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST));
            response.getWriter().close();
        } else {
            final Person person = AccessControl.getPerson();
            if (!file.isPrivate() || file.isPersonAllowedToAccess(person)) {
                response.setContentType(file.getContentType());
                response.addHeader("Content-Disposition", "attachment; filename=" + file.getFilename());
                response.setContentLength(file.getSize().intValue());
                final DataOutputStream dos = new DataOutputStream(response.getOutputStream());
                dos.write(file.getContents());
                dos.close();
            } else if (file.isPrivate() && person == null) {
                response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
                response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_UNAUTHORIZED));
                response.getWriter().close();
            } else {
                response.setStatus(HttpServletResponse.SC_FORBIDDEN);
View Full Code Here


        this.classes = classes;
    }

    @Override
    public HtmlComponent render(Object object, Class type) {
        File file = (File) object;

        HtmlImage image = new HtmlImage();

        image.setSource(file.getDownloadUrl());
        image.setTitle(file.getDisplayName());

        image.setClasses(classes);

        return image;
    }
View Full Code Here

        return new Layout() {

            @Override
            public HtmlComponent createComponent(Object object, Class type) {
                if (object != null && object instanceof File) {
                    File file = (File) object;
                    HtmlBlockContainer container = new HtmlBlockContainer();
                    HtmlLink link = getLink(file);
                    container.addChild(link);
                    link.setIndented(false);
                    link.setText(getLinkText(file));
                    return container;
                }
                return new HtmlLink();
            }

            private HtmlLink getLink(File file) {
                HtmlLink link = new HtmlLinkWithPreprendedComment(GenericChecksumRewriter.NO_CHECKSUM_PREFIX);
//    if (file.hasLocalContent()) {
//        link.setContextRelative(true);
//    } else {
                link.setContextRelative(false);
//    }
                link.setModuleRelative(false);
                link.setUrl(file.getDownloadUrl());
                return link;
            }

            private String getLinkText(File file) {
                if (getKey() != null) {
                    return RenderUtils.getResourceString(getBundle(), getKey());
                }
                if (!StringUtils.isEmpty(getText())) {
                    return getText();
                }
                return file.getDisplayName();
            }
        };
    }
View Full Code Here

TOP

Related Classes of org.fenixedu.academic.domain.File

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.