/******************************************************************************************************************* * * * ******************************************************************************************************************/ public DefaultLayout (final @Nonnull Builder builder) { this.id = builder.getId(); this.typeUri = builder.getType(); }
@Override @Nonnull public Object createView (final @Nonnull SiteNode siteNode) throws NotFoundException { return viewFactory.createView(typeUri, id, siteNode); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public ViewAndController createViewAndController (final @Nonnull SiteNode siteNode) throws NotFoundException, HttpStatusException { return viewFactory.createViewAndController(typeUri, id, siteNode); }
layout = (layout == null) ? overridingLayout : layout.withOverride(overridingLayout); .withId(new Id("")) .withType("emptyPlaceholder") .build(); layout.accept(new LayoutLoggerVisitor(LayoutLoggerVisitor.Level.INFO));
final boolean sameType = this.getTypeUri().equals(override.getTypeUri()); this.typeUri = override.getTypeUri(); // FIXME: don't like this approach, as it requires typeUri non final for (final Layout overridingChild : override.findChildren().results()) final Layout overriddenChild = childrenMapById.get(overridingChild.getId()); childrenMapById.put(overridingChild.getId(), overridingChild); final int i = children.indexOf(overriddenChild); this.childrenMapById.clear(); for (final Layout overridingChild : override.findChildren().results())
if (!layout.getTypeUri().startsWith("http://northernwind.tidalwave.it/component/Sitemap/")) layout.accept(new VisitorSupport<Layout, Void>()
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull // TODO: push up to CompositeSupport public <Type> Type accept (final @Nonnull Visitor<Layout, Type> visitor) throws NotFoundException { visitor.preVisit(this); visitor.visit(this); for (final Layout child : children) { child.accept(visitor); } visitor.postVisit(this); return visitor.getValue(); }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override public boolean handleUri (final @Nonnull URL context, final @Nonnull String relativeUri) throws NotFoundException, IOException { final SiteNode siteNode = site.find(SiteNode).withRelativeUri("/" + relativeUri).result(); // siteView.setCaption(structure.getProperties().getProperty("Title")); TODO siteView.renderSiteNode(siteNode); return true; } }
@Nonnull private ComponentType createComponent (@Nonnull Layout layout) { try { return (ComponentType)layout.createView(siteNode); } catch (NotFoundException e) { return createPlaceHolderComponent(layout); } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull private DefaultLayout loadLayout (final @Nonnull ResourceFile layoutFile) throws IOException { log.trace(">>>> reading layout from {}...", layoutFile.getPath().asString()); final @Cleanup InputStream is = layoutFile.getInputStream(); return modelFactory.createLayout().build().as(Unmarshallable).unmarshal(is); } }
@Override public Layout build (final @Nonnull Layout.Builder builder) { assertThat(builder.getType(), is("emptyPlaceholder")); return emptyPlaceHolderLayout; } }));
/******************************************************************************************************************* * ******************************************************************************************************************/ @Test public void must_properly_instantiate_view_and_controller() throws Exception { final ViewAndController viewAndController = underTest.createViewAndController(id, siteNode); final Object oController = viewAndController.getController(); final Object oView = viewAndController.getView(); assertThat(oController, is(not(nullValue()))); assertThat(oView, is(not(nullValue()))); assertThat(oController, is(instanceOf(MockController.class))); assertThat(oView, is(instanceOf(MockView.class))); final MockController controller = (MockController)oController; final MockView view = (MockView)oView; assertThat(controller.view, is(sameInstance(view))); assertThat(controller.siteNode, is(sameInstance(siteNode))); assertThat(controller.id, is(id)); assertThat(controller.site, is(sameInstance(site))); assertThat(controller.service2, is(sameInstance(service2))); assertThat(view.siteNode, is(sameInstance(siteNode))); assertThat(view.id, is(id)); assertThat(view.site, is(sameInstance(site))); assertThat(view.service1, is(sameInstance(service1))); } }
/******************************************************************************************************************* * * {@inheritDoe} * ******************************************************************************************************************/ @Nonnull private Layout loadLayout() throws IOException, NotFoundException { Layout layout = null; for (final FileObject layoutFile : Utilities.getInheritedPropertyFiles(resource.getFile(), "Layout_en.xml")) { log.trace(">>>> reading layout from /{}...", layoutFile.getPath()); final DefaultLayout overridingLayout = new DefaultLayoutXmlUnmarshaller(layoutFile).unmarshal(); layout = (layout == null) ? overridingLayout : layout.withOverride(overridingLayout); if (log.isDebugEnabled()) { overridingLayout.accept(new LayoutLoggerVisitor(LayoutLoggerVisitor.Level.DEBUG)); } } return layout; } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ public void add (final @Nonnull Layout layout) // FIXME: drop this - used only by the CloneVisitor and Infoglue converter { children.add(layout); // FIXME: clone childrenMapById.put(layout.getId(), layout);// FIXME: clone }
throw new HttpErrorException(404, e); throw new HttpErrorException(500, e);
final Object controller = viewControllerConstructor.newInstance( computeConstructorArguments(viewControllerConstructor, id, siteNode, view)); return new ViewAndController(view, controller);
when(modelFactory.createLayout()).thenReturn(new Layout.Builder(modelFactory, new Layout.Builder.CallBack()
/******************************************************************************************************************* * * Creates a new instance with the given configuration file and mapped to the given URI. * * @param file the file with the configuration * @param relativeUri the bound URI * ******************************************************************************************************************/ public DefaultSiteNode (final @Nonnull FileObject file) throws IOException, NotFoundException { resource = new DefaultResource(file); layout = loadLayout(); if (site.isLogConfigurationEnabled() || log.isDebugEnabled()) { log.info(">>>> layout for /{}:", resource.getFile().getPath()); layout.accept(new LayoutLoggerVisitor(LayoutLoggerVisitor.Level.INFO)); } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Status process (final @Nonnull Request request) throws NotFoundException, IOException, HttpStatusException { try { final String relativeUri = request.getRelativeUri(); final Site site = siteProvider.get().getSite(); final SiteNode node = site.find(SiteNode).withRelativeUri(relativeUri).result(); requestContext.setNode(node); siteView.renderSiteNode(node); // // Check *after* finding the SiteNode, since a "not found" must have been already handled here. // enforceTrailingSlash(relativeUri, site); return BREAK; } finally { requestContext.clearNode(); } }
/******************************************************************************************************************* * * {@inheritDoc} * ******************************************************************************************************************/ @Override @Nonnull public Layout withChild (final @Nonnull Layout layout) { final DefaultLayout clone = clone(); clone.children.add(layout); clone.childrenMapById.put(layout.getId(), layout); return clone; }