/** * Add new element. * @param bundle The element * @return This object */ public final T append(@NotNull final JaxbBundle bundle) { this.append(bundle.element()); return (T) this; }
/** * Render it. * @return JAX-RS response */ public final Response.ResponseBuilder render() { final Response.ResponseBuilder builder = Response.ok(); for (final Class<? extends Inset> type : BasePage.defaults(this.resource.getClass())) { this.inset(type).render(this, builder); } for (final Method method : this.resource.getClass().getMethods()) { if (method.isAnnotationPresent(Inset.Runtime.class)) { this.inset(method).render(this, builder); } } builder.entity(this); return builder; }
@Override public void render(final BasePage<?, ?> page, final Response.ResponseBuilder builder) { if (!BaseRs.this.auth().identity().equals(Identity.ANONYMOUS)) { try { page.append( new JaxbBundle("token", BaseRs.this.user().token()) ); } catch (final IOException ex) { throw new IllegalStateException(ex); } page.link(new Link("user:refresh", "/u/refresh")); } } };
/** * Add new HATEOAS link. * @param link The link to add * @return This object */ public final T link(@NotNull final Link link) { link.attachTo(this.home()); this.links.add(link); return (T) this; }
/** * Get all specified (by annotations) default insets. * @param type The type to fetch them from or NULL * @return List of them */ private static Set<Class<? extends Inset>> defaults( final Class<?> type) { final Set<Class<? extends Inset>> insets = new HashSet<Class<? extends Inset>>(0); if (type != null) { if (type.isAnnotationPresent(Inset.Default.class)) { insets.addAll( Arrays.asList( type.getAnnotation(Inset.Default.class).value() ) ); } insets.addAll(BasePage.defaults(type.getSuperclass())); for (final Class<?> iface : type.getInterfaces()) { insets.addAll(BasePage.defaults(iface)); } } return insets; }
/** * Get page generation time, in milliseconds. * @return Page generation time */ @XmlElement public final long getMillis() { return System.currentTimeMillis() - this.home().started(); }
@Override public void render(final BasePage<?, ?> page, final Response.ResponseBuilder builder) { if (!BaseRs.this.auth().identity().equals(Identity.ANONYMOUS)) { try { page.append(new JxHuman(BaseRs.this.human())); } catch (final IOException ex) { throw new IllegalStateException(ex); } } } };
@Override public void render(final BasePage<?, ?> page, final Response.ResponseBuilder builder) { if (!BaseRs.this.auth().identity().equals(Identity.ANONYMOUS)) { page.link(new Link("menu:home", "/")); page.link(new Link("menu:counters", "/counters")); page.link(new Link("menu:locks", "/k")); } } };
/** * Get SSL or non-SSL flag. * @return The flag */ @XmlAttribute public final boolean isSsl() { return this.home().securityContext().isSecure(); }
@Override public void render(@NotNull final BasePage<?, ?> page, @NotNull final Response.ResponseBuilder builder) { page.append( new JaxbBundle("version", "") .add("name", this.version) .up() .add("revision", this.revision) .up() .add("date", this.date) .up() ); }
@Override public void render(final BasePage<?, ?> page, final Response.ResponseBuilder builder) { page.link( new Link( "ask", BaseRs.this.uriInfo().getBaseUriBuilder().clone() .path(AskRs.class) .path(AskRs.class, "post") ) ); page.link( new Link( "upload-photo", BaseRs.this.uriInfo().getBaseUriBuilder().clone() .path(ProfileRs.class) .path(ProfileRs.class, "photo") ) ); page.link( new Link( "history", BaseRs.this.uriInfo().getBaseUriBuilder().clone() .path(HistoryRs.class) .path(HistoryRs.class, "index") ) ); } };
/** * Append new element. * @param element The element to append * @return This object */ public final T append(@NotNull final Object element) { if (!element.getClass().isAnnotationPresent(XmlRootElement.class)) { throw new IllegalArgumentException( Logger.format( "class %[type]s doesn't have @XmlRootElement annotation", element ) ); } this.elements.add(element); XslResolver.class.cast( this.home().providers().getContextResolver( Marshaller.class, MediaType.APPLICATION_XML_TYPE ) ).add(element.getClass()); return (T) this; }
@Override public void render(@NotNull final BasePage<?, ?> page, @NotNull final Response.ResponseBuilder builder) { if (this.resource.httpHeaders().getCookies() .containsKey(FlashInset.COOKIE)) { final FlashInset.Flash cookie = new FlashInset.Flash( this.resource.httpHeaders().getCookies().get(FlashInset.COOKIE) ); page.append( FlashInset.bundle( cookie.level(), cookie.message(), cookie.msec() ) ); builder.cookie( new CookieBuilder(this.resource.uriInfo().getBaseUri()) .name(FlashInset.COOKIE) .build() ); } }