/** * Resolves static content with a given path in a given publication. * <p>Requires localization path to request the content, so resolves it using localization ID if the path is missing. * If you already know publication path, providing it in a request would give you a bit better performance. </p> * If file is resolved, caches the file locally, so won't download it again unless it needs to be refreshed. * * @param requestDto request DTO * @return requested static file * @throws StaticContentNotFoundException if cannot resolve static file for any reason * @dxa.publicApi */ @NotNull public StaticContentItem getStaticContent(@NotNull StaticContentRequestDto requestDto) throws ContentProviderException { log.trace("getStaticContent: {}", requestDto); StaticContentRequestDto adaptedRequest = requestDto.isLocalizationPathSet() ? requestDto : requestDto.toBuilder().localizationPath( _resolveLocalizationPath(requestDto.getLocalizationId())).build(); final String contentPath = _getContentPath(adaptedRequest.getBinaryPath(), adaptedRequest.getLocalizationPath()); return _getStaticContentFile(contentPath, adaptedRequest); }
private StaticContentItem _getStaticContentFile(String path, StaticContentRequestDto requestDto) throws ContentProviderException { String parentPath = StringUtils.join(new String[]{ webApplicationContext.getServletContext().getRealPath("/"), STATIC_FILES_DIR, requestDto.getLocalizationId() }, File.separator); int publicationId = Integer.parseInt(requestDto.getLocalizationId()); BinaryMeta binaryMeta; ComponentMetaFactory factory = new ComponentMetaFactory(publicationId); binaryMeta = dynamicMetaRetriever.getBinaryMetaByURL(_prependFullUrlIfNeeded(pathInfo.getFileName(), requestDto.getBaseUrl())); if (binaryMeta == null) { throw new StaticContentNotFoundException("No binary meta found for: [" + publicationId + "] " + boolean shouldRefresh = isToBeRefreshed(file, componentTime) || requestDto.isNoMediaCache();
@Override public boolean isVersioned() { return requestDto.getBinaryPath().contains("/system/"); } };
public static StaticContentRequestDtoBuilder builder(String binaryPath, String localizationId) { return hiddenBuilder().localizationId(localizationId).binaryPath(binaryPath); }
/** * {@inheritDoc} * * @dxa.publicApi */ @Override public StaticContentItem getStaticContent(final String path, String localizationId, String localizationPath) throws ContentProviderException { return staticContentResolver.getStaticContent( StaticContentRequestDto.builder(path, localizationId) .localizationPath(localizationPath) .baseUrl(webRequestContext.getBaseUrl()) .noMediaCache(!FileUtils.isEssentialConfiguration(path, localizationPath) && webRequestContext.isPreview()) .build()); }