What protocols are allowed in hrefs in Swing's HTMLEditorKit class?

John O

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.

hqcasanova

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!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What protocols are allowed in hrefs in Swing's HTMLEditorKit class?

From Dev

what's the supported sip encryption protocols by Asterisk?

From Dev

What are the allowed types for an enum (class)?

From Dev

Append all hrefs in class with hash

From Dev

Swing HTMLEditorKit / JEditorPane doesn't handle <br> and empty lines correctly

From Dev

What are the allowed Modes in Dynamics AX TextIO Class?

From Dev

What's the difference between SFTP, SCP and FISH protocols?

From Dev

What's the maximum number of repetitions allowed in vbscript

From Dev

What are ports and protocols really?

From Dev

What are the rules for implicit adjustment of hrefs in Polymer elements?

From Dev

Class-internal Protocols in Swift

From Dev

Class-Only Protocols in Swift

From Java

Why the URL class does not support setting username for protocols other than http(s)?

From Dev

What is the point in having protocols if they are not checked?

From Dev

What are the "protocols" on my Brother printer?

From Dev

What are the 'chrome:' and 'resource:' protocols in Firefox?

From Dev

CUPS printing protocols: what's the difference between RAW/JetDirect - IPP - IPP14 - LPD?

From Dev

What's the maximum number of repetitions allowed in a Python regex?

From Dev

What is the maximum number of categoryBitMask's allowed in Sprite Kit?

From Dev

What's allowed to do with NF in an awk code block or function?

From Dev

Restrict Javascript modification of particular objects' hrefs / find out WHAT is modifying the hrefs

From Dev

What's the difference between the 2 ways of showing window in Swing?

From Dev

Java Swing - What's the proper way of doing a stage based GUI?

From Dev

Experiences with Scala swing, how does it add to what's already available in Java swing? Are there any challenges?

From Dev

Subclassing v.s. Protocols

From Dev

Friend function in-class definition only allowed in non-local class definitions. What does it mean?

From Dev

Friend function in-class definition only allowed in non-local class definitions. What does it mean?

From Dev

What's the class equivalent of instancesRespondToSelector?

From Dev

How to get hrefs from from elements with a certain class through CasperJS?

Related Related

  1. 1

    What protocols are allowed in hrefs in Swing's HTMLEditorKit class?

  2. 2

    what's the supported sip encryption protocols by Asterisk?

  3. 3

    What are the allowed types for an enum (class)?

  4. 4

    Append all hrefs in class with hash

  5. 5

    Swing HTMLEditorKit / JEditorPane doesn't handle <br> and empty lines correctly

  6. 6

    What are the allowed Modes in Dynamics AX TextIO Class?

  7. 7

    What's the difference between SFTP, SCP and FISH protocols?

  8. 8

    What's the maximum number of repetitions allowed in vbscript

  9. 9

    What are ports and protocols really?

  10. 10

    What are the rules for implicit adjustment of hrefs in Polymer elements?

  11. 11

    Class-internal Protocols in Swift

  12. 12

    Class-Only Protocols in Swift

  13. 13

    Why the URL class does not support setting username for protocols other than http(s)?

  14. 14

    What is the point in having protocols if they are not checked?

  15. 15

    What are the "protocols" on my Brother printer?

  16. 16

    What are the 'chrome:' and 'resource:' protocols in Firefox?

  17. 17

    CUPS printing protocols: what's the difference between RAW/JetDirect - IPP - IPP14 - LPD?

  18. 18

    What's the maximum number of repetitions allowed in a Python regex?

  19. 19

    What is the maximum number of categoryBitMask's allowed in Sprite Kit?

  20. 20

    What's allowed to do with NF in an awk code block or function?

  21. 21

    Restrict Javascript modification of particular objects' hrefs / find out WHAT is modifying the hrefs

  22. 22

    What's the difference between the 2 ways of showing window in Swing?

  23. 23

    Java Swing - What's the proper way of doing a stage based GUI?

  24. 24

    Experiences with Scala swing, how does it add to what's already available in Java swing? Are there any challenges?

  25. 25

    Subclassing v.s. Protocols

  26. 26

    Friend function in-class definition only allowed in non-local class definitions. What does it mean?

  27. 27

    Friend function in-class definition only allowed in non-local class definitions. What does it mean?

  28. 28

    What's the class equivalent of instancesRespondToSelector?

  29. 29

    How to get hrefs from from elements with a certain class through CasperJS?

HotTag

Archive