public FormFilter(final String loginUrl, final String callback) { super(FormClient.class, CommonProfile.class); this.loginUrl = loginUrl; this.callback = Route.normalize(callback) + "?client_name=FormClient"; }
/** * Add <a href="https://github.com/Rebilly/ReDoc">ReDoc</a> UI to swagger * (has no effects on RAML). * * @param path Redoc base path. * @return This options. */ public Options redoc(String path) { this.redoc = Route.normalize(path); return this; }
/** * Creates a new {@link Options} object. * * @param path Path to mount the export tool. Usually <code>/swagger</code> or <code>/raml</code>. */ public Options(String path) { this.path = Route.normalize(Objects.requireNonNull(path, "Path required.")); }
private String authCallbackPath(final Config conf) { String fullcallback = conf.getString("auth.callback"); String root = conf.getString("application.path"); String callback = URI.create(fullcallback).getPath().replace(root, ""); return Route.normalize(callback); }
/** * Set the route name. Route's name, helpful for debugging but also to implement dynamic and * advanced routing. See {@link Route.Chain#next(String, Request, Response)} * * * @param name A route's name. * @return This definition. */ @Override @Nonnull public Definition name(final String name) { checkArgument(!Strings.isNullOrEmpty(name), "A route's name is required."); this.name = normalize(prefix != null ? prefix + "/" + name : name); return this; }
/** * Creates a new lambda and set a pattern prefix. * * @param prefix Prefix. * @return A new lambda. */ public Lambda prefix(String prefix) { return new Lambda(declaringClass, owner, desc, implementationName, name, Route.normalize(prefix + "/" + pattern), method.orElse(null), tag); }
/** * Set HTTP pattern. * * @param pattern New HTTP Pattern. * @return This method. */ public RouteMethod pattern(String pattern) { this.pattern = rewritePattern(Route.normalize(pattern)); return this; }
@Override public Route.Collection path(String path, Runnable action) { this.path.addLast(Route.normalize(path)); Route.Collection collection = with(action); this.path.removeLast(); return collection; }
private String file(final String key) { String file = Route.normalize(key.trim()); return text(getClass().getResourceAsStream(file)); }
@Override public void enterPath(FuzzyDocParser.PathContext ctx) { this.prefix.addLast(Route.normalize(str(ctx.pattern.getText()))); this.insideRoute.addLast(true); if (ctx.doc != null) { this.summary.addLast(cleanJavadoc(file, ctx.doc.getText())); } }
/** * <pre>{@code * route("/api/pattern"); * }</> * @param ctx */ @Override public void enterRoute(final FuzzyDocParser.RouteContext ctx) { this.prefix.addLast(Route.normalize(str(ctx.pattern.getText()))); this.insideRoute.addLast(true); this.summary.addLast(cleanJavadoc(file, ctx.doc.getText())); }
/** * <p> * Creates a new {@link AssetHandler}. The location pattern can be one of. * </p> * * Given <code>/</code> like in <code>assets("/assets/**", "/")</code> with: * * <pre> * GET /assets/js/index.js it translates the path to: /assets/js/index.js * </pre> * * Given <code>/assets</code> like in <code>assets("/js/**", "/assets")</code> with: * * <pre> * GET /js/index.js it translate the path to: /assets/js/index.js * </pre> * * Given <code>/META-INF/resources/webjars/{0}</code> like in * <code>assets("/webjars/**", "/META-INF/resources/webjars/{0}")</code> with: * * <pre> * GET /webjars/jquery/2.1.3/jquery.js it translate the path to: /META-INF/resources/webjars/jquery/2.1.3/jquery.js * </pre> * * @param pattern Pattern to locate static resources. */ public AssetHandler(final String pattern) { init(Route.normalize(pattern), Paths.get("public"), getClass().getClassLoader()); }
@Override public void enterMvcRoute(final FuzzyDocParser.MvcRouteContext ctx) { String path = pattern(ctx.annotations); List<String> methods = methods(ctx.annotations); if (methods.isEmpty() && path == null) { // not an mvc method return; } String comment = ctx.doc.getText(); String pattern = prefix.stream().collect(Collectors.joining()) + "/" + Optional.ofNullable(path) .orElse("/"); if (methods.size() == 0) { doc.add(doc("get", normalize(pattern), file, summary(), comment)); } else { methods.stream() .forEach(method -> doc.add(doc(method, normalize(pattern), file, summary(), comment))); } }
/** * <pre>{@code * use("/api/pattern"); * }</> * @param ctx */ @Override public void enterUse(final FuzzyDocParser.UseContext ctx) { if (ctx.comma.size() > 0) { String comment = ctx.doc.getText(); String method = Optional.ofNullable(ctx.method).map(it -> str(it.getText())).orElse("*"); String pattern = Optional.ofNullable(ctx.pattern).map(it -> str(it.getText())) .orElse("*"); doc.add( doc(method, normalize(pattern), file, summary(), comment)); } else { this.prefix.addLast(Route.normalize(str(ctx.pattern.getText()))); popInsideRoute(); this.summary.addLast(cleanJavadoc(file, ctx.doc.getText())); } }
@SuppressWarnings("unchecked") public boolean excludes(final String path) { Object value = get("excludes"); if (value == null) { return false; } List<String> excludes; if (value instanceof List) { excludes = (List<String>) value; } else { excludes = ImmutableList.of(value.toString()); } String spath = Route.normalize(path); return excludes.stream() .map(it -> new RoutePattern("GET", it)) .anyMatch(pattern -> pattern.matcher("GET" + spath).matches()); }
@Override public Response cookie(final Definition cookie) { requireNonNull(cookie, "Cookie required."); // use default path if none-set cookie.path(cookie.path().orElse(Route.normalize(req.contextPath() + "/"))); return cookie(cookie.toCookie()); }
@Override public void enterScript(final FuzzyDocParser.ScriptContext ctx) { if (ctx.dot == null && !insideRoute()) { /** * reset prefix when '.' is missing: * * use("prefix") * .get() * * vs * * get("pattern") * * but ignore dot when route(prefix) is present (kotlin) */ popPrefix(); popSummary(); } String comment = Optional.ofNullable(ctx.doc).map(it -> it.getText()).orElse(""); if (ctx.method != null) { String method = ctx.method.getText(); String pattern = prefix.stream().collect(Collectors.joining("")) + "/" + Optional.ofNullable(ctx.pattern) .map(it -> str(it.getText())) .orElse("/"); doc.add(doc(method, normalize(pattern), file, summary(), comment)); } }
private void mvcRoutes(String path, final Class type, Consumer<RouteMethod> callback) { Env env = Env.DEFAULT.build(ConfigFactory.empty() .withValue("application.env", ConfigValueFactory.fromAnyRef("dev"))); MvcRoutes.routes(env, new RouteMetadata(env), "", true, type) .forEach(r -> { RouteMethod method = toRouteMethod(r); javadoc(method, javadoc.pop(type.getName(), r.method(), r.pattern())); if (path.length() > 0) { method.pattern(Route.normalize(path) + method.pattern()); } // Set default tag Annotation rootPath = type.getAnnotation(org.jooby.mvc.Path.class); if (rootPath != null) { method.attribute("route.tag", mvcRouteTag(type.getSimpleName())); } callback.accept(method); }); }
@SuppressWarnings({"rawtypes", "unchecked" }) @Override public void render(final Object value, final Context ctx) throws Exception { Object model = value; /** View? */ if (value instanceof View) { View view = (View) value; String path = path(Route.normalize(prefix + "/" + view.name() + suffix)); Map data = view.model(); model = Rocker.template(path).bind(data); } /** RockerModel: */ if (model instanceof RockerModel) { ArrayOfByteArraysOutput output = ((RockerModel) model).render(ArrayOfByteArraysOutput.FACTORY, template -> { if (template instanceof RequestRockerTemplate) { RequestRockerTemplate rrt = (RequestRockerTemplate) template; rrt.locals = ctx.locals(); } }); ctx.type(MediaType.html) .length(output.getByteLength()) // FIXME: make more efficient. Context should provide a way to send partial results .send(Channels.newInputStream(output.asReadableByteChannel())); } }