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);
      }
    }
  }
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));
     
      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) {
         
          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) {
           
            ex.printStackTrace();
          }
        }
      } else {
        System.out.println("No valid iterator for tag TITLE found: "+iterator);
      }
    }
  }
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)); 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) { 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) { ex.printstacktrace(); } } } else { system.out.println("no valid iterator for tag title found: "+iterator); } } }