使用小程序描述符和 JavaScript 在 jnlp 中投票小程序下载进度
我有一个使用deployJava 脚本部署的WebStart 小程序。 jnlp 文件如下所示:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="" href="launch.jnlp" spec="1.0+">
<information>
<title>someApp</title>
<vendor>someCompany</vendor>
<homepage href="http://www.someCompanysWebsite.net"/>
<description>someDescription</description>
<description kind="short">someShortDescription</description>
<offline-allowed/>
</information>
<update check="background"/>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.5+"/>
<jar href="mainJar.jar" main="true"/>
<jar href="lib1.jar"/>
<jar href="lib2.jar"/>
<jar href="lib3.jar"/>
<jar href="platform.jar"/>
<jar href="plugin.jar"/>
<jar href="slf4j-api-1.6.1.jar"/>
<jar href="slf4j-simple-1.6.1.jar"/>
</resources>
<applet-desc height="1" main-class="com.companyName.applet.appletClass" name="appletName" width="1">
</applet-desc>
</jnlp>
如您所见,我的小程序大小为 1x1,因此我不想用它显示任何内容。它只是用于向 javascript 公开一些 java 方法。因此,如果我进行 javascript 调用,例如
//javascript code
var applet = document.getElementById('appletName');
,我会获得小程序的有效句柄,并且我能够在 javascript 中调用其方法,如下所示:
//javascript code
applet.doStuff();
当然,每个小程序都定义了 isActive() 方法,因此在我的 javascript 代码中我可以这样检查小程序是否已完全加载:
//javascript code
function isFullyLoaded()
{
if ( !applet.isActive() ){
setTimeout('isFullyLoaded()',1000);
}
else
{
//do nice stuff requiring the applet is loaded
}
}
但是,由于小程序的加载可能需要一段时间,我希望有一个加载进度指示。快速浏览一下 Sun(或 Oracle,如果您愿意的话)会显示以下内容: http://download.oracle.com/javase/tutorial/deployment/applet /customProgressIndicatorForApplet.html
但是,这意味着我想在小程序加载时显示加载栏或任何内容。我不喜欢小程序的外观,这就是为什么我只想用 javascript 轮询小程序加载,就像在某个时间间隔内那样:
//javascript code
alert(applet.getLoadingProgress());
我应该做什么以及应该更改 jnlp 声明或类似的内容。任何指示或评论将不胜感激。请注意,我不需要自定义进度条,而只是一个结构,以便我可以在加载期间使用 javascript 轮询进度。
干杯。
编辑: @阿莫尔 我将提请您注意,JNLP 部署了小程序和应用程序,在加载期间,每当发生以下情况时,都会调用通用 DownloadServiceListener 类的方法 Progress(java.net.URL url, java.lang.String version, long readSoFar, long Total, intoverallPercent)下载所需的 jar 包。了解 jar 的总数和尚未下载的 jar 的数量将作为完美的进度指示器。我还想提请您注意,如果您调试 JNLP 部署,您将看到这些方法被调用并记录为网络级事件。所以,我的问题是如何使用 javascript 掌握这些方法,以便我可以对进度进行一些估计,因为我不希望用户查看 java 控制台来估计进度。我不想还显示不确定的进度加载器,因为实现它很容易,但没有任何实际用途。
I have a WebStart applet that I deploy using the deployJava script. The jnlp file looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jnlp codebase="" href="launch.jnlp" spec="1.0+">
<information>
<title>someApp</title>
<vendor>someCompany</vendor>
<homepage href="http://www.someCompanysWebsite.net"/>
<description>someDescription</description>
<description kind="short">someShortDescription</description>
<offline-allowed/>
</information>
<update check="background"/>
<security>
<all-permissions/>
</security>
<resources>
<j2se version="1.5+"/>
<jar href="mainJar.jar" main="true"/>
<jar href="lib1.jar"/>
<jar href="lib2.jar"/>
<jar href="lib3.jar"/>
<jar href="platform.jar"/>
<jar href="plugin.jar"/>
<jar href="slf4j-api-1.6.1.jar"/>
<jar href="slf4j-simple-1.6.1.jar"/>
</resources>
<applet-desc height="1" main-class="com.companyName.applet.appletClass" name="appletName" width="1">
</applet-desc>
</jnlp>
As you can see, my applet is 1x1 in size, so I don't want to display anything with it. It just serves to expose some java methods to javascript. So, if I make a javascript call, for example
//javascript code
var applet = document.getElementById('appletName');
I get a valid handle to the applet and I am able to call its methods in javascript like this:
//javascript code
applet.doStuff();
Of course, every applet has the isActive() method defined, so in my javascript code I can check like this if the applet is fully loaded:
//javascript code
function isFullyLoaded()
{
if ( !applet.isActive() ){
setTimeout('isFullyLoaded()',1000);
}
else
{
//do nice stuff requiring the applet is loaded
}
}
However, as the loading of the applet might take a while, I would like to have a progress indication of its loading. A quick look at Sun (or Oracle, if you are so inclined) shows this:
http://download.oracle.com/javase/tutorial/deployment/applet/customProgressIndicatorForApplet.html
However, this implies that I want to show a loading bar or anything when the applet loads. I dislike applet appearance and that is why I just want to poll applet loading with javascript, like that on some interval:
//javascript code
alert(applet.getLoadingProgress());
What should I do and should I change jnlp declaration or anything like that. Any pointers or comments would be appreciated. Note that I don't want a custom progress bar, but just a structure so that I can poll progress with javascript during loading.
Cheers.
Edit:
@amol
I will bring to your attention that JNLP deployed applets and application, during their loading, call a generic DownloadServiceListener class's method progress(java.net.URL url, java.lang.String version, long readSoFar, long total, int overallPercent) whenever one of the jars required is downloaded. Knowing the total numbers of jars and the number of jars yet to be downloaded will serve as a perfect progress indicatior. I want also to bring to your attention that if you debug the JNLP deployment, you will see these methods being called and logging as network level events. So, my question is how to get a hang of these methods using javascript so i can have some estimate about progress as I don't want the user to look at java console to estimate progress. I don't want to also show an indeterminate progress loader, as it is a breeze to implement that, but no practical use whatsoever.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定如何轮询,但是我过去用来实现您所描述的内容的方法如下 -
我通常在中插入相关的html
单击按钮时的 DOM 或
某事),显示你的
javascript/html 特定加载
指标。
JavaScript 方法。 JS 现在知道小程序已完全加载,取下加载指示器并进行任何进一步的 JS-> 小程序通信等。
(使用这种方法不可能显示确定的进度条。但是有一个通用的加载指示器,它掩盖了整个 html 主体或不确定的进度条都是非常有可能的,并且实现起来很容易)
I am not sure how to poll as such, but the approach I have used in the past to achieve what you are describing is as follows -
I usually insert relevant html in the
DOM on click of a button or
something), display your
javascript/html specific loading
indicator.
javascript method. JS now knows that the applet is fully loaded, takes down the loading indicator and does any further JS->applet communication, etc.
(Display a determinate progress bar is not possible using this approach. But a a generic loading indicator that masks over the entire html body or an indeterminate progress bar is very much possible and breeze to implement)
在您发布的 Oracle 站点的文档中 (http://download. oracle.com/javase/tutorial/deployment/applet/customProgressIndicatorForApplet.html),小程序调用下面的函数来指示其进度,然后更新小程序 UI 并相应的进度条。
我相信,您可以简单地用对 Javascript 函数的调用来替换对 updateProgressUI(overallPercent) 的调用,该函数会更新网页中的进度指示器。
对此进行测试并让我们知道是否可行。
In the documentation from the Oracle site which you posted (http://download.oracle.com/javase/tutorial/deployment/applet/customProgressIndicatorForApplet.html), the applet calls the function below to indicate its progress, which then updates the Applet UI and the progress bar accordingly.
I believe, you can simply, replace the call to
updateProgressUI(overallPercent)
, with some call to a Javascript function which updates a progress indicator in the web page.Test this and let us know if it is possible.
使用 “图像”属性。
Change it using the 'image' attribute.