GeoPubby  Version 0.1.0.0
DataURLServlet Class Reference

Servlet for serving RDF documents containing a description of a given resource. More...

Inheritance diagram for DataURLServlet:
Collaboration diagram for DataURLServlet:

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
 
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 Member Functions

void addHighDegreePropertyLinks (Model model, HypermediaControls controller)
 

Private Attributes

Configuration config
 
String initError
 

Static Private Attributes

static final long serialVersionUID = 6825866213915066364L
 

Detailed Description

Servlet for serving RDF documents containing a description of a given resource.

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().

◆ addHighDegreePropertyLinks()

void addHighDegreePropertyLinks ( Model  model,
HypermediaControls  controller 
)
private
54  {
55  // TODO: This should re-use the logic from ResourceDescription and ResourceProperty to decide where to create these links
56  // Add links to RDF documents with descriptions of the blank nodes
57  Resource r = model.getResource(controller.getAbsoluteIRI());
58  StmtIterator it = r.listProperties();
59  while (it.hasNext()) {
60  Statement stmt = it.nextStatement();
61  if (!stmt.getObject().isAnon()) continue;
62  String pathDataURL = controller.getValuesDataURL(stmt.getPredicate());
63  if (pathDataURL == null) continue;
64  ((Resource) stmt.getResource()).addProperty(RDFS.seeAlso,
65  model.createResource(pathDataURL));
66  }
67  it = model.listStatements(null, null, r);
68  while (it.hasNext()) {
69  Statement stmt = it.nextStatement();
70  if (!stmt.getSubject().isAnon()) continue;
71  String pathDataURL = controller.getInverseValuesDataURL(stmt.getPredicate());
72  if (pathDataURL == null) continue;
73  ((Resource) stmt.getSubject().as(Resource.class)).addProperty(RDFS.seeAlso,
74  model.createResource(pathDataURL));
75  }
76  }

References HypermediaControls.getAbsoluteIRI(), HypermediaControls.getInverseValuesDataURL(), and HypermediaControls.getValuesDataURL().

Referenced by 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
protected

Reimplemented from BaseServlet.

29  {
30  HypermediaControls controller = config.getControls(relativeURI, false);
31 
32  ResourceDescription description = controller == null ?
33  null : controller.getResourceDescription();
34  // Check if resource exists in dataset
35  if (description == null) {
36  response.setStatus(404);
37  response.setContentType("text/plain");
38  response.getOutputStream().println("Nothing known about <" + controller.getAbsoluteIRI() + ">");
39  return true;
40  }
41  Model model = description.getModel();
42 
43  addHighDegreePropertyLinks(model, controller);
44 
45  addDocumentMetadata(model, controller,
46  addQueryString(controller.getDataURL(), request),
47  "RDF description of " + description.getTitle());
48 
49  ModelResponse server = new ModelResponse(model, request, response);
50  server.serve();
51  return true;
52  }
HypermediaControls getControls(String relativeRequestURI, boolean isRelativeToPubbyRoot)
Definition: Configuration.java:210
ResourceDescription getResourceDescription()
Definition: HypermediaControls.java:112
Model getModel()
Definition: ResourceDescription.java:276
String addQueryString(String dataURL, HttpServletRequest request)
Definition: BaseServlet.java:161
void addDocumentMetadata(Model model, HypermediaControls controller, String documentURL, String title)
Definition: BaseServlet.java:53
void addHighDegreePropertyLinks(Model model, HypermediaControls controller)
Definition: DataURLServlet.java:54

References BaseServlet.addDocumentMetadata(), DataURLServlet.addHighDegreePropertyLinks(), BaseServlet.addQueryString(), BaseServlet.config, HypermediaControls.getAbsoluteIRI(), Configuration.getControls(), HypermediaControls.getDataURL(), ResourceDescription.getModel(), HypermediaControls.getResourceDescription(), ResourceDescription.getTitle(), and ModelResponse.serve().

◆ 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
String getWebApplicationBaseURI()
Definition: Configuration.java:269

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 = 6825866213915066364L
staticprivate