2

我使用一个应用程序(AppWorx!请有人创建这个标签!),它允许以 html 格式输入有关计划作业的文档。

我一直在尝试创建具有如下链接的待命文档:

<a href="tel:+1806xxxxxxx">1 (806) xxx - xxxx</a>

该页面显示在 Java 应用程序本身内部,并且任何指向 http:// 的链接都会在用户的浏览器窗口中打开。但是像上面这样的电话链接会导致弹出一个大错误窗口,显示以下错误:

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 链接也不起作用(这是某种沙盒的东西吗?)。尽管如此,这里没有人以任何其他方式启动应用程序。

4

1 回答 1

1

谁能告诉我这个类的限制是什么?

为了让您了解 EditorKit 类的过时程度,从 Java 7 HTMLEditorKit 开始支持 HTML 3.2 版(带有一些扩展),并且正在向 4.0 版迁移”。毫不奇怪,URL类(负责MalformedURLException您发布的跟踪中的)仅支持基本协议,其中一些您在上面提到:

  • Http
  • Https
  • FTP
  • 文件

谁能告诉我是否存在解决方法?

好吧,你可以用代码弄脏你的手(如果你可以访问它),使用自定义协议处理程序并注册它。幸运的是, J2ME 波兰项目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: &lt;a href=&quot;tel:+441231234567#22&quot;&gt;Call Me&lt;/a&gt;
 * 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;
    }

}

希望有帮助!

于 2013-11-05T22:51:03.550 回答