public String toPath() { String encodedFilename = IOUtility.urlEncode(getFileName()); // / was encoded by %2F, revert this encoding otherwise filename doesn't look nice in browser download // Example for filesnames containing a /: // - relative reference from a unzipped zip file // - another path segment was explicitly added to distinguish between same filenames encodedFilename = encodedFilename.replace("%2F", "/"); return PATH_PREFIX + '/' + getUiSession().getUiSessionId() + '/' + getJsonAdapterId() + '/' + encodedFilename; }
protected String calcContentDispositionHeaderValue(String originalFilename) { // Internet Explorer 11 cannot parse names with characters 0x00-0x1F, neither in filename= nor encoded in filename*= // Note: 0x00-0x1F are the same in UTF-16 and ISO-8859-1, thus replacing them here is safe. if (originalFilename != null) { originalFilename = originalFilename.replaceAll("[\\x00-\\x1F]", ""); } if (StringUtility.isNullOrEmpty(originalFilename)) { originalFilename = DEFAULT_FILENAME; } String isoFilename = getIsoFilename(originalFilename); //remove ", because it is used to encapsulate the file name isoFilename = StringUtility.replace(isoFilename, "\"", ""); if (StringUtility.isNullOrEmpty(isoFilename)) { // in case no valid character remains isoFilename = DEFAULT_FILENAME; } return "attachment; filename=\"" + isoFilename + "\"; filename*=utf-8''" + IOUtility.urlEncode(originalFilename); }
protected void handleModelOpenUri(BinaryResource res, IOpenUriAction openUriAction) { String filename = ObjectUtility.nvl(res.getFilename(), "binaryData"); String filenameEncoded = IOUtility.urlEncode(filename); // add another path segment to filename to distinguish between different resources // with the same filename (also makes hash collisions irrelevant). long counter = RESOURCE_COUNTER.getAndIncrement(); filenameEncoded = counter + "/" + filenameEncoded; BinaryResourceHolder holder = new BinaryResourceHolder(res); if (openUriAction == OpenUriAction.DOWNLOAD) { holder.addHttpResponseInterceptor(new DownloadHttpResponseInterceptor(res.getFilename())); } m_downloads.put(filenameEncoded, holder, openUriAction); String downloadUrl = BinaryResourceUrlUtility.createDynamicAdapterResourceUrl(this, filenameEncoded); handleModelOpenUri(downloadUrl, openUriAction); }