/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public DefaultRequest withRelativeUri (final @Nonnull String relativeUri) { return new DefaultRequest(baseUrl, new ResourcePath(relativeUri).urlDecoded().asString(), relativeUri, parametersMap, headersMap, preferredLocales); }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test(dataProvider = "urlEncodedPathProvider", dependsOnMethods = "must_properly_compute_asString") public void must_properly_url_decode (final @Nonnull String plainPathAsString, final @Nonnull String encodedPathAsString) { final ResourcePath underTest = new ResourcePath(encodedPathAsString); assertThat(underTest.urlDecoded().asString(), is(plainPathAsString)); }
/******************************************************************************************************************* * * Traverse the file system with a {@link FilePredicate}. * * @param file the file to traverse * @param fileFilter the filter for directory contents * @param predicate the predicate * ******************************************************************************************************************/ private void traverse (final @Nonnull ResourcePath rootPath, final @Nonnull ResourceFile file, final @Nonnull FileFilter fileFilter, final @Nonnull FilePredicate predicate) { log.trace("traverse({}, {}, {}, {})", rootPath, file, fileFilter, predicate); final ResourcePath relativePath = file.getPath().urlDecoded().relativeTo(rootPath); if (fileFilter.accept(file)) { predicate.apply(file, relativePath); } for (final ResourceFile child : file.findChildren().results()) { traverse(rootPath, child, fileFilter, predicate); } }
/******************************************************************************************************************* * * {@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; }
/******************************************************************************************************************* * * Returns the parent {@code SiteNode}. * * @return the parent node * @throws NotFoundException if the parent doesn't exist * @throws UnsupportedEncodingException * ******************************************************************************************************************/ @Nonnull private SiteNode getParent() throws NotFoundException { final ResourcePath parentRelativePath = getResource().getFile().getParent().getPath().urlDecoded() .relativeTo(site.getNodeFolder().getPath()); return site.find(SiteNode.class).withRelativePath(parentRelativePath.asString()).result(); }