/******************************************************************************************************************* * * * ******************************************************************************************************************/ 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"); }
@Override protected List<? extends SiteNode> computeResults() { log.info("findChildrenSiteNodes()"); final List<SiteNode> results = new ArrayList<SiteNode>(); results.add(new ChildSiteNode(siteNode, siteNode.getRelativeUri().appendedWith("lightbox"), siteNode.getProperties())); for (final Item item : itemMapById.values()) { final ResourcePath relativeUri = siteNode.getRelativeUri().appendedWith(item.getId().stringValue()); results.add(new ChildSiteNode(siteNode, relativeUri, siteNode.getProperties())); } log.info(">>>> returning: {}", results); return results; } };
@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; } };
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public String createLink (final @Nonnull ResourcePath relativeUri) { final ResourcePath link = new ResourcePath(contextPath).appendedWith(relativeUri); String linkAsString = requestHolder.get().getBaseUrl() + link.asString(); for (final LinkPostProcessor linkPostProcessor : linkPostProcessors) { linkAsString = linkPostProcessor.postProcess(linkAsString); } return linkAsString; }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "appendPrependProvider", dependsOnMethods = "must_properly_compute_asString") public void must_properly_append_string (final @Nonnull String pathAsString, final @Nonnull String secondPathAsString, final @Nonnull String expectedAppendedPathAsString, final @Nonnull String expectedPrependedPathAsString) { final ResourcePath underTest = new ResourcePath(pathAsString); assertThat(underTest.appendedWith(secondPathAsString).asString(), is(expectedAppendedPathAsString)); }
@Nonnull public static ResourceFile folder (final @Nonnull ResourceFile parent, final @Nonnull String fileName) { final ResourcePath parentPath = parent.getPath(); return new MockResourceFile(parent, parentPath.appendedWith(fileName), true); }
@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); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "appendPrependProvider", dependsOnMethods = "must_properly_compute_asString") public void must_properly_append_path (final @Nonnull String pathAsString, final @Nonnull String secondPathAsString, final @Nonnull String expectedAppendedPathAsString, final @Nonnull String expectedPrependedPathAsString) { final ResourcePath underTest = new ResourcePath(pathAsString); final ResourcePath appendingPath = new ResourcePath(secondPathAsString); assertThat(underTest.appendedWith(appendingPath).asString(), is(expectedAppendedPathAsString)); }
relativeUri = relativeUri.appendedWith(getParent().getRelativeUri()).appendedWith(segment);
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull protected ResourceFile createMockFile (final @Nonnull ResourceFileSystem fileSystem, final @Nonnull ResourceFile parentFolder, final @Nonnull String name) { final ResourcePath path = parentFolder.getPath().appendedWith(name); final ResourceFile file = createMockFile(name); when(file.getParent()).thenReturn(parentFolder); when(file.getPath()).thenReturn(path); when(file.toString()).thenReturn(path.asString()); when(fileSystem.findFileByPath(eq(path.asString()))).thenReturn(file); final Collection<ResourceFile> children = new ArrayList<>(parentFolder.findChildren().results()); children.add(file); when(parentFolder.findChildren()).thenReturn(new ListFinder(children)); return file; }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull protected ResourceFile createMockFolder (final @Nonnull ResourceFileSystem fileSystem, final @Nonnull ResourceFile parentFolder, final @Nonnull String name) { final ResourcePath path = parentFolder.getPath().appendedWith(name); final ResourceFile folder = createMockFolder(name); when(folder.getParent()).thenReturn(parentFolder); when(folder.getPath()).thenReturn(path); when(folder.toString()).thenReturn(path.asString()); when(fileSystem.findFileByPath(eq(path.asString()))).thenReturn(folder); final Collection<ResourceFile> children = new ArrayList<>(parentFolder.findChildren().results()); children.add(folder); when(parentFolder.findChildren()).thenReturn(new ListFinder(children)); return folder; }
final String size = mediaUri.getTrailing(); // 1920 mediaUri = mediaUri.withoutTrailing(); mediaUri = mediaUri.appendedWith(fileName.replaceAll("\\..*$", "")) .appendedWith("" + size) .appendedWith("image." + extension); mediaUri = mediaUri.prependedWith(uriPrefix); final String redirect = mediaUri.asString(); final String mediaId = mediaUri.getTrailing(); // 20120802-0010 mediaUri = mediaUri.withoutTrailing(); mediaUri = mediaUri.appendedWith(size).appendedWith(mediaId + "." + extension);