/** * Returns the mime-type associated with this extension, or the server's default. */ public static String getMIMETypeOrDefault(String extension) { String mimeType = getMIMEType(extension); if (StringUtils.isNotEmpty(mimeType)) { return mimeType; } if (StringUtils.isNotEmpty(extension)) { log.info("Cannot find MIME type for extension \"{}\"", extension); } String defaultExtension = ServerConfiguration.getInstance().getDefaultExtension(); if (StringUtils.isBlank(defaultExtension)) { defaultExtension = DEFAULT_EXTENSION; } return getMIMEType(defaultExtension); }
protected static String getIcon(String repository, String path) { if (ItemType.DELETED_NODE_MIXIN.equals(path)) { return ".resources/icons/16/document_deleted.gif"; } if (StringUtils.equals(repository, "website")) { return ".resources/icons/16/document_plain_earth.gif"; } if (StringUtils.equals(repository, "dms")) { String type = NodeDataUtil.getString(repository, path + "/type"); if("folder".equals(type)){ return ".resources/icons/16/folder.gif"; } else if(StringUtils.isNotEmpty(type)){ return StringUtils.removeStart(MIMEMapping.getMIMETypeIcon(type), "/"); } } return ".resources/icons/16/mail.gif"; }
@Override public void onEvent(EventIterator iterator) { // reload everything reload(); } });
protected String getMimeType(String extension, HttpServletResponse response) { final String mimeType; if (isRegisteredExtensionsOnly()) { if (StringUtils.isBlank(extension)) { extension = serverConfiguration.getDefaultExtension(); if (StringUtils.isBlank(extension)) { extension = MIMEMapping.DEFAULT_EXTENSION; } } mimeType = MIMEMapping.getMIMEType(extension); if (mimeType == null) { return null; } } else { mimeType = MIMEMapping.getMIMETypeOrDefault(extension); } return mimeType; }
MIMEMapping.init(); versionConfig.init();
@Test public void testGetIconStyleReturnsDefaultValueIfMimeTypeHasNoIconAssigned() throws Exception { // GIVEN // WHEN String icon = MIMEMapping.getMIMETypeIconStyle(MIME_TYPE_HTML); // THEN assertThat(icon, equalTo(MIMEMapping.DEFAULT_ICON_STYLE)); }
private String resolveContentType(String... paths) { String extension = null; boolean sameExtensionForAllResources = true; for (String path: paths) { String actualExtension = resolveExtension(path); if (extension == null) { extension = actualExtension; } else if (!StringUtils.equalsIgnoreCase(extension, actualExtension)) { sameExtensionForAllResources = false; break; } } if (sameExtensionForAllResources) { return MIMEMapping.getMIMETypeOrDefault(extension); } return MIMEMapping.getMIMETypeOrDefault(StringUtils.EMPTY); // use default content type }
@Before public void setUp() throws Exception { servlet = new ClasspathSpool() { @Override public String getInitParameter(String s) { return "/info/magnolia/cms/servlets"; } }; servlet.init(); request = mock(HttpServletRequest.class); response = mock(HttpServletResponse.class); ServletOutputStream outputStream = mock(ServletOutputStream.class); when(response.getOutputStream()).thenReturn(outputStream); ComponentsTestUtil.setInstance(SystemContext.class, new MockContext()); Session configMimeMapping = SessionTestUtil.createSession(RepositoryConstants.CONFIG, "/server/MIMEMapping/css.extension=css\n" + "/server/MIMEMapping/css.mime-type=text/css\n" + "/server/MIMEMapping/html.extension=html\n" + "/server/MIMEMapping/html.mime-type=text/html\n" ); MockUtil.setSystemContextSessionAndHierarchyManager(configMimeMapping); MIMEMapping.init(); }
@Test public void testGetIconStyleReturnsCorrectIconStyle1() throws Exception { // GIVEN // WHEN String icon = MIMEMapping.getMIMETypeIconStyle(MIME_TYPE_PNG); // THEN assertThat(icon, equalTo(ICON_STYLE_PNG)); }
@Override protected boolean boolVote(Object value) { if (!MgnlContext.isWebContext()) { return false; } final String extension = getAggregationStateProvider().get().getExtension(); final String contentType = MIMEMapping.getMIMETypeOrDefault(extension); if (getAllowed().size() > 0 && !getAllowed().contains(contentType)) { return false; } if (getRejected().size() > 0 && getRejected().contains(contentType)) { return false; } return true; } }
@Override @Before public void setUp() throws Exception { super.setUp(); ComponentsTestUtil.setImplementation(WebContainerResources.class, WebContainerResourcesImpl.class); filter = new ContentTypeFilter(); request = mock(HttpServletRequest.class); response = mock(HttpServletResponse.class); String configMimeMapping = "/server/MIMEMapping/foo\n" + "/server/MIMEMapping/foo.@type=mgnl:contentNode\n" + "/server/MIMEMapping/foo.mime-type=mime/foo\n" + "/server/MIMEMapping/bar\n" + "/server/MIMEMapping/bar.@type=mgnl:contentNode\n" + "/server/MIMEMapping/bar.mime-type=mime/bar\n" + "/server/MIMEMapping/html\n" + "/server/MIMEMapping/html.extension=html\n" + "/server/MIMEMapping/html.mime-type=text/html"; session = MgnlContext.getJCRSession(RepositoryConstants.CONFIG); new PropertiesImportExport().createNodes(session.getRootNode(), IOUtils.toInputStream(configMimeMapping)); session.save(); MIMEMapping.init(); }
public String getContentType() { return MIMEMapping.getMIMEType(StringUtils.substringAfterLast(this.getPath(), ".")); }
protected void writeInnerHtml(Writer out, final boolean showImage, File control, StringBuffer htmlControlFileName, String link) throws IOException { out.write(htmlControlFileName.toString()); if (!showImage) { String iconPath = MIMEMapping.getMIMETypeIcon(control.getExtension()); out.write(Spacer.getHtml(0, 0)); out.write("<a href="); out.write(link); out.write(" target=\"_blank\">"); //$NON-NLS-1$ out.write("<img src=\"" //$NON-NLS-1$ + this.getRequest().getContextPath() + iconPath + "\" class=\"" //$NON-NLS-1$ + CssConstants.CSSCLASS_FILEICON + "\" border=\"0\">"); //$NON-NLS-1$ out.write(control.getFileName() + "." + control.getExtension() + "</a>"); //$NON-NLS-1$ //$NON-NLS-2$ } }
@Override @After public void tearDown() throws Exception { // TODO MAGNOLIA-6576 there's no way to reset the MIMEMappings, it's leaking into other tests. session.removeItem("/server/MIMEMapping"); MIMEMapping.reload(); super.tearDown(); }
@Test public void testGetIconStyleReturnsCorrectIconStyle2() throws Exception { // GIVEN // WHEN // icon for this particular type is not set, but "parent" mime-type is set for all videos and it uses icon-file-video String icon = MIMEMapping.getMIMETypeIconStyle(MIME_TYPE_VIDEO_QUICKTIME); // THEN assertThat(icon, equalTo(ICON_STYLE_VIDEO)); }
final HttpServletResponse response = MgnlContext.getWebContext().getResponse(); if (!response.containsHeader("Content-Type")) { response.setContentType(StringUtils.defaultIfBlank(getContentType(definition), MIMEMapping.getMIMETypeOrDefault(MIMEMapping.DEFAULT_EXTENSION)));
@Before public void setUp() throws Exception { MockWebContext ctx = new MockWebContext(); MockSession session = new MockSession(RepositoryConstants.CONFIG); ctx.addSession(RepositoryConstants.CONFIG, session); Node zipMime = NodeUtil.createPath(session.getRootNode(), "/server/MIMEMapping/zip", NodeTypes.ContentNode.NAME); zipMime.setProperty("mime-type", "application/zip"); zipMime.setProperty("extension", "zip"); MgnlContext.setInstance(ctx); ComponentsTestUtil.setInstance(SystemContext.class, ctx); definition = new BasicUploadFieldDefinition(); basicUploadField = new BasicUploadField(mock(ImageProvider.class), mock(UiContext.class), definition, mock(SimpleTranslator.class)); basicUploadField.setPropertyDataSource(mock(Property.class)); DragAndDropWrapper.WrapperTransferable transferable = mock(DragAndDropWrapper.WrapperTransferable.class); Html5File[] files = new Html5File[1]; file = mock(Html5File.class); doCallRealMethod().when(file).setStreamVariable(any(StreamVariable.class)); doCallRealMethod().when(file).getStreamVariable(); files[0] = file; when(transferable.getFiles()).thenReturn(files); event = new DragAndDropEvent(transferable, mock(TargetDetails.class)); MIMEMapping.init(); }
@Override protected boolean boolVote(Object value) { String extension; if (value instanceof String) { extension = StringUtils.substringAfterLast((String) value, "."); } else { extension = MgnlContext.getAggregationState().getExtension(); } if (StringUtils.isEmpty(MIMEMapping.getMIMEType(extension))) { return false; // check for MIMEMapping, extension must exist } if (allow != null && allow.length > 0 && !ArrayUtils.contains(allow, extension)) { return false; } if (deny != null && deny.length > 0 && ArrayUtils.contains(deny, extension)) { return false; } return true; }
if (!showImage) String iconPath = MIMEMapping.getMIMETypeIcon(control.getExtension());
@After public void tearDown() throws Exception { // TODO MAGNOLIA-6576 there's no way to reset the MIMEMappings, it's leaking into other tests. configMimeMapping.removeItem("/server/MIMEMapping"); MIMEMapping.reload(); ComponentsTestUtil.clear(); }