@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; }
final Layout layout = siteNode.getLayout(); 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 public ResourceProperties getNodeProperties() { if (contentHolder.get() == null) // FIXME: should never occur { log.warn("NO CONTENT IN CONTEXT"); // Thread.dumpStack(); // FIXME return dynamicNodePropertiesHolder.get(); } return nodeHolder.get().getProperties().merged(dynamicNodePropertiesHolder.get()); }
@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); } } });
view.setTitle(siteNode.getPropertyGroup(view.getId()).getProperty(PROPERTY_TITLE)); final ResourceProperties viewProperties = siteNode.getPropertyGroup(view.getId()); for (final String relativePath : siteNode.getPropertyGroup(view.getId()).getProperty(PROPERTY_LINKS)) final String navigationTitle = targetSiteNode.getProperties().getProperty(PROPERTY_NAVIGATION_LABEL, "no nav. label"); view.addLink(navigationTitle, site.createLink(targetSiteNode.getRelativeUri()));
/* visible for testing */ void onSiteNodeSelected (final @ListensTo @Nonnull SiteNodeSelectedEvent selectionEvent) { log.debug("onSiteNodeSelected({})", selectionEvent); if (!selectionEvent.getSiteNode().isPresent()) { presentation.clear(); } else { final SiteNode siteNode = selectionEvent.getSiteNode().get(); final ResourceProperties properties = siteNode.getProperties(); log.debug(">>>> properties: {}", properties); presentation.populate("Viewer not implemented for " + siteNode.getFile()); presentation.populateProperties(properties.as(Presentable).createPresentationModel()); presentation.showUp(); } } }
/******************************************************************************************************************* * * {@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()); }
final int currentYear = getCurrentYear(pathParams); final ResourceProperties siteNodeProperties = siteNode.getProperties(); final ResourceProperties viewProperties = siteNode.getPropertyGroup(view.getId());
/******************************************************************************************************************* * * . * ******************************************************************************************************************/ @Nonnull protected ResourceProperties getViewProperties() { return siteNode.getPropertyGroup(view.getId()); }
/* visible for testing */ void onOpenSite (final @ListensTo @Nonnull OpenSiteEvent event) { try { log.debug("onOpenSite({})", event); final ResourceFile root = event.getFileSystem().findFileByPath(ROOT_SITE_NODE_PATH); final SiteNode rootSiteNode = modelFactory.createSiteNode(site, root); presentation.populate(rootSiteNode.as(Presentable).createPresentationModel()); presentation.expandFirstLevel(); messageBus.publish(emptySelectionEvent()); } catch (IOException | NotFoundException e) { log.warn("", e); } } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ @PostConstruct private void initialize() { loadItems(siteNode.getProperties()); }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ 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"); }
final ResourceProperties siteNodeProperties = siteNode.getPropertyGroup(view.getId());
@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; } };
final XPathFactory xPathFactory = XPathFactory.newInstance(); // FIXME: inject final String s = siteNode.getProperties().getProperty(PROPERTY_IMAGES); final Document document = db.parse(new InputSource(new StringReader(s))); final XPath xPath = xPathFactory.newXPath();
@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()); } }
for (final String relativePath : siteNode.getPropertyGroup(view.getId()).getProperty(PROPERTY_CONTENTS)) final ResourceProperties viewProperties = siteNode.getPropertyGroup(view.getId()); view.setClassName(viewProperties.getProperty(PROPERTY_CLASS, "nw-" + view.getId()));
/******************************************************************************************************************* * * ******************************************************************************************************************/ 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"); } }
/******************************************************************************************************************* * * * ******************************************************************************************************************/ @Nonnull private String getMetadataString (final @Nonnull Id id, final @Nonnull String format) throws NotFoundException { // FIXME: should use current SiteNode properties final ResourceProperties properties = siteProvider.get().getSite().find(SiteNode.class) .withRelativePath("/") .result() .getProperties(); return mediaMetadataProvider.getMetadataString(id, format, properties); }