@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(); }
@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"; } } }
/******************************************************************************************************************* * ******************************************************************************************************************/ // 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));
@BeforeClass // FIXME: should be BeforeMethod? public void setUp() { context = new ClassPathXmlApplicationContext(contextName); siteProvider = context.getBean(SiteProvider.class); site = context.getBean(Site.class); when(siteProvider.getSite()).thenReturn(site); when(site.find(eq(Content.class))).thenReturn(new MockContentSiteFinder()); when(site.find(eq(SiteNode.class))).thenReturn(new MockSiteNodeSiteFinder()); when(site.createLink(any(ResourcePath.class))).thenAnswer(new Answer<String>() { @Override @Nonnull public String answer (final @Nonnull InvocationOnMock invocation) { return "/LINK" + ((ResourcePath)invocation.getArguments()[0]).asString(); // return ((ResourcePath)invocation.getArguments()[0]).prepend("LINK").asString(); } }); } }
/******************************************************************************************************************* * * 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 } }
final SiteNode rootSiteNode = site.find(SiteNode).withRelativeUri("/").result(); final ResourceProperties rootSiteNodeProperties = rootSiteNode.getProperties(); final ResourceProperties properties = rootSiteNodeProperties.getGroup(PROPERTY_GROUP_ID);
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ 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 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(); } }
/******************************************************************************************************************* * * {@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; }
when(site.find(eq(Resource.class))).thenReturn( new DefaultSiteFinder<>("name", map, new RegexTreeMap<Resource>()));
@BeforeMethod public void setup() throws Exception { final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("META-INF/CommonsAutoBeans.xml", "META-INF/XsltTemplateTestBeans.xml", "META-INF/CachedUriResolverBeans.xml"); filter = context.getBean(XsltMacroFilter.class); context.getBean(CachedURIResolver.class).setCacheFolderPath("target/CachedUriResolver"); final SiteProvider siteProvider = context.getBean(SiteProvider.class); final Site site = mock(Site.class); when(siteProvider.getSite()).thenReturn(site); final ResourceFileSystemProvider fileSystemProvider = mock(ResourceFileSystemProvider.class); when(site.getFileSystemProvider()).thenReturn(fileSystemProvider); final File root = new File("src/main/resources/content/library/XsltTemplates").getAbsoluteFile(); final ResourceFileSystemProvider localFileSystemProvider = new LocalFileSystemProvider(); final ResourceFile file = localFileSystemProvider.getFileSystem().findFileByPath(root.getAbsolutePath()); final List<Resource> resources = new ArrayList<>(); for (final ResourceFile xsltFile : file.findChildren().results()) { final Resource resource = mock(Resource.class); when(resource.getFile()).thenReturn(xsltFile); resources.add(resource); } when(site.find(eq(Resource.class))).thenReturn(new MockResourceFinder(resources)); }
/******************************************************************************************************************* * * {@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();
@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())); } }