/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public String getPathParams (final @Nonnull SiteNode siteNode) { final String siteNodeRelativeUri = siteNode.getRelativeUri().asString(); return (relativeUri.length() <= siteNodeRelativeUri.length()) ? "" : relativeUri.substring(siteNodeRelativeUri.length()); }
@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; }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ 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 @Nonnull protected String filter (final @Nonnull Matcher matcher) throws NotFoundException { final String relativePath = matcher.group(1); final Site site = siteProvider.get().getSite(); final SiteNode siteNode = site.find(SiteNode.class).withRelativePath(relativePath).result(); return site.createLink(siteNode.getRelativeUri()); } }
@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; } };
/******************************************************************************************************************* * * ******************************************************************************************************************/ private void appendUrl (final @Nonnull StringBuilder builder, final @Nonnull SiteNode siteNode, final @Nullable SiteNode childSiteNode) throws IOException { final SiteNode n = (childSiteNode != null) ? childSiteNode : siteNode; final DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); final ResourceProperties properties = n.getProperties(); // // FIXME: if you put the sitemap property straightly into the child site node, you can simplify a lot, // just using a single property and only peeking into a single node final Key<String> priorityKey = (childSiteNode == null) ? PROPERTY_SITEMAP_PRIORITY : PROPERTY_SITEMAP_CHILDREN_PRIORITY; final float sitemapPriority = Float.parseFloat(siteNode.getProperties().getProperty(priorityKey, "0.5")); if (sitemapPriority > 0) { builder.append(" <url>\n"); builder.append(String.format(" <loc>%s</loc>%n", site.createLink(n.getRelativeUri()))); builder.append(String.format(" <lastmod>%s</lastmod>%n", dateTimeFormatter.print(getSiteNodeDateTime(properties)))); builder.append(String.format(" <changefreq>%s</changefreq>%n", properties.getProperty(PROPERTY_SITEMAP_CHANGE_FREQUENCY, "daily"))); builder.append(String.format(" <priority>%s</priority>%n", Float.toString(sitemapPriority))); builder.append(" </url>\n"); } }
@Override @Nonnull protected List<? extends SiteNode> computeResults() { final SiteNode content = mock(SiteNode.class); when(content.getRelativeUri()).thenReturn(new ResourcePath("URI-" + relativePath.substring(1))); return Arrays.asList(content); }
log.debug(">>>> sitemap processing {} / layout {} ...", siteNode.getRelativeUri(), layout); appendUrl(builder, siteNode, null);
@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; } };
@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); }
@Override public void apply (final @Nonnull ResourceFile folder, final @Nonnull ResourcePath relativePath) { try { final SiteNode siteNode = modelFactory.createSiteNode(DefaultSite.this, folder); nodeMapByRelativePath.put(relativePath.asString(), siteNode); if (!siteNode.isPlaceHolder()) { final ResourcePath relativeUri = siteNode.getRelativeUri(); // Nodes which manage path params are registered with a relativeUri having a wildcard suffix if ("true".equals(siteNode.getProperties().getProperty(SiteNode.PROPERTY_MANAGES_PATH_PARAMS, "false"))) { final String suffix = relativeUri.asString().endsWith("/") ? "(|.*$)" : "(|/.*$)"; nodeMapByRelativeUri.putRegex("^" + RegexTreeMap.escape(relativeUri.asString()) + suffix, siteNode); } else { nodeMapByRelativeUri.put(relativeUri.asString(), siteNode); } } } catch (IOException | NotFoundException e) { throw new RuntimeException(e); } } });
relativeUri = relativeUri.appendedWith(getParent().getRelativeUri()).appendedWith(segment);
when(siteNode.getRelativeUri()).thenReturn(new ResourcePath(relativeUri)); when(siteNode.toString()).thenReturn(String.format("Node(path=%s)", path));
when(parentSiteNode.getRelativeUri()).thenReturn(new ResourcePath(parentUri));
final String navigationTitle = targetSiteNode.getProperties().getProperty(PROPERTY_NAVIGATION_LABEL, "no nav. label"); view.addLink(navigationTitle, site.createLink(targetSiteNode.getRelativeUri()));