1 25 26 package org.snipsnap.net; 27 28 import org.snipsnap.config.Configuration; 29 import org.snipsnap.config.ConfigurationProxy; 30 import org.snipsnap.snip.Blog; 31 import org.snipsnap.snip.Snip; 32 import org.snipsnap.snip.SnipSpaceFactory; 33 import org.snipsnap.serialization.SerializerFactory; 34 import org.snipsnap.serialization.Serializer; 35 import javax.servlet.RequestDispatcher ; 36 import javax.servlet.ServletConfig ; 37 import javax.servlet.ServletException ; 38 import javax.servlet.http.HttpServlet ; 39 import javax.servlet.http.HttpServletRequest ; 40 import javax.servlet.http.HttpServletResponse ; 41 import java.io.IOException ; 42 import java.io.Writer ; 43 import java.util.Properties ; 44 45 50 public class RdfServlet extends HttpServlet { 51 private Configuration config; 52 53 public void init(ServletConfig servletConfig) throws ServletException { 54 config = ConfigurationProxy.getInstance(); 55 } 56 57 public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException , ServletException { 58 59 String name = request.getPathInfo(); 61 if (null == name || "/".equals(name)) { 62 name = config.getStartSnip(); 63 } else { 64 name = name.substring(1); 65 } 66 name = name.replace('+', ' '); 67 68 Snip snip = SnipSpaceFactory.getInstance().load(name); 70 71 if (snip == null) { 73 snip = SnipSpaceFactory.getInstance().load("snipsnap-notfound"); 74 } 75 76 response.setContentType("text/xml; charset=UTF-8"); 78 Writer writer = response.getWriter(); 79 80 try { 82 Serializer ser = SerializerFactory.createSerializer(SerializerFactory.RDF_10); 83 Properties props = new Properties (); 84 props.setProperty("uri.prefix", config.getUrl("/rdf")); 85 props.setProperty("rdf.format", "RDF/XML-ABBREV"); 86 ser.configure(props); 87 88 ser.serialize(snip, writer); 89 } catch (Exception e) { 90 } 92 93 writer.close(); 94 } 95 } 96 | Popular Tags |