BUG: DhText Gets Interpreted as HTML CodeID: Q194899
|
If the text of a DhText object includes HTML tags, they will be interpreted (and the enclosed text rendered) as HTML and not straight text.
To work around this issue, change the HTML characters to their respective
character references.
WARNING: Once this issue is resolved, the workaround mentioned above will
generate improper code for the following symbols: "<",">", and "&". You
should confirm that the build you are running on doesn't have a fix for
this issue.
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
The DhText element currently creates a <SPAN> tag, followed by your literal text, followed by a closing </SPAN> tag. Your HTML characters are not translated into references, so if DhText contains HTML tags, the characters will be rendered as HTML. For example calling dhText.setText("X + Y < Z. A + B > C."); will generate the following HTML:
<SPAN>X+Y<Z.A+B>C.</SPAN>
This will incorrectly result in "X + Y C."
boolean noTranslation() {
String content="<B>&>";
DhText text=new DhText(content);
text.setVisible(false);
add(text);
com.ms.wfc.html.om.IHTMLElement peer;
peer=(com.ms.wfc.html.om.IHTMLElement)text.getPeer();
String inner=peer.getInnerHTML();
remove(text);
return content.equals(inner);
}
import com.ms.wfc.html.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
public class Class1 extends DhDocument
{
public Class1()
{
initForm();
}
private void initForm()
{
}
protected void onDocumentLoad(Object sender, Event e)
{
DhText text=new DhText();
String message="<B>BOLD</B><HR><U>UNDERLINE</U>&<TAG&>";
// Workaround: Uncomment the next two lines for one possible
// workaround.
// if (noTranslation())
// message=toHTMLViewable(message);
text.setText(message);
add(text);
}
boolean noTranslation() {
String content="<B>&<";
DhText text=new DhText(content);
text.setVisible(false);
add(text);
com.ms.wfc.html.om.IHTMLElement peer;
peer=(com.ms.wfc.html.om.IHTMLElement)text.getPeer();
String inner=peer.getInnerHTML();
remove(text);
return content.equals(inner);
}
static String toHTMLViewable(String text) {
// indexOf() returns -1 if not found:
if (text.indexOf('<')+text.indexOf('>')+text.indexOf('&')==-3)
return text;
StringBuffer buffer=new StringBuffer(text);
int index=0;
String amp="amp;";
String less="<";
String greater=">";
while (buffer.length()>index) {
if (buffer.charAt(index)=='&') {
buffer.insert(index+1,amp);
} else if (buffer.charAt(index)=='<') {
buffer.setCharAt(index,'&');
buffer.insert(index+1,less);
} else if (buffer.charAt(index)=='>') {
buffer.setCharAt(index,'&');
buffer.insert(index+1,greater);
}
index++;
}
return buffer.toString();
}
}
<HTML>
<BODY>
<hr>
<OBJECT classid="java:com.ms.wfc.html.DhModule"
height=0 width=0 ... VIEWASTEXT>
<PARAM NAME=__CODECLASS VALUE=Class1>
<PARAM NAME=CABBASE VALUE=Project1.CAB>
</OBJECT>
<!-- Insert HTML here -->
</BODY>
</HTML>
Bold text saying "BOLD"Expect result is as follows:
A horizontal line
Underlined text saying "UNDERLINE"
Text saying "<TAG>"
Text saying "<B>BOLD</B><HR><U>UNDERLINE</U><TAG>"
For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java,
please see the following pages on the Microsoft Technical Support site:
http://support.microsoft.com/support/visualj/
http://support.microsoft.com/support/java/
© Microsoft Corporation 1998, All Rights Reserved.
Contributions by Derek Jamison, Microsoft Corporation
Additional query words:
Keywords : kbJava kbVJ600bug kbwfchtml kbwfccontrol
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: April 8, 1999