GeoPubby  Version 0.1.0.0
RootServlet Class Reference

A catch-all servlet managing the URI space of the web application. More...

Inheritance diagram for RootServlet:
Collaboration diagram for RootServlet:

Public Member Functions

void init () throws ServletException
 
void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
 

Protected Member Functions

boolean doGet (String relativeURI, HttpServletRequest request, HttpServletResponse response, Configuration config) throws IOException, ServletException
 
void addDocumentMetadata (Model model, HypermediaControls controller, String documentURL, String title)
 
void addPageMetadata (Context context, HypermediaControls controller, PrefixMapping prefixes)
 
void send404 (HttpServletResponse response, String resourceURI) throws IOException
 
void sendInitialization500 (HttpServletResponse response, String message) throws IOException
 
String addQueryString (String dataURL, HttpServletRequest request)
 

Private Attributes

Configuration config
 
String initError
 

Static Private Attributes

static final long serialVersionUID = -4812044304620174504L
 

Detailed Description

A catch-all servlet managing the URI space of the web application.

Member Function Documentation

◆ addDocumentMetadata()

void addDocumentMetadata ( Model  model,
HypermediaControls  controller,
String  documentURL,
String  title 
)
protectedinherited
54  {
55  ModelUtil.addNSIfUndefined(model, "foaf", FOAF.getURI());
56  ModelUtil.addNSIfUndefined(model, "rdfs", RDFS.getURI());
57 
58  // Add document metadata
59  Resource topic = model.getResource(controller.getAbsoluteIRI());
60  Resource document = model.getResource(documentURL);
61  document.addProperty(FOAF.primaryTopic, topic);
62  document.addProperty(RDFS.label, title);
63 
64  // Add custom metadata
65  for (Dataset dataset: config.getDatasets()) {
66  MetadataConfiguration metadata = dataset.getMetadataConfiguration();
67  metadata.addCustomMetadata(model, document);
68  metadata.addMetadataFromTemplate(model, controller);
69  }
70  }
List< Dataset > getDatasets()
The conf:dataset blocks.
Definition: Configuration.java:199
Configuration config
Definition: BaseServlet.java:38

References MetadataConfiguration.addCustomMetadata(), MetadataConfiguration.addMetadataFromTemplate(), ModelUtil.addNSIfUndefined(), BaseServlet.config, HypermediaControls.getAbsoluteIRI(), and Configuration.getDatasets().

Referenced by ValuesDataURLServlet.doGet(), and DataURLServlet.doGet().

◆ addPageMetadata()

void addPageMetadata ( Context  context,
HypermediaControls  controller,
PrefixMapping  prefixes 
)
protectedinherited
75  {
76  try {
77  Model metadataModel = ModelFactory.createDefaultModel();
78  for (Dataset dataset: config.getDatasets()) {
79  MetadataConfiguration metadata = dataset.getMetadataConfiguration();
80  Resource document = metadata.addMetadataFromTemplate(metadataModel, controller);
81  // Replaced the commented line by the following one because the
82  // RDF graph we want to talk about is a specific representation
83  // of the data identified by the getDataURL() URI.
84  // Olaf, May 28, 2010
85  // context.put("metadata", metadata.getResource(resource.getDataURL()));
86  context.put("metadata", document);
87  }
88 
89  Map<String,String> nsSet = metadataModel.getNsPrefixMap();
90  nsSet.putAll(prefixes.getNsPrefixMap());
91  context.put("prefixes", nsSet.entrySet());
92  context.put("blankNodesMap", new HashMap<Resource,String>());
93  }
94  catch (Exception e) {
95  context.put("metadata", Boolean.FALSE);
96  }
97  }

References MetadataConfiguration.addMetadataFromTemplate(), BaseServlet.config, and Configuration.getDatasets().

Referenced by ValuesURLServlet.doGet(), and PageURLServlet.doGet().

◆ addQueryString()

String addQueryString ( String  dataURL,
HttpServletRequest  request 
)
protectedinherited
161  {
162  if (request.getParameter("output") == null) {
163  return dataURL;
164  }
165  return dataURL + "?output=" + request.getParameter("output");
166  }

Referenced by ValuesDataURLServlet.doGet(), and DataURLServlet.doGet().

◆ doGet() [1/2]

void doGet ( HttpServletRequest  request,
HttpServletResponse  response 
) throws IOException, ServletException
inherited
106  {
107  if (initError != null) {
108  if(config==null) {
109  System.out.println("Calling initConfiguration from BaseServlet!");
110  Boolean res=ServletContextInitializer.initConfiguration(getServletContext());
111  if(res)
112  initError=null;
113  else {
114  initError=getServletContext().getAttribute(ServletContextInitializer.ERROR_MESSAGE).toString();
115  }
116  System.out.println("Successful result? "+res.toString());
117  }
118  config = (Configuration) getServletContext().getAttribute(
119  ServletContextInitializer.SERVER_CONFIGURATION);
120  }
121  if(initError!=null) {
122  sendInitialization500(response, initError);
123  return;
124  }
125  String relativeURI = request.getRequestURI().substring(
126  request.getContextPath().length() + request.getServletPath().length());
127  // Some servlet containers keep the leading slash, some don't
128  if (!"".equals(relativeURI) && "/".equals(relativeURI.substring(0, 1))) {
129  relativeURI = relativeURI.substring(1);
130  }
131  if (!doGet(relativeURI, request, response, config)) {
132  send404(response, null);
133  }
134 
135 
136  }
String initError
Definition: BaseServlet.java:39
void send404(HttpServletResponse response, String resourceURI)
Definition: BaseServlet.java:138
void sendInitialization500(HttpServletResponse response, String message)
Definition: BaseServlet.java:152
abstract boolean doGet(String relativeURI, HttpServletRequest request, HttpServletResponse response, Configuration config)

References BaseServlet.config, BaseServlet.doGet(), ServletContextInitializer.ERROR_MESSAGE, ServletContextInitializer.initConfiguration(), BaseServlet.initError, BaseServlet.send404(), BaseServlet.sendInitialization500(), and ServletContextInitializer.SERVER_CONFIGURATION.

◆ doGet() [2/2]

boolean doGet ( String  relativeURI,
HttpServletRequest  request,
HttpServletResponse  response,
Configuration  config 
) throws IOException, ServletException
protected

Reimplemented from BaseServlet.

25  {
26 
27  // static/ directory handled by default servlet
28  if (relativeURI.contains("static/")) {
29  getServletContext().getNamedDispatcher("default").forward(request, response);
30  return true;
31  }
32 
33  // Older versions of Pubby used to have /pathpage and /pathdata,
34  // more limited versions of what is now /values and /values.data.
35  // 301-redirect the old locations to the new ones.
36  Matcher m = Pattern.compile("^(pathpage|pathdata)(/.*)$").matcher(relativeURI);
37  if (m.matches()) {
38  String valuesURL = config.getWebApplicationBaseURI() +
39  ("pathpage".equals(m.group(1)) ? "values" : "values.data")
40  + m.group(2);
41  response.setStatus(301);
42  response.sendRedirect(IRIEncoder.toURI(valuesURL));
43  return true;
44  }
45 
46  // Homepage.
47  if ("".equals(relativeURI)) {
48  // Get the URL where a description of the index resource may be found
49  String indexURL = HypermediaControls.createFromIRI(config.getIndexIRI(), config).getBrowsableURL();
50  if (!config.getWebApplicationBaseURI().equals(indexURL)) {
51  // We need to redirect to the URL
52  response.sendRedirect(IRIEncoder.toURI(indexURL));
53  return true;
54  }
55  }
56 
57  // Assume it's a resource URI -- will produce 404 if not
58  getServletContext().getNamedDispatcher("WebURIServlet").forward(request, response);
59  return true;
60  }
String getIndexIRI()
The "home" resource.
Definition: Configuration.java:257
String getWebApplicationBaseURI()
Definition: Configuration.java:269

References BaseServlet.config, HypermediaControls.createFromIRI(), Configuration.getIndexIRI(), Configuration.getWebApplicationBaseURI(), and IRIEncoder.toURI().

◆ init()

void init ( ) throws ServletException
inherited
41  {
42  config = (Configuration) getServletContext().getAttribute(
43  ServletContextInitializer.SERVER_CONFIGURATION);
44  if(config==null){
45  initError = (String) getServletContext().getAttribute(
46  ServletContextInitializer.ERROR_MESSAGE);
47  }else {
48  initError=null;
49  }
50  }

References BaseServlet.config, ServletContextInitializer.ERROR_MESSAGE, BaseServlet.initError, and ServletContextInitializer.SERVER_CONFIGURATION.

◆ send404()

void send404 ( HttpServletResponse  response,
String  resourceURI 
) throws IOException
protectedinherited
138  {
139  response.setStatus(404);
140  VelocityHelper template = new VelocityHelper(getServletContext(), response);
141  Context context = template.getVelocityContext();
142  context.put("project_name", config.getProjectName());
143  context.put("project_link", config.getProjectLink());
144  context.put("server_base", config.getWebApplicationBaseURI());
145  context.put("title", "404 Not Found");
146  if (resourceURI != null) {
147  context.put("uri", resourceURI);
148  }
149  template.renderXHTML("404.vm");
150  }
String getProjectName()
Definition: Configuration.java:265
String getProjectLink()
Definition: Configuration.java:261

References BaseServlet.config, Configuration.getProjectLink(), Configuration.getProjectName(), and Configuration.getWebApplicationBaseURI().

Referenced by BaseServlet.doGet().

◆ sendInitialization500()

void sendInitialization500 ( HttpServletResponse  response,
String  message 
) throws IOException
protectedinherited
152  {
153  response.setStatus(500);
154  VelocityHelper template = new VelocityHelper(getServletContext(), response);
155  Context context = template.getVelocityContext();
156  context.put("message", message);
157  context.put("title", "Configuration error");
158  template.renderXHTML("500init.vm");
159  }

Referenced by BaseServlet.doGet().

Member Data Documentation

◆ config

◆ initError

String initError
privateinherited

◆ serialVersionUID

final long serialVersionUID = -4812044304620174504L
staticprivate