Back to project page js-android-sdk.
The source code is released under:
GNU Lesser General Public License
If you think the Android project js-android-sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (c) 2014. Lorem ipsum dolor sit amet, consectetur adipiscing elit. * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan. * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna. * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus. * Vestibulum commodo. Ut rhoncus gravida arcu. *//*from w w w . j a v a 2 s .c o m*/ package com.jaspersoft.android.sdk.util; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; import java.io.IOException; import java.util.Locale; import java.util.TimeZone; public class LocalesHttpRequestInterceptor implements ClientHttpRequestInterceptor { private static final String ACCEPT_TIMEZONE = "Accept-Timezone"; @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { String timeZone = createGmtOffsetString(true, true, TimeZone.getDefault().getRawOffset()); // Because of HTTP accepts this type separator '-' we replace default one String locale = Locale.getDefault().toString().replaceAll("_", "-"); request.getHeaders().setAcceptLanguage(locale); request.getHeaders().add(ACCEPT_TIMEZONE, timeZone); return execution.execute(request, body); } private String createGmtOffsetString(boolean includeGmt, boolean includeMinuteSeparator, int offsetMillis) { int offsetMinutes = offsetMillis / 60000; char sign = '+'; if (offsetMinutes < 0) { sign = '-'; offsetMinutes = -offsetMinutes; } StringBuilder builder = new StringBuilder(9); if (includeGmt) { builder.append("GMT"); } builder.append(sign); appendNumber(builder, 2, offsetMinutes / 60); if (includeMinuteSeparator) { builder.append(':'); } appendNumber(builder, 2, offsetMinutes % 60); return builder.toString(); } private void appendNumber(StringBuilder builder, int count, int value) { String string = Integer.toString(value); for (int i = 0; i < count - string.length(); i++) { builder.append('0'); } builder.append(string); } }