Problem getting the Content HTMLEditorKit
I have to make a Swing Rich Text Editor. For Bullets and Numbering I have written a sample code which is working fine.
I am pasting the code below.
publicclass OrderedActionextends HTMLEditorKit.InsertHTMLTextAction
{
private Tag baseTag;
private Field field;//This is a subclass of JTextPane
public OrderedAction(String sLabel, Field afield, HTML.Tag listType)
{
super(sLabel,"", listType, HTML.Tag.OL);
baseTag= listType;
field = afield;
}
publicvoid actionPerformed(ActionEvent ae){
try{
// System.out.println("Inside OrderedAction");
String sListType ="OL" ;
HTMLDocument htmlDoc = (HTMLDocument)(field.getDocument());
int iStart = field.getSelectionStart();
int iEnd= field.getSelectionEnd();
// HtmlTextAction textAction = new HtmlTextAction("URL");
HtmlTextAction tAction =new HtmlTextAction("URL");
Element e = tAction.findElementMatchedTag(htmlDoc, iStart, HTML.Tag.OL);
if(e ==null){
String selText = field.getText(iStart, iEnd - iStart);
// System.out.println(selText);
StringBuffer sbNew =new StringBuffer();
String sToken = ((selText.indexOf("\r") > -1) ?"\r" :"\n");
StringTokenizer stTokenizer =new StringTokenizer(selText, sToken);
sbNew.append("<" + sListType +">");
while(stTokenizer.hasMoreTokens())
{
sbNew.append("<li>");
sbNew.append(stTokenizer.nextToken());
sbNew.append("</li>");
}
sbNew.append("</" + sListType +">");
htmlDoc.remove(iStart, iEnd - iStart);
insertHTML(field, htmlDoc, iStart, sbNew.toString(), 1, 1,null);
}else{
// TagRemovalParserCallback callback = new TagRemovalParserCallback(htmlDoc.getReader(iStart));
String selText = field.getText(iStart, iEnd - iStart);
htmlDoc.remove(iStart, iEnd + 1 - iStart);
htmlDoc.insertString(iStart,selText,null);
// this.insertHTML(field, htmlDoc, iStart, selText, 1, 1, null);
}
}catch(BadLocationException ex){
ex.printStackTrace();
}
}
class HtmlTextActionextends HTMLEditorKit.HTMLTextAction{
public HtmlTextAction(String s){
super(s);
}
public Element findElementMatchedTag(HTMLDocument htmlDoc,int i, HTML.Tag tag){
return this.findElementMatchingTag(htmlDoc, i, tag);
}
publicvoid actionPerformed(ActionEvent ae){
}
}
}
This particular code is working fine. But now I want to get the content of the html document including the html tags. How can I get the end tag of sayOL? From the Element object I am not getting the enclosing OL tag. Any help will be appreciated.

