本文整理汇总了Java中org.apache.cordova.CordovaResourceApi.OpenForReadResult类的典型用法代码示例。如果您正苦于以下问题:Java OpenForReadResult类的具体用法?Java OpenForReadResult怎么用?Java OpenForReadResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OpenForReadResult类属于org.apache.cordova.CordovaResourceApi包,在下文中一共展示了OpenForReadResult类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: remapChromeUri
import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public Uri remapChromeUri(Uri uri) {
Uri ret = Uri.parse(replacePatternsInLine(uri.toString()));
if (ret.getPath().endsWith(".css") || uri.getPath().equals("manifest.json")) {
Uri fileUri = Uri.parse("file:///android_asset/www" + uri.getPath());
fileUri = webView.getResourceApi().remapUri(fileUri);
try {
OpenForReadResult readResult = webView.getResourceApi().openForRead(fileUri, true);
try {
byte[] newData = replaceI18nPlaceholders(readResult.inputStream);
return Uri.parse("data:text/css;charset=utf-8;base64," + Base64.encode(newData));
} finally {
if (readResult != null) {
readResult.inputStream.close();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
return ret;
}
示例2: getStorage
import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
private JSONObject getStorage(String namespace) throws IOException, JSONException {
JSONObject oldMap = new JSONObject();
CordovaResourceApi resourceApi = webView.getResourceApi();
try {
OpenForReadResult readResult = resourceApi.openForRead(getStorageFile(namespace));
ByteArrayOutputStream readBytes = new ByteArrayOutputStream((int)readResult.length);
resourceApi.copyResource(readResult, readBytes);
byte[] bytes = readBytes.toByteArray();
String content = (new String(bytes)).trim();
if (content.length() > 0) {
oldMap = new JSONObject(content);
}
} catch (FileNotFoundException e) {
//Suppress the file not found exception
}
return oldMap;
}
示例3: shouldInterceptRequest
import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
try {
// Check the against the whitelist and lock out access to the WebView directory
// Changing this will cause problems for your application
if (isUrlHarmful(url)) {
LOG.w(TAG, "URL blocked by whitelist: " + url);
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
CordovaResourceApi resourceApi = appView.getResourceApi();
Uri origUri = Uri.parse(url);
// Allow plugins to intercept WebView requests.
Uri remappedUri = resourceApi.remapUri(origUri);
if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
}
// If we don't need to special-case the request, let the browser load it.
return null;
} catch (IOException e) {
if (!(e instanceof FileNotFoundException)) {
LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
}
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
}
示例4: shouldInterceptLoadRequest
import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
try {
// Check the against the white-list.
if (!parentEngine.pluginManager.shouldAllowRequest(url)) {
LOG.w(TAG, "URL blocked by whitelist: " + url);
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
CordovaResourceApi resourceApi = parentEngine.resourceApi;
Uri origUri = Uri.parse(url);
// Allow plugins to intercept WebView requests.
Uri remappedUri = resourceApi.remapUri(origUri);
if (!origUri.equals(remappedUri)) {
OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
}
// If we don't need to special-case the request, let the browser load it.
return null;
} catch (IOException e) {
if (!(e instanceof FileNotFoundException)) {
LOG.e(TAG, "Error occurred while loading a file (returning a 404).", e);
}
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
}
示例5: shouldInterceptRequest
import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public AmazonWebResourceResponse shouldInterceptRequest(AmazonWebView view, String url) {
try {
// Check the against the whitelist and lock out access to the WebView directory
// Changing this will cause problems for your application
if (isUrlHarmful(url)) {
LOG.w(TAG, "URL blocked by whitelist: " + url);
// Results in a 404.
return new AmazonWebResourceResponse("text/plain", "UTF-8", null);
}
CordovaResourceApi resourceApi = appView.getResourceApi();
Uri origUri = Uri.parse(url);
// Allow plugins to intercept AmazonWebView requests.
Uri remappedUri = resourceApi.remapUri(origUri);
if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
return new AmazonWebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
}
// If we don't need to special-case the request, let the browser load it.
return null;
} catch (IOException e) {
if (!(e instanceof FileNotFoundException)) {
LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
}
// Results in a 404.
return new AmazonWebResourceResponse("text/plain", "UTF-8", null);
}
}
示例6: shouldInterceptLoadRequest
import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
try {
// Check the against the white-list.
if ((url.startsWith("http:") || url.startsWith("https:")) && !appView.getWhitelist().isUrlWhiteListed(url)) {
LOG.w(TAG, "URL blocked by whitelist: " + url);
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
CordovaResourceApi resourceApi = appView.getResourceApi();
Uri origUri = Uri.parse(url);
// Allow plugins to intercept WebView requests.
Uri remappedUri = resourceApi.remapUri(origUri);
if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
}
// If we don't need to special-case the request, let the browser load it.
return null;
} catch (IOException e) {
if (!(e instanceof FileNotFoundException)) {
LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
}
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
}
示例7: shouldInterceptLoadRequest
import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
try {
// Check the against the white-list.
if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) {
LOG.w(TAG, "URL blocked by whitelist: " + url);
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
CordovaResourceApi resourceApi = appView.getResourceApi();
Uri origUri = Uri.parse(url);
// Allow plugins to intercept WebView requests.
Uri remappedUri = resourceApi.remapUri(origUri);
if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
}
// If we don't need to special-case the request, let the browser load it.
return null;
} catch (IOException e) {
if (!(e instanceof FileNotFoundException)) {
LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
}
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
}
示例8: shouldInterceptRequest
import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
try {
// Check the against the white-list.
if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) {
LOG.w(TAG, "URL blocked by whitelist: " + url);
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
CordovaResourceApi resourceApi = appView.getResourceApi();
Uri origUri = Uri.parse(url);
// Allow plugins to intercept WebView requests.
Uri remappedUri = resourceApi.remapUri(origUri);
if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
}
// If we don't need to special-case the request, let the browser load it.
return null;
} catch (IOException e) {
if (!(e instanceof FileNotFoundException)) {
LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
}
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
}
示例9: shouldInterceptRequest
import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
try {
// Check the against the white-list.
if ((url.startsWith("http:") || url.startsWith("https:")) && !Config.isUrlWhiteListed(url)) {
LOG.w(TAG, "URL blocked by whitelist: " + url);
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
CordovaResourceApi resourceApi = appView.getResourceApi();
Uri origUri = Uri.parse(url);
// Allow plugins to intercept WebView requests.
Uri remappedUri = resourceApi.remapUri(origUri);
if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri)) {
OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
}
// If we don't need to special-case the request, let the browser load it.
return null;
} catch (IOException e) {
if (!(e instanceof FileNotFoundException)) {
LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
}
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
}
示例10: shouldInterceptLoadRequest
import org.apache.cordova.CordovaResourceApi.OpenForReadResult; //导入依赖的package包/类
@Override
public WebResourceResponse shouldInterceptLoadRequest(XWalkView view, String url) {
try {
// Check the against the whitelist and lock out access to the WebView directory
// Changing this will cause problems for your application
if (isUrlHarmful(url)) {
LOG.w(TAG, "URL blocked by whitelist: " + url);
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
CordovaResourceApi resourceApi = appView.getResourceApi();
Uri origUri = Uri.parse(url);
// Allow plugins to intercept WebView requests.
Uri remappedUri = resourceApi.remapUri(origUri);
if (!origUri.equals(remappedUri) || needsSpecialsInAssetUrlFix(origUri) || needsKitKatContentUrlFix(origUri)) {
OpenForReadResult result = resourceApi.openForRead(remappedUri, true);
return new WebResourceResponse(result.mimeType, "UTF-8", result.inputStream);
}
// If we don't need to special-case the request, let the browser load it.
return null;
} catch (IOException e) {
if (!(e instanceof FileNotFoundException)) {
LOG.e("IceCreamCordovaWebViewClient", "Error occurred while loading a file (returning a 404).", e);
}
// Results in a 404.
return new WebResourceResponse("text/plain", "UTF-8", null);
}
}