// the following stuff did not work and I don't know why!
private void detectTitle() {
    Document doc = this.contentView.getDocument();
    if (doc instanceof HTMLDocument) {
      HTMLDocument hdoc = (HTMLDocument)doc;
      System.out.println("Document Property:" + hdoc.getProperty(Document.TitleProperty));
      // the following stuff did not work and I don't know why!
      Element element = hdoc.getElement(hdoc.getDefaultRootElement(), StyleConstants.NameAttribute, HTML.Tag.TITLE);
      if (element != null && element.getStartOffset() >= 0) {
        try {
          System.out.println("Element-based NameAttribute search: " + doc.getText(element.getStartOffset(), element.getEndOffset() - element.getStartOffset()));
        } catch (BadLocationException ex) {
          // TODO Auto-generated catch block
          ex.printStackTrace();
        }
      } else {
        System.out.println("Element with NameAttribute TITLE not found: "+element);
      }
      dumpTags(hdoc, HTML.Tag.HEAD);
      dumpTags(hdoc, HTML.Tag.BODY);
      dumpTags(hdoc, HTML.Tag.TITLE);
      dumpTags(hdoc, HTML.Tag.H1);
      HTMLDocument.Iterator iterator = hdoc.getIterator(HTML.Tag.TITLE);
      if (iterator != null && iterator.isValid()) {
        int startOffset = iterator.getStartOffset();
        if (startOffset >= 0) {
          try {
            System.out.println("HTMLDocument.Iterator for tags TITLE: " + doc.getText(startOffset, iterator.getEndOffset() - startOffset));
          } catch (BadLocationException ex) {
            // TODO Auto-generated catch block
            ex.printStackTrace();
          }
        }
      } else {
        System.out.println("No valid iterator for tag TITLE found: "+iterator);
      }
    }
  }
HTMLDocument hdoc = (HTMLDocument)doc;
System.out.println("Document Property:" + hdoc.getProperty(Document.TitleProperty));
// the following stuff did not work and I don't know why!
Element element = hdoc.getElement(hdoc.getDefaultRootElement(), StyleConstants.NameAttribute, HTML.Tag.TITLE);
if (element != null && element.getStartOffset() >= 0) {
private void detectTitle() {
Document doc = this.contentView.getDocument();
if (doc instanceof HTMLDocument) {
HTMLDocument hdoc = (HTMLDocument)doc;
System.out.println("Document Property:" + hdoc.getProperty(Document.TitleProperty));
// the following stuff did not work and I don't know why!
Element element = hdoc.getElement(hdoc.getDefaultRootElement(), StyleConstants.NameAttribute, HTML.Tag.TITLE);
if (element != null && element.getStartOffset() >= 0) {
try {
System.out.println("Element-based NameAttribute search: " + doc.getText(element.getStartOffset(), element.getEndOffset() - element.getStartOffset()));
} catch (BadLocationException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
} else {
System.out.println("Element with NameAttribute TITLE not found: "+element);
private void detectTitle() {
Document doc = this.contentView.getDocument();
if (doc instanceof HTMLDocument) {
HTMLDocument hdoc = (HTMLDocument)doc;
System.out.println("Document Property:" + hdoc.getProperty(Document.TitleProperty));
// the following stuff did not work and I don't know why!
Element element = hdoc.getElement(hdoc.getDefaultRootElement(), StyleConstants.NameAttribute, HTML.Tag.TITLE);
if (element != null && element.getStartOffset() >= 0) {
try {
System.out.println("Element-based NameAttribute search: " + doc.getText(element.getStartOffset(), element.getEndOffset() - element.getStartOffset()));
} catch (BadLocationException ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
}
} else {
System.out.println("Element with NameAttribute TITLE not found: "+element);
}
dumpTags(hdoc, HTML.Tag.HEAD);
dumpTags(hdoc, HTML.Tag.BODY);
dumpTags(hdoc, HTML.Tag.TITLE);
dumpTags(hdoc, HTML.Tag.H1);
HTMLDocument.Iterator iterator = hdoc.getIterator(HTML.Tag.TITLE);
if (iterator != null && iterator.isValid()) {
int startOffset = iterator.getStartOffset();
if (startOffset >= 0) {
try {