/*
* �ON content management system.
* Copyright (C) 2002 Guillaume Bort(gbort@msn.com). All rights reserved.
*
* Copyright (c) 2000 The Apache Software Foundation. All rights reserved.
* Copyright 2000-2002 (C) Intalio Inc. All Rights Reserved.
*
* �ON is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* �ON core framework, �ON content server, �ON backoffice, �ON frontoffice
* and �ON admin application are parts of �ON and are distributed under
* same terms of licence.
*
*
* �ON includes software developed by the Apache Software Foundation (http://www.apache.org/)
* and software developed by the Exolab Project (http://www.exolab.org).
*
* �ON is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
package org.nextime.ion.frontoffice.smartCache;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import org.nextime.ion.framework.business.Section;
public class SmartCacheAgent extends Thread {
private String cachePath;
private String path;
private String id;
private String prefix;
public SmartCacheAgent(
String cachePath,
String prefix,
String id,
String path) {
this.cachePath = cachePath;
this.path = path;
this.id = id;
this.prefix = prefix;
setName("smartCacheAgent");
start();
}
public void run() {
try {
String allPath = path;
if (allPath.indexOf("?") == -1) {
allPath += "?nocache=true";
} else {
allPath += "&nocache=true";
}
URL url = new URL(allPath);
BufferedReader reader =
new BufferedReader(new InputStreamReader(url.openStream()));
String content = "<!-- �ON smart cache for url : " + path + " -->";
String line = "";
while (line != null) {
line = reader.readLine();
if (line != null) {
content += line;
}
}
FileOutputStream fos =
new FileOutputStream(
new File(cachePath, prefix + "$" + id + ".html"));
fos.write(content.getBytes());
fos.close();
} catch (Exception e) {
//e.printStackTrace();
}
}
}