@Override protected List<? extends SiteNode> computeResults() { log.info("findCompositeContents()"); final List<SiteNode> results = new ArrayList<>(); try { final ResourceProperties componentProperties = siteNode.getPropertyGroup(view.getId()); for (final Content post : findAllPosts(componentProperties)) { try { final ResourcePath relativeUri = siteNode.getRelativeUri().appendedWith(post.getExposedUri()); results.add(new ChildSiteNode(siteNode, relativeUri, post.getProperties())); } catch (NotFoundException | IOException e) { log.warn("While reading properties", e); } } } catch (NotFoundException | IOException e) { log.warn("While reading property group", e); } log.info(">>>> returning: {}", results); return results; } };
/******************************************************************************************************************* * * 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 public ResourceProperties getContentProperties() { if (contentHolder.get() == null) // FIXME: should never occur { log.warn("NO CONTENT IN CONTEXT"); // Thread.dumpStack(); // FIXME return modelFactory.createProperties().build(); } return contentHolder.get().getProperties(); }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @Nonnull private Content findPostByExposedUri (final List<Content> allPosts, final @Nonnull ResourcePath exposedUri) throws NotFoundException, IOException { for (final Content post : allPosts) { try { if (exposedUri.equals(post.getExposedUri())) { return post; } } catch (NotFoundException e) { log.warn("{}", e.toString()); } catch (IOException e) { log.warn("", e); } } throw new NotFoundException("Blog post with exposedUri=" + exposedUri.asString()); }
/* visible for testing */ void onOpenSite (final @ListensTo @Nonnull OpenSiteEvent event) { log.debug("onOpenSite({})", event); final ResourceFile root = event.getFileSystem().findFileByPath(ROOT_DOCUMENT_PATH); final Content rootContent = modelFactory.createContent().withFolder(root).build(); presentation.populate(rootContent.as(Presentable).createPresentationModel()); presentation.expandFirstLevel(); messageBus.publish(emptySelectionEvent()); } }
@Override public int compare (final @Nonnull Content post1, final @Nonnull Content post2) { final DateTime dateTime1 = post1.getProperties().getDateTimeProperty(DATE_KEYS, TIME0); final DateTime dateTime2 = post2.getProperties().getDateTimeProperty(DATE_KEYS, TIME0); return dateTime2.compareTo(dateTime1); } };
@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); }
/******************************************************************************************************************* * * Adds to {@code destinationPosts} all the {@code sourcePosts} that matches the selected {@code category}; all * posts if the category is empty. * * @param sourcePosts the source posts * @param destinationPosts the destination posts * @param category the category * ******************************************************************************************************************/ private void filterByCategory (final @Nonnull List<Content> sourcePosts, final @Nonnull List<Content> destinationPosts, final @Nonnull String category) { for (final Content post : sourcePosts) { try { if (category.equals("") || category.equals(post.getProperties().getProperty(PROPERTY_CATEGORY, "---"))) { destinationPosts.add(post); } } catch (IOException e2) { log.warn("", e2); } } }
@Override @Nonnull protected List<? extends Content> computeResults() { try { final Content content = mock(Content.class); if (relativePath.equals("/")) { when(content.getExposedUri()).thenReturn(new ResourcePath()); } else { when(content.getExposedUri()).thenReturn(new ResourcePath("EXPOSED-" + relativePath.substring(1) .replace('/', '-') .replace(' ', '-'))); } return Arrays.asList(content); } catch (NotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } }
/******************************************************************************************************************* * * Adds to {@code destinationPosts} all the {@code sourcePosts} that matches the selected {@code tag}; all * posts if the category is empty. * * @param sourcePosts the source posts * @param destinationPosts the destination posts * @param tag the tag * ******************************************************************************************************************/ private void filterByTag (final @Nonnull List<Content> sourcePosts, final @Nonnull List<Content> destinationPosts, final @Nonnull String tag) { for (final Content post : sourcePosts) { try { final List<String> tags = Arrays.asList(post.getProperties().getProperty(PROPERTY_TAGS, "").split(",")); if (tags.contains(tag)) { destinationPosts.add(post); } } catch (IOException e2) { log.warn("", e2); } } }
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$"; } } }
for (final String tag : post.getProperties().getProperty(PROPERTY_TAGS).split(","))
htmlBuilder.append(content.getProperties().getProperty(PROPERTY_FULL_TEXT)).append("\n"); htmlBuilder.append(content.getProperties().getProperty(PROPERTY_TEMPLATE)).append("\n");
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ 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() { ContextManager.Locator.set(null); context = (ClassPathXmlApplicationContext)helper.createSpringContext(); underTest = context.getBean(DefaultContentEditorPresentationControl.class); embeddedServer = context.getBean(EmbeddedServer.class); presentation = context.getBean(ContentEditorPresentation.class); content = mock(Content.class); properties = mock(ResourceProperties.class); presentable = mock(Presentable.class); pm = mock(PresentationModel.class); propertyBinder = mock(PropertyBinder.class); when(embeddedServer.putDocument(anyString(), any(Document.class))).thenReturn(registeredUrl); when(content.getProperties()).thenReturn(properties); when(presentable.createPresentationModel(anyVararg())).thenReturn(pm); when(properties.as(eq(Presentable))).thenReturn(presentable); when(properties.as(eq(PropertyBinder))).thenReturn(propertyBinder); document = new Document().withContent("proxy for: full text") .withMimeType("text/html"); when(propertyBinder.createBoundDocument(any(Key.class), any(PropertyBinder.UpdateCallback.class))) .thenAnswer(invocation -> document); underTest.initialize(); }
final ResourceProperties contentProperties = content.getProperties(); appendTitle(contentProperties, htmlFragmentBuilder, "h" + titleLevel++); appendText(contentProperties, htmlFragmentBuilder);
/******************************************************************************************************************* * * {@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"); } }
post.getProperties().getProperty(PROPERTY_TITLE); // Skip folders used for categories - this throws exception
@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())); } }