當前位置: 首頁>>代碼示例>>Java>>正文


Java MimetypesFileTypeMap類代碼示例

本文整理匯總了Java中javax.activation.MimetypesFileTypeMap的典型用法代碼示例。如果您正苦於以下問題:Java MimetypesFileTypeMap類的具體用法?Java MimetypesFileTypeMap怎麽用?Java MimetypesFileTypeMap使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MimetypesFileTypeMap類屬於javax.activation包,在下文中一共展示了MimetypesFileTypeMap類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createContent

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
private String createContent(
		Reference ref,
		String name,
		String title,
		String description,
		byte[] data) throws RemoteException, ContentFault {
	ParentReference parent = getReferenceToParent(ref);
	parent.setChildName(Constants.createQNameString(
			Constants.NAMESPACE_CONTENT_MODEL,
			normalizeNodeName(name)));
	NamedValue[] properties = new NamedValue[]{
			Utils.createNamedValue(Constants.PROP_NAME, name),
			Utils.createNamedValue(Constants.PROP_TITLE, title),
			Utils.createNamedValue(Constants.PROP_DESCRIPTION, description)};
	CMLCreate create = new CMLCreate("1", parent, null, null, null, Constants.TYPE_CONTENT, properties);
	CML cml = new CML();
	cml.setCreate(new CMLCreate[]{create});
	UpdateResult[] result = getAlfrescoRepositoryService().update(cml);
	Reference newContentNode = result[0].getDestination();
	Content content = getAlfrescoContentService().write(
			newContentNode,
			Constants.PROP_CONTENT,
			data,
			new ContentFormat(new MimetypesFileTypeMap().getContentType(name), null));
	return content.getNode().getUuid();
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:27,代碼來源:GestioDocumentalPluginAlfrescoCaib.java

示例2: createContent

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
public String createContent(
		Reference ref,
		String name,
		String title,
		String description,
		byte[] data) throws RemoteException, ContentFault {
	ParentReference parent = getReferenceToParent(ref);
	parent.setChildName(Constants.createQNameString(
			Constants.NAMESPACE_CONTENT_MODEL,
			normalizeNodeName(name)));
	NamedValue[] properties = new NamedValue[]{
			Utils.createNamedValue(Constants.PROP_NAME, name),
			Utils.createNamedValue(Constants.PROP_TITLE, title),
			Utils.createNamedValue(Constants.PROP_DESCRIPTION, description)};
	CMLCreate create = new CMLCreate("1", parent, null, null, null, Constants.TYPE_CONTENT, properties);
	CML cml = new CML();
	cml.setCreate(new CMLCreate[]{create});
	UpdateResult[] result = getAlfrescoRepositoryService().update(cml);
	Reference newContentNode = result[0].getDestination();
	Content content = getAlfrescoContentService().write(
			newContentNode,
			Constants.PROP_CONTENT,
			data,
			new ContentFormat(new MimetypesFileTypeMap().getContentType(name), null));
	return content.getNode().getUuid();
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:27,代碼來源:AlfrescoUtils.java

示例3: render

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
public void render(
		Map model,
		HttpServletRequest request,
		HttpServletResponse response) throws Exception {
	response.setHeader(HEADER_PRAGMA, "");
	response.setHeader(HEADER_EXPIRES, "");
	response.setHeader(HEADER_CACHE_CONTROL, "");
	byte[] data = (byte[])model.get(MODEL_ATTRIBUTE_DATA);
	String fileName = (String)model.get(MODEL_ATTRIBUTE_FILENAME);
	String contentType = (String)model.get(MODEL_ATTRIBUTE_CONTENTTYPE);
	if (data == null)
		data = new byte[0];
	if (fileName == null)
		fileName = "unknown";
	response.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
	if (contentType == null)
		response.setContentType(new MimetypesFileTypeMap().getContentType(fileName));
	else
		response.setContentType(contentType);
	response.getOutputStream().write(data);
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:23,代碼來源:ArxiuView.java

示例4: loadMimeTypes

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
/**
 * Load MIME types
 */
public static void loadMimeTypes() {
	try {
		List<MimeType> mimeTypeList = MimeTypeDAO.findAll("mt.id");
		MimeTypeConfig.mimeTypes = new MimetypesFileTypeMap();

		for (MimeType mt : mimeTypeList) {
			String entry = mt.getName();

			for (String ext : mt.getExtensions()) {
				entry += " " + ext;
			}

			log.debug("loadMimeTypes => Add Entry: {}", entry);
			MimeTypeConfig.mimeTypes.addMimeTypes(entry);
		}
	} catch (DatabaseException e) {
		log.error(e.getMessage(), e);
	}
}
 
開發者ID:openkm,項目名稱:document-management-system,代碼行數:23,代碼來源:MimeTypeConfig.java

示例5: getTempFileHttpEntity

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
private HttpEntity<byte[]> getTempFileHttpEntity(String filePath) throws IOException {
    String fullPath = uploadTempDir + filePath.replace("../", ""); //보안을 위해서 ../ 를 공백 처리한다.

    File file = new File(fullPath);

    String fileType = new MimetypesFileTypeMap().getContentType(file);
    String[] fileTypeArr = fileType.split("/");

    InputStream is = new FileInputStream(fullPath);
    byte[] fileBytes = IOUtils.toByteArray(is);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(new MediaType(fileTypeArr[0], fileTypeArr[1]));
    headers.setContentLength(file.length());

    return new HttpEntity<byte[]>(fileBytes, headers);
}
 
開發者ID:oreumio,項目名稱:rest,代碼行數:18,代碼來源:FileController.java

示例6: addResourcesInMessage

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
private String addResourcesInMessage(final MimeMessageHelper mailMessage, final String htmlText) throws Exception {
    final Document document = Jsoup.parse(htmlText);

    final List<String> resources = new ArrayList<>();

    final Elements imageElements = document.getElementsByTag("img");
    resources.addAll(imageElements.stream()
            .filter(imageElement -> imageElement.hasAttr("src"))
            .map(imageElement -> {
                final String src = imageElement.attr("src");
                imageElement.attr("src", "cid:" + src);
                return src;
            })
            .collect(Collectors.toList()));

    final String html = document.html();
    mailMessage.setText(html, true);

    for (final String res : resources) {
        final FileSystemResource templateResource = new FileSystemResource(new File(templatesPath, res));
        mailMessage.addInline(res, templateResource, MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(res));
    }

    return html;
}
 
開發者ID:gravitee-io,項目名稱:gravitee-management-rest-api,代碼行數:26,代碼來源:EmailServiceImpl.java

示例7: registerMediaTypes

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
private void registerMediaTypes() {
  // Common MIME types used for uploading attachments.
  mediaTypes = new MimetypesFileTypeMap();
  mediaTypes.addMimeTypes("application/msword doc");
  mediaTypes.addMimeTypes("application/vnd.ms-excel xls");
  mediaTypes.addMimeTypes("application/pdf pdf");
  mediaTypes.addMimeTypes("text/richtext rtx");
  mediaTypes.addMimeTypes("text/csv csv");
  mediaTypes.addMimeTypes("text/tab-separated-values tsv tab");
  mediaTypes.addMimeTypes("application/x-vnd.oasis.opendocument.spreadsheet ods");
  mediaTypes.addMimeTypes("application/vnd.oasis.opendocument.text odt");
  mediaTypes.addMimeTypes("application/vnd.ms-powerpoint ppt pps pot");
  mediaTypes.addMimeTypes("application/vnd.openxmlformats-officedocument."
      + "wordprocessingml.document docx");
  mediaTypes.addMimeTypes("application/vnd.openxmlformats-officedocument."
      + "spreadsheetml.sheet xlsx");
  mediaTypes.addMimeTypes("audio/mpeg mp3 mpeg3");
  mediaTypes.addMimeTypes("image/png png");
  mediaTypes.addMimeTypes("application/zip zip");
  mediaTypes.addMimeTypes("application/x-tar tar");
  mediaTypes.addMimeTypes("video/quicktime qt mov moov");
  mediaTypes.addMimeTypes("video/mpeg mpeg mpg mpe mpv vbs mpegv");
  mediaTypes.addMimeTypes("video/msvideo avi");
}
 
開發者ID:google,項目名稱:gdata-java-client,代碼行數:25,代碼來源:SitesHelper.java

示例8: download

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
@RequestMapping(value = "download")
public String download(HttpServletRequest request, HttpServletResponse response) throws IOException {
    ServletContext servletContext = request.getSession().getServletContext();

    String filename = servletContext.getRealPath("Schedule_Sample.xlsx");

    File file = new File(filename);

    response.setContentType(new MimetypesFileTypeMap().getContentType(file));
    response.setContentLength((int) file.length());
    response.setHeader("content-disposition", "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));

    InputStream is = new FileInputStream(file);
    FileCopyUtils.copy(is, response.getOutputStream());

    return null;
}
 
開發者ID:tranquang9a1,項目名稱:ECRM,代碼行數:18,代碼來源:ScheduleController.java

示例9: getResult

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
/**
 * @return A MimeMultipart object containing the zipped result files
 */
public MimeMultipart getResult() {

    File file = new File(JPLAG_RESULTS_DIRECTORY + File.separator
            + submissionID + getUsername() + ".zip");

    MimeMultipart mmp = new MimeMultipart();

    FileDataSource fds1 = new FileDataSource(file);
    MimetypesFileTypeMap mftp = new MimetypesFileTypeMap();
    mftp.addMimeTypes("multipart/zip zip ZIP");
    fds1.setFileTypeMap(mftp);

    MimeBodyPart mbp = new MimeBodyPart();

    try {
        mbp.setDataHandler(new DataHandler(fds1));
        mbp.setFileName(file.getName());

        mmp.addBodyPart(mbp);
    } catch (MessagingException me) {
        me.printStackTrace();
    }
    return mmp;
}
 
開發者ID:jplag,項目名稱:jplag,代碼行數:28,代碼來源:AccessStructure.java

示例10: setContentTypeHeader

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
/**
 * Sets the content type header for the HTTP Response
 *
 * @param response
 *            HTTP response
 * @param file
 *            file to extract content type
 */
private static void setContentTypeHeader(HttpResponse response, String path) {
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    ////////////////////////////////////////
    //NOTE: this does not work and behaves different between Java releases!!!!!
    ///////////////////////////////////////
    String contentType = mimeTypesMap.getContentType(path); 
    //patching mistake from the above broken code.
    if (path.endsWith("css")) {
        contentType = "text/css";
    } else if (path.endsWith("html")) {
        contentType = "text/html";
    } else if (path.endsWith("jpg")) {
        contentType = "image/jpeg";
    }
    response.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType);
}
 
開發者ID:oci-pronghorn,項目名稱:NettyStages,代碼行數:25,代碼來源:HttpStaticFileServerHandler.java

示例11: isImage

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
/**
 * Obtains a files MIME type and returns true if it is of type image
 * @param fileName
 * @param output
 * @return true if an image; false otherwise
 */
public static boolean isImage(String fileName, boolean output) {
	
	MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
	String mimeType = mimeTypesMap.getContentType(fileName);
	
	if(output){
		System.out.println("Validating input file...");
		System.out.println("File type: "+mimeType);
	}
	
	if(mimeType.startsWith("image")){
		return true;
	}else{
		
		if(output){
			System.out.println("Invalid file type input. Please enter an image");
		}
		
		return false;
	}
	
}
 
開發者ID:openimaj,項目名稱:openimaj,代碼行數:29,代碼來源:CityLandscapeUtilities.java

示例12: setContentTypeHeader

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
/**
 * Sets the content type header for the HTTP Response
 *
 * @param response
 *            HTTP response
 * @param file
 *            file to extract content type
 */
private static void setContentTypeHeader(HttpResponse response, String path) {
  String contentType = null;

  if(path.endsWith(".css")) {
    contentType = "text/css";
  }
  else if(path.endsWith(".js")) {
    contentType = "application/javascript";
  }
  else if(path.endsWith(".html")) {
    contentType = "text/html";
  }
  else {
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    contentType = mimeTypesMap.getContentType(path);
  }

  response.headers().set(CONTENT_TYPE, contentType);
}
 
開發者ID:camunda,項目名稱:camunda-bpm-workbench,代碼行數:28,代碼來源:HttpClasspathServerHandler.java

示例13: getMIMEType

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
/**
 * Return the mimetype of the file depending of his extension and the mime.types file
 * 
 * @param strFilename
 *            the file name
 * @return the file mime type
 */
public static String getMIMEType( String strFilename )
{
    try
    {
        MimetypesFileTypeMap mimeTypeMap = new MimetypesFileTypeMap( AppPathService.getWebAppPath( ) + File.separator + FILE_MIME_TYPE );

        return mimeTypeMap.getContentType( strFilename.toLowerCase( ) );
    }
    catch( IOException e )
    {
        AppLogService.error( e );

        return DEFAULT_MIME_TYPE;
    }
}
 
開發者ID:lutece-platform,項目名稱:lutece-core,代碼行數:23,代碼來源:FileSystemUtil.java

示例14: createItem

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
private Item createItem(File file, Document doc){
	
	Matcher matcher = fileNamePattern.matcher(file.getName());
	if (matcher.matches()) {
		String resourceName = matcher.group(1);
		String version = matcher.group(2);
		
		String suffix = FilenameUtils.getExtension(file.getName());
	
		Item item = new Item();
	
		item.file = file;
		item.doc = doc;
		item.resourceName = resourceName;
		item.version = version;
		item.fileSuffix = suffix;
		item.size = FileUtils.sizeOf(file);
		item.obsolete = false;
		item.mimetype = new MimetypesFileTypeMap().getContentType(file);
		
		return item;
	} else {
		return null;
	}
}
 
開發者ID:lexml,項目名稱:madoc,代碼行數:26,代碼來源:DirectoryCatalogStore.java

示例15: downloadFile

import javax.activation.MimetypesFileTypeMap; //導入依賴的package包/類
protected void downloadFile(HttpServletResponse response, String filePath) throws ServletException, IOException {  
	 File fileToDownload = new File(filePath);  
	 FileInputStream fileInputStream = new FileInputStream(fileToDownload);  
	  
	 ServletOutputStream out = response.getOutputStream();     
	 String mimeType =  new MimetypesFileTypeMap().getContentType(filePath);   
	  
	 response.setContentType(mimeType);   
	 response.setContentLength(fileInputStream.available());  
	 response.setHeader( "Content-Disposition", "attachment; filename=\""+ fileToDownload.getName() + "\"" );  
	  
	 int c;  
	 while((c=fileInputStream.read()) != -1){  
	  out.write(c);  
	 }  
	 out.flush();  
	 out.close();  
	 fileInputStream.close();  
}
 
開發者ID:WhiteBearSolutions,項目名稱:WBSAirback,代碼行數:20,代碼來源:WBSImagineServlet.java


注:本文中的javax.activation.MimetypesFileTypeMap類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。