// 处理参数 public static void process(ImgObject image) { String key = image.getGomefsKey() == null ? image.getSourceKey() : image.getGomefsKey(); // if (!(image.getIsPressed() == 0 && image.getIsThumbNail() == 0 && // image.getWaterMark() == WaterMarkEnum.WATERMARK_NONE)) { // String zoomPara = image.toParaString(); // image.getHeaders().add(HttpHeaders.ETAG, zoomPara); // } if (!image.isOriginal()) { String zoomPara = image.toParaString(); image.getHeaders().add(HttpHeaders.ETAG, zoomPara); } else { image.getHeaders().add(HttpHeaders.ETAG, image.toNullString()); } image.getHeaders().add(HttpHeaders.CONTENT_LENGTH, String.valueOf(image.getZoomData().length)); image.getHeaders().add(HttpHeaders.CONTENT_TYPE, fileTypeMap.getContentType(key.toLowerCase())); if (image.isHtml()) { // html 编码 MediaType mediaType = new MediaType("text", "html", Charset.forName("UTF-8")); image.getHeaders().setContentType(mediaType); } // long lastModified = image.gomefsKey == null ? 0 : // KeyUtils.getCreateTime(image.gomefsKey); // image.headers.setLastModified(lastModified * 1000); image.getHeaders().setCacheControl("max-age=315360000"); // year 10 long time = System.currentTimeMillis() + YEAR_30; image.getHeaders().setExpires(time); }
@Override protected ModelAndView svnHandle( final SVNConnection connection, final BaseCommand cmd, final long headRevision, final UserRepositoryContext userRepositoryContext, final HttpServletRequest request, final HttpServletResponse response, final BindException exception) throws Exception { final MultipleEntriesCommand command = (MultipleEntriesCommand) cmd; final Map<String, Object> model = new HashMap<String, Object>(); final List<PathRevision> imageEntries = new ArrayList<PathRevision>(); logger.debug("Showing thumbnail images"); // Check what entries are image files - and add them to the list of thumbnails. for (final PathRevision entry : command.getEntries()) { logger.debug("entry: " + entry); if (mimeFileTypeMap.getContentType(entry.getPath()).startsWith("image")) { imageEntries.add(entry); } } logger.debug( imageEntries.size() + " entries out of " + command.getEntries().length + " are image files"); model.put("thumbnailentries", imageEntries); return new ModelAndView(getViewName(), model); }
/** * @param request the <code>HttpRequest</code> * @param response the <code>HttpResponse</code> * @param hasBody <code>true</code> to write the message body; <code>false</code> otherwise. */ private void perform(final HttpRequest request, final HttpResponse response, boolean hasBody) { final String path = request.getRequestedPath(); final File file = new File(path.substring(1)); // remove the leading '/' if (!file.exists()) { throw new HttpException(HttpStatus.CLIENT_ERROR_NOT_FOUND); } else if (!file.isFile()) { throw new HttpException(HttpStatus.CLIENT_ERROR_FORBIDDEN, path + "is not a file"); } final long lastModified = file.lastModified(); response.setHeader("Last-Modified", DateUtil.parseToRFC1123(lastModified)); response.setHeader("Cache-Control", "public"); String mimeType = mimeTypeMap.getContentType(file); if ("text/plain".equals(mimeType)) { mimeType += "; charset=utf-8"; } response.setHeader("Content-Type", mimeType); final String ifModifiedSince = request.getHeader("If-Modified-Since"); if (ifModifiedSince != null) { final long ims = DateUtil.parseToMilliseconds(ifModifiedSince); if (lastModified <= ims) { response.setStatus(HttpStatus.REDIRECTION_NOT_MODIFIED); logger.debug("not modified"); return; } } if (hasBody) { response.write(file); } }
/** @param args */ public static void main(String[] args) { FileTypeMap fileTypeMap = FileTypeMap.getDefaultFileTypeMap(); String path = "."; File dir = new File(path); File[] listFiles = dir.listFiles(); for (File file : listFiles) { System.out.println(file.getName() + ":" + fileTypeMap.getContentType(file)); } }
/* (non-Javadoc) * @see uk.ac.ox.oucs.oxam.logic.PaperFileService#deposit(uk.ac.ox.oucs.oxam.logic.PaperFile, uk.ac.ox.oucs.oxam.logic.Callback) */ public void deposit(PaperFile paperFile, InputStream in) { PaperFileImpl impl = castToImpl(paperFile); String path = impl.getPath(); ContentResourceEdit resource = null; try { try { contentHostingService.checkResource(path); resource = contentHostingService.editResource(path); // Ignore PermissionException, IdUnusedException, TypeException // As they are too serious to continue. } catch (IdUnusedException iue) { // Will attempt to create containing folders. resource = contentHostingService.addResource(path); // Like the basename function. String filename = StringUtils.substringAfterLast(path, "/"); ResourceProperties props = resource.getPropertiesEdit(); props.addProperty(ResourceProperties.PROP_DISPLAY_NAME, filename); resource.setContentType(mimeTypes.getContentType(filename)); } resource.setContent(in); contentHostingService.commitResource(resource, NotificationService.NOTI_NONE); LOG.debug("Sucessfully copied file to: " + path); } catch (OverQuotaException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ServerOverloadException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (PermissionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InUseException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TypeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IdUsedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IdInvalidException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InconsistentException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { // Close the stream here as this is where it's created. if (resource.isActiveEdit()) { contentHostingService.cancelResource(resource); } } }
/** * Use the specified file as the content for this part. * * @param file the file * @since JavaMail 1.4 */ public void attachFile(File file) throws IOException, MessagingException { FileTypeMap map = FileTypeMap.getDefaultFileTypeMap(); String contentType = map.getContentType(file); if (contentType == null) throw new MessagingException("Unable to determine MIME type of " + file); /*GPL->GNU@03/15/2011 - Fix for adding attachments into MimeBodyPart start*/ // setContent(new FileInputStream(file), contentType); setContent(file); /*GPL->GNU@03/15/2011 - Fix for adding attachments into MimeBodyPart end*/ setFileName(file.getName()); }
public ModelAndView downloadDocuments(HttpServletRequest request, HttpServletResponse response) throws ServletException { JSONObject jobj = new JSONObject(); JSONObject myjobj = new JSONObject(); KwlReturnObject kmsg = null; String details = ""; String auditAction = ""; try { String url = request.getParameter("url"); url = StringUtil.checkForNull(url); String applicant = request.getParameter("applicant"); applicant = StringUtil.checkForNull(applicant); Hashtable ht; if (applicant.equalsIgnoreCase("applicant")) { kmsg = hrmsExtApplDocsDAOObj.downloadDocument(url); ht = getExtDocumentDownloadHash(kmsg.getEntityList()); } else { kmsg = documentDAOObj.downloadDocument(url); ht = getDocumentDownloadHash(kmsg.getEntityList()); } String src = storageHandlerImplObj.GetDocStorePath(); // String src = "/home/trainee/"; if (request.getParameter("mailattch") != null) { src = src + ht.get("svnname"); } else { src = src + ht.get("userid").toString() + "/" + ht.get("svnname"); } File fp = new File(src); byte[] buff = new byte[(int) fp.length()]; FileInputStream fis = new FileInputStream(fp); int read = fis.read(buff); javax.activation.FileTypeMap mmap = new javax.activation.MimetypesFileTypeMap(); response.setContentType(mmap.getContentType(src)); response.setContentLength((int) fp.length()); response.setHeader( "Content-Disposition", request.getParameter("dtype") + "; filename=\"" + ht.get("Name") + "\";"); response.getOutputStream().write(buff); response.getOutputStream().flush(); response.getOutputStream().close(); String map = ht.get("relatedto").toString(); String refid = ht.get("recid").toString(); myjobj.put("success", true); } catch (Exception e) { System.out.println(e.getMessage()); } return new ModelAndView("jsonView", "model", myjobj.toString()); }
public static MediaType getMediaType(String filename) { String mediaType = fileTypeMap.getContentType(filename); return (StringUtils.hasText(mediaType) ? MediaType.parseMediaType(mediaType) : null); }