/******************************************************************************************************************* * * * ******************************************************************************************************************/ private void appendTitle (final @Nonnull StringBuilder builder, final @Nonnull ResourceProperties siteNodeProperties) throws IOException { try { builder.append(String.format("<h2>%s</h2>%n", siteNodeProperties.getProperty(PROPERTY_TITLE))); } catch (NotFoundException e) { // ok, no title } }
/******************************************************************************************************************* * * Appends the title. * ******************************************************************************************************************/ private void appendTitle (final @Nonnull ResourceProperties contentProperties, final @Nonnull StringBuilder htmlBuilder, final @Nonnull String titleMarkup) throws IOException { try { final String title = contentProperties.getProperty(PROPERTY_TITLE); htmlBuilder.append(String.format("<%s>%s</%s>%n", titleMarkup, title, titleMarkup)); } catch (NotFoundException e) { // ok, no title } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull private DateTime getSiteNodeDateTime (final @Nonnull ResourceProperties properties) { final DateTimeFormatter isoFormatter = ISODateTimeFormat.dateTime(); try { return isoFormatter.parseDateTime(properties.getProperty(Properties.PROPERTY_LATEST_MODIFICATION_DATE)); } catch (NotFoundException e) { } catch (IOException e) { log.warn("", e); } return new DateTime(0); } }
/******************************************************************************************************************* * * Appends the text. * ******************************************************************************************************************/ private void appendText (final @Nonnull ResourceProperties contentProperties, final @Nonnull StringBuilder htmlBuilder) throws IOException { try { htmlBuilder.append(contentProperties.getProperty(PROPERTY_FULL_TEXT)).append("\n"); } catch (NotFoundException e) { log.warn("", e); htmlBuilder.append(e.toString()); } }
@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) { try { final String propertyName = matcher.group(1); return context.get().getNodeProperties().getProperty(new Key<String>(propertyName), ""); } catch (IOException e) { return "ERR"; } } }
@Override @Nonnull protected String filter (final @Nonnull Matcher matcher) { try { final String propertyName = matcher.group(1); return requestContext.get().getContentProperties().getProperty(new Key<String>(propertyName), ""); } catch (IOException e) { return "ERR"; } } }
@Override public <Type> Type getProperty (final @Nonnull Key<Type> key, final @Nonnull Type defaultValue) throws IOException { try { requestContext.setContent(content); return delegate.getProperty(key, defaultValue); } finally { requestContext.clearContent(); } } }
@Override public <Type> Type getProperty (final @Nonnull Key<Type> key) throws NotFoundException, IOException { try { requestContext.setContent(content); return delegate.getProperty(key); } finally { requestContext.clearContent(); } }
@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} * ******************************************************************************************************************/ @Nonnull private ResourcePath getDefaultExposedUri() throws NotFoundException, IOException { String title = getResource().getProperties().getProperty(PROPERTY_TITLE); title = deAccent(title); title = title.replaceAll(" ", "-") .replaceAll(",", "") .replaceAll("\\.", "") .replaceAll(";", "") .replaceAll("/", "") .replaceAll("!", "") .replaceAll("\\?", "") .replaceAll(":", "") .replaceAll("[^\\w-]*", ""); return new ResourcePath(title.toLowerCase()); }
/******************************************************************************************************************* * * 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; }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public ResourcePath getExposedUri() throws NotFoundException, IOException { try { return new ResourcePath(getProperties().getProperty(PROPERTY_EXPOSED_URI)); } catch (NotFoundException e) { return getDefaultExposedUri(); } }
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ @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 public boolean matches (final ResourceProperties properties) { try { for (final Entry<Key<String>, String> e : expectedValuesMap.entrySet()) { if (!e.getValue().equals(properties.getProperty(e.getKey()))) { return false; } } return true; } catch (NotFoundException | IOException e) { return false; } }
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ 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()); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @BeforeMethod public void setup() throws Exception { context = new ClassPathXmlApplicationContext("DefaultMetadataTestBeans.xml"); context.getBean(MetadataInterpolatorFactory.class); // initialize it properties = mock(ResourceProperties.class); final ResourceProperties resourceProperties = mock(ResourceProperties.class); when(resourceProperties.getProperty(PROPERTY_LENS_IDS)).thenReturn(Arrays.asList("1:Lens1", "2:Lens2")); when(properties.getGroup(PROPERTY_GROUP_ID)).thenReturn(resourceProperties); }
@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"; } } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(enabled = false) public void must_clear_the_presentation_on_error() throws IOException, NotFoundException { // given when(properties.getProperty(eq(PROPERTY_TITLE))).thenThrow(new IOException("test")); when(properties.getProperty(eq(PROPERTY_TITLE), anyString())).thenThrow(new IOException("test")); reset(presentation); // when underTest.onContentSelected(ContentSelectedEvent.of(content)); // then verify(presentation).clear(); verifyNoMoreInteractions(presentation); } }
@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())); } }
/******************************************************************************************************************* * * Initializes this controller. * ******************************************************************************************************************/ @PostConstruct /* package */ void initialize() throws IOException, NotFoundException { final ResourceProperties viewProperties = getViewProperties(); final ResourceProperties siteNodeProperties = siteNode.getProperties(); setCustomTemplate(viewProperties); view.addAttribute("language", requestLocaleManager.getLocales().get(0).getLanguage()); view.addAttribute("titlePrefix", viewProperties.getProperty(PROPERTY_TITLE_PREFIX, "")); view.addAttribute("description", viewProperties.getProperty(PROPERTY_DESCRIPTION, "")); view.addAttribute("title", siteNodeProperties.getProperty(PROPERTY_TITLE, "")); view.addAttribute("screenCssSection", computeScreenCssSection()); view.addAttribute("printCssSection", computePrintCssSection()); view.addAttribute("rssFeeds", computeRssFeedsSection()); view.addAttribute("scripts", computeScriptsSection()); view.addAttribute("inlinedScripts", computeInlinedScriptsSection()); }