@Nonnull private static String toString (final @CheckForNull Resource resource) { return (resource == null) ? "null" : resource.getFile().getPath().asString(); } }
@Override @Nonnull public ResourceProperties getProperties() { return getResource().getProperties(); }
final ResourceFile file = getResource().getFile(); final String segment = getResource().getProperties() .getProperty(PROPERTY_EXPOSED_URI, decode(file.getName(), "UTF-8")); relativeUri = relativeUri.appendedWith(getParent().getRelativeUri()).appendedWith(segment);
when(resource.getFile()).thenReturn(resourceFile); when(resource.getProperties()).thenReturn(properties);
@Override @Nonnull public Finder<SiteNode> findChildren() { return new ResourceFinder<>(getResource().getFile(), folder -> modelFactory.createSiteNode(site, folder)); } }
@Override @Nonnull public ResourceProperties getProperties() { return new ResourcePropertiesDelegate(requestContext, this, getResource().getProperties()); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @SuppressWarnings("unchecked") public FolderBasedFinderSupport (final @Nonnull Type parentResource) { try { final Site site = siteProvider.get().getSite(); this.typeClass = getInterface(parentResource); this.resourceRootPath = site.find(typeClass).withRelativePath("/").result().getFile().getPath(); this.parentFile = parentResource.getFile(); } catch (NotFoundException e) { throw new RuntimeException(e); // never occurs } }
/******************************************************************************************************************* * * {@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()); }
/******************************************************************************************************************* * ******************************************************************************************************************/ // 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(); }
@Override @Nonnull public Finder<Content> findChildren() { return new ResourceFinder<>( getResource().getFile(), folder -> modelFactory.createContent().withFolder(folder).build()); }
when(resource.getFile()).thenReturn(file);
@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)); }
final ResourceFile file = resource.getFile(); final String mimeType = file.getMimeType(); final Object content = mimeType.startsWith("text/") ? macroExpander.get().filter(file.asText("UTF-8"), mimeType)
when(resource.getFile()).thenReturn(resourceFile);
/******************************************************************************************************************* * * 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(); }