/** * Find the TCM Uri of a page by URL * * @param url the URL * @param publicationId the Publication Id * @return a TCMURI if found. * @throws FactoryException */ @Override public TCMURI findPageIdByUrl(final String url, final int publicationId) throws FactoryException { return pageProvider.getPageIdForUrl(url, publicationId); }
/** * Retrieves content of a Dynamic Component Presentation by looking up its componentId, templateId and * publicationId. * * @param componentId int representing the Component item id * @param templateId int representing the Component Template item id * @param publicationId int representing the Publication id of the DCP * @return String representing the content of the DCP * @throws ItemNotFoundException if the requested DCP cannot be found */ @Override public String getDynamicComponentPresentation(int componentId, int templateId, int publicationId) throws ItemNotFoundException, SerializationException { return getDynamicComponentPresentationItem(componentId, templateId, publicationId).getSourceContent(); }
@Override public PageProviderResultItem<String> getPageById(final int id, final int publication) throws IOException, ItemNotFoundException, SerializationException { final PageMeta pageMeta = getPageMetaById(id, publication); PageProviderResultItem<String> pageResult = new PageResultItemImpl(pageMeta.getPublicationId(), pageMeta .getId(), pageMeta.getURLPath()); pageResult.setLastPublishDate(pageMeta.getLastPublicationDate()); pageResult.setRevisionDate(pageMeta.getModificationDate()); pageResult.setContentSource(getPageContentById(id, publication)); return pageResult; }
@Override public PageProviderResultItem<String> getPageByURL(final String url, final int publication) throws ItemNotFoundException, SerializationException { final PageMeta pageMeta = getPageMetaByURL(url, publication); PageProviderResultItem<String> pageResult = new PageResultItemImpl(pageMeta.getPublicationId(), pageMeta .getId(), pageMeta.getURLPath()); pageResult.setLastPublishDate(pageMeta.getLastPublicationDate()); pageResult.setRevisionDate(pageMeta.getModificationDate()); pageResult.setContentSource(getPageContentById(pageMeta.getId(), pageMeta.getPublicationId())); return pageResult; }
CacheElement<Page> cacheElement = cacheProvider.loadPayloadFromLocalCache(cacheKey); Page page; if (cacheElement.isExpired() || cacheElement.getPayload() == null) { PageProviderResultItem<String> resultItem; resultItem = pageProvider.getPageByURL(url, publicationId); String pageSource = resultItem.getSourceContent(); cacheProvider.storeInItemCache(cacheKey, cacheElement); cacheElement.setExpired(true); throw new ItemNotFoundException("Page with url: " + url + " not found."); cacheProvider.storeInItemCache(cacheKey, cacheElement, resultItem.getPublicationId(), resultItem .getItemId()); cacheElement.setExpired(false);
@Override public ComponentPresentationResultItem<String> getDynamicComponentPresentationItem(int componentId, int templateId, int publicationId) throws ItemNotFoundException, SerializationException { ComponentPresentation result = getComponentPresentation(componentId, templateId, publicationId); String resultString; ComponentPresentationResultItemImpl resultModel; if (result != null) { resultModel = new ComponentPresentationResultItemImpl(result.getPublicationId(), result.getComponentId(), result.getComponentTemplateId()); assertQueryResultNotNull(result, componentId, templateId, publicationId); resultString = result.getContent(); if (!StringUtils.isEmpty(resultString)) { resultModel.setContentSource(decodeAndDecompressContent(resultString)); } else { resultModel.setContentSource(resultString); } } else { resultModel = new ComponentPresentationResultItemImpl(0, 0, 0); } return resultModel; }
private <T extends Page> T producePage(PageProviderResultItem<String> resultItem, RequestContext context, Class<T> pageClass) throws FactoryException { String pageSource = resultItem.getSourceContent(); Page page = deserialize(pageSource, pageClass); page.setLastPublishedDate(resultItem.getLastPublishDate()); page.setRevisionDate(resultItem.getRevisionDate()); page.setUrl(resultItem.getUrl()); LOG.debug("Running pre caching processors"); this.executeProcessors(page, RunPhase.BEFORE_CACHING, context); return (T) page; }
private String addToCache(String componentURI, String key, CacheElement<String> cacheElement, String result) throws ParseException { String toReturn = result == null ? "" : result; cacheElement.setPayload(toReturn); TCMURI tcmUri = new TCMURI(componentURI); cacheProvider.storeInItemCache(key, cacheElement, tcmUri.getPublicationId(), tcmUri.getItemId()); LOG.debug("Added link url: {} for uri: {} to cache", result, componentURI); return toReturn; }
/** * Tries to discover the Publication Id for an images URl * * @param imagesUrl the image URL path * @return int representing the SDL Tridion Publication item id */ @Override public int discoverPublicationIdByImagesUrl(final String imagesUrl) { final HttpServletRequest request = HttpUtils.getCurrentRequest(); if (this.useCdDynamic) { LOG.debug("Using cd_dynamic_conf.xml to determine publication Id"); return publicationProvider.discoverPublicationByBaseUrl(HttpUtils.appendDefaultPageIfRequired(HttpUtils .getOriginalFullUrl(request, this.stripServletContextPath))); } else { LOG.debug("Determining Pub Id on Images URL: {}.", imagesUrl); return publicationProvider.discoverPublicationByImagesUrl(HttpUtils.getOriginalFullUrl(request, this .stripServletContextPath)); } }
/** * Gets the Publication TCMURI item id for the current request * * @return int representing the SDL Tridion Publication item id */ @Override public int getPublicationId() { final HttpServletRequest request = HttpUtils.getCurrentRequest(); if (this.useCdDynamic) { LOG.debug("Using cd_dynamic_conf.xml (7) or the Dynamic Mappings retriever to determine publication Id"); return publicationProvider.discoverPublicationByBaseUrl(HttpUtils.appendDefaultPageIfRequired(HttpUtils .getOriginalFullUrl(request, this.stripServletContextPath))); } else { LOG.debug("Determining Pub Id on page URL."); return publicationProvider.discoverPublicationIdByPageUrlPath(HttpUtils.appendDefaultPageIfRequired (HttpUtils.getOriginalFullUrl(request, this.stripServletContextPath))); } }
/** * Gets the Publication Url property as defined in Tridion Publication metadata corresponding to the current request * * @return String representing the SDL Tridion Publication Url metadata property */ @Override public String getPublicationUrl() { return publicationProvider.discoverPublicationUrl(getPublicationId()); }
/** * Gets the Images URL property as defined in Tridion Publication metadata corresponding to the current request * * @return String representing the SDL Tridion Images URL metadata property */ @Override public String getImagesUrl() { return publicationProvider.discoverImagesUrl(getPublicationId()); }
/** * Gets the Publication Path property as defined in Tridion Publication metadata corresponding to the current * request * * @return String representing the SDL Tridion Publication Path metadata property */ @Override public String getPublicationPath() { return publicationProvider.discoverPublicationPath(getPublicationId()); }
/** * Gets the Images Path property as defined in Tridion Publication metadata corresponding to the current request * * @return String representing the SDL Tridion Images Path metadata property */ @Override public String getImagesPath() { return publicationProvider.discoverImagesPath(getPublicationId()); }
/** * For use in the RS scenario. * * @return a publication descriptor */ @Override public PublicationDescriptor getPublicationDescriptor() { return publicationProvider.getPublicationDescriptor(getPublicationId()); }
/** * Method to check whether a page exists in the Tridion Broker. * * @param url the Url to check * @param publicationId the publication Id * @return boolean indicating the page is present */ @Override public Boolean isPagePublished(String url, int publicationId) { LOG.debug("Enter isPagePublished with url: {} and publicationId: {}", url, publicationId); try { return pageProvider.checkPageExists(url, publicationId); } catch (ItemNotFoundException | SerializationException e) { LOG.error(e.getLocalizedMessage(), e); } return false; }
@Override public PageProviderResultItem<String> getPageById(final int id, final int publication) throws IOException, ItemNotFoundException, SerializationException { final PageMeta pageMeta = getPageMetaById(id, publication); if (pageMeta == null) { throw new ItemNotFoundException("Unable to find page meta by id '" + id + "' and publication '" + publication + "'."); } PageProviderResultItem<String> pageResult = new PageResultItemImpl(pageMeta.getPublicationId(), pageMeta .getItemId(), pageMeta.getUrl()); pageResult.setLastPublishDate(pageMeta.getLastPublishDate()); pageResult.setRevisionDate(pageMeta.getModificationDate()); pageResult.setContentSource(getPageContentById(id, publication)); return pageResult; }
@Override public PageProviderResultItem<String> getPageByURL(final String url, final int publication) throws ItemNotFoundException, SerializationException { PageMeta pageMeta = getPageMetaByURL(url, publication); if (pageMeta == null) { throw new ItemNotFoundException("Unable to find page meta by url '" + url + "' and publication '" + publication + "'."); } PageProviderResultItem<String> pageResult = new PageResultItemImpl(pageMeta.getPublicationId(), pageMeta .getItemId(), pageMeta.getUrl()); pageResult.setLastPublishDate(pageMeta.getLastPublishDate()); pageResult.setRevisionDate(pageMeta.getModificationDate()); pageResult.setContentSource(getPageContentById(pageMeta.getItemId(), pageMeta.getPublicationId())); return pageResult; }
/** * Gets the Page URL in the current Publication corresponding to the given generic URL * * @param url String representing the generic URL (i.e. URL path without PublicationUrl prefix) * @return String representing the current Publication URL followed by the given URL */ @Override public String getLocalPageUrl(final String url) { if (StringUtils.isEmpty(url)) { return ""; } String publicationUrl = publicationProvider.discoverPublicationUrl(getPublicationId()); if (StringUtils.isNotEmpty(publicationUrl) && !url.startsWith(publicationUrl)) { return String.format("%s%s", publicationUrl, url.startsWith("/") ? url : "/" + url); } return url; }
/** * Gets the Binary URL in the current Publication corresponding to the given generic URL * * @param url String representing the generic URL (i.e. URL path without PublicationUrl prefix) * @return String representing the current Publication URL followed by the given URL */ @Override public String getLocalBinaryUrl(final String url) { String binaryUrl = publicationProvider.discoverImagesUrl(getPublicationId()); return url.replaceFirst(binaryUrl, ""); }