/** * <p>parseJsonFileTree.</p> * * @param contentProvider a {@link com.sdl.webapp.common.api.content.ContentProvider} object. * @param filePath a {@link java.lang.String} object. * @param locId a {@link java.lang.String} object. * @param locPath a {@link java.lang.String} object. * @return a {@link com.fasterxml.jackson.databind.JsonNode} object. * @throws com.sdl.webapp.common.api.localization.LocalizationFactoryException if any. */ public JsonNode parseJsonFileTree(ContentProvider contentProvider, String filePath, String locId, String locPath) throws LocalizationFactoryException { try { final StaticContentItem item = contentProvider.getStaticContent(filePath, locId, locPath); try (final InputStream in = item.getContent()) { return objectMapper.readTree(in); } } catch (ContentProviderException | IOException e) { throw new LocalizationFactoryException("Exception while reading configuration of localization: [" + locId + "] " + locPath, e); } }
/** * Resolves a link. This translates the input URL to a link that can be used on a web page. What the input URL * is exactly depends on the implementation and what the source of the data is - it might for example be a Tridion * "tcm:" URL which refers to a Tridion component. * * @param url The TCM URI to resolve. * @param localizationId The localization ID to use. * @return The translated URL. */ @Contract("null, _ -> null; !null, _ -> !null") default String resolveLink(@Nullable String url, @Nullable String localizationId) { return resolveLink(url, localizationId, false); } }
@NotNull @Override protected EntityModel _getEntityModel(String componentId) throws ContentProviderException { EntityModelData modelData = modelService.loadEntity(componentId); try { return builderPipeline.createEntityModel(modelData); } catch (DxaException e) { throw new ContentProviderException("Cannot build the entity model for componentId" + componentId, e); } }
staticContentItem = contentProvider.getStaticContent(requestPath, localization.getId(), localization.getPath()); } catch (StaticContentNotFoundException e) { fallbackForContentProvider(req, requestPath, res); res.getHeaders().setContentType(MediaType.parseMediaType(staticContentItem.getContentType())); staticContentItem.getLastModified(), staticContentItem.isVersioned())) { try (final InputStream in = staticContentItem.getContent(); final OutputStream out = res.getBody()) { IOUtils.copy(in, out);
private <T> T _loadPage(String serviceUrl, Class<T> type, PageRequestDto pageRequest) throws ContentProviderException { try { T page = modelServiceClient.getForType(serviceUrl, type, pageRequest.getUriType(), pageRequest.getPublicationId(), pageRequest.getPath(), pageRequest.getIncludePages()); log.trace("Loaded '{}' for pageRequest '{}'", page, pageRequest); return page; } catch (ModelServiceInternalServerErrorException e) { throw new ContentProviderException("Cannot load page from model service", e); } catch (ItemNotFoundInModelServiceException e) { throw new PageNotFoundException("Cannot load page '" + pageRequest + "'", e); } }
binaryMeta = dynamicMetaRetriever.getBinaryMetaByURL(_prependFullUrlIfNeeded(pathInfo.getFileName(), requestDto.getBaseUrl())); if (binaryMeta == null) { throw new StaticContentNotFoundException("No binary meta found for: [" + publicationId + "] " + pathInfo.getFileName()); componentMeta = factory.getMeta(itemId); if (componentMeta == null) { throw new StaticContentNotFoundException("No meta meta found for: [" + publicationId + "] " + pathInfo.getFileName()); ImageUtils.writeToFile(file, pathInfo, binaryData.getBytes()); } catch (IOException e) { throw new StaticContentNotLoadedException("Cannot write new loaded content to a file " + file, e);
private String _resolveLocalizationPath(String localizationId) throws StaticContentNotLoadedException { PublicationMeta meta; try { meta = publicationMetaFactory.getMeta(TcmUtils.buildPublicationTcmUri(localizationId)); } catch (StorageException e) { throw new StaticContentNotLoadedException("Cannot resolve localization path for localization '" + localizationId + "'", e); } log.debug("Resolved url '{}' for publication id {}", meta.getPublicationPath(), localizationId); return meta.getPublicationUrl(); }
private static String resolveLink(String itemId, WebRequestContext webRequestContext, LinkResolver linkResolver) { String publicationId = webRequestContext.getLocalization().getId(); String url = TcmUtils.isTcmUri(itemId) ? itemId : TcmUtils.buildTcmUri(publicationId, itemId); return linkResolver.resolveLink(url, publicationId); } }
/** * <p>parseJsonFileObject.</p> * * @param contentProvider a {@link com.sdl.webapp.common.api.content.ContentProvider} object. * @param filePath a {@link java.lang.String} object. * @param locId a {@link java.lang.String} object. * @param locPath a {@link java.lang.String} object. * @param resultType a {@link com.fasterxml.jackson.core.type.TypeReference} object. * @param <T> a T object. * @return a T object. * @throws com.sdl.webapp.common.api.localization.LocalizationFactoryException if any. */ public <T> T parseJsonFileObject(ContentProvider contentProvider, String filePath, String locId, String locPath, TypeReference<T> resultType) throws LocalizationFactoryException { try { final StaticContentItem item = contentProvider.getStaticContent(filePath, locId, locPath); try (final InputStream in = item.getContent()) { return objectMapper.readValue(in, resultType); } } catch (ContentProviderException | IOException e) { throw new LocalizationFactoryException("Exception while reading configuration of localization: [" + locId + "] " + locPath, e); } }
private <T> T _loadPage(String serviceUrl, Class<T> type, PageRequestDto pageRequest) throws ContentProviderException { Localization localization = webRequestContext.getLocalization(); try { T page = modelServiceClient.getForType(serviceUrl, type, pageRequest.getUriType(), pageRequest.getPublicationId() != 0 ? pageRequest.getPublicationId() : localization.getId(), pageRequest.getPath(), pageRequest.getIncludePages()); log.trace("Loaded '{}' for localization '{}' and pageRequest '{}'", page, localization, pageRequest); return page; } catch (DxaItemNotFoundException e) { throw new PageNotFoundException("Cannot load page '" + pageRequest + "'", e); } catch (InternalServerErrorException e) { throw new ContentProviderException("Cannot load page from model service", e); } }
/** * Checks if the given file needs to be refreshed, and, if file doesn't exist, also checks and created if all the folders structure. * Basically performs subsequent calls to {@link #isFileOlderThan(File, long)} and {@link #parentFolderExists(File, boolean)}. * * @param file file to check * @param time time to check * @return whether file needs to be refreshed ({@code time} is older than file creation time * @throws ContentProviderException if case folders cannot be created */ public static boolean isToBeRefreshed(File file, long time) throws ContentProviderException { if (isFileOlderThan(file, time)) { if (!parentFolderExists(file, true)) { throw new ContentProviderException("Failed to create parent directory for file: " + file); } return true; } return false; }
private static String resolveLink(String itemId, WebRequestContext webRequestContext, LinkResolver linkResolver) { String publicationId = webRequestContext.getLocalization().getId(); String url = TcmUtils.isTcmUri(itemId) ? itemId : TcmUtils.buildTcmUri(publicationId, itemId); return linkResolver.resolveLink(url, publicationId); }
private boolean loadVersionFromBroker(String id, String path, LocalizationImpl.Builder builder) throws LocalizationFactoryException { try { StaticContentItem item = contentProvider.getStaticContent(VERSION_PATH, id, path); try (final InputStream in = item.getContent()) { builder.setVersion(objectMapper.readTree(in).get("version").asText()); return true; } } catch (StaticContentNotFoundException e) { LOG.debug("No published version.json found for localization [{}] {}", id, path); } catch (ContentProviderException | IOException e) { throw new LocalizationFactoryException("Exception while reading configuration of localization: [" + id + "] " + path, e); } return false; }
@NotNull protected EntityModel _getEntityModel(String componentId) throws ContentProviderException { EntityModelData modelData = modelService.loadEntity(webRequestContext.getLocalization().getId(), componentId); try { return builderPipeline.createEntityModel(modelData); } catch (DxaException e) { throw new ContentProviderException("Cannot build the entity model for componentId" + componentId, e); } }
private SitemapItem resolveLinks(SitemapItem sitemapItem, Localization localization) { sitemapItem.setUrl(linkResolver.resolveLink(sitemapItem.getUrl(), localization.getId())); for (SitemapItem subItem : sitemapItem.getItems()) { resolveLinks(subItem, localization); } return sitemapItem; }
private List<XpmRegion> loadXpmRegions(Localization localization) { final StaticContentItem item; try { item = contentProvider.getStaticContent(REGIONS_PATH, localization.getId(), localization.getPath()); } catch (ContentProviderException e) { LOG.error("Exception while reading XPM regions configuration", e); return null; } try (final InputStream in = item.getContent()) { SimpleModule module = new SimpleModule("ComponentTypeMapper", Version.unknownVersion()); module.addAbstractTypeMapping(ComponentType.class, ComponentTypeImpl.class); objectMapper.registerModule(module); // important, otherwise won't have any effect on mapper's configuration return objectMapper.readValue(in, new TypeReference<List<XpmRegionImpl>>() { }); } catch (IOException e) { LOG.error("Exception while reading XPM regions configuration", e); return null; } } }
/** * {@inheritDoc} * * @dxa.publicApi */ @Override public <T extends EntityModel> void populateDynamicList(DynamicList<T, SimpleBrokerQuery> dynamicList, Localization localization) throws ContentProviderException { if (localization == null) { log.info("Localization should not be null to populate dynamic list {}, skipping", dynamicList); return; } SimpleBrokerQuery query = dynamicList.getQuery(localization); try { dynamicList.setQueryResults(_convertEntities(executeMetadataQuery(query), dynamicList.getEntityType(), localization), query.isHasMore()); } catch (DxaException e) { throw new ContentProviderException("Cannot populate a dynamic list " + dynamicList.getId() + " localization " + localization.getId(), e); } }
.componentUrl(linkResolver.resolveLink("tcm:" + compMeta.getPublicationId() + '-' + compMeta.getId(), null)) .publicationId(String.valueOf(compMeta.getPublicationId())) .owningPublicationId(String.valueOf(compMeta.getOwningPublicationId()))
return out.toByteArray(); } catch (IOException e) { throw new ContentProviderException("Exception while processing image data", e);
.componentUrl(linkResolver.resolveLink("tcm:" + compMeta.getPublicationId() + '-' + compMeta.getId(), null)) .publicationId(String.valueOf(compMeta.getPublicationId())) .owningPublicationId(String.valueOf(compMeta.getOwningPublicationId()))