List of usage examples for org.springframework.util StringUtils getFilenameExtension
@Nullable public static String getFilenameExtension(@Nullable String path)
From source file:org.web4thejob.web.util.MediaUtil.java
public static final byte[] signMedia(String name, byte[] media) { byte[] mediaFormat = Arrays.copyOf(StringUtils.getFilenameExtension(name).toLowerCase().getBytes(), MEDIA_TYPE_SIGNATURE);//from ww w.j a v a2 s . c om return ArrayUtils.addAll(mediaFormat, media); }
From source file:net.sourceforge.subsonic.command.SavePlaylistCommand.java
public SavePlaylistCommand(Playlist playlist) { this.playlist = playlist; name = StringUtils.stripFilenameExtension(playlist.getName()); suffix = StringUtils.getFilenameExtension(playlist.getName()); formats = new String[] { "m3u", "pls", "xspf" }; }
From source file:com.example.securelogin.app.common.validation.FileExtensionValidator.java
@Override public boolean isValid(MultipartFile value, ConstraintValidatorContext context) { if (value == null) { return true; }/* w w w. j a v a 2s . c om*/ String fileNameExtension = StringUtils.getFilenameExtension(value.getOriginalFilename()); if (!StringUtils.hasLength(fileNameExtension)) { return false; } for (String extension : extensions) { if (fileNameExtension.equals(extension) || ignoreCase && fileNameExtension.equalsIgnoreCase(extension)) { return true; } } return false; }
From source file:net.solarnetwork.web.support.WebUtils.java
/** * Resolve a ModelAndView with an empty model and a view name determined by the * URL "suffix".//from w ww .jav a 2 s.c om * * <p>If the {@link #getViewName()} method returns a value, that view name is used * for every request. Otherwise, this sets the view name to the value of the URL * "suffix", that is, everything after the last period in the URL. This uses * {@link StringUtils#getFilenameExtension(String)} on the request URI to accomplish * this. For example a URL like {@code /myController.json} would resolve to a view * named {@code json}. This can be handy when you want to return different data formats * for the same business logic, such as XML or JSON.</p> * * <p>The {@code viewName} parameter can be used to override the view mapping logic * and instead simply return a {@link ModelAndView} object for the given name. * For normal controllers with a configurable view name property, that property can * be passed in here, but usually the value will not be configured.</p> * * @param request the HTTP request * @param viewName the custom view name * @return a view name (never <em>null</em>) */ public static String resolveViewFromUrlExtension(HttpServletRequest request, String viewName) { // resolve the final view name based on the URL suffix, i.e. "*.xml" -> "xml" String resolvedViewName = viewName; if (resolvedViewName == null) { resolvedViewName = StringUtils.getFilenameExtension(request.getRequestURI()); } return resolvedViewName; }
From source file:com.asual.summer.core.view.AbstractResponseView.java
protected String getFilename(HttpServletRequest request) { String requestUri = urlPathHelper.getLookupPathForRequest(request); String filename = WebUtils.extractFullFilenameFromUrlPath(requestUri); String extension = StringUtils.getFilenameExtension(filename); return filename.replaceFirst("\\." + extension + "$", "") + "." + getExtension(); }
From source file:de.codecentric.boot.admin.web.servlet.resource.PreferMinifiedFilteringResourceResolver.java
private Resource findMinified(Resource resource) { try {//from w w w .jav a 2 s.c om String basename = StringUtils.stripFilenameExtension(resource.getFilename()); String extension = StringUtils.getFilenameExtension(resource.getFilename()); Resource minified = resource.createRelative(basename + extensionPrefix + '.' + extension); if (minified.exists()) { return minified; } } catch (IOException ex) { logger.trace("No minified resource for [" + resource.getFilename() + "]", ex); } return null; }
From source file:com.iwancool.dsm.service.impl.AbstractBaseService.java
/** * ????//from w w w .j av a2s . co m * * @author long * @param type * @return * @throws Exception * @return String * @exception * @author long * @since 1.0.0 * @date 2015715 ?7:03:40 */ public String getRandomFileName(String type) throws Exception { Random random = new Random(1000); int randomNum = random.nextInt(9999); return System.currentTimeMillis() + "_" + randomNum + "." + StringUtils.getFilenameExtension(type); }
From source file:org.web4thejob.web.zbox.MediaBox.java
@Override public void onEvent(Event event) throws Exception { if (event instanceof UploadEvent) { Media media = ((UploadEvent) event).getMedia(); if (media == null) { ZkUtil.displayMessage(L10nMessages.L10N_NOTHING_SELECTED_ERROR.toString(), true, this); return; }// w ww. ja v a2s.c om name = media.getName(); if (imageHolder && !MediaUtil.isImage(StringUtils.getFilenameExtension(name))) { ZkUtil.displayMessage(L10nMessages.L10N_INVALID_IMAGE_FORMAT_ERROR.toString(), true, this); } else { if (media.isBinary()) { setRawValue(MediaUtil.signMedia(name, media.getByteData())); } else { setRawValue(MediaUtil.signMedia(name, media.getStringData().getBytes())); } } return; } super.onEvent(event); }
From source file:org.openmrs.module.metadatasharing.publish.PublishUtils.java
/** * Removes extension from the given path. If present. *///from w w w.j a v a2 s.c o m private static String removeExtension(String path) { if (StringUtils.getFilenameExtension(path) != null) { path = path.substring(0, path.length() - StringUtils.getFilenameExtension(path).length() - 1); } return path; }
From source file:org.cloudfoundry.tools.io.compiler.ResourceJavaFileManager.java
private Kind getKind(File file) { String extension = StringUtils.getFilenameExtension(file.getName()); extension = extension == null ? "" : "." + extension; for (Kind kind : Kind.values()) { if (kind.extension.equals(extension)) { return kind; }/*from ww w.ja va 2s. com*/ } return Kind.OTHER; }