//import org.b3log.latke.cron.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.b3log.latke.cron.Cron;
import org.b3log.latke.cron.CronService;
import org.b3log.latke.servlet.AbstractServletListener;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class test_CronService {
private static final Logger LOGGER = Logger.getLogger(test_CronService.class.getName());
class CronService{
/**
* Loads cron.xml.
*/
private void loadCronXML() {
//final String webRoot = AbstractServletListener.getWebRoot();
//final File cronXML = new File(webRoot + File.separator + "WEB-INF" + File.separator + "cron.xml");
final File cronXML = new File("D:\\workspace1306014\\b3log130614\\WebContent\\WEB-INF\\cron.xml");
if (!cronXML.exists()) {
LOGGER.log(Level.INFO, "Not found cron.xml, no cron jobs need to schedule");
return;
}
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
try {
final DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
final Document document = documentBuilder.parse(cronXML);
final Element root = document.getDocumentElement();
root.normalize();
final NodeList crons = root.getElementsByTagName("cron");
LOGGER.log(Level.CONFIG, "Reading cron jobs: ");
for (int i = 0; i < crons.getLength(); i++) {
final Element cronElement = (Element) crons.item(i);
final Element urlElement = (Element) cronElement.getElementsByTagName("url").item(0);
final Element descriptionElement = (Element) cronElement.getElementsByTagName("description").item(0);
final Element scheduleElement = (Element) cronElement.getElementsByTagName("schedule").item(0);
final String url = urlElement.getTextContent();
final String description = descriptionElement.getTextContent();
final String schedule = scheduleElement.getTextContent();
System.out.println(url+" "+description+" "+schedule);
LOGGER.log(Level.CONFIG, "Cron[url={0}, description={1}, schedule={2}]", new Object[] {url, description, schedule});
//CRONS.add(new Cron(url, description, schedule));
}
} catch (final Exception e) {
LOGGER.log(Level.SEVERE, "Reads cron.xml failed", e);
throw new RuntimeException(e);
}
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
test_CronService p=new test_CronService();
CronService k=p.new CronService();
k.loadCronXML();
}
}
输出:
/upgrade/checker.do Upgrade checker, see issue 257 (http://code.google.com/p/b3log-solo/issues/detail?id=257). every 5 minutes
/console/stat/viewcnt Async Blog/Article counter every 30 minutes
/console/stat/onlineVisitorRefresh Online Visitor Refresher every 1 minutes
源代码:http://pan.baidu.com/share/link?shareid=2867708466&uk=3878681452