Java Code Examples for org.osgl.http.H#Format
The following examples show how to use
org.osgl.http.H#Format .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TemplatePathResolver.java From actframework with Apache License 2.0 | 6 votes |
protected String amendSuffix(String path, ActContext context) { if (path.contains(".")) { return path; } H.Format fmt = context.accept(); if (UNKNOWN == fmt) { fmt = HTML; } if (isAcceptFormatSupported(fmt)) { return S.concat(path, ".", fmt.name()); } if (context instanceof ActionContext) { ActionContext actionContext = $.cast(context); H.Request req = actionContext.req(); throw E.unsupport("Error handling %s request to %s - Request accept not supported: %s", req.method(), req.url(), fmt); } throw E.unsupport("Request accept not supported: %s", fmt); }
Example 2
Source File: AppConfig.java From actframework with Apache License 2.0 | 6 votes |
private void setRenderJsonContenTypeIE(final String contentType) { if (H.Format.JSON.contentType().equalsIgnoreCase(contentType)) { renderJsonIeFix = false; return; } renderJsonIeFix = true; jsonIE = H.Format.of("json_ie", contentType); jsonContentTypeProvider = new $.Func0<H.Format>() { @Override public H.Format apply() throws NotAppliedException, $.Break { ActionContext context = ActionContext.current(); if (null != context) { UserAgent ua = context.userAgent(); if (ua.isIE()) { return jsonIE; } } return H.Format.JSON; } }; }
Example 3
Source File: ActErrorPageRender.java From actframework with Apache License 2.0 | 6 votes |
private Template getTemplate(int statusCode, ActionContext context) { H.Format format = context.accept(); String key = statusCode + "" + format; $.Var<Template> templateBag = templateCache.get(key); if (null == templateBag) { ViewManager vm = Act.viewManager(); if (null == vm) { // unit testing return null; } context.templatePath(templatePath(statusCode, context)); Template t = vm.load(context); if (null == t) { // try default one if (Act.isDev()) { context.templatePath("/error/dev/errorPage." + context.accept().name()); } else { context.templatePath("/error/errorPage." + context.accept().name()); } t = vm.load(context); } templateBag = $.var(t); templateCache.put(key, templateBag); } return templateBag.get(); }
Example 4
Source File: ViewManager.java From actframework with Apache License 2.0 | 6 votes |
public DirectRender loadDirectRender(ActionContext context) { H.Format accept = context.accept(); if (directViewBlackList.contains(accept)) { return null; } View view = directViewQuickLookup.get(accept); if (null != view) { return view.directRenderFor(accept); } for (View view1 : viewList) { DirectRender dr = view1.directRenderFor(accept); if (null != dr) { directViewQuickLookup.put(accept, view1); return dr; } } directViewBlackList.add(accept); return null; }
Example 5
Source File: RequestBodyParser.java From actframework with Apache License 2.0 | 5 votes |
public static RequestBodyParser get(H.Request req) { H.Format contentType = req.contentType(); RequestBodyParser parser = parsers.get(contentType); if (null == parser) { parser = TextParser.INSTANCE; } return parser; }
Example 6
Source File: NetworkHandler.java From actframework with Apache License 2.0 | 5 votes |
@Override public String apply(H.Request req, String url) throws NotAppliedException, $.Break { $.Var<H.Format> fmtBag = $.var(); String processedUrl = process(url, fmtBag); H.Format fmt = fmtBag.get(); if (null != fmt) { req.accept(fmt); } return processedUrl; }
Example 7
Source File: TemplatePathResolver.java From actframework with Apache License 2.0 | 4 votes |
public static boolean isAcceptFormatSupported(H.Format fmt) { return (UNKNOWN == fmt || HTML == fmt || JSON == fmt || XML == fmt || TXT == fmt || CSV == fmt) || supportedFormats.contains(fmt); }
Example 8
Source File: EndpointTester.java From actframework with Apache License 2.0 | 4 votes |
public ReqBuilder accept(H.Format format) { this.accept = format; return this; }
Example 9
Source File: MailerContext.java From actframework with Apache License 2.0 | 4 votes |
public H.Format contentType() { return accept(); }
Example 10
Source File: ActionContext.java From actframework with Apache License 2.0 | 4 votes |
public ActionContext accept(H.Format fmt) { req().accept(fmt); return this; }
Example 11
Source File: ResponseCache.java From actframework with Apache License 2.0 | 4 votes |
@Override public ActResponse contentType(H.Format fmt) { contentType = fmt.contentType(); return super.contentType(fmt); }
Example 12
Source File: ActionContext.java From actframework with Apache License 2.0 | 4 votes |
public H.Format accept() { return req().accept(); }
Example 13
Source File: EndPointTestContext.java From actframework with Apache License 2.0 | 4 votes |
public EndPointTestContext accept(H.Format format){ this.accept = format; return this; }
Example 14
Source File: JobContext.java From actframework with Apache License 2.0 | 4 votes |
@Override public JobContext accept(H.Format fmt) { return this; }
Example 15
Source File: CliContext.java From actframework with Apache License 2.0 | 4 votes |
@Override public H.Format accept() { throw E.unsupport(); }
Example 16
Source File: HttpFormatValueResolver.java From actframework with Apache License 2.0 | 4 votes |
@Override public H.Format resolve(String value) { return H.Format.resolve(value); }
Example 17
Source File: MailerContext.java From actframework with Apache License 2.0 | 4 votes |
@Override public H.Format accept() { return null != fmt ? fmt : mailerConfig().contentType(); }
Example 18
Source File: WebSocketContext.java From actframework with Apache License 2.0 | 4 votes |
@Override public WebSocketContext accept(H.Format fmt) { throw E.unsupport(); }
Example 19
Source File: WebSocketContext.java From actframework with Apache License 2.0 | 4 votes |
@Override public H.Format accept() { throw E.unsupport(); }
Example 20
Source File: ActContext.java From actframework with Apache License 2.0 | votes |
CTX_TYPE accept(H.Format fmt);