GeoPubby  Version 0.1.0.0
GeoBrowserServlet Class Reference
Inheritance diagram for GeoBrowserServlet:
Collaboration diagram for GeoBrowserServlet:

Public Member Functions

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

Protected Member Functions

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 = 7594710471966527559L
 

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,
final Configuration  config 
) throws ServletException, IOException

Reimplemented from BaseServlet.

21  {
22 
23  VelocityHelper template = new VelocityHelper(getServletContext(), response);
24  Context context = template.getVelocityContext();
25  context.put("project_name", config.getProjectName());
26  context.put("project_link", config.getProjectLink());
27  List<String> sources=new LinkedList<String>();
28  List<String> sourceURLs=new LinkedList<String>();
29  for(Dataset ds:config.getDatasets()) {
30  sources.add(ds.sparqlEndpoint);
31  sourceURLs.add(ds.datasetBase);
32  }
33  context.put("endpoint", sources);
34  context.put("labelprops", config.getLabelProperties());
35  context.put("typeprops", config.getTypeProperties());
36  context.put("geoprops", config.getGeoProperties());
37  context.put("crsprops", config.getCrsProperties());
38  context.put("sourceURLs", sourceURLs);
39  context.put("server_base", config.getWebApplicationBaseURI());
40  template.renderXHTML("geobrowser.vm");
41  return true;
42  }
Collection< Property > getTypeProperties()
Definition: Configuration.java:237
String getProjectName()
Definition: Configuration.java:265
Collection< Property > getLabelProperties()
Definition: Configuration.java:225
Collection< Property > getCrsProperties()
Definition: Configuration.java:233
Collection< Property > getGeoProperties()
Definition: Configuration.java:229
String getProjectLink()
Definition: Configuration.java:261
String getWebApplicationBaseURI()
Definition: Configuration.java:269

References BaseServlet.config, Configuration.getCrsProperties(), Configuration.getDatasets(), Configuration.getGeoProperties(), Configuration.getLabelProperties(), Configuration.getProjectLink(), Configuration.getProjectName(), Configuration.getTypeProperties(), and Configuration.getWebApplicationBaseURI().

◆ 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  }

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 = 7594710471966527559L
staticprivateinherited