我使用一个应用程序(AppWorx!有人请创建此标记!),允许以html格式输入有关预定作业的文档。
我一直在努力创建一个带有类似链接的待命文档:
<a href="tel:+1806xxxxxxx">1 (806) xxx - xxxx</a>
该页面显示在Java应用程序本身内,并且在用户的浏览器窗口中打开了http://的任何链接。但是上面的tel链接导致弹出一个大错误窗口,显示以下错误:
java.net.MalformedURLException: For input string: "+1806xxxxxxx"
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at java.net.URL.<init>(Unknown Source)
at com.appworx.client.screen.modmgr.M$2.hyperlinkUpdate(NotesPanel.java:191)
at javax.swing.JEditorPane.fireHyperlinkUpdate(Unknown Source)
at javax.swing.text.html.HTMLEditorKit$LinkController.activateLink(Unknown Source)
at javax.swing.text.html.HTMLEditorKit$LinkController.mouseClicked(Unknown Source)
at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
其他协议也失败(http除外)。如果我有mailto:链接,而不是如上所述得到错误,它会将我带到电子邮件地址的域名部分。
我相信应用程序编译的这个类的任何版本都是几年(也许很多年)。
有谁能告诉我这门课的局限性,或者是否存在变通办法?
Appworx的文档表明,除非从jnlp调用应用程序,否则即使是http链接也无法工作(这是沙箱的事情吗?)。虽然在这方面,没有人在这里以任何其他方式启动应用程序。
答案 0 :(得分:1)
有谁能告诉我这门课的局限性是什么?
为了让您了解EditorKit类的过时性,从Java 7开始HTMLEditorKit“支持HTML 3.2版(带有一些扩展),并且正在向4.0版迁移” 。毫不奇怪,URL类(负责您发布的跟踪中的MalformedURLException
)仅支持基本协议,其中一些是您在上面提到的:
有人能告诉我是否存在变通办法吗?
好吧,你可以轻松搞定代码(如果你有权访问它),使用自定义协议处理程序并注册它。幸运的是,tel
提供的package de.enough.polish.browser.protocols;
import java.io.IOException;
import javax.microedition.io.StreamConnection;
import javax.microedition.midlet.MIDlet;
import de.enough.polish.browser.ProtocolHandler;
/**
* Protocol handler to handle the <code>tel:</code> protocol. This class calls the given phonenumber on MIDP 2.0 phones.
* Example: <a href="tel:+441231234567#22">Call Me</a>
* Note that this handler requires MIDP 2.0 or higher.
* The tel protocol handler allows you to separate the phone number and the dialtone (dtmf) that should be send after
* establishing the phone call using the '#' sign.
*
* This protocol could actually be realized using the ExternalProtocolHandler as well, however in this
* way we can deal post dial tones (DTMF) in a better way - in the HTML code they just need to be
* separated from the phonenumber using a '#'.
*/
public class TelProtocolHandler
extends ProtocolHandler
{
private MIDlet midlet;
/**
* Creates an TellProtocolHandler object using the default "tel" protocol name.
*
* @param midlet the midlet object of the application
*/
public TelProtocolHandler(MIDlet midlet)
{
this( "tel", midlet );
}
/**
* Creates an TelProtocolHandler object using the specified protocol name.
*
* @param protocolName the name of the protocol to handle
* @param midlet the midlet object of the application
*/
public TelProtocolHandler(String protocolName, MIDlet midlet)
{
super( protocolName );
this.midlet = midlet;
}
/* (non-Javadoc)
* @see de.enough.polish.browser.ProtocolHandler#getConnection(java.lang.String)
*/
public StreamConnection getConnection(String url) throws IOException
{
this.midlet.platformRequest( "tel:" + extractMsisdn(url));
return null;
}
/**
* Strips the MSISDN part off an url.
* In contrast to other protocol handlers, the external protocol handler only uses a single colon to
* separate the external protocol from the folllowing protocol, e.g. external:http://www.j2mepolish.org
*
* @param url the url to remove the protocol from
*
* @return the host and part part of the given url
*/
protected String extractMsisdn(String url)
{
String msisdn = url.substring(this.protocolName.length() + 1);
String separator = null;
//#if polish.dtmf.separator:defined
//#= separator = "${polish.dtmf.separator}";
//# if (!separator.equals("#")) {
//# int pos = msisdn.indexOf('#');
//# if (pos != -1) {
//# msisdn = msisdn.substring(0, pos) + separator + msisdn.substring(pos + 1);
//# }
//# }
//#endif
return msisdn;
}
}
协议已经有了一个:
{{1}}
希望有所帮助!