Hi, All,

Attached please find servlet Cached.java that serves raw Content
of any mime type. Current cached.jsp handles mime type text/* only.
If no objection, it is going to be committed in a few days.

John


----------------------- Cached.java -----------------------

diff -Nur --exclude='*.txt' --exclude='*.xml' 
nutch-svn-20050322/src/java/org/apache/nutch/servlet/Cached.java 
nutch-svn-20050322.xing/src/java/org/apache/nutch/servlet/Cached.java
--- nutch-svn-20050322/src/java/org/apache/nutch/servlet/Cached.java    
1969-12-31 16:00:00.000000000 -0800
+++ nutch-svn-20050322.xing/src/java/org/apache/nutch/servlet/Cached.java       
2005-03-22 15:23:50.411108272 -0800
@@ -0,0 +1,93 @@
+/**
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.apache.nutch.servlet;
+
+import org.apache.nutch.searcher.NutchBean;
+import org.apache.nutch.searcher.Hit;
+import org.apache.nutch.searcher.HitDetails;
+
+import org.apache.nutch.util.NutchConf;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.util.Properties;
+
+import java.io.OutputStream;
+import java.io.IOException;
+
+/**
+ * @author John Xing
+ */
+
+public class Cached extends HttpServlet {
+
+  NutchBean bean = null;
+
+  public void init() {
+    try {
+      bean = NutchBean.get(this.getServletContext());
+    } catch (IOException e) {
+      // nothing
+    }
+  }
+
+  public void destroy() {
+    // maybe clean bean?
+    // nothing now
+  }
+ 
+  public void doGet(HttpServletRequest request, HttpServletResponse response)
+    throws IOException {
+
+    // quit if no bean
+    if (bean == null)
+      return;
+
+    bean.LOG.info("request from " + request.getRemoteAddr());
+
+    Hit hit = new Hit(Integer.parseInt(request.getParameter("idx")),
+                    Integer.parseInt(request.getParameter("id")), 0.0f, null);
+    HitDetails details = bean.getDetails(hit);
+
+    // mimetype
+    Properties metaData = bean.getParseData(details).getMetadata();
+    String contentType = (String) metaData.get("Content-Type");
+
+    // raw bytes
+    byte[] bytes = bean.getContent(details);
+
+    // response
+    response.setContentType(contentType);
+
+    OutputStream os = response.getOutputStream();
+    os.write(bytes);
+    // need this?
+    //os.flush();
+    os.close();
+
+    return;
+  }
+
+  public void doPost(HttpServletRequest request, HttpServletResponse response)
+    throws IOException {
+    doGet(request, response);
+  }
+
+}

__________________________________________
http://www.neasys.com - A Good Place to Be
Come to visit us today!


-------------------------------------------------------
This SF.net email is sponsored by: 2005 Windows Mobile Application Contest
Submit applications for Windows Mobile(tm)-based Pocket PCs or Smartphones
for the chance to win $25,000 and application distribution. Enter today at
http://ads.osdn.com/?ad_id=6882&alloc_id=15148&op=click
_______________________________________________
Nutch-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nutch-developers

Reply via email to