@Override public Link link() { return new Link( "rexsl:amazon", UriBuilder .fromUri("https://www.amazon.com/ap/oa") // @checkstyle MultipleStringLiterals (2 lines) .queryParam("client_id", "{client_id}") .queryParam("redirect_uri", "{redirect_uri}") .queryParam("scope", "{scope}") .queryParam("response_type", "{response_type}") .build(this.app, this.redirectUri(), "profile", "code") ); }
/** * 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; }
/** * Attach to this resource and make {@code HREF} attribute * absolute, using the URI information of the resource. * @param res The resource to attach to */ public void attachTo(@NotNull @Valid final Resource res) { synchronized (this.elements) { if (!this.href.isAbsolute()) { if (this.href.getPath().charAt(0) == '.') { this.href = Link.combine( res.uriInfo().getRequestUri(), this.href.getPath().substring(1), this.href.getQuery() ); } else if (this.href.getPath().charAt(0) == '/') { this.href = Link.combine( res.uriInfo().getBaseUri(), this.href.getPath(), this.href.getQuery() ); } } } }
/** * Create and return a DOM element, inside the document provided. * @param doc The document * @return The element just created */ private Element element(final Document doc) { final Element element = doc.createElement(this.name); for (final Map.Entry<String, String> attr : this.attrs.entrySet()) { element.setAttribute(attr.getKey(), attr.getValue()); } for (final JaxbBundle child : this.children) { element.appendChild(child.element(doc)); } for (final Element child : this.elements) { element.appendChild(doc.importNode(child, true)); } if (!this.links.isEmpty()) { final Element lnks = doc.createElement("links"); for (final Link link : this.links) { final Element lnk = doc.createElement("link"); lnk.setAttribute("rel", link.getRel()); lnk.setAttribute("href", link.getHref().toString()); lnk.setAttribute("type", link.getType()); lnks.appendChild(lnk); } element.appendChild(lnks); } element.appendChild(doc.createTextNode(this.content)); return element; }
/** * Set HREF attribute of the link. * @param uri The value of it */ public void setHref(@NotNull final String uri) { this.setHref(URI.create(uri)); }
/** * Add new JAXB bundle. * @param bundle The bundle to add * @return This object */ @NotNull public Link with(@NotNull final JaxbBundle bundle) { this.with(bundle.element()); return this; }
@Override public Link link() { return new Link( "rexsl:github", UriBuilder .fromUri("https://github.com/login/oauth/authorize") // @checkstyle MultipleStringLiterals (2 lines) .queryParam("client_id", "{client_id}") .queryParam("redirect_uri", "{redirect_uri}") .build(this.app, this.redirectUri()) ); }
@Override public Link link() { return new Link( "rexsl:facebook", UriBuilder .fromUri("https://www.facebook.com/dialog/oauth") // @checkstyle MultipleStringLiterals (2 lines) .queryParam("client_id", "{client_id}") .queryParam("redirect_uri", "{redirect_uri}") .build(this.app, this.redirectUri()) ); }
@Override public Link link() { return new Link( "rexsl:linkedin", UriBuilder .fromUri("https://www.linkedin.com/uas/oauth2/authorization") // @checkstyle MultipleStringLiterals (2 lines) .queryParam("client_id", "{client_id}") .queryParam("redirect_uri", "{redirect_uri}") .queryParam("state", "{state}") .build(this.app, this.redirectUri(), LinkedIn.STATE) ); }
@Override public Link link() { return new Link( "rexsl:google", UriBuilder .fromUri("https://accounts.google.com/o/oauth2/auth") // @checkstyle MultipleStringLiterals (2 lines) .queryParam("client_id", "{id}") .queryParam("redirect_uri", "{uri}") .queryParam("response_type", "code") .queryParam(Google.STATE, Google.FLAG) .queryParam( "scope", "https://www.googleapis.com/auth/userinfo.profile" ) .build(this.app, this.resource.uriInfo().getBaseUri()) ); }
@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")); } } };
/** * Its links. * @return Links */ @XmlElementWrapper(name = "links") @XmlElement(name = "link") public Collection<Link> getLinks() { final Collection<Link> links = new LinkedList<Link>(); links.add( new Link( "photo", new Human.Photo(this.human).uri() ) ); return links; }
/** * Its links. * @return Links * @throws IOException If fails */ @XmlElementWrapper(name = "links") @XmlElement(name = "link") public Collection<Link> getLinks() throws IOException { final Collection<Link> links = new LinkedList<Link>(); links.add( new Link( "open", this.base.uriInfo().getBaseUriBuilder().clone() .path(TalkRs.class) .path(TalkRs.class, "index") .build(this.talk.number()) ) ); return links; }
/** * Its links. * @return Links * @throws IOException If fails */ @XmlElementWrapper(name = "links") @XmlElement(name = "link") public Collection<Link> getLinks() throws IOException { final Collection<Link> links = new LinkedList<Link>(); links.add( new Link( "photo", new Human.Photo(this.role.talker()).uri() ) ); return links; }
@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") ) ); } };
@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")); } } };
/** * Get entrance page JAX-RS response. * @return The JAX-RS response * @throws Exception If some problem inside */ @GET @Path("/") public Response index() throws Exception { return new PageBuilder() .stylesheet("/xsl/locks.xsl") .build(StPage.class) .init(this) .append( new JaxbBundle( "documentation", IOUtils.toString( this.getClass().getResourceAsStream( "doc-locks.html" ) ) ) ) .append(this.list()) .append(new JaxbBundle("menu", "locks")) .link(new Link("lock", "./lock")) .link(new Link("label", "./label")) .link(new Link("unlock", "./unlock")) .render() .build(); }