--- /dev/null
+
+<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <title>KiSS Crawler overview page</title>
+
+ <meta http-equiv="pragma" content="no-cache">
+ <meta http-equiv="cache-control" content="no-cache">
+ <meta http-equiv="expires" content="0">
+ <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
+ <meta http-equiv="description" content="This is my page">
+
+ <!--
+ <link rel="stylesheet" type="text/css" href="styles.css">
+ -->
+ </head>
+
+ <body>
+ <h1>KiSS Crawler Overview</h1>
+
+ <TABLE border="1">
+ <tr>
+ <td>
+ Currently running:
+ </td>
+ <td>
+ <c:out value="${running}"/>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ Last executed at:
+ </td>
+ <td>
+ <c:out value="${lastExecuted}"/>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ Last result:
+ </td>
+ <td>
+ <c:out value="${lastResult}"/>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ Last message:
+ </td>
+ <td>
+ <c:out value="${lastMessage}" escapeXml="false"/>
+ </td>
+ </tr>
+ </TABLE>
+ <c:if test="${!running}">
+ <FORM action="runnow">
+ <INPUT type="submit" name="runnow" value="Run Crawler as soon as possible">
+ </FORM>
+ </c:if>
+ </body>
+</html>
--- /dev/null
+/*
+ * Copyright 2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wamblee.crawler.kiss.scheduling;
+
+/**
+ *
+ */
+public interface CrawlerScheduler {
+
+ void initialize() throws Exception;
+
+ boolean isCrawlerRunning() throws Exception;
+
+ void scheduleNow() throws Exception;
+
+ void shutdown() throws Exception;
+
+}
--- /dev/null
+/*
+ * Copyright 2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wamblee.crawler.kiss.servlet;
+
+import java.io.IOException;
+import java.util.Date;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.wamblee.crawler.kiss.scheduling.CrawlerSchedule;
+import org.wamblee.crawler.kiss.scheduling.CrawlerScheduler;
+import org.wamblee.general.BeanKernel;
+
+/**
+ *
+ */
+public class CrawlerServlet extends HttpServlet {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void doPost(HttpServletRequest aRequest,
+ HttpServletResponse aResponse) throws ServletException, IOException {
+
+ CrawlerScheduler scheduler = BeanKernel.getBeanFactory().find(
+ CrawlerScheduler.class);
+ CrawlerSchedule status = BeanKernel.getBeanFactory().find(
+ CrawlerSchedule.class);
+
+ try {
+ if ( aRequest.getParameter("runnow") != null ) {
+ status.setLastExecuted(new Date(System.currentTimeMillis() - 24*3600*1000));
+ scheduler.scheduleNow();
+ aResponse.sendRedirect("");
+ return;
+ }
+ aRequest.setAttribute("running", scheduler.isCrawlerRunning());
+ aRequest.setAttribute("lastExecuted", status.getLastExecuted());
+ aRequest.setAttribute("lastResult", status.getLastResult());
+ aRequest.setAttribute("lastException", status.getLastException());
+ String msg = "";
+ Throwable e = status.getLastException();
+ while ( e != null ) {
+ msg = msg + e.getMessage() + "<br/>";
+ e = e.getCause();
+ }
+ aRequest.setAttribute("lastMessage", msg);
+ } catch (Exception e) {
+ throw new ServletException("Error getting status", e);
+ }
+ aRequest.getRequestDispatcher("WEB-INF/overview.jsp").forward(aRequest,
+ aResponse);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
+ * javax.servlet.http.HttpServletResponse)
+ */
+ @Override
+ protected void doGet(HttpServletRequest aRequest,
+ HttpServletResponse aResponse) throws ServletException, IOException {
+ doPost(aRequest, aResponse);
+ }
+}