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; }
try (final InputStream in = staticContentItem.getContent(); final OutputStream out = res.getBody()) { IOUtils.copy(in, out);
/** * <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); } }
/** * <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 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; } } }