BUG: DhText Gets Interpreted as HTML Code

ID: Q194899


The information in this article applies to:
  • Microsoft Visual J++, version 6.0


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 this to be a bug in the Microsoft products listed at the beginning of this article.


MORE INFORMATION

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

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

} 

Steps to Reproduce Behavior

  1. In Visual J++, select New Project from the File menu.


  2. In the New Project dialog box, click the New tab.


  3. In the Visual J++ Projects tree, click Web Pages.


  4. Click Code-Behind HTML.


  5. Click Open to create the project.


  6. 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();
       }
    } 


  7. Modify Page1.html as follows:
    
    <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> 


  8. Run the project.


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 "<B>BOLD</B><HR><U>UNDERLINE</U>&lt;TAG&gt;"


REFERENCES

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: November 16, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.