HTMLEditorKit

As far as I know JEditorPane uses HTMLEditorKit for parsing and redering HTML. Does anybody know if sun is going to continue to upgrade the rendering and parsing elements of this package to conform to newer HTML specifications? Also, does anybody know if there are any third parties that have produced similar packages? I've made a simple web browser with Java that is meant to be a kiosk-mode browser (ie it is restricted in the websites it can visit), and I've noticed that some HTML elements either do not render or render incorrectly with HTMLEditorKit.

make that rendering html

Similar Messages

  • How to set the physical font in JEditorPane with HTMLEditorKit

    I am now creating a swing application which use JEditorKit to make a HMTL editor by the following code:
    JEditorPane editor = new JEditorPane();
    HTMLEditorKit kit = new HTMLEditorKit();
    HTMLDocument doc = new HTMLDocument();
    editor.setEditorKit(kit);
    editor.setDocument(doc);
    editor.setContentType("text/html; charset="+sEncoding);
    editor.getDocument();
    u can see that the encoding of the html file is generated dynamically. At the same time, I also hope that the font is also set dynamically. Moreover, I don't want the font to be installed on each platform, so I am using the following code:
    FileInputStream fis = new FileInputStream("Cyberbit.ttf");
    Font font = Font.createFont(Font.TRUETYPE_FONT, fis);
    Therefore, I can use this font in the Java application. However, how can I make the html file can use this font also? How can I make the HTML file to use this font in the JVM? thx!
    Stephen

    However, how can I make the html file can use this font also? How can I make the HTML file to use this font in the JVM? thx!This is my exact problem!
    Hope you would have got the solution , could you give me some sugesstion..pls?

  • How to embed image in html when using JTextPane, HTMLEditorKit, JavaMail

    I am developing a specialized e-mail client that has to be able to send e-mail messages (in html format with images and attachments) that can be read by standard e-mail clients, and receive similar messages from standard e-mail clients.
    I have everything working except for embedding images.
    Images are to appear in the document mixed in with the text, but that's not what I mean by "embed". By "embed" I mean that the image itself is encoded within the html.
    Here's a bit of code to set the context.
    JTextPane bodyPane = new JTextPane();
    bodyPane.setEditorKit(htmlEditorKit);
    bodyPane.setTransferHandler(new DropHandler());
    bodyPane.setDocument(new HTMLDocument());
    In the DropHandler I have the following:
    HTMLDocument htmlDoc = (HTMLDocument) bodyPane.getDocument();
    HTMLEditorKit htmlKit = (HTMLEditorKit) bodyPane.getEditorKit();
    int caretPos = bodyPane.getCaretPosition();
    At this point get "filename", the full path to an image file that has been dropped onto bodyPane.
    String htmlString = "<img src=\"file:///" + filename.replace("\\","/") + "\">";
    htmlKit.insertHTML(htmlDoc, caretPos, htmlString, 0, 0, HTML.Tag.IMG);
    This works just fine. The image is displayed in the document at the point of insertion.
    However, the image itself is an external file. I need to send an e-mail with this image and could send the image file as an attachment, but I obviously can't assume that the recipient of the email is going to save the attachment into the proper location.
    What is the best way to do this?
    There is a technique for embedding the actual image in the html, using this syntax:
    String htmlString = "<a href=\"data:image/png;base64,---mimed png image here--\" alt=\"Red dot\"></a>";
    I can't get this to work in JTextPane, so perhaps it's not supported. Also, there may be limitations on the size of an image. And apparently Internet Explorer doesn't support this.
    From what I read, using a "content identifier", that is, "cid:" and adding the image as another part of the e-mail message is probably the thing to do. I haven't taken the time to explore this yet.
    Does JTextPane support cid? Is that a nonsense question? I suspect what I need to do when the message is being composed is use absolute paths to local files with the images, and then when assembling the e-mail, attach the files and rewrite the html to build in the cid linkage. Similarly, when reading a message with cid's, the thing to do is save the body parts as files and rewrite the cid to point to the actual file.
    I have seen others ask similar questions, one as recently as last December, and the reply was to refer to a Sun tutorial. But that tutorial doesn't address the full problem of 1) inserting an image into a document (instead of attaching an image to a component) and 2) sending it as an e-mail message.
    I have yet to see an example that shows the complete package.
    Am I right that the data option I mentioned is not going to work?
    Am I right that cid is the best approach, and do I understand how to use it?
    Is there something else?
    Thanks
    John

    Hi Rocky,
    Are you using the DC?
    if yes then you need to put the image inside the component folder. after that close the application
    & reopen. You will get the image.
    In case this does not work then try refreshing the portal through server side. Once the cache is cleared, it will be up to view.
    Also check the Activity list you have created. It should be added to the dtr properly or else it wont be reflected once reimported the configurations.
    Regards
    Chander Kararia

  • Force word wrap in JTextPane (using HTMLEditorKit)

    Hi!
    I have a JTextPane on a JScrollPane inside a JPanel. My text pane is using HTMLEditorKit.
    I set the scrolling policies of my JScrollPane to: JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED & JScrollPane.HORIZONTAL_SCROLLBAR_NEVER.
    I did not find in JTextPane�s API any relevant property I can control word-wrapping with (similar to JTextArea�s setLineWrap) and I have tried a few things to force word-wrapping but nothing worked...
    What happens is my text is NOT being wrapped (even though there is no horizontal scrolling) and typed characters (it is an enabled editable text componenet) are being added to the same long line�
    I�d like to force word-wrapping (always) using the vertical scroll bar whenever the texts extends for more then one (wrapped) line.
    Any ideas?
    Thanks!!
    Message was edited by:
    io1

    Your suggestion of using the example only holds if it fits the requirements of the featureDid your questions state anywhere what your requirement was?
    You first questions said you had a problem, so I gave you a solution
    You next posting stated what your where currently doing, but it didn't say it was a requirement to do it that way. So again I suggested you change your code to match the working example.
    Finally on your third posting you state you have some server related issues causing the requirement which I did not know about in my first two postings.
    State your problem and special requirments up front so we don't waste time quessing.
    I've used code like this and it wraps fine:
    JTextPane textPane = new JTextPane();
    textPane.setContentType( "text/html" );
    HTMLEditorKit editorKit = (HTMLEditorKit)textPane.getEditorKit();
    HTMLDocument doc = (HTMLDocument)textPane.getDocument();
    textPane.setText( "<html><body>some long text ...</body></html>" );
    JScrollPane scrollPane = new JScrollPane( textPane );If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • JEdtiorPane/HTMLEditorKit word wrapping problems

    Hi,
    I have a JFrame component that has a splitPane, on the left side is a JTree and the right side has a JEditorPane that has it's content updated with HTML using a method to generate the HTML via the setText() method . (no url, and no html file)
    The searching I did indicates that word wrapping is the default behavior, and I saw a lot of posts from people trying to get rid of the word wrapping, but it isn't wrapping at all for me. I get the horizontal scroll bar.
    I had the same problem using a JTextPane...anyone know how to wrap text?
    here's the relevant code:
    descriptionPanel = new JPanel(new BorderLayout());
              descriptionEditorPane = new JEditorPane();
              HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
              descriptionEditorPane.setEditorKit(htmlEditorKit);
              descriptionEditorPane.setSize(new Dimension(610,800));
              descriptionEditorPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              descriptionPanel.add(descriptionEditorPane);

    Did you place the components into scroll panes and then put those into the split pane?
    If so, then I guess that calling setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) on the editor pane's scroll pane might solve your problem.

  • HTMLEditorKit.Parser.parse() method is not giving a proper HTMLDocument alw

    Hi,
    I am developing util program for HTML filter, for my project. I have find using HTMLDocument we can do that.
    But when I created I found few starnge things.
    HTMLEditorKit.Parser.parse() method is not giving a proper HTMLDocument always. the below application will show the HTML one if you comment the String str ="" ; and uncomment the next line.
    I am wondering why this happens.
    import java.io.StringReader;
    import java.io.StringWriter;
    import javax.swing.text.html.HTMLDocument;
    import javax.swing.text.html.HTMLEditorKit;
    import javax.swing.text.html.HTMLWriter;
    import javax.swing.text.html.parser.ParserDelegator;
    public class HTMLDocExample {
    public static void main(String args[]) throws Exception {
    System.out.println("start the parsing");
    String data = "dsfdssfsdf<A HREF='http://yahoo.com'>HTMLEditorKit.Parser</A><h1>dsfdsf</h1><table border='1' class='test'><tr><td><input type='text'>dfsf</input><select id='id1' name='name1'><option>fff</option><option>aaaaa</option></select><input type='text'/><a href=#></a></td></tr></table>";
    String str ="" ;
    //String str ="<TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE>" ;
    StringReader br = new StringReader(data + str );
    HTMLEditorKit htmlKit = new HTMLEditorKit();
    HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
    HTMLEditorKit.Parser parser = new ParserDelegator();
    HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0);
    parser.parse(br, callback, true);
    StringWriter writer = new StringWriter();
    HTMLWriter hWriter = new HTMLWriter(writer, htmlDoc);
    hWriter.write();
    String outPut = writer.toString();
    System.out.println(outPut);
    System.exit(0);
    }

    import java.io.StringReader;
    import java.io.StringWriter;
    import javax.swing.text.html.HTMLDocument;
    import javax.swing.text.html.HTMLEditorKit;
    import javax.swing.text.html.HTMLWriter;
    import javax.swing.text.html.parser.ParserDelegator;
    public class HTMLDocExample {
      public static void main(String args[]) throws Exception {
        System.out.println("start the parsing"); 
        String data = "dsfdssfsdf<A HREF='http://yahoo.com'>HTMLEditorKit.Parser</A><h1>dsfdsf</h1><table border='1' class='test'><tr><td><input type='text'>dfsf</input><select id='id1' name='name1'><option>fff</option><option>aaaaa</option></select><input type='text'/><a href=#></a></td></tr></table>";
        //String str ="" ;
        String str ="<TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE><TABLE >test</TABLE>" ;
        StringReader br = new StringReader(data + str );   
        HTMLEditorKit htmlKit = new HTMLEditorKit();
        HTMLDocument htmlDoc = (HTMLDocument) htmlKit.createDefaultDocument();
        HTMLEditorKit.Parser parser = new ParserDelegator();
        HTMLEditorKit.ParserCallback callback = htmlDoc.getReader(0);
        parser.parse(br, callback, true);
        StringWriter writer = new StringWriter();
        HTMLWriter hWriter = new HTMLWriter(writer, htmlDoc);
        hWriter.write();
        String outPut = writer.toString();       
        System.out.println(outPut);
        System.exit(0);
    }

  • Same Image every time in JTextField with HTMLEditorKit and HTMLDocument

    Hi all
    I have a JTextPane with HTMLEditorKit as editorkit and HTMLDocument as document. I am trying to load an html file into the text pane. the html file contains image. When loading first time it is shown perfectly. After I change the image file with other file with the same name(overwrite it) and trying to load the html file again,the image is the first time loaded image. As i think the image is kept somewhere in "cash" or kind of that. But I need to refresh the html every time it is loaded and not to read from "cash".
    And code which i use:
    package client.temp;
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.text.BadLocationException;
    import javax.swing.text.html.HTMLDocument;
    import javax.swing.text.html.HTMLEditorKit;
    public class TestPanel extends JPanel {
    public TestPanel(File htmlFile) {
    JTextPane textPane = new JTextPane();
    JScrollPane scrollPane = new JScrollPane();
    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
    HTMLDocument htmlDocument = new HTMLDocument();
    setLayout(new BorderLayout());
    scrollPane.getViewport().add(textPane, null);
    add(scrollPane, BorderLayout.CENTER);
    URL baseUrl = null;
    try {
    baseUrl = htmlFile.getParentFile().toURL();
    } catch (MalformedURLException e) {
    e.printStackTrace();
    htmlDocument.setBase(baseUrl);
    textPane.setEditorKit(htmlEditorKit);
    try {
    FileInputStream fi = new FileInputStream(htmlFile);
    InputStreamReader isr = new InputStreamReader(fi, "UTF8");
    BufferedReader r = new BufferedReader(isr);
    htmlEditorKit.read(r, htmlDocument, 0);
    r.close();
    isr.close();
    fi.close();
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } catch (BadLocationException e) {
    e.printStackTrace();
    textPane.setDocument(htmlDocument);
    public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JButton b = new JButton();
    b.setText("push");
    b.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    TestPanel panel = new TestPanel(new File("c:\\temp\\temp.html"));
    JFrame fShow = new JFrame();
    fShow.getContentPane().setLayout(new BorderLayout());
    fShow.getContentPane().add(panel, BorderLayout.CENTER);
    fShow.setSize(800, 600);
    fShow.setVisible(true);
    frame.getContentPane().add(b);
    frame.pack();
    frame.setVisible(true);
    and here is the html file structure of my temp.html file
    <html>
    <body>
    <p>
    <img src='image01.jpg'>
    </p>
    </body>
    </html>
    the folder in which the temp.html located (in my case c:\\temp\\) contains image01.jpg file too.
    The piece above works correctly when clicking on the button first time.i.e. shows the image01.jpg correctly. After closing the showing frame fShow(not exiting application) and replacement of the image01.jpg by other file named image01.jpg, but with other content and clicking button again shows the first image again.If I exit the application and start again the picture is shown correctly.
    I need this because I am getting images from database while the template is same always.
    Thanks in advance.

    URL baseUrl = null;
    try {
    baseUrl = htmlFile.getParentFile().toURL();
    } catch (MalformedURLException e) {
    e.printStackTrace();
    htmlDocument.setBase(baseUrl);All you want is to defeat the cache. You could do it using random number generation.
    String newURL = htmlFile.getParentFile().toURL().toString();
    String rand = "rand="+new java.utl.Random().nextLong();
    if ( newURL.indexOf("?")>=0)
    newURL +="&"+rand;
    else
    newURL +="?"+rand;
    baseURL = new URL(newURL);
    htmlDocument.setBase(baseURL);
    This will ensure that u are using different url everytime.(well mostly!)

  • HTMLEditorKit, Custom Tags and CSS???

    I have an editor that will allow the user to insert merge fields. The document is in HTML and the editor supports basic document styling (bold, italics, etc).
    For the merge fields I would like to use either a custom tag or a generic tag like span. Unfortunately, HTMLEditorKit only supports HTML 3.2 (which does not contain the span tag). How can I create a custom tag called "merge"?
    Once I've created my custom tag, will the Cascading Style Sheet support in Java allow something like "merge {color: red}"?
    Any help of suggestions would be greatly appreciated!
    -- John

    Hi John,
    I'm trying to do the same thing (an editor for document containing merge fields...)
    For your first problem, I used the var tag which is not very used but exists in HTML 3.2 !
    And yes: HTMLDocument support CSS
    Since June, I think you've finded a solution
    If you success in creating a custom tag, please explain to me how do you make...
    my e-mail is [email protected]
    Thanks
    Luc

  • Htmleditorkit memory leak

    We are using the HtmlEditorKit class to parse documents in a Java program using Java version 1.4.1_02. While the class seems to work correctly, we eventually run out of memory when processing large numbers of documents. The problem seems to worsen when we process big documents. We had the same problem with Java version 1.4.0_03. In our class constructor we have the following code:
    // create the HTML document
    kit = new HTMLEditorKit();
    doc = kit.createDefaultDocument();
    Inside our processing loop we do the following:
    if (doc.getLength() > 0 ) {
    doc.remove(0, doc.getLength());
    // Create a reader on the HTML content.
    Reader rd = getReader(inFilePath);
    // Parse the HTML. -- Here is a memory leak
    kit.read(rd, doc, 0);
    // Close a reader
    rd.close();
    Any help will be much appreciated.
    Michael Sperling
    516-998-4803

    Hi,
    if you process HTML files in a loop I assume you do not want to actually show them on the screen. It seems as if you rather do something with the HTML file such as reading the HTML code and change it / store it / transform it as you go in batch type of manner on multiple files.
    If the above is true I would not recommend to use HTMLEditorKit.read at all because this will not only parse HTML, it will also build a HTMLDocument with respective element structure each time. This in turn is only necessary for showing the HTML file in a text component and to work on the document interactively.
    Depending on the actual purpose of your processing loop, you might want to simply parse the HTML file using class HTMLEditorKit.ParserCallback. By creating a subclass if HTMLEditorKit.ParserCallback you can implement / customize the way you would like to process HTML files.
    The customized subclass of HTMLEditorKit.ParserCallback then can be used by calling
    new ParserDelegator().parse(new FileReader(srcFileName), MyParserCallback, true);
    HTH
    Ulrich

  • FW: Caret Location Right Justified for LI when using HTMLEditorKit

    It appears that when using the HTMLEditorKit and inserting any sort of list
    item (ordered list or unordered list) into a view (while in edit mode), the
    caret is initially *---------| right justified with respect to the bullet
    image. If the identical html is loaded all at once however the caret is *-|
    left justified with respect to the bullet image. Is this a bug in
    HTMLEditorKit?

    Sure it is. In this special case IBM's JDK does a better job (at least under Linux).
    Generally I'm totally disappointed by the whole HTML package. I've been trying to implement a really primitive WYSIWIG-HTML-editor which understands <p>, <ul>, <h1> <b>, <i> and <a href>. It is a nightmare!
    - Dynamically modifying the document's structure (e.g., by making a <li> out of a <p>) works more or less, but you have absolutely no control over caret movement, and different JDK's make it differently!
    - The HTMLDocument inserts crude "extra-tags" (e.g., those <p-implied>'s. You never know exactly the structure of your document, and after a long debugging session you notice that the HTMLDocument was bluntly inserting yet another artificial element you did not specify. No docs at all what's going on.
    - It is nearly unbelievable how complicated so simple things like
    are internally modelled.
    - Frankly spoken: The whole document model sucks. Has to be harmonized with XML, DOM, JDOM, and all those nice new technologies where Java does a good job (unless you need a GUI...)
    If anybody has an idea to make it properly -> pls let me know
    thx
    Karl

  • Problem with HTMLEditorKit

    Hi,
    I want to display following html in JEditotKit.
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>ExploreCollbarativeNetworks</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    INPUT.fancyButton
    font-family: Verdana, Arial,Georgia;
    border-right: #000000 1px solid;
    border-top: #000000 1px solid;
    font-weight: bold;
    font-size: 11px;
    border-left: #000000 1px solid;
    cursor: hand;
    color: black;
    border-bottom: #000000 1px solid;
    height: 20px;
    background-color: #F3F9FF;
    <!--
    body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    .style1 {
    color: #FF7830;
    font-weight: bold;
    -->
    </style>
    <link rel="stylesheet" href="style.css" type="text/css">
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function openfile()
    document.execCommand("Open",null,"index.htm")
    function Saveasfile()
    document.execCommand("SaveAs",null,"index.htm")
    function showques()
    tot=0;
    for(i=0;i<document.form1.c.length;i++)
    if(document.form1.c.checked==true)
    tot=tot+1
    if(tot==1)
    //alert("sssssssss")
    ob=document.getElementById('table1')
    ob1=document.getElementById('p1')
    ob.style.display="block"
    ob1.style.display="none"
    document.form1.next.disabled=true
    if(tot==2)
    ob=document.getElementById('table1')
    ob1=document.getElementById('p1')
    ob.style.display="block"
    ob1.style.display="none"
    document.form1.next.disabled=false
    //alert(tot)
    function showques1()
    ob=document.getElementById('table1')
    ob1=document.getElementById('table2')
    ob.style.display="none"
    ob1.style.display="block"
    document.form1.previous1.disabled=false
    function showques2()
    ob=document.getElementById('table1')
    ob1=document.getElementById('table2')
    ob.style.display="block"
    ob1.style.display="none"
    document.form1.previous.disabled=false
    //-->
    </SCRIPT>
    <style type="text/css">
    <!--
    .style2 {font-size: 2pt}
    .style13 {color: #000000}
    .style15 {font-size: 12px}
    .style16 {font-size: 12px; color: #000000; }
    .style17 {color: #CCCCCC}
    .style19 {color: #F1F4F8}
    .style22 {color: #FFFFFF}
    -->
    </style>
    </head>
    <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
    <form name="form1" method="post" action="">
    <table width="975" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td>
    <TABLE border="0" cellspacing="0" cellpadding="0" width="975" align="center">
    <TR>
    <TD width="100%" >
    <TABLE width="975" border="0" align="center" cellpadding="0" cellspacing="0">
    <TR>
    <TD >
    <table width="750%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td>
    </td>
    </tr>
    <tr>
    <td>
    <table width="750" border="0" cellspacing="1" cellpadding="1" align="left" bgcolor="#FFFFFF" bordercolor="#CCCCCC">
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr>
    <td colspan="2"><img src="images/forum.gif" width="94" height="31"></td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr bgcolor="#DDEEFF" valign="middle">
    <td width="6%" height="20" align="center"><b> <img src="images/plusbottom1.gif" width="11" height="11" align="absmiddle" id="img" border="0"></b></td>
    <td width="94%" align="left" bgcolor="#DDEEFF">
    <b> <span class="bgcolor2">Please name your
    GM partnership? </span></b></td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr>
    <td colspan="2">
    <div style="display:none" id="d1">
    <table width="734" border="0" id="t1" style="display:none" align="right">
    <tr>
    <td width="10 px" valign="top" height="20" bgcolor="#EBEBEB" >
    <div align="center"><strong>Q.1</strong></div>
    </td>
    <td width="724" bgcolor="#EBEBEB" align="left" >
    <div align="justify"><b class="bgcolor1">Please
    name your GM partnership? </b> </div>
    </td>
    </tr>
    <tr>
    <td width="10 px" valign="top" height="20" align="center" ><b>Ans</b></td>
    <td width="724" align="left" >fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf </td>
    </tr>
    <tr>
    <td width="10 px" valign="top" height="20" bgcolor="#EBEBEB" >
    <div align="center"><strong>Q.2</strong></div>
    </td>
    <td width="724" bgcolor="#EBEBEB" align="left" >
    <b>What is you role on the partnership?
    </b> </td>
    </tr>
    <tr>
    <td width="10 px" valign="top" height="20" align="center" ><b>Ans</b></td>
    <td width="724" align="left" >fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf </td>
    </tr>
    </table>
    </div>
    </td>
    </tr>
    <tr bgcolor="#DDEEFF">
    <td width="6%" bgcolor="#DDEEFF" height="20" align="center"><b > <img src="images/plusbottom1.gif" width="11" height="11" align="absmiddle" id="img1" border="0"></b></td>
    <td width="94%" align="left"> <b> <span class="bgcolor2">Please
    name your GM partnership? </span></b></td>
    </tr>
    <tr>
    <td colspan="2"></td>
    </tr>
    <tr>
    <td colspan="2">
    <div style="display:none" id="d2">
    <table width="734" border="0" style="display:none" id="t2" align="right">
    <tr bgcolor="#EBEBEB" align="left">
    <td width="10 px" valign="top" height="20" >
    <div align="center"><strong>Q.1</strong></div>
    </td>
    <td width="724" bgcolor="#EBEBEB" align="left" >
    <div align="justify"><b>Please name your
    GM partnership? </b> </div>
    </td>
    </tr>
    <tr>
    <td width="10 px" valign="top" height="20" align="center" ><b>Ans</b></td>
    <td width="724" align="left" >fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf </td>
    </tr>
    <tr bgcolor="#EBEBEB" align="left">
    <td width="10 px" valign="top" height="20" >
    <div align="center"><strong>Q.2</strong></div>
    </td>
    <td width="724" align="left" >
    <div align="justify"><b>What is you role
    on the partnership? </b>
    </div>
    </td>
    </tr>
    <tr>
    <td width="10 px" valign="top" height="20" align="center" ><b>Ans</b></td>
    <td width="724" align="left" >fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf fgdhsgfjhdsgfjhsdgfhd
    dsfgdsf sdgfsdjf sdgfsdjhf sdfgsdjf dsfgdjsf
    sdhjfgdsjf dsfgdsjf sdfgsdjf sdfgsdjhf
    dsfgdjshf dsfgdsjhf dsfgdsjf </td>
    </tr>
    <tr>
    <td width="10 px"> </td>
    <td height="94%" width="724" align="left"> </td>
    </tr>
    </table>
    </div>
    </td>
    </tr>
    <tr>
    <td colspan="2"> </td>
    </tr>
    <tr>
    <td colspan="2"> </td>
    </tr>
    <tr>
    <td colspan="2"> </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    </table>
    </TD>
    </TR>
    </TABLE>
    </TD>
    </TR>
    </TABLE>
    </td>
    </tr>
    </table>
    </form>
    <script>
    function show()
    obj=document.getElementById("img")
    obj1=document.getElementById("d1")
    obj2=document.getElementById("t1")
    obj3=document.getElementById("img1")
    obj4=document.getElementById("d2")
    obj5=document.getElementById("t2")
    check=false
    if(obj1.style.display=="none")
    obj.src="images/minusbottom1.gif"
    obj1.style.display="block"
    obj2.style.display="block"
    obj3.src="images/plusbottom1.gif"
    obj4.style.display="none"
    obj5.style.display="none"
    check=true
    if(!check)
    obj.src="images/plusbottom1.gif"
    obj1.style.display="none"
    //alert(obj2.src)
    function show1()
    obj=document.getElementById("img")
    obj1=document.getElementById("d1")
    obj2=document.getElementById("t1")
    obj3=document.getElementById("img1")
    obj4=document.getElementById("d2")
    obj5=document.getElementById("t2")
    check=false
    if(obj4.style.display=="none")
    obj.src="images/plusbottom1.gif"
    obj1.style.display="none"
    obj2.style.display="none"
    obj3.src="images/minusbottom1.gif"
    obj4.style.display="block"
    obj5.style.display="block"
    check=true
    if(!check)
    obj3.src="images/plusbottom1.gif"
    obj4.style.display="none"
    </script>
    </body>
    </html>
    It is generated by our web designer, I am not knowing anything abt html. When i tried to display it in JEditor kit, it is not displayed properly.
    JEditorPane jPane = new javax.swing.JEditorPane();
    jPane.setDocument(getHTMLDocument());
    My getHTMLDocument() is as under :
    public HTMLDocument getHTMLDocument()
    HTMLDocument m_oHTMLMessageDoc = new HTMLDocument();
    HTMLEditorKit m_oHTMLEditor = new HTMLEditorKit();
    InputStreamReader in = null;
    m_oHTMLMessageDoc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
    try {
    in = new InputStreamReader(new FileInputStream("d:\\help.html"));
    m_oHTMLEditor.read(in, m_oHTMLMessageDoc, 0);
    catch (IOException ex) {
    ex.printStackTrace();
    catch (BadLocationException ex) {
    ex.printStackTrace();
    return m_oHTMLMessageDoc;
    It is displaying javascript functions as text.
    Can anybody please help me to display this html file.
    Thanks in advance,
    Dimple

    Answered in your other posting.

  • HTMLEditorKit renders tables width attribute wrong inside paragraph

    I noticed that the following html
    <html>
    <body>
    <p>
    <table width="100%" border="1">
    <tr>
    <td>
    something
    </td>
    </tr>
    </table>
    </p>
    </body>
    </html>
    .. doesn't 'stretch' the tables width to 100% when using JTextPane and HTMLEditorKit - it's only a few chars wide. Mozilla, Explorer and other browsers display the table right. If I remove the <p> then it works as expected.
    Is there a workaround for this behavior.. it sure would be nice to have it display the table like the 'standard' browsers do.

    I noticed that the following html
    <html>
    <body>
    <p>
    <table width="100%" border="1">
    <tr>
    <td>
    something
    </td>
    </tr>
    </table>
    </p>
    </body>
    </html>
    .. doesn't 'stretch' the tables width to 100% when using JTextPane and HTMLEditorKit - it's only a few chars wide. Mozilla, Explorer and other browsers display the table right. If I remove the <p> then it works as expected.
    Is there a workaround for this behavior.. it sure would be nice to have it display the table like the 'standard' browsers do.

  • Does HTMLEditorKit's object support include support for applets?

    Hello,
    I have a Swing application containing a JEditorPane used to display some HTML pages. I would like to embed a Java applet in one of the pages, but have had no success getting it to load.
    Is it possible to load an applet within an HTML document displayed by JEditorPane/HTMLEditorKit? From http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/text/html/HTMLEditorKit.html:
    "The <applet> tag is not supported, but some support is provided for the <object> tag."
    What does "some support" mean exactly? (I'm using JDK 1.5)
    The applet I've written loads successfully in Firefox using the following code:
    <applet code=cprgraph.CPRGraphApplet width="557" height="319"></applet>as well as
    <object codetype="application/java" classid="java:cprgraph/CPRGraphApplet.class" width=557 height=319>
    </object>The applet is in the package cprgraph, and located in a directory cprgraph which is in my CLASSPATH.
    If HTMLEditorKit can't load applets, is there an alternative that can? Or any other way to embed a JComponent in an HTML document displayed by a Java application?
    Thanks,
    Ben

    Use Java SE 6.0 beta or wait untill it is released in Fall 2006

  • Parsing HTML into DOM using HTMLEditorKit

    I am trying to parse an HTML file using javax.swing.text.html.HTMLEditorKit. My limitations are that I cannot install new libraries like jtidy and I must use a .jsp file, not a servlet. I'm able to get the url and parse it using ParserCallBack, but the new handleText method will not write to the page. Further more I cannot pass anything out of this method to use later because it is void. I want to get some data back from this method or at least do something useful within it. Is that possible?
         java.net.URL url = new java.net.URL("http://" + request.getServerName() + "/" + urls.get(i));
         java.io.InputStream is = url.openStream();
         java.io.InputStreamReader isr = new java.io.InputStreamReader(is);
         java.io.BufferedReader br = new java.io.BufferedReader(isr);
       javax.swing.text.html.HTMLEditorKit.ParserCallback callback =
          new javax.swing.text.html.HTMLEditorKit.ParserCallback () {
            public void handleText(char[] data, int pos) {
                out.println(data);
        new javax.swing.text.html.parser.ParserDelegator().parse(br, callback, false);Attempting to print from within this method gives this error:
    Attempt to use a non-final variable out from a different method. From enclosing blocks, only final local variables are available.
    Maybe I need to try and write the output xml file all from inside the parserCallback?

    Those are rather stupid requirements. Okay, I can see the one about not using external libraries because nobody knows how to deal with the licences. But making you use a JSP instead of a servlet just gets in the way of writing the Java code which you could probably do perfectly well if you didn't have to cram it into a JSP scriptlet. Stupid.
    But anyway: the error message says you need a final local variable. So don't just sit there, give it a final local variable. I forget just what type "out" is supposed to be, but something like "final JSPWriter fakeOut = out", followed by using "fakeOut" rather than "out" should work.

  • Replacing HTML tags using HTMLEditorKit etc.

    Hi
    Not sure if this is the best place to ask this. I've searched without finding much.
    Basically I am trying to create a HTML template system for output. User's can change the templates to change the program output.
    The templates are basic HTML with custom tags inserted, that reside in a templates directory. For example, a simple template might be:
    <html><body>
    <table width="100%"><tr><td width="25%">Here is the output:</td>
    <td> <insertOutputHere> </td>
    </tr></table>
    </body></html>
    ^^ Users would be able to edit these template .htm files to affect the output .htm files. For instance, changing where the <insertOutputHere> tag is, or formatting the table it is output to.
    I am using the Swing HTMLDocument, HTMLWriter, HTMLEditorKit classes to load and parse the .htm files, iterate the tags and replace any custom tags (defined in code) with the program output. I have been able to locate these custom tags no problem, but I don't know how to replace this tag entirely with my output (Which will be formatted HTML string). I have been trying to use the insertBefore, insertAfter methods with limited success. In particular I have an 'include' custom tag which includes other files by recursion - it works except the <include> tag is not removed, and depending on which insert method I use, it usually goes into an infinite loop of parsing the <include> tag WITHOUT removing it, then picking it up again when its done.
    Basically I'm looking for any advice as to how to go about COMPLETELY REPLACING these tags with a well structured HTML string. I can post some code if need be but I barely comprehend what I've done, LOL.
    TIA

    I've looked over my mess of comments :)
    setOuterHTML is what I was previously using and it was quite unpredictable at times, as far as I could tell it is very strict with it's requirements for structured HTML (EG no floating line breaks, everything must be "paragraph-ised" which b0rks up the layout) and I can't rely on anyone using/extending these classes to write well structured HTML.
    I remember the problems being quite odd, such as the output for one custom tag being displayed twice for some and not at all for others, and while it isn't critical data, it was still displayed in a way that it could be interpreted as correct - I just knew it wasn't.
    So I dropped setOuterHTML to try insertAfterEnd - this leaves the tags in there and, like roughly explained above, it would pick up tags infinitely because they were not being replaced.
    Here is a relevant method to give a better idea of what I've done:
           public HTMLDocument parseHTMLfile(String filename, Custom_HTML_Tag tags[]) {
          //create a document
             HTMLDocument doc = (HTMLDocument)kit.createDefaultDocument();
             fileDepth++;
             try {
             //read in the file
                BufferedReader rd = new BufferedReader(new FileReader(filename));
                kit.read(rd, doc, 0);
                if (tags != null) {
                //replace tags with page content
                   ElementIterator it = new ElementIterator(doc);
                   Element e;
                   while ((e = it.next()) != null) {
                   //look for includes
                      if (e.getName().equals("include")) {
                         if (fileDepth >= 5){
                         //WARNING:
                            System.out.println("fileDepth has reached 5, include may be recursive. aborting.");
                            continue;
                         String href = (String)e.getAttributes().getAttribute(HTML.Attribute.HREF);
                      //grab parent of current file (IE the folder in which it sits)
                         File f = new File(filename);
                         String include = f.getParent() + sep + href;
                         f = new File(include);
                         if (f.exists()) {
                            HTMLDocument htmld = parseHTMLfile(include, tags);
                            StringWriter sw = new StringWriter();
                            HTMLWriter w = new HTMLWriter(sw, htmld);
                            w.write();
                            doc.setOuterHTML(e, sw.toString());
                         else {
                         //couldnt find include file - warning
                      for (int i=0; i < tags.length; i++) {
                         if (e.getName().equals(tags.getName())) {
    //doc.setOuterHTML(e, tags[i].getText());
    doc.insertAfterEnd(e, tags[i].getText());
    //System.out.println("found tag: " + tags[i].getName() + ": " + tags[i].getText());
    catch (BadLocationException ble) {// cant happen?
    System.err.println("ERROR (" + 999 + "): Could not parse document " + filename + "; BadLocationException");
    System.err.println(ble);
    catch (FileNotFoundException fnf) {
    System.err.println("ERROR (" + 999 + "): Could not parse document " + filename + "; File not found");
    //System.err.println(fnf);
    catch (IOException ioe) {
    System.err.println("ERROR (" + 999 + "): Could not parse document " + filename + "; I/O Error:");
    System.err.println(ioe);
    fileDepth--;
    return doc;
    setInnerHTML kills it with the 'Can not set inner HTML of a leaf' error
    Thanks

  • Parsing HTML using Swing's HTMLEditorKit

    Hi all,
    I posted this question on the "Java programming", but I think I posted on the wrong forum. So, please let me know if I have posted on the wrong forum, again.
    Anyway, I have read an article on parsing HTML using the Swing HTML Parser (http://java.sun.com/products/jfc/tsc/articles/bookmarks/index.html). However, I find that the HTMLEditorKit is unable to understand the <Meta> tag under the <Head> tag? Is this true? I am getting an error message:
    javax.swing.text.ChangedCharSetException
    at javax.swing.text.html.parser.DocumentParser.handleEmptyTag(DocumentParser.java:172)
    at javax.swing.text.html.parser.Parser.startTag(Parser.java:327)
    at javax.swing.text.html.parser.Parser.parseTag(Parser.java:1786)
    at javax.swing.text.html.parser.Parser.parseContent(Parser.java:1821)
    at javax.swing.text.html.parser.Parser.parse(Parser.java:1980)
    at javax.swing.text.html.parser.DocumentParser.parse(DocumentParser.java:109)
    at javax.swing.text.html.parser.ParserDelegator.parse(ParserDelegator.java:74)
    at URLReader.main(URLReader.java:58)
    Below is a simple code to write out the html file it reads in:
    public static void main(String[] args) throws Exception {
    HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback () {
    public void handleText(char[] data, int pos) {
    try {
    System.out.println(data);
    } catch (Exception e) {
    System.out.println("IOE: " + e);
    Reader reader = new FileReader("myFile.html");
    new ParserDelegator().parse(reader, callback, false);
    The html file that is having a problem reading in is:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>NWS WSR-88D Radar System Transmit/Receive Status</title>
    </head>
    <p>A <foo>xx</foo>link</html>
    If I take away <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">, there is no problem.
    Any suggestions? Thanks in advance.

    Hi,
    Setting the third argument really works!!! Yee..... haa....!!!
    WORKING SOLUTION: new ParserDelegator().parse(reader, callback, TRUE);
    MANY... MANY THANKS for looking at the problem!!!
    Send third argument in parse method as true.

Maybe you are looking for