@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()); } }
/******************************************************************************************************************* * * 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; }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @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); }
@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); }
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ @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(); }
final Content script = site.find(Content).withRelativePath(relativePath).result(); builder.append(script.getProperties().getProperty(PROPERTY_TEMPLATE));
/******************************************************************************************************************* * * 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$"; } } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @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; }
final Content content = site.find(Content).withRelativePath(relativePath).result();
when(siteNodeFinder.withRelativePath(anyString())).thenReturn(siteNodeFinder); // FIXME: anyString()
final Content content = site.find(Content).withRelativePath(relativePath).result(); final ResourceProperties contentProperties = content.getProperties(); appendTitle(contentProperties, htmlFragmentBuilder, "h" + titleLevel++);
/******************************************************************************************************************* * * {@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 Resource resource = siteProvider.get().getSite().find(Resource.class).withRelativePath(relativePath).result(); final ResourceFile file = resource.getFile(); final String mimeType = file.getMimeType();
/******************************************************************************************************************* * * 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 template = site.find(Content.class).withRelativePath(templateRelativePath).result(); view.setTemplate(template.getProperties().getProperty(PROPERTY_TEMPLATE)); final SiteNode targetSiteNode = site.find(SiteNode).withRelativePath(relativePath).result(); final String navigationTitle = targetSiteNode.getProperties().getProperty(PROPERTY_NAVIGATION_LABEL, "no nav. label");
@PostConstruct /* package */ void initialize() throws IOException { try { // First search the template in a path, which could be useful for retrieving from a library; if not // found, a property with the contents is searched. final ResourceProperties viewProperties = siteNode.getPropertyGroup(view.getId()); final String templateRelativePath = viewProperties.getProperty(PROPERTY_TEMPLATE_PATH); final Content template = site.find(Content.class).withRelativePath(templateRelativePath).result(); view.setTemplate(template.getProperties().getProperty(PROPERTY_TEMPLATE)); } catch (NotFoundException e) { // ok, use the default template } final ResourceProperties viewProperties = siteNode.getPropertyGroup(view.getId()); view.setClassName(viewProperties.getProperty(PROPERTY_CLASS, "nw-" + view.getId())); } }
final Media media = siteProvider.get().getSite().find(Media).withRelativePath(mediaUri.asString()).result(); final ResourceFile file = media.getFile(); log.info(">>>> serving contents of {} ...", file.getPath().asString());