@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) throws NotFoundException { final String relativePath = matcher.group(1); final Site site = siteProvider.get().getSite(); final SiteNode siteNode = site.find(SiteNode.class).withRelativePath(relativePath).result(); return site.createLink(siteNode.getRelativeUri()); } }
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ @Nonnull private String computeRssFeedsSection() { try { for (final String relativePath : getViewProperties().getProperty(PROPERTY_RSS_FEEDS, Collections.<String>emptyList())) { site.find(SiteNode).withRelativePath(relativePath).doWithResults(createRssLink); } } catch (IOException e) { log.error("", e); } return createRssLink.toString(); }
/******************************************************************************************************************* * ******************************************************************************************************************/ // FIXME: this should be shared between instances private void initialize() throws IOException, NotFoundException { log.info("Retrieving XSLT templates"); final String template = IOUtils.toString(getClass().getResourceAsStream("/it/tidalwave/northernwind/core/impl/filter/XsltTemplate.xslt")); final StringBuilder xsltBuffer = new StringBuilder(); for (final Resource resource : siteProvider.get().getSite().find(Resource.class).withRelativePath(XSLT_TEMPLATES_PATH).results()) { final ResourceFile file = resource.getFile(); log.info(">>>> {}", file.getPath().asString()); xsltBuffer.append(file.asText("UTF-8")); } final ST t = new ST(template, '%', '%').add("content", xsltBuffer.toString()); xslt = t.render(); }
@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) { try { // FIXME: should be pushed into @PostConstruct, but can't - see NW-224 final Site site = siteProvider.get().getSite(); final SiteNode rootSiteNode = site.find(SiteNode).withRelativeUri("/").result(); // See NW-223 // END FIXME final String propertyName = matcher.group(1); return rootSiteNode.getProperties().getProperty(new Key<String>(propertyName), ""); } catch (NotFoundException | IOException e) { return "ERR"; } } }
builder.append("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"); site.find(SiteNode.class).doWithResults(new Predicate<SiteNode>()
final SiteNode rootSiteNode = site.find(SiteNode).withRelativeUri("/").result(); final ResourceProperties rootSiteNodeProperties = rootSiteNode.getProperties(); final ResourceProperties properties = rootSiteNodeProperties.getGroup(PROPERTY_GROUP_ID);
@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) throws NotFoundException, IOException { final String relativePath = matcher.group(1); final String contentRelativePath = matcher.group(2); final String language = matcher.group(4); final Site site = siteProvider.get().getSite(); final SiteNode siteNode = site.find(SiteNode.class).withRelativePath(relativePath).result(); final Content content = site.find(Content.class).withRelativePath(contentRelativePath).result(); final ResourcePath path = siteNode.getRelativeUri().appendedWith(content.getExposedUri()); final String link = site.createLink(path); return ((language == null) || (postProcessor == null)) ? link : postProcessor.postProcess(link, language); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Status process (final @Nonnull Request request) throws NotFoundException, IOException, HttpStatusException { try { final String relativeUri = request.getRelativeUri(); final Site site = siteProvider.get().getSite(); final SiteNode node = site.find(SiteNode).withRelativeUri(relativeUri).result(); requestContext.setNode(node); siteView.renderSiteNode(node); // // Check *after* finding the SiteNode, since a "not found" must have been already handled here. // enforceTrailingSlash(relativeUri, site); return BREAK; } finally { requestContext.clearNode(); } }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull private String getMetadataString (final @Nonnull Id id, final @Nonnull String format) throws NotFoundException { // FIXME: should use current SiteNode properties final ResourceProperties properties = siteProvider.get().getSite().find(SiteNode.class) .withRelativePath("/") .result() .getProperties(); return mediaMetadataProvider.getMetadataString(id, format, properties); }
/******************************************************************************************************************* * * Finds all the posts. * ******************************************************************************************************************/ @Nonnull private List<Content> findAllPosts (final @Nonnull ResourceProperties siteNodeProperties) throws NotFoundException, IOException { final List<Content> allPosts = new ArrayList<>(); for (final String relativePath : siteNodeProperties.getProperty(PROPERTY_CONTENTS)) { final Content postsFolder = site.find(Content).withRelativePath(relativePath).result(); allPosts.addAll(postsFolder.findChildren().results()); } log.debug(">>>> all posts: {}", allPosts.size()); return allPosts; }
/******************************************************************************************************************* * * Returns the template. * ******************************************************************************************************************/ @Nonnull private String getTemplate (final @Nonnull ResourceProperties viewProperties) throws IOException { try { final String templateRelativePath = viewProperties.getProperty(PROPERTY_WRAPPER_TEMPLATE_RESOURCE); final Content content = site.find(Content).withRelativePath(templateRelativePath).result(); final ResourceProperties templateProperties = content.getProperties(); return templateProperties.getProperty(PROPERTY_TEMPLATE, "$content$"); } catch (NotFoundException e) { return "$content$"; } } }
final Content script = site.find(Content).withRelativePath(relativePath).result(); builder.append(script.getProperties().getProperty(PROPERTY_TEMPLATE));
/******************************************************************************************************************* * * ******************************************************************************************************************/ @SuppressWarnings("unchecked") public FolderBasedFinderSupport (final @Nonnull Type parentResource) { try { final Site site = siteProvider.get().getSite(); this.typeClass = getInterface(parentResource); this.resourceRootPath = site.find(typeClass).withRelativePath("/").result().getFile().getPath(); this.parentFile = parentResource.getFile(); } catch (NotFoundException e) { throw new RuntimeException(e); // never occurs } }
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ private void setCustomTemplate (final @Nonnull ResourceProperties viewProperties) throws IOException { try { final String templateRelativePath = viewProperties.getProperty(PROPERTY_TEMPLATE_PATH); final Content template = site.find(Content).withRelativePath(templateRelativePath).result(); view.setTemplate(template.getProperties().getProperty(PROPERTY_TEMPLATE)); } catch (NotFoundException e) { log.warn("Cannot find custom template, using default ({})", e.toString()); } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull protected List<? extends Type> computeResults() { final List<Type> result = new ArrayList<>(); for (final ResourceFile childFile : parentFile.findChildren().withRecursion(true).results()) { if (childFile.isFolder()) { try { final String relativeUri = childFile.getPath().relativeTo(resourceRootPath).urlDecoded().asString(); result.add(siteProvider.get().getSite().find(typeClass).withRelativePath(relativeUri).result()); } catch (NotFoundException e) { log.error("", e); } } } return result; }
/******************************************************************************************************************* * * Returns the parent {@code SiteNode}. * * @return the parent node * @throws NotFoundException if the parent doesn't exist * @throws UnsupportedEncodingException * ******************************************************************************************************************/ @Nonnull private SiteNode getParent() throws NotFoundException { final ResourcePath parentRelativePath = getResource().getFile().getParent().getPath().urlDecoded() .relativeTo(site.getNodeFolder().getPath()); return site.find(SiteNode.class).withRelativePath(parentRelativePath.asString()).result(); }
final Content content = site.find(Content).withRelativePath(relativePath).result();
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Nonnull protected String loadTemplate (final @Nonnull GalleryAdapterContext context, final @Nonnull String templateName) throws IOException { try { final SiteNode siteNode = context.getSiteNode(); final GalleryView view = context.getView(); final Site site = context.getSite(); final ResourceProperties viewProperties = siteNode.getPropertyGroup(view.getId()); final String templateRelativePath = viewProperties.getProperty(new Key<String>(templateName + "Path")); final Content template = site.find(Content).withRelativePath(templateRelativePath).result(); return template.getProperties().getProperty(PROPERTY_TEMPLATE); } catch (NotFoundException e) { return loadDefaultTemplate(templateName + ".txt"); } }
final Content content = site.find(Content).withRelativePath(relativePath).result(); final ResourceProperties contentProperties = content.getProperties(); appendTitle(contentProperties, htmlFragmentBuilder, "h" + titleLevel++);
final Resource resource = siteProvider.get().getSite().find(Resource.class).withRelativePath(relativePath).result(); final ResourceFile file = resource.getFile(); final String mimeType = file.getMimeType();