Pregunta

I use an application (AppWorx! Someone please create this tag!) that allows documentation to be entered about scheduled jobs as html.

I've been trying to create on-call documentation that would have a link something like this:

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

The page is displayed inside the Java app itself, and any link to http:// is opened in the user's browser window. But a tel link like above causes a big error window to pop up that shows the following error:

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)

Other protocols fail as well (except http). If I have a mailto: link, instead of getting the error as above, it takes me to the domain portion of the email address.

I believe that whatever version of this class that the app was compiled with is several (and maybe many) years old.

Can anyone tell me what the limitations of this class are, or if workarounds exist?

The documentation for Appworx suggests that even http links will not work unless the app is invoked from the jnlp (is this a sandbox thing somehow?). Though on that note, no one here starts the application any other way.

¿Fue útil?

Solución

Can anyone tell me what the limitations of this class are?

To give you an idea of how outdated the EditorKit classes are, as of Java 7 HTMLEditorKit "supports HTML version 3.2 (with some extensions), and is migrating toward version 4.0". No surprise then that the URL class (responsible for the MalformedURLException in the trace you posted) supports just the basic protocols, some of which you mentioned above:

  • Http
  • Https
  • Ftp
  • File
  • Jar

Can anyone tell me if workarounds exist?

Well, you can get your hands dirty with the code (if you have access to it), use a custom protocol handler and register it. Luckily for you there is one already for the tel protocol courtesy of the J2ME Polish project:

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;
    }

}

Hope that helps!

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top