Skip to main content

How do I get JEditorPane to display ?

11 replies [Last post]
viravan
Offline
Joined: 2003-06-23

JEditorPane will correctly display &# followed by a unicode character expressed in decimal, but it will not interpret and display &# followed by a unicode character expressed in hexadecimal. For example:

</p>
<p>Character(decimal)DecimalCharacter(hex)HexEntityName<br />
?8352?20A0�EURO-CURRENCY SIGN � (see 8364 for euro)<br />
?8353?20A1�COLON SIGN<br />
?8354?20A2�CRUZEIRO SIGN<br />
?8355?20A3�FRENCH FRANC SIGN � (present in WGL4)<br />
?8356?20A4�LIRA SIGN � (present in WGL4) � [pound sign is � (£)]<br />
?8357?20A5�MILL SIGN<br />
?8358?20A6�NAIRA SIGN<br />
?8359?20A7�PESETA SIGN � (present in WGL4)<br />
?8360?20A8�RUPEE SIGN<br />
?8361?20A9�WON SIGN<br />
?8362?20AA�NEW SHEQEL SIGN<br />
?8363?20AB�DONG SIGN<br />
?8364?20AC€EURO SIGN � (present in WGL4, ANSI and MacRoman, and in Symbol font)<br />
?8365?20AD�KIP SIGN<br />
?8366?20AE�TUGRIK SIGN<br />
?8367?20AF�DRACHMA SIGN<br />
?8368?20B0�GERMAN PENNY SYMBOL<br />
?8369?20B1�PESO SIGN</p>
<p>

Is there a quick fix (e.g., by overriding the parser) or is this fixed in tiger?

;o)

V.V.

PS: also see link shown below:

http://forum.java.sun.com/thread.jsp?forum=57&thread=365564&start=15&ran...

The problem at the link shown below was fixed by manually changing the hex notation to a decimal notation when the html file is created by yours truly. Unfortunately, if the file comes from the web, I cannot edit it without first reading it in, look for the presence of the hex notation, convert it, and use the setText method to display the page!

Message was edited by: viravan

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
shan-man
Offline
Joined: 2006-02-17

Hi V. V.

viravan wrote:
> Hi Shannon:
>
> >It is marked as fixed for "dragon", or 1.5.1.
>
> Does that mean 1.5.0 beta is about ready to be
> released?
>

This means that the fix didn't meet criteria for tiger at this stage.

Unfortunately, I can't comment on release dates :(

Regards,
Shannon

smohler@yahoo.com
Offline
Joined: 2006-02-17

Nashat,

What are the legal implications regarding your recommendation to "copy the Parser code"? Is it acceptable for a commercial or not-for-profit company to do this in order to work around bugs like this, or even to enhance the capabilities of this package?

Kind Regards,

-- Sherman

quietclack
Offline
Joined: 2006-02-17

Hello,

I was wondering if anyone knew a workaround for viewing html on the Mac. I am building a multi-platform program in Java and while my html

tags are showing up on the PC in JEditorPane, when I run the program on the Mac, the html tables do not show up in JEditorPane.

The html tables exist, since they show up on PC and Mac in regular browsers. Is there a magic switch for the Mac to display tables or another kind of browser component which acts like JEditorPane (reads hyperlinks, etc.)?

I would appreciate any help or suggestions regarding this matter.

Thanks,

quietclack

nashat
Offline
Joined: 2008-03-19

Unfortunately this bug is still not fixed. I suppose there is no simple way to fix it by overriding Parser
method since most methods are private or package private. You should at least copy the Parser code and fix this bug in parseEntityReference() private method.
Could you also please file a bug on this ?
Thank you.
Anton.

viravan
Offline
Joined: 2003-06-23

>Unfortunately this bug is still not fixed.
>...You should at least copy the Parser code and fix this bug in parseEntityReference() private method.

Hmmm..., I'll give it a shot but life would be a great deal easier if the html package is made a bit more open so that simple fixes can be done and tested by the developers.

>Could you also please file a bug on this ?

Ok, I have filed a bug report on this (the report has been assigned an internal review ID of: 229270).

I am wondering if I should also file a bug report on OOM problem noted at the link shown below:

http://www.javadesktop.org/forums/thread.jspa?threadID=849&tstart=0

Thanks,

V.V.

Message was edited by: viravan

viravan
Offline
Joined: 2003-06-23

FWIW, a workaround is posted at the link shown below:

http://forum.java.sun.com/thread.jsp?forum=57&thread=471215

;o)

V.V.

nashat
Offline
Joined: 2008-03-19

Thank you for filing the bug! Though I've also filed it and already fixed :) The bug ID is 4964339.
The workaround you mentioned is really simple and I think it makes sense ;)

viravan
Offline
Joined: 2003-06-23

>Thank you for filing the bug! Though I've also filed it and already fixed The bug ID is 4964339.

With the new look of the JDC Forums, the ability to search the bug database seems to have disappeared so I can't really see what the bug's disposition is -- I assume the fix will be in the newer release of the j2sdk.

I am wondering if you can take a look at the problem described in the link shown below and let me know if I should file a bug report on it:

http://www.javadesktop.org/forums/thread.jspa?threadID=849&tstart=0

Thanks,

V.V.

shan-man
Offline
Joined: 2006-02-17

Hi viravan,

viravan wrote:
> With the new look of the JDC Forums, the ability to
> search the bug database seems to have disappeared so
> I can't really see what the bug's disposition is -- I
> assume the fix will be in the newer release of the
> j2sdk.

You can still search the bug database here:
http://developer.java.sun.com/developer/bugParade/index.jshtml

However, this particular bug isn't showing up in search results yet. Perhaps it still needs to be indexed. Here's a direct link to the report:
http://developer.java.sun.com/developer/bugParade/bugs/4964339.html

It is marked as fixed for "dragon", or 1.5.1.

Regards,
Shannon

viravan
Offline
Joined: 2003-06-23

Hi Shannon:

>It is marked as fixed for "dragon", or 1.5.1.

Does that mean 1.5.0 beta is about ready to be released?

V.V.

viravan
Offline
Joined: 2003-06-23

Just an update to the original question:

The workaround shown below apparently only work if the hex notation is a single character (e.g., ƒ ) but the scheme breaks down as soon as the hex notation is followed by a valid hex character (e.g., ƒ12,345.67). This is because the [b]parseEntityReference[/b] method gobbled up the [b];[/b] character before the [b]handleText[/b] method is called (the ƒ12,345.67 string of characters is passed as [b]𙈒,345.67[/b])...

Unless somehow I can gain access to the unadulterated string (just wondering if the [b]pos[/b] argument in handleText call is good for anything?), I guess I'll have to wait until [b]tiger[/b] is released...

[code]
public class myHTMLEditorKit extends HTMLEditorKit {
public Document createDefaultDocument() {
StyleSheet styles = getStyleSheet();
StyleSheet ss = new StyleSheet();
ss.addStyleSheet(styles);
HTMLDocument doc = new myHTMLDocument(ss);
doc.setParser(getParser());
doc.setAsynchronousLoadPriority(4);
doc.setTokenThreshold(100);
return doc;
}
}

public class myHTMLDocument extends HTMLDocument {
static final String hex="0123456789ABCDEFabcdef";
public myHTMLDocument(StyleSheet styles) {
super(styles);
}

public HTMLEditorKit.ParserCallback getReader(int pos) {
Object desc = getProperty(Document.StreamDescriptionProperty);
if (desc instanceof URL) setBase((URL) desc);
HTMLReader reader = new myHTMLReader(pos);
return reader;
}

public class myHTMLReader extends HTMLReader {
public myHTMLReader(int offset) {
super(offset,0,0,null);
}

public void handleText(char[] data, int pos) {
if (data.length>3) {
if (data[0]=='&') {
if (data[1]=='#') {
if (data[2]=='x') {
int n=0,j;
for (int i=3;i j=hex.indexOf(""+data[i]);
if (j<0) {
super.handleText(data,pos);
return;
}
if (j>15) j-=6;
n=(n*16)+j;
}
char newdata[]= {
(char) n
};
super.handleText(newdata,pos);
return;
}
}
}
}
super.handleText(data,pos);
}
}
}
[/code]

V.V.