Example usage for javax.activation MimetypesFileTypeMap MimetypesFileTypeMap

List of usage examples for javax.activation MimetypesFileTypeMap MimetypesFileTypeMap

Introduction

In this page you can find the example usage for javax.activation MimetypesFileTypeMap MimetypesFileTypeMap.

Prototype

public MimetypesFileTypeMap() 

Source Link

Document

The default constructor.

Usage

From source file:com.qmetry.qaf.automation.util.FileUtil.java

public static String getContentType(File f) {
    MimetypesFileTypeMap fileTypeMap = new MimetypesFileTypeMap();
    FileNameMap fileNameMap = URLConnection.getFileNameMap();
    String ct = fileNameMap.getContentTypeFor(f.getName());
    return StringUtil.isBlank(ct) ? fileTypeMap.getContentType(f) : ct;
}

From source file:com.emc.ecs.sync.source.DbListFilesystemSource.java

@Override
public Iterator<FileSyncObject> iterator() {
    return new ReadOnlyIterator<FileSyncObject>() {
        JdbcTemplate jdbc;//from ww w.j a va 2 s  .  com
        SqlRowSet rs;

        @Override
        protected FileSyncObject getNextObject() {
            if (rs == null) {
                jdbc = new JdbcTemplate(dataSource);
                rs = jdbc.queryForRowSet(selectQuery);
            }

            if (rs.next()) {
                File file = new File(rs.getString(filenameColumn));
                FileSyncObject object = new FileSyncObject(DbListFilesystemSource.this,
                        new MimetypesFileTypeMap(), file, getRelativePath(file), isFollowLinks());
                if (metadataColumns != null) {
                    for (String colName : metadataColumns) {
                        String value = rs.getString(colName);
                        if (value != null) {
                            object.getMetadata().setUserMetadataValue(colName, value);
                        }
                    }
                }
                return object;
            } else {
                // no more results
                return null;
            }
        }
    };
}

From source file:com.emc.vipr.sync.source.DbListFilesystemSource.java

@Override
public Iterator<FileSyncObject> iterator() {
    return new ReadOnlyIterator<FileSyncObject>() {
        JdbcTemplate tmpl;/*from w w w.  ja  va2s .  com*/
        SqlRowSet rs;

        @Override
        protected FileSyncObject getNextObject() {
            if (rs == null) {
                tmpl = new JdbcTemplate(dataSource);
                rs = tmpl.queryForRowSet(selectQuery);
            }

            if (rs.next()) {
                File file = new File(rs.getString(filenameColumn));
                FileSyncObject object = new FileSyncObject(DbListFilesystemSource.this,
                        new MimetypesFileTypeMap(), file, getRelativePath(file));
                if (metadataColumns != null) {
                    for (String colName : metadataColumns) {
                        String value = rs.getString(colName);
                        if (value != null) {
                            object.getMetadata().setUserMetadataValue(colName, value);
                        }
                    }
                }
                return object;
            } else {
                // no more results
                return null;
            }
        }
    };
}

From source file:com.eryansky.common.web.servlet.StaticContentServlet.java

/**
 * ??.//from   w  ww  . ja  va  2 s . c  o  m
 */
@Override
public void init() throws ServletException {
    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    CacheManager ehcacheManager = (CacheManager) context.getBean("ehCacheManager");
    contentInfoCache = ehcacheManager.getCache("contentInfoCache");

    //?mimeTypes, css,.
    mimetypesFileTypeMap = new MimetypesFileTypeMap();
    mimetypesFileTypeMap.addMimeTypes("text/css css");
}

From source file:org.craftercms.studio.impl.v1.content.pipeline.CheckImageSizeProcessor.java

public void process(PipelineContent content, ResultTO result) throws ContentProcessException {
    String name = content.getProperty(DmConstants.KEY_FILE_NAME);
    MimetypesFileTypeMap mimeTypesMap = new MimetypesFileTypeMap();
    String mimetype = mimeTypesMap.getContentType(name);
    //String isImage = content.getProperty(WcmConstants.KEY_IS_IMAGE);
    boolean process = (StringUtils.isEmpty(mimetype)) ? false
            : mimetype.startsWith("image/") && !StringUtils.equalsIgnoreCase(mimetype, "image/svg+xml");
    if (process) {
        String allowLessSize = content.getProperty(DmConstants.KEY_ALLOW_LESS_SIZE);
        boolean lessSize = ContentFormatUtils.getBooleanValue(allowLessSize);
        String allowedWidth = content.getProperty(DmConstants.KEY_ALLOWED_WIDTH);
        String allowedHeight = content.getProperty(DmConstants.KEY_ALLOWED_HEIGHT);
        int width = (StringUtils.isEmpty(allowedWidth)) ? -1 : ContentFormatUtils.getIntValue(allowedWidth);
        int height = (StringUtils.isEmpty(allowedHeight)) ? -1 : ContentFormatUtils.getIntValue(allowedHeight);
        InputStream in = content.getContentStream();
        ContentAssetInfoTO assetInfo = (result.getItem() == null) ? new ContentAssetInfoTO()
                : (ContentAssetInfoTO) result.getItem();
        in = checkForImageSize(in, width, height, lessSize, assetInfo);
        content.getProperties().put(DmConstants.KEY_WIDTH, String.valueOf(assetInfo.getWidth()));
        content.getProperties().put(DmConstants.KEY_HEIGHT, String.valueOf(assetInfo.getHeight()));
        assetInfo.getWidth();//from www.  ja v a  2 s. c  om
        result.setItem(assetInfo);
        content.setContentStream(in);
    }
}

From source file:com.lushapp.common.web.servlet.StaticContentServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    String cacheManager = config.getInitParameter("CacheManager");
    CacheManager ehcacheManager = (CacheManager) context.getBean(cacheManager);
    String cacheKey = config.getInitParameter("cacheKey");
    contentInfoCache = ehcacheManager.getCache(cacheKey);

    //?mimeTypes, css,.
    mimetypesFileTypeMap = new MimetypesFileTypeMap();
    mimetypesFileTypeMap.addMimeTypes("text/css css");
}

From source file:com.tdclighthouse.prototype.services.callbacks.ImageCreationCallBack.java

@Override
public String doInSession(Session session) throws RepositoryException {
    String result = null;/* ww  w . j a  v  a 2s  .co m*/
    try {
        // FIXME refactor
        Node node = createImageSetNode(session, contentType);
        result = DocumentManager.getHandle(node).getIdentifier();
        String mimeType = new MimetypesFileTypeMap().getContentType(file);
        Node galleryProcessorService = session.getNode(PluginConstants.Paths.GALLERY_PROCESSOR_SERVICE);

        for (NodeIterator sizes = galleryProcessorService.getNodes(); sizes.hasNext();) {
            Node size = sizes.nextNode();
            if (size.isNodeType(PluginConstants.NodeType.FRONTEND_PLUGINCONFIG)) {
                Node subjectNode = getNode(node, size.getName(), PluginConstants.NodeType.HIPPOGALLERY_IMAGE);
                Long height = size.getProperty(PluginConstants.PropertyName.HEIGHT).getLong();
                Long width = size.getProperty(PluginConstants.PropertyName.WIDTH).getLong();
                BufferedImage bufferedImage = ImageIO.read(file);
                InputStream inputStream;
                if (height == 0 && width == 0) {
                    inputStream = new FileInputStream(file);
                    height = (long) bufferedImage.getHeight();
                    width = (long) bufferedImage.getWidth();
                } else {
                    ImageSize scaledSize = getScaledSize(height, width, bufferedImage);
                    BufferedImage scaledImage = ImageUtils.scaleImage(bufferedImage,
                            scaledSize.width.intValue(), scaledSize.height.intValue(),
                            ScalingStrategy.BEST_QUALITY);
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    ImageIO.write(scaledImage, "jpg", byteArrayOutputStream);
                    byteArrayOutputStream.flush();
                    inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
                    height = (long) scaledImage.getHeight();
                    width = (long) scaledImage.getWidth();
                }
                subjectNode.setProperty(PluginConstants.PropertyName.JCR_DATA,
                        session.getValueFactory().createBinary(inputStream));
                subjectNode.setProperty(PluginConstants.PropertyName.JCR_MIME_TYPE, mimeType);
                subjectNode.setProperty(PluginConstants.PropertyName.JCR_LAST_MODIFIED,
                        new GregorianCalendar());
                subjectNode.setProperty(PluginConstants.PropertyName.HIPPOGALLERY_HEIGHT, height);
                subjectNode.setProperty(PluginConstants.PropertyName.HIPPOGALLERY_WIDTH, width);
            }
        }

    } catch (IOException | WorkflowException e) {
        throw new RepositoryException(e);
    }
    return result;
}

From source file:de.knurt.fam.core.model.config.FileUploadController.java

public FileUploadController(TemplateResource tr, HttpServletResponse response) {
    reinitOptions();//from  w ww.j  a va 2  s  .co  m
    this.tr = tr;
    this.response = response;
    this.factory = new DiskFileItemFactory();
    this.mftm = new MimetypesFileTypeMap();
    this.uploadDir = new FileOfUser(tr.getAuthUser()).getUploadDir();
}

From source file:org.sakaiproject.nakamura.docproxy.disk.DiskDocumentResult.java

/**
 * {@inheritDoc}/*from  w  w w.j ava2 s.  com*/
 * 
 * @see org.sakaiproject.kernel.api.docproxy.ExternalDocumentResultMetadata#getContentType()
 */
public String getContentType() {
    MimetypesFileTypeMap map = new MimetypesFileTypeMap();
    return map.getContentType(file);
}

From source file:de.jakusys.jackhammer.cli.command.UploadingFileAlternationListener.java

private void uploadFile(File file) {

    MimetypesFileTypeMap mimetypesFileTypeMap = new MimetypesFileTypeMap();

    try {//from  www . ja v a  2 s.c  o m
        String relPath = PathRelativizer.relativize(root, file.getParentFile());
        Node parent = getNode(relPath);
        String contentType = mimetypesFileTypeMap.getContentType(file);
        JcrUtils.putFile(parent, file.getName(), contentType, new FileInputStream(file));

        session.save();
    } catch (RepositoryException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } catch (FileNotFoundException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    }
}