001 // This file is part of the Attempto Java Packages. 002 // Copyright 2008, Attempto Group, University of Zurich (see http://attempto.ifi.uzh.ch). 003 // 004 // The Attempto Java Packages is free software: you can redistribute it and/or modify it under the 005 // terms of the GNU Lesser General Public License as published by the Free Software Foundation, 006 // either version 3 of the License, or (at your option) any later version. 007 // 008 // The Attempto Java Packages is distributed in the hope that it will be useful, but WITHOUT ANY 009 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 010 // PURPOSE. See the GNU Lesser General Public License for more details. 011 // 012 // You should have received a copy of the GNU Lesser General Public License along with the Attempto 013 // Java Packages. If not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.acewiki; 016 017 import java.io.IOException; 018 019 import javax.servlet.ServletException; 020 import javax.servlet.http.HttpServletRequest; 021 import javax.servlet.http.HttpServletResponse; 022 023 import ch.uzh.ifi.attempto.acewiki.core.ontology.Ontology; 024 import ch.uzh.ifi.attempto.ape.APELocal; 025 026 import nextapp.echo2.app.ApplicationInstance; 027 import nextapp.echo2.webcontainer.WebContainerServlet; 028 029 /** 030 * This servlet class should be launched by the web server in order to start an AceWiki application. If you are using a 031 * web application archive (WAR) then the web.xml file should contain something like this: 032 * 033 * <pre> 034 * <servlet> 035 * <servlet-name>GeoWiki</servlet-name> 036 * <servlet-class>ch.uzh.ifi.attempto.acewiki.AceWikiServlet</servlet-class> 037 * <init-param> 038 * <param-name>ontology</param-name> 039 * <param-value>geo</param-value> 040 * </init-param> 041 * <init-param> 042 * <param-name>baseuri</param-name> 043 * <param-value>http://attempto.ifi.uzh.ch/acewiki/</param-value> 044 * </init-param> 045 * <init-param> 046 * <param-name>title</param-name> 047 * <param-value>Geography Wiki</param-value> 048 * </init-param> 049 * <init-param> 050 * <param-name>description</param-name> 051 * <param-value>This wiki contains geographical knowledge.</param-value> 052 * </init-param> 053 * <init-param> 054 * <param-name>login</param-name> 055 * <param-value>no</param-value> 056 * </init-param> 057 * </servlet> 058 * </pre> 059 * 060 * The parameter 'ontology' is mandatory and specifies the name of the ontology. This name is used in the URIs of the 061 * OWL statements and for the file names on the server. The 'baseuri' parameter defines the base URI for the 062 * OWL statements. The values of the parameters 'title' and 'description' are shown on the start page of the wiki. Finally, 063 * the 'login' parameter defines whether users have to login before they can use the wiki. Note that the login feature 064 * is implemented only very rudimentary. 065 *<p> 066 * Furthermore, SWI Prolog needs to be installed on the server and you need to have a compiled version of the Attempto APE 067 * distribution. See the documentation of {@link APELocal} for more information. The server has to know the command of your 068 * SWI Prolog installation and the location of the ape.exe file. This is done by context parameters in the web.xml file: 069 * 070 * <pre> 071 * <context-param> 072 * <param-name>prologcommand</param-name> 073 * <param-value>swipl</param-value> 074 * </context-param> 075 * 076 * <context-param> 077 * <param-name>apecommand</param-name> 078 * <param-value>/path/to/file/ape.exe</param-value> 079 * </context-param> 080 * </pre> 081 * 082 * One last tiny thing: The server delay window (that is shown on the client when the server is busy) looks for the 083 * wait icon "../wait.gif". You should copy the file "src/ch/uzh/ifi/attempto/acewiki/core/gui/img/wait.gif" to the 084 * respective folder on the server. (This should be improved, I admit.) 085 * 086 * @author Tobias Kuhn 087 */ 088 public class AceWikiServlet extends WebContainerServlet { 089 090 private static final long serialVersionUID = -7342857942059126499L; 091 092 private Ontology ontology; 093 094 /** 095 * Creates a new AceWiki servlet object. 096 */ 097 public AceWikiServlet() { 098 } 099 100 public ApplicationInstance newApplicationInstance() { 101 String ontologyName = getInitParameter("ontology"); 102 String baseURI = getInitParameter("baseuri"); 103 String title = getInitParameter("title"); 104 String description = getInitParameter("description"); 105 boolean login = "yes".equals(getInitParameter("login")); 106 107 if (!APELocal.isInitialized()) { 108 String prologCommand = getServletContext().getInitParameter("prologcommand"); 109 String apeCommand = getServletContext().getInitParameter("apecommand"); 110 if (prologCommand == null) prologCommand = "swipl"; 111 if (apeCommand == null) apeCommand = "ape.exe"; 112 APELocal.init(prologCommand, apeCommand); 113 } 114 115 if (ontology == null) { 116 ontology = Ontology.loadOntology(ontologyName, baseURI); 117 } 118 119 Logger.log("syst", "syst", 0, "appl", "new application instance: " + ontologyName); 120 return new AceWikiApp(ontology, title, description, login); 121 } 122 123 protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 124 try { 125 super.process(request, response); 126 } catch (RuntimeException ex) { 127 Logger.log("syst", "syst", 0, "fail", "fatal error: " + ex); 128 ex.printStackTrace(); 129 throw ex; 130 } catch (IOException ex) { 131 Logger.log("syst", "syst", 0, "fail", "fatal error: " + ex); 132 ex.printStackTrace(); 133 throw ex; 134 } catch (ServletException ex) { 135 Logger.log("syst", "syst", 0, "fail", "fatal error: " + ex); 136 ex.printStackTrace(); 137 throw ex; 138 } 139 } 140 141 // This was a try to support specific URLs for each wiki articles: 142 /* 143 protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 144 String pageParameter = request.getParameter("page"); 145 if (app != null && pageParameter != null) { 146 final OntologyElement oe = app.getWiki().getOntology().get(request.getParameter("page")); 147 if (taskQueue == null) { 148 taskQueue = app.createTaskQueue(); 149 } 150 if (oe != null) { 151 app.enqueueTask(taskQueue, new Runnable() { 152 public void run() { 153 app.getWiki().showPage(oe); 154 } 155 }); 156 try {wait(500);} catch (Exception ex) {} 157 } 158 } 159 160 super.process(request, response); 161 } 162 */ 163 164 }