PageImpl extends ResourceImpl<ResourceContent> implements Page { public Pagelet[] getPreview() { Site site = getURI().getSite(); PageTemplate t = null; if (StringUtils.isNotBlank(template)) { t = site.getTemplate(template); } else { t = site.getDefaultTemplate(); logger.warn("Page {} has no template associated, using site default '{}'", uri, t.getIdentifier()); } if (preview == null && t == null) { logger.warn("Can't calculate the page preview due to missing page template '{}'", template); return new Pagelet[] {}; } else if (preview == null && t.getStage() == null) { logger.warn("Can't calculate the page preview due to missing stage definition in page template '{}'", template); return new Pagelet[] {}; } else if (preview == null) { this.preview = new ArrayList<Pagelet>(); List<Pagelet> stage = composers.get(t.getStage()); Set<PageletRenderer> previewRenderers = new HashSet<PageletRenderer>(); if (stage != null) { for (Pagelet p : stage) { Module m = site.getModule(p.getModule()); if (m == null) { logger.warn("Skipping pagelet '{}' for preview calculation: module '{}' can't be found", p, p.getModule()); continue; } PageletRenderer r = m.getRenderer(p.getIdentifier()); if (r == null) { logger.warn("Skipping pagelet '{}' for preview calculation: pagelet renderer '{}' can't be found", p, p.getIdentifier()); continue; } PagePreviewMode previewMode = r.getPreviewMode(); if (previewMode.equals(PagePreviewMode.First) && !previewRenderers.contains(r)) { preview.add(p); previewRenderers.add(r); } else if (PagePreviewMode.All.equals(previewMode)) { preview.add(p); previewRenderers.add(r); } else if (PagePreviewMode.Boundary.equals(previewMode)) { preview.clear(); for (Pagelet p2 : stage) { if (p2.equals(p)) break; preview.add(p2); } break; } } } } return preview.toArray(new Pagelet[preview.size()]); } PageImpl(ResourceURI uri); @Override boolean supportsContentLanguage(Language language); String getLayout(); void setLayout(String layout); String getTemplate(); void setTemplate(String template); void setStationary(boolean stationary); boolean isStationary(); Composer getComposer(String composerId); Composer getStage(); Composer[] getComposers(); Pagelet addPagelet(Pagelet pagelet, String composer); Pagelet addPagelet(Pagelet pagelet, String composer, int position); Pagelet[] getPagelets(); Pagelet[] getPagelets(String composer); Pagelet[] getPagelets(String composer, String module, String id); Pagelet removePagelet(String composer, int position); Pagelet[] getPreview(); void addPageContentListener(PageContentListener listener); void removePageContentListener(PageContentListener listener);  }
@Test public void testGetPreview() { assertNotNull(page.getPreview()); }