代码名称一个WebBrowser从FileSystemStorage加载HTML [英] Codename One WebBrowser loading HTML from FileSystemStorage

查看:147
本文介绍了代码名称一个WebBrowser从FileSystemStorage加载HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个代号为1的应用程序,用于查看离线报告,这些报告以HTML格式显示,资源包含在单独的文件夹中。该应用程序下载HTML并复制资源的文件夹结构,因为它们是在HTML中引用的。当我用普通浏览器打开报告并将其指向/.cn1文件夹时,它会正确加载并显示。在使用模拟器时,HTML被加载到Codename One Web浏览器对象中并显示出来(我可以看到报告的标题),这只是Web浏览器没有加载任何资源。我也将基本URL设置为该文件夹。

  WebBrowser wbBrowser =(WebBrowser)findByName(WebBrowser,f); 
FileSystemStorage fs = FileSystemStorage.getInstance();
wbBrowser.setPage(getTextFromFile(fs.getAppHomePath()+/Reports/Report_2.html),fs.getAppHomePath()+/ Reports / Report_2_files_files);

这是我目前使用的代码。在报表查看器窗体显示后运行。我已经在Android Lollipop中的默认浏览器和Mozilla Firefox Android应用程序中打开了报告,并且它显示了包含所有图像和CSS的网页,因此我不确定它是否是代码名称一个安全问题。任何想法将不胜感激。编辑:我试图简化应用程序,我只是运行下面的代码;

  WebBrowser wbBrowser =(WebBrowser)findByName(WebBrowser,Display.getInstance()。getCurrent()); 
FileSystemStorage fs = FileSystemStorage.getInstance();
fs.mkdir(fs.getAppHomePath()+[Folder Name]);
Util.downloadUrlToFile(http:// [IpAddress] /mobile/admin/Report_2.html,fs.getAppHomePath()+[文件夹名称] /Report_2.html,true); (fs.getAppHomePath()+[Folder Name] /Report_2.html)== true){
wbBrowser.setURL(fs.getAppHomePath()+
if(FileSystemStorage.getInstance [文件夹名称] /Report_2.html);
Dialog.show(Success,文件已被下载并显示为+ wbBrowser.getTitle(),Ok,);
}
else {
Dialog.show(Failiure,文件尚未下载,确定,);
}

在Android棒棒糖设备上运行时,尽管没有,但仍显示成功对话框在设备上运行搜索时发现它们(我不知道一个存储文件的代码名在哪里存储)。没有其他代码在设备上的任何地方运行,但当我将HTML文档自己存储在设备上并使用硬编码引用(即 / Storage / emulated / 0 / Android / data / Report_2)时,我获得了成功。 HTML )。 wbBrowser.getTitle()在设备上运行时为空/。尽管当这行代码在其他地方时,它变成了:页面。 Report_2.html的HTML是;

 <!DOCTYPE html> 
< html>
< head>
< title>测试页< /标题>
< / head>
< body>
< h1> Hello World< / h1>
< / body>
< / html>


解决方案

几天之后,我意识到 setURL()需要格式为 file://路径名的路径,我使用 /路径名,它在 setURL()上无效,但在 setPage()我从文件中读取HTML。这是一个用户错误。


I am developing an app in Codename one for viewing of reports offline which come in a HTML format with resources contained in a separate folder. The application downloads the HTML and copies the folder structure of the resources as they are reference in the HTML. When I open the Report with a normal browser and point it to the "/.cn1" folder it loads and displays correctly. When using the simulator, HTML is loaded into the Codename One Web Browser object and is displayed (I can see the title of the report), it's just that the Web Browser is not loading any of the resources. I have also set the Base URL to the folder.

    WebBrowser wbBrowser = (WebBrowser) findByName("WebBrowser",  f);
    FileSystemStorage fs = FileSystemStorage.getInstance();
    wbBrowser.setPage(getTextFromFile(fs.getAppHomePath() + "/Reports/Report_2.html"), fs.getAppHomePath() + "/Reports/Report_2_files_files");

This is the code I am currently using. which runs after the Report Viewer form is shown. I have opened the report on the Default browser and Mozilla Firefox Android app in Android Lollipop and it displays the webpage correctly with all images and CSS included so I'm not sure if it is a codename one security issue. Any Ideas would be greatly appreciated.

EDIT : I have tried to simplify the app and am just running the below code;

        WebBrowser wbBrowser = (WebBrowser) findByName("WebBrowser", Display.getInstance().getCurrent());
        FileSystemStorage fs = FileSystemStorage.getInstance();
        fs.mkdir(fs.getAppHomePath() + "[Folder Name]");
        Util.downloadUrlToFile("http://[IpAddress]/mobile/admin/Report_2.html", fs.getAppHomePath() + "[Folder Name]/Report_2.html", true);
        if (FileSystemStorage.getInstance().exists(fs.getAppHomePath() + "[Folder Name]/Report_2.html") == true) {
            wbBrowser.setURL(fs.getAppHomePath() + "[Folder Name]/Report_2.html");
            Dialog.show("Success", "File has been downloaded and shown as " + wbBrowser.getTitle(), "Ok", "");
        } 
        else {
            Dialog.show("Failiure", "File has not been downloaded", "Ok", "");
        }

When run on an Android Lollipop device, the success dialog is displayed despite me not finding them when running a search on the device (I don't know where codename one stores files are stored). No other code is running anywhere on the device but I have had success when the storing the HTML document myself on the device and using a hardcoded reference (i.e /Storage/emulated/0/Android/data/Report_2.html). wbBrowser.getTitle() is null/"" when ran on the device. although when this line of code was somewhere else it became about:page. The HTML of Report_2.html is;

<!DOCTYPE html>
<html>
<head>
    <title>Test Page</title>
</head>
<body>
    <h1>Hello World</h1>
</body>
</html>

解决方案

After a few days, I realised that setURL() requires a path in the format of file://pathname, I was using /pathname, which didn't work on setURL() but did on setPage() when I read the HTML from the file. This was a User Error.

这篇关于代码名称一个WebBrowser从FileSystemStorage加载HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆