content-parser/impl-html/src/main/java/net/sf/mmm/content/parser/impl/html/ContentParserHtml.java
/**
   * @see #parse(InputStream, long)
   * 
   * @param inputStream is the fresh input stream of the content to parse. It
   *        will be {@link InputStream#close() closed} by this method (on
   *        success and in exceptional state).
   * @param filesize is the size (content-length) of the content to parse in
   *        bytes or <code>0</code> if NOT available (unknown). If available,
   *        the parser may use this value for optimized allocations.
   * @param context is the {@link MutableGenericContext} where metadata can be
   *        added.
   * @throws Exception on error.
   */


@param inputStream is the fresh input stream of the content to parse. It
will be  InputStream#close() closed by this method (on
success and in exceptional state).
@param filesize is the size (content-length) of the content to parse in
bytes or 0 if NOT available (unknown). If available,
the parser may use this value for optimized allocations.
@param context is the  MutableGenericContext where metadata can be
added.
@throws Exception on error.
@param inputStream is the fresh input stream of the content to parse . It will be InputStream#close () closed by this method ( on success and in exceptional state ) . @param filesize is the size ( content - length ) of the content to parse in bytes or 0 if NOT available ( unknown ) . If available the parser may use this value for optimized allocations . @param context is the MutableGenericContext where metadata can be added . @throws Exception on error .
protected void parseJtidy(InputStream inputStream, long filesize, MutableGenericContext context)
      throws Exception {
    Tidy tidy = new Tidy();
    tidy.setErrout(new PrintWriter(new NullWriter()));
    Document xmlDoc = tidy.parseDOM(inputStream, null);
    Element htmlElement = xmlDoc.getDocumentElement();
    Element headElement = getFirstChildElement(htmlElement, TAG_HEAD);
    String title = null;
    if (headElement != null) {
      NodeList nodeList = headElement.getChildNodes();
      for (int nodeIndex = 0; nodeIndex < nodeList.getLength(); nodeIndex++) {
        Node node = nodeList.item(nodeIndex);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
          Element childElement = (Element) node;
          String tagName = childElement.getTagName();
          if (tagName.equals(TAG_TITLE)) {
            title = getTextContent(childElement);
          } else if (tagName.equals(TAG_META)) {
            String metaName = childElement.getAttribute(ATR_META_NAME);
            if (metaName.equalsIgnoreCase("keywords")) {
              context.setVariable(VARIABLE_NAME_KEYWORDS,
                  childElement.getAttribute(ATR_META_CONTENT));
            } else if (metaName.equalsIgnoreCase("author")) {
              context.setVariable(VARIABLE_NAME_CREATOR,
                  childElement.getAttribute(ATR_META_CONTENT));
            }
          }
        }
      }
    }
    if (title != null) {
      context.setVariable(VARIABLE_NAME_TITLE, title);
    }
    Element bodyElement = getFirstChildElement(htmlElement, TAG_BODY);
    if (bodyElement != null) {
      context.setVariable(VARIABLE_NAME_TEXT, getTextContent(bodyElement));
    }
  }
protected void parseJtidy ( InputStream inputStream , long filesize , MutableGenericContext context ) throws Exception { Tidy tidy = new Tidy ( ) ; tidy . setErrout ( new PrintWriter ( new NullWriter ( ) ) ) ; Document xmlDoc = tidy . parseDOM ( inputStream , null ) ; Element htmlElement = xmlDoc . getDocumentElement ( ) ; Element headElement = getFirstChildElement ( htmlElement , TAG_HEAD ) ; String title = null ; if ( headElement != null ) { NodeList nodeList = headElement . getChildNodes ( ) ; for ( int nodeIndex = 0 ; nodeIndex < nodeList . getLength ( ) ; nodeIndex ++ ) { Node node = nodeList . item ( nodeIndex ) ; if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { Element childElement = ( Element ) node ; String tagName = childElement . getTagName ( ) ; if ( tagName . equals ( TAG_TITLE ) ) { title = getTextContent ( childElement ) ; } else if ( tagName . equals ( TAG_META ) ) { String metaName = childElement . getAttribute ( ATR_META_NAME ) ; if ( metaName . equalsIgnoreCase ( "keywords" ) ) { context . setVariable ( VARIABLE_NAME_KEYWORDS , childElement . getAttribute ( ATR_META_CONTENT ) ) ; } else if ( metaName . equalsIgnoreCase ( "author" ) ) { context . setVariable ( VARIABLE_NAME_CREATOR , childElement . getAttribute ( ATR_META_CONTENT ) ) ; } } } } } if ( title != null ) { context . setVariable ( VARIABLE_NAME_TITLE , title ) ; } Element bodyElement = getFirstChildElement ( htmlElement , TAG_BODY ) ; if ( bodyElement != null ) { context . setVariable ( VARIABLE_NAME_TEXT , getTextContent ( bodyElement ) ) ; } }
@see #parse(InputStream, long)
@see #parse ( InputStream long )
// read header data... // read body data...