search/indexer/mmm-search-indexer-api/src/main/java/net/sf/mmm/search/indexer/base/ResourceSearchIndexerImpl.java
/**
   * @see #createEntry(SearchIndexer, DataResource, String)
   *
   * @param indexer is the {@link SearchIndexer} used for indexing.
   * @param resource is the {@link DataResource} to index.
   * @param resourceUri is the {@link MutableSearchEntry#getUri() URI} for the {@link MutableSearchEntry
   *        entry}.
   * @param options are the {@link ContentParserOptionsBean options}.
   * @return the created {@link MutableSearchEntry}.
   */
@see #createEntry(SearchIndexer, DataResource, String)
@param indexer is the  SearchIndexer used for indexing.
@param resource is the  DataResource to index.
@param resourceUri is the  MutableSearchEntry#getUri() URI for the {@link MutableSearchEntry
entry}.
@param options are the  ContentParserOptionsBean options.
@return the created  MutableSearchEntry.
@see #createEntry ( SearchIndexer DataResource String ) @param indexer is the SearchIndexer used for indexing . @param resource is the DataResource to index . @param resourceUri is the MutableSearchEntry#getUri () URI for the { @link MutableSearchEntry entry } . @param options are the ContentParserOptionsBean options . @return the created MutableSearchEntry .
protected MutableSearchEntry createEntry(SearchIndexer indexer, DataResource resource, String resourceUri,
      ContentParserOptions options) {
    String filename = resource.getName();
    String extension = this.fileUtil.getExtension(filename);
    MutableSearchEntry entry = indexer.createEntry();
    entry.setUri(resourceUri);
    long fileSize = resource.getSize();
    entry.setSize(fileSize);
    ContentParser parser = this.parserService.getParser(extension);
    if (parser != null) {
      if (parser.getPrimaryKeys().contains(extension)) {
        extension = parser.getExtension();
      }
      try {
        InputStream inputStream = resource.openStream();
        try {
          GenericContext context = parser.parse(inputStream, fileSize, options);
          String title = getStringProperty(context, ContentParser.VARIABLE_NAME_TITLE);
          if (title != null) {
            entry.setTitle(title);
          }
          String creator = getStringProperty(context, ContentParser.VARIABLE_NAME_CREATOR);
          if (creator != null) {
            entry.setCreator(creator);
          }
          String text = getStringProperty(context, ContentParser.VARIABLE_NAME_TEXT);
          if (text != null) {
            entry.setText(text);
          }
        } catch (Exception e) {
          getLogger().error("Failed to extract data from resource: " + resource.getUri(), e);
          StringWriter sw = new StringWriter();
          e.printStackTrace(new PrintWriter(sw));
          entry.setText(sw.toString());
        }
      } catch (RuntimeException e) {
        getLogger().error("Failed to open resource " + resource.getUri(), e);
      }
    }
    entry.setType(extension);
    return entry;
  }
protected MutableSearchEntry createEntry ( SearchIndexer indexer , DataResource resource , String resourceUri , ContentParserOptions options ) { String filename = resource . getName ( ) ; String extension = this . fileUtil . getExtension ( filename ) ; MutableSearchEntry entry = indexer . createEntry ( ) ; entry . setUri ( resourceUri ) ; long fileSize = resource . getSize ( ) ; entry . setSize ( fileSize ) ; ContentParser parser = this . parserService . getParser ( extension ) ; if ( parser != null ) { if ( parser . getPrimaryKeys ( ) . contains ( extension ) ) { extension = parser . getExtension ( ) ; } try { InputStream inputStream = resource . openStream ( ) ; try { GenericContext context = parser . parse ( inputStream , fileSize , options ) ; String title = getStringProperty ( context , ContentParser . VARIABLE_NAME_TITLE ) ; if ( title != null ) { entry . setTitle ( title ) ; } String creator = getStringProperty ( context , ContentParser . VARIABLE_NAME_CREATOR ) ; if ( creator != null ) { entry . setCreator ( creator ) ; } String text = getStringProperty ( context , ContentParser . VARIABLE_NAME_TEXT ) ; if ( text != null ) { entry . setText ( text ) ; } } catch ( Exception e ) { getLogger ( ) . error ( "Failed to extract data from resource: " + resource . getUri ( ) , e ) ; StringWriter sw = new StringWriter ( ) ; e . printStackTrace ( new PrintWriter ( sw ) ) ; entry . setText ( sw . toString ( ) ) ; } } catch ( RuntimeException e ) { getLogger ( ) . error ( "Failed to open resource " + resource . getUri ( ) , e ) ; } } entry . setType ( extension ) ; return entry ; }
@see #createEntry(SearchIndexer, DataResource, String)
 @param indexer is the {@link SearchIndexer} used for indexing.
@see #createEntry ( SearchIndexer DataResource String ) @param indexer is the { @link SearchIndexer } used for indexing .
// normalize the extension (e.g. "htm" -> "html") // this is just a hack!!! // however it helps perfectly for debugging...