Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

Problem with HTMLEditorKit

Thread view: 
Plutian - 26 Jan 2004 16:54 GMT
Hi all,

I'm developing an application which can let user to open and modify the HTML
document within the class extended JInternalFrame. But I experienced a
problem when closing the subclass of JInternalFrame. The code for saving the
modificatino of the content is in follow:

 public void internalFrameClosed(InternalFrameEvent e){
   try{
     docReader = new
DocumentReader((HTMLEditorKit)this.editorPane.getEditorKit(),

(HTMLDocument)this.editorPane.getDocument(), path);
     SwingUtilities.invokeLater(docReader);
   }
   catch(Exception ex){
     ex.printStackTrace(System.err);
   }
 }

The implementation of the DocumentReader is:

public class DocumentReader implements Runnable{

 private HTMLEditorKit kit = null;
 private HTMLDocument doc = null;
 private String path = null;
 private Writer writer = null;
 private HTMLWriter htmlWriter = null;

 public DocumentReader(HTMLEditorKit kit, HTMLDocument doc, String path)
throws IOException{
   this.kit = kit;
   this.doc = doc;
   this.path = path;
   this.writer = new FileWriter(new File(this.path));
   this.htmlWriter = new HTMLWriter(this.writer, this.doc);
 }

 public void run(){
   try {
     this.kit.write(this.writer, this.doc, 0, this.doc.getLength());
   }
   catch (Exception e) {
     e.printStackTrace();
   }
 }
}

The DocumentReader is implemented the Runnable interface which take the
EditorKit, Document and the path to which the content save. The error appear
immediately after close the InternalFrame. The error is:

java.lang.NullPointerException
at javax.swing.text.AbstractWriter.write(AbstractWriter.java:489)
at javax.swing.text.html.HTMLWriter.emptyTag(HTMLWriter.java:315)
at javax.swing.text.html.HTMLWriter.write(HTMLWriter.java:187)
at javax.swing.text.html.HTMLEditorKit.write(HTMLEditorKit.java:290)
at
hk.edu.ouhk.ias.marking.essay.controller.DocumentReader.run(DocumentReader.j
ava:29)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.ja
va:197)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java
:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
Christian Kaufhold - 26 Jan 2004 17:45 GMT
> I'm developing an application which can let user to open and modify the HTML
> document within the class extended JInternalFrame. But I experienced a
> problem when closing the subclass of JInternalFrame. The code for saving the
> modificatino of the content is in follow:

How is JInternalFrame relevant to the problem?

>  public DocumentReader(HTMLEditorKit kit, HTMLDocument doc, String path)
> throws IOException{

Use File, not String, for representing filenames.

>    this.kit = kit;
>    this.doc = doc;
>    this.path = path;
>    this.writer = new FileWriter(new File(this.path));
>    this.htmlWriter = new HTMLWriter(this.writer, this.doc);

You are not using HTMLWriter anywhere.

>  }
>
[quoted text clipped - 18 lines]
> at javax.swing.text.html.HTMLEditorKit.write(HTMLEditorKit.java:290)
> at

Please post Java version together with stack trace or the line numbers
are useless.

The problem is that 'null' is passed to AbstractWriter.write(String)
(which fails silently in 1.4.2 - since when?) - just override it to
ignore it?

Somewhat guessing, I would say this happens because the Document has
a title element, but its TitleProperty is 'null'.

Christian
Plutian - 27 Jan 2004 01:48 GMT
> Somewhat guessing, I would say this happens because the Document has
> a title element, but its TitleProperty is 'null'.
>
> Christian

Hi Christian,

Thx a lot, I think your guessing is correct. I viewed the source code
of the HTMLWriter and found that the NullPointerException is occurred
when getting the TitleProperty of the Document. So is it normal? and
the only way is to overwrite the Writer and ignore the null??

Thx,
Plutian
Christian Kaufhold - 27 Jan 2004 12:59 GMT
Hello!

>> Somewhat guessing, I would say this happens because the Document has
>> a title element, but its TitleProperty is 'null'.

> Thx a lot, I think your guessing is correct. I viewed the source code
> of the HTMLWriter and found that the NullPointerException is occurred
> when getting the TitleProperty of the Document. So is it normal? and
> the only way is to overwrite the Writer and ignore the null??

It seems to happen if either
a) the Document contained an empty title element on reading
  (<TITLE>/<TITLE)
b) the Document originally did not contain a title element and it is
  added later without also updating the title property.
c) the title property is unset.

The only way to fix it is to change the writer. (But also the reader not
to produce it that way). It depends on your taste whether the writer
should offically handle this or whether the client of the HTMLDocument
is responsible for not putting it into this state.

Christian
Plutian - 27 Jan 2004 15:35 GMT
Thx a lot!!!!! It's very useful and the problem is solved!!!

"Christian Kaufhold" <usenet@chka.de>
???????:0t40165fdei586bn1f4@simia.chka.de...
> Hello!
>
[quoted text clipped - 19 lines]
>
> Christian
Andrew Thompson - 26 Jan 2004 18:01 GMT
"Plutian" ...

Tips when seeking help..
a) http://www.physci.org/codes/sscce.jsp
b) Ask a question.

--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.