if(isRealtimeURL(url)) {
return false;
}
DiskCacheEntry dce = null;
if( DiskCacheUtils.isCached(url) ) {
try {
dce = JetspeedDiskCache.getInstance().getEntry( url );
if(!dce.hasExpired())
{
return false;
}
addRealtimeURL( url );
//only update this if the URL on which it is based is newer
//than the one on disk.
URL sock;
// Determine the URL's protocol
String protocol = url.substring(0, url.indexOf(":/"));
// Check if a proxy is set. If no port is set, use the default port (-1)
String proxyHost = URLManager.getProxyHost( protocol );
if (proxyHost != null)
{
// Open the URL using a proxy
sock = new URL(protocol,
proxyHost,
URLManager.getProxyPort( protocol ),
url);
}
else
{
sock = new URL( url );
}
URLConnection conn = null;
conn = sock.openConnection();
File file = dce.getFile();
long mod = dce.getLastModified();
long filesize = 0;
if(file != null)
{
filesize = file.length();
}
if(mod > 0 || filesize > 0)
conn.setIfModifiedSince(mod);
conn.connect();
long last = conn.getLastModified();
long expires = conn.getExpiration();
int clength = conn.getContentLength();
int respCode = 200;
if(conn instanceof HttpURLConnection) {
respCode = ( ( HttpURLConnection )conn ).getResponseCode();
}
if (respCode != 304 /*NOT MODIFIED*/ &&
(clength == -1 || clength > 0) &&
( last == 0 ||
last > dce.getLastModified()) ) {
logger.info( "URLFetcher: Found updated URL: " +
url +
" Modified " + last + " Expires: " + expires +
" CLength: " + clength );
//force this URL to update.
JetspeedDiskCache.getInstance().getEntry( url, getReader( conn ) );
//Trying to deal with a problem under FreeBSD
conn.getInputStream().close();
//Set the last modified and expiration times for entry
//FIXME: 0 is used in FileWatcher to mean not initialized...
if(last > 0)
dce.setLastModified(last);
else
dce.setLastModified( System.currentTimeMillis() );
dce.setExpirationTime(expires);
//removeRealtimeURL( url ); (done in finally)
return true;
//now make sure that the entry that depends on this HREF
//is updated in the PortletFactory.
} else {
if(last > 0)
dce.setLastModified(last);
else
dce.setLastModified( System.currentTimeMillis() );
dce.setExpirationTime(expires);
logger.info( "DiskCacheDaemon: URL still valid: " + url +
" Modified " + last + " Expires: " + expires +
" CLength: " + clength);