Java Code Examples for javax.activation.MimetypesFileTypeMap#addMimeTypes()

The following examples show how to use javax.activation.MimetypesFileTypeMap#addMimeTypes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessStructure.java    From jplag with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @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;
}
 
Example 2
Source File: BinaryResourceDownloadMeta.java    From eplmp with Eclipse Public License 1.0 5 votes vote down vote up
private static void initFileTypeMap() {
    fileTypeMap = new MimetypesFileTypeMap();

    // Additional MIME types
    fileTypeMap.addMimeTypes("application/atom+xml atom");
    fileTypeMap.addMimeTypes("application/msword doc dot");
    fileTypeMap.addMimeTypes("application/mspowerpoint ppt pot");
    fileTypeMap.addMimeTypes("application/msexcel xls");
    fileTypeMap.addMimeTypes("application/pdf pdf");
    fileTypeMap.addMimeTypes("application/rdf+xml rdf rss");
    fileTypeMap.addMimeTypes("application/x-vnd.openxmlformat docx docm dotx dotm");
    fileTypeMap.addMimeTypes("application/x-vnd.openxmlformat xlsx xlsm");
    fileTypeMap.addMimeTypes("application/x-vnd.openxmlformat pptx pptm potx");
    fileTypeMap.addMimeTypes("application/x-javascript js");
    fileTypeMap.addMimeTypes("application/x-rar-compressed rar");
    fileTypeMap.addMimeTypes("application/x-textedit bat cmd");
    fileTypeMap.addMimeTypes("application/zip zip");
    fileTypeMap.addMimeTypes("audio/mpeg mp3");
    fileTypeMap.addMimeTypes("image/bmp bmp");
    fileTypeMap.addMimeTypes("image/gif gif");
    fileTypeMap.addMimeTypes("image/jpeg jpg jpeg jpe");
    fileTypeMap.addMimeTypes("image/png png");
    fileTypeMap.addMimeTypes("text/css css");
    fileTypeMap.addMimeTypes("text/csv csv");
    fileTypeMap.addMimeTypes("text/html htm html");
    fileTypeMap.addMimeTypes("text/xml xml");
    fileTypeMap.addMimeTypes("video/quicktime qt mov moov");
    fileTypeMap.addMimeTypes("video/mpeg mpeg mpg mpe mpv vbs mpegv");
    fileTypeMap.addMimeTypes("video/msvideo avi");
    fileTypeMap.addMimeTypes("video/mp4 mp4");
    fileTypeMap.addMimeTypes("video/ogg ogg");

    FileTypeMap.setDefaultFileTypeMap(fileTypeMap);
}
 
Example 3
Source File: MockServletContextTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Introduced to dispel claims in a thread on Stack Overflow:
 * <a href="http://stackoverflow.com/questions/22986109/testing-spring-managed-servlet">Testing Spring managed servlet</a>
 */
@Test
public void getMimeTypeWithCustomConfiguredType() {
	FileTypeMap defaultFileTypeMap = FileTypeMap.getDefaultFileTypeMap();
	assertThat(defaultFileTypeMap, instanceOf(MimetypesFileTypeMap.class));
	MimetypesFileTypeMap mimetypesFileTypeMap = (MimetypesFileTypeMap) defaultFileTypeMap;
	mimetypesFileTypeMap.addMimeTypes("text/enigma    enigma");
	assertEquals("text/enigma", sc.getMimeType("filename.enigma"));
}
 
Example 4
Source File: FileFilter.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
public FileFilter(final FileService fileService,
                  final SystemService systemService) {
    this.fileService = fileService;
    this.systemService = systemService;
    fileTypeMap = new MimetypesFileTypeMap();
    fileTypeMap.addMimeTypes("image/bmp bmp");
    fileTypeMap.addMimeTypes("application/x-shockwave-flash swf");
}
 
Example 5
Source File: ImageFilter.java    From yes-cart with Apache License 2.0 5 votes vote down vote up
public ImageFilter(final ImageService imageService,
                   final SystemService systemService) {
    this.imageService = imageService;
    this.systemService = systemService;
    fileTypeMap = new MimetypesFileTypeMap();
    fileTypeMap.addMimeTypes("image/bmp bmp");
    fileTypeMap.addMimeTypes("image/png png");
    fileTypeMap.addMimeTypes("application/x-shockwave-flash swf");
}
 
Example 6
Source File: HttpStaticFileServerHandler.java    From codes-scratch-zookeeper-netty with Apache License 2.0 5 votes vote down vote up
/**
 * This will set the content types of files. If you want to support any
 * files add the content type and corresponding file extension here.
 *
 * @param response
 * @param file
 */
private static void setContentTypeHeader(HttpResponse response, File file) {
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    mimeTypesMap.addMimeTypes("image png tif jpg jpeg bmp");
    mimeTypesMap.addMimeTypes("text/plain txt");
    mimeTypesMap.addMimeTypes("application/pdf pdf");

    String mimeType = mimeTypesMap.getContentType(file);

    response.headers().set(CONTENT_TYPE, mimeType);
}
 
Example 7
Source File: MailDaemon.java    From Open-Lowcode with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * sends invitation
 * 
 * @param session     session connection to the SMTP server
 * @param toemails    list of recipient e-mails
 * @param subject     invitation subject
 * @param body        invitation start
 * @param fromemail   user sending the invitation
 * @param startdate   start date of the invitation
 * @param enddate     end date of the invitation
 * @param location    location of the invitation
 * @param uid         unique id
 * @param cancelation true if this is a cancelation
 */
private void sendInvitation(Session session, String[] toemails, String subject, String body, String fromemail,
		Date startdate, Date enddate, String location, String uid, boolean cancelation) {
	try {
		// prepare mail mime message
		MimetypesFileTypeMap mimetypes = (MimetypesFileTypeMap) MimetypesFileTypeMap.getDefaultFileTypeMap();
		mimetypes.addMimeTypes("text/calendar ics ICS");
		// register the handling of text/calendar mime type
		MailcapCommandMap mailcap = (MailcapCommandMap) MailcapCommandMap.getDefaultCommandMap();
		mailcap.addMailcap("text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain");

		MimeMessage msg = new MimeMessage(session);
		// set message headers

		msg.addHeader("Content-type", "text/HTML; charset=UTF-8");
		msg.addHeader("format", "flowed");
		msg.addHeader("Content-Transfer-Encoding", "8bit");
		InternetAddress fromemailaddress = new InternetAddress(fromemail);
		msg.setFrom(fromemailaddress);
		msg.setReplyTo(InternetAddress.parse(fromemail, false));
		msg.setSubject(subject, "UTF-8");
		msg.setSentDate(new Date());

		// set recipient

		InternetAddress[] recipients = new InternetAddress[toemails.length + 1];

		String attendeesinvcalendar = "";
		for (int i = 0; i < toemails.length; i++) {
			recipients[i] = new InternetAddress(toemails[i]);
			attendeesinvcalendar += "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE:MAILTO:"
					+ toemails[i] + "\n";
		}

		recipients[toemails.length] = fromemailaddress;
		msg.setRecipients(Message.RecipientType.TO, recipients);

		Multipart multipart = new MimeMultipart("alternative");
		// set body
		MimeBodyPart descriptionPart = new MimeBodyPart();
		descriptionPart.setContent(body, "text/html; charset=utf-8");
		multipart.addBodyPart(descriptionPart);

		// set invitation
		BodyPart calendarPart = new MimeBodyPart();

		String method = "METHOD:REQUEST\n";
		if (cancelation)
			method = "METHOD:CANCEL\n";

		String calendarContent = "BEGIN:VCALENDAR\n" + method + "PRODID: BCP - Meeting\n" + "VERSION:2.0\n"
				+ "BEGIN:VEVENT\n" + "DTSTAMP:" + iCalendarDateFormat.format(new Date()) + "\n" + "DTSTART:"
				+ iCalendarDateFormat.format(startdate) + "\n" + "DTEND:" + iCalendarDateFormat.format(enddate)
				+ "\n" + "SUMMARY:" + subject + "\n" + "UID:" + uid + "\n" + attendeesinvcalendar
				+ "ORGANIZER:MAILTO:" + fromemail + "\n" + "LOCATION:" + location + "\n" + "DESCRIPTION:" + subject
				+ "\n" + "SEQUENCE:0\n" + "PRIORITY:5\n" + "CLASS:PUBLIC\n" + "STATUS:CONFIRMED\n"
				+ "TRANSP:OPAQUE\n" + "BEGIN:VALARM\n" + "ACTION:DISPLAY\n" + "DESCRIPTION:REMINDER\n"
				+ "TRIGGER;RELATED=START:-PT00H15M00S\n" + "END:VALARM\n" + "END:VEVENT\n" + "END:VCALENDAR";

		calendarPart.addHeader("Content-Class", "urn:content-classes:calendarmessage");
		calendarPart.setContent(calendarContent, "text/calendar;method=CANCEL");
		multipart.addBodyPart(calendarPart);
		msg.setContent(multipart);
		logger.severe("Invitation is ready");
		Transport.send(msg);

		logger.severe("EMail Invitation Sent Successfully!! to " + attendeesinvcalendar);
	} catch (Exception e) {
		logger.severe(
				"--- Exception in sending invitation --- " + e.getClass().toString() + " - " + e.getMessage());
		if (e.getCause() != null)
			logger.severe(" cause  " + e.getCause().getClass().toString() + " - " + e.getCause().getMessage());
		throw new RuntimeException("email sending error " + e.getMessage() + " for server = server:"
				+ this.smtpserver + " - port:" + this.port + " - user:" + this.user);
	}

}
 
Example 8
Source File: FileDropTargetListener.java    From magarena with GNU General Public License v3.0 4 votes vote down vote up
private String tryMimetypesFileTypeMap(File aFile) {
    final MimetypesFileTypeMap mtftp = new MimetypesFileTypeMap();
    mtftp.addMimeTypes("image " + IMAGE_FORMATS);
    mtftp.addMimeTypes("application/zip zip");
    return mtftp.getContentType(aFile);
}
 
Example 9
Source File: StaticContentFilter.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void init(FilterConfig filterConfig) throws ServletException {
    this.filterConfig = filterConfig;
    // 初始化mimeTypes, 默认缺少css的定义,添加之.
    mimetypesFileTypeMap = new MimetypesFileTypeMap();
    mimetypesFileTypeMap.addMimeTypes("text/css css");
}