Content tmp = (Content)it.next(); tmp.setContentToDelete( true ); }
for (Iterator it = contents.iterator(); it.hasNext();) { Content tmp = (Content) it.next(); tmp.setContentToDelete( true ); tmp.save(); } } catch ( Exception e1 ) { logger.error( "Error while marking old contents as outdated", e1 ); }
    public void run()    {        if (!isRunning && failures < 3)        {            isRunning = true;            //check if content needs update - this is neccessary because of            //a) we could be in a cluster enviroment, so another iquiver instance might already            //did update this content source and            //b) maybe we had a transport failure in past            if (checkForUpdate())            {                ContentSource source = fetcher.getFetchLocation();                List contents = null;                String contentType = null;                //does the content source explicit overwrite the content type?                try                {                    if (source.getContentType() != null)                    {                        contentType = source.getContentType().getContentTypeName();                    }                }                catch ( TorqueException e )                {                    logger.error( "Check for explicit overwritten content type of content source "                            + source.getContentSourceName() + " failed!", e );                }                List documents = null;                try                {                    contents = source.getContents();                    documents = fetcher.fetch();                    //restet failure count on success                    if (failures != 0)                    {                        failures = 0;                    }                    //Parse and convert the document into net.sf.iquiver.om.Content instances and save them into                    // the database                    List contentDocs = new ArrayList();                    for (Iterator it = documents.iterator(); it.hasNext();)                    {                        Document doc = (Document) it.next();                        try                        {                            Content content = null;                            //does the content source explicit overwrite the content type?                            if (contentType != null)                            {                                doc.setContentTypeStr( contentType );                            }                            //transports might be able to set all neccessary document values without a special                            // parser                            if (fetcher.isParsingRequired())                            {                                Parser parser = ParserFactory.getParserForContentType( doc.getContentTypeStr() );                                content = new Content( parser.parse( doc ) );                                //does the content source explicit overwrite the content type?                                if (contentType != null)                                {                                    //the used parser might have set another content type                                    content.setContentTypeStr( contentType );                                }                            }                            else                            {                                content = new Content( doc );                            }                            content.setContentReceiveDatetime( new Date() );                            content.setContentSourceId( source.getContentSourceId() );                            content.save();                            contentDocs.add( content );                        }                        catch ( UnsupportedEncodingException e )                        {                            logger.error( "Encoding of retrieved content is not supported!", e );                        }                        catch ( Exception e )                        {                            logger.error( "Error while saving retrieved content!", e );                        }                    }                    if (!contentDocs.isEmpty())                    {                        // Add the documents to the search index - we use one index per content source                        IndexScheduler scheduler = IndexScheduler.getInstance( indexDir + File.separator                                + String.valueOf( source.getContentSourceId() ) );                        scheduler.scheduleForIndexing( contentDocs );                    }                                        //mark old contents as outdated                    for ( Iterator it = contents.iterator(); it.hasNext(); )                    {                        Content tmp = (Content)it.next();                        tmp.setContentToDelete( true );                    }                                    }                catch ( TransportException e )                {                    logger.error( e );                    failures++;                    // stopping this content fetch thread for the current application session after three sequenced                    // failures                    if (failures >= 3)                    {                        String id = fetcher.getFetchLocation().getContentSourceName();                        logger                                .error( "Content fetching from content source \""                                        + id                                        + "\" failed for three times. Content fetching for this source will be stopped now for this session." );                    }                    isRunning = false;                    return;                }                catch ( TorqueException e )                {                    logger.error("Database error occured while fetching already stored contents from database!", e);                }            }            else            {                if (logger.isDebugEnabled())                {                    logger.debug( "Found up-to-date data, ignoring content source "                            + fetcher.getFetchLocation().getContentSourceName() );                }            }            isRunning = false;        }    }