@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()); } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public List<Locale> getLocales() { final Locale requestLocale = localeHolder.get(); final List<Locale> locales = new ArrayList<>(siteProvider.get().getSite().getConfiguredLocales()); if (requestLocale != null) { locales.remove(requestLocale); locales.add(0, requestLocale); } log.debug(">>>> locales: {}", locales); return locales; }
/******************************************************************************************************************* * * 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; }
@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) { final ResourcePath relativePath = new ResourcePath(matcher.group(1)); return siteProvider.get().getSite().createLink(relativePath); } }
@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)); }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @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) { final ResourcePath relativePath = new ResourcePath(matcher.group(1)).prependedWith("media"); return siteProvider.get().getSite().createLink(relativePath); } }
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ @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) 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); }
@Override public boolean apply (final @Nonnull SiteNode rssSiteNode) { try { final String title = rssSiteNode.getProperties().getProperty(PROPERTY_TITLE, "RSS"); builder.append(String.format("<link rel=\"alternate\" type=\"%s\" title=\"%s\" href=\"%s\" />%n", RSS_MIME_TYPE, title, site.createLink(rssSiteNode.getRelativeUri()))); } catch (IOException e) { log.warn("", e); // shouldn't occur } return false; }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Status process (final @Nonnull Request request) { final Site site = siteProvider.get().getSite(); for (final Locale locale : request.getPreferredLocales()) { if (site.getConfiguredLocales().contains(locale)) { requestLocaleManager.setRequestLocale(locale); break; } } return CONTINUE; } }
@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"; } } }
@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(); } }); } }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ private void appendYearSelector (final @Nonnull StringBuilder builder, final @Nonnegative int firstYear, final @Nonnegative int lastYear, final @Nonnegative int selectedYear) { builder.append("<div class='nw-calendar-yearselector'>\n"); String separator = ""; for (int year = firstYear; year <= lastYear; year++) { builder.append(separator); separator = " | "; if (year != selectedYear) { final String url = site.createLink(siteNode.getRelativeUri().appendedWith("" + year)); builder.append(String.format("<a href='%s'>%d</a>%n", url, year)); } else { builder.append(year); } } builder.append("</div>\n"); }
/******************************************************************************************************************* * ******************************************************************************************************************/ // 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 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"); view.addLink(navigationTitle, site.createLink(targetSiteNode.getRelativeUri()));
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ @Nonnull private String computeScreenCssSection() { final StringBuilder builder = new StringBuilder(); try { for (final String relativeUri : getViewProperties().getProperty(PROPERTY_SCREEN_STYLE_SHEETS, Collections.<String>emptyList())) { final String link = relativeUri.startsWith("http") ? relativeUri : site.createLink(new ResourcePath(relativeUri)); builder.append(String.format(LINK_RELSTYLESHEET_MEDIASCREEN_HREF, link)); } } catch (IOException e) { log.error("", e); } return builder.toString(); }
builder.append("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"); site.find(SiteNode.class).doWithResults(new Predicate<SiteNode>()
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ @Nonnull private String computePrintCssSection() { final StringBuilder builder = new StringBuilder(); try { for (final String relativeUri : getViewProperties().getProperty(PROPERTY_PRINT_STYLE_SHEETS, Collections.<String>emptyList())) { final String link = relativeUri.startsWith("http") ? relativeUri : site.createLink(new ResourcePath(relativeUri)); final String template = "<link rel=\"stylesheet\" media=\"print\" href=\"%s\" type=\"text/css\" />\n"; builder.append(String.format(template, link)); } } catch (IOException e) { log.error("", e); } return builder.toString(); }
final Content script = site.find(Content).withRelativePath(relativePath).result(); builder.append(script.getProperties().getProperty(PROPERTY_TEMPLATE));