Microsoft KB Archive/194899

= BUG: DhText Gets Interpreted as HTML Code =

Article ID: 194899

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Visual J++ 6.0 Standard Edition

-



This article was previously published under Q194899



SYMPTOMS
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.



RESOLUTION
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.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
The DhText element currently creates a  tag, followed by your literal text, followed by a closing  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: X+YC. This will incorrectly result in "X + Y C."

To see if any translation is occurring, you can create a DhText object, obtain the peer class, and inspect the Inner HTML results. The following method demonstrates one possible implementation of checking for translation of the original message: boolean noTranslation {

String content="&>"; 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);

}

Steps to Reproduce Behavior
 In Visual J++, select New Project from the File menu. In the New Project dialog box, click the New tab. In the Visual J++ Projects tree, click Web Pages.</li> Click Code-Behind HTML.</li> Click Open to create the project.</li>  Modify Class1.java as follows: 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; } }                       </li>  Modify Page1.html as follows: <HTML> <BODY> <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>

</BODY> </HTML> </li> Run the project.</li></ol>

You will get the following Web page:

Bold text saying "BOLD"

A horizontal line

Underlined text saying "UNDERLINE"

Text saying "<TAG>"

Expect result is as follows:

Text saying "BOLD<HR><U>UNDERLINE</U>&lt;TAG&gt;"

<div class="references_section">