KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snipsnap > net > RdfServlet


1 /*
2  * This file is part of "SnipSnap Wiki/Weblog".
3  *
4  * Copyright (c) 2002 Stephan J. Schmidt, Matthias L. Jugel
5  * All Rights Reserved.
6  *
7  * Please visit http://snipsnap.org/ for updates and contact.
8  *
9  * --LICENSE NOTICE--
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  * --LICENSE NOTICE--
24  */

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 JavaDoc;
36 import javax.servlet.ServletConfig JavaDoc;
37 import javax.servlet.ServletException JavaDoc;
38 import javax.servlet.http.HttpServlet JavaDoc;
39 import javax.servlet.http.HttpServletRequest JavaDoc;
40 import javax.servlet.http.HttpServletResponse JavaDoc;
41 import java.io.IOException JavaDoc;
42 import java.io.Writer JavaDoc;
43 import java.util.Properties JavaDoc;
44
45 /**
46  * Output a snip as RDF
47  * @author Marco Mosconi
48  * @version $Id: RdfServlet.java 1615 2004-05-26 08:20:33Z leo $
49  */

50 public class RdfServlet extends HttpServlet JavaDoc {
51     private Configuration config;
52
53     public void init(ServletConfig JavaDoc servletConfig) throws ServletException JavaDoc {
54         config = ConfigurationProxy.getInstance();
55     }
56
57     public void doGet(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc, ServletException JavaDoc {
58
59         // handle the snip name
60
String JavaDoc 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         // load snip
69
Snip snip = SnipSpaceFactory.getInstance().load(name);
70
71         // snip doesn't exist
72
if (snip == null) {
73             snip = SnipSpaceFactory.getInstance().load("snipsnap-notfound");
74         }
75
76         // set output
77
response.setContentType("text/xml; charset=UTF-8");
78         Writer JavaDoc writer = response.getWriter();
79
80         // serialize snip
81
try {
82             Serializer ser = SerializerFactory.createSerializer(SerializerFactory.RDF_10);
83             Properties JavaDoc props = new Properties JavaDoc();
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 JavaDoc e) {
90             // some exception handling here ...
91
}
92
93         writer.close();
94     }
95 }
96
Popular Tags