[Mulgara-svn] r1658 - in trunk/src/jar/web: . java/org/mulgara/webquery resources
pag at mulgara.org
pag at mulgara.org
Mon Apr 6 17:47:49 UTC 2009
Author: pag
Date: 2009-04-06 10:47:48 -0700 (Mon, 06 Apr 2009)
New Revision: 1658
Modified:
trunk/src/jar/web/build.xml
trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java
trunk/src/jar/web/java/org/mulgara/webquery/Template.java
trunk/src/jar/web/resources/debug.html
trunk/src/jar/web/resources/template.html
trunk/src/jar/web/resources/template_head.html
trunk/src/jar/web/resources/tutorial.html
trunk/src/jar/web/resources/tutorial_head.html
Log:
Updated links to handle different deployment scenarios
Modified: trunk/src/jar/web/build.xml
===================================================================
--- trunk/src/jar/web/build.xml 2009-04-06 16:34:43 UTC (rev 1657)
+++ trunk/src/jar/web/build.xml 2009-04-06 17:47:48 UTC (rev 1658)
@@ -63,7 +63,7 @@
</target>
<target name="web-compile"
- depends="-web-prepare, util-jar, config-jar, querylang-jar, query-jar, -web-unjar-config"
+ depends="-web-prepare, util-jar, config-jar, querylang-jar, query-jar, -web-unjar-config, server-jar"
description="Compiles all web related files included generated
source code"
unless="web.classes.uptodate">
Modified: trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java
===================================================================
--- trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java 2009-04-06 16:34:43 UTC (rev 1657)
+++ trunk/src/jar/web/java/org/mulgara/webquery/QueryServlet.java 2009-04-06 17:47:48 UTC (rev 1658)
@@ -81,6 +81,9 @@
/** Serialization by default */
private static final long serialVersionUID = -8407263937557243990L;
+ /** This path is needed to help with variations in different servlet environments. */
+ public static final String SERVLET_PATH = "/webui";
+
/** Session value for the TQL interpreter. */
private static final String TQL_INTERPRETER = "session.tql.interpreter";
@@ -111,10 +114,12 @@
/** Debugging text. */
private String debugText = "";
+ /** The path of the base servlet. */
+ private String basePath = SERVLET_PATH;
+
/** Indicates if this servlet has been initialized. */
private boolean initialized = false;
-
/**
* Creates the servlet for the named host.
* @param hostname The host name to use, or <code>null</code> if this is not known.
@@ -171,17 +176,19 @@
* @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
- String path = req.getPathInfo();
+ String path = req.getRequestURI();
+ basePath = calcBasePath(path);
debugText = path;
// case analysis for request type
String ext = getExtension(path);
if (ext.equals(".jpg") || ext.equals(".png") || ext.equals(".jpeg")) {
resp.setContentType("image/jpeg");
- new ResourceBinaryFile(path).sendTo((OutputStream)resp.getOutputStream());
+ new ResourceBinaryFile(relPath(path)).sendTo((OutputStream)resp.getOutputStream());
} else if (ext.equals(".css")) {
resp.setContentType("text/css");
- new ResourceBinaryFile(path).sendTo(resp.getOutputStream());
+ new ResourceBinaryFile(relPath(path)).sendTo(resp.getOutputStream());
} else {
+
// file request
resp.setContentType("text/html");
resp.setHeader("pragma", "no-cache");
@@ -208,7 +215,9 @@
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
- if (!req.getPathInfo().startsWith("/" + EXECUTE_LINK)) {
+ log("POST request: " + req);
+ basePath = calcBasePath(req.getRequestURI());
+ if (!req.getRequestURI().contains("/" + EXECUTE_LINK)) {
resp.sendError(SC_BAD_REQUEST, "Sent a command to the wrong page.");
return;
}
@@ -585,12 +594,13 @@
* the second string is the value to repace the tag with.
*/
private String[][] getTemplateTags() {
- return new String[][] {
+ return new String[][] {
new String[] {HOSTNAME_TAG, hostname},
new String[] {SERVERNAME_TAG, servername},
new String[] {JARURL_TAG, resourcePath},
new String[] {EXECUTE_TAG, EXECUTE_LINK},
new String[] {DEBUG_TAG, debugText},
+ new String[] {BASE_PATH_TAG, basePath}
};
}
@@ -722,13 +732,37 @@
* @return The extension, including the . character. If there is no extension, then an empty string.
*/
private static String getExtension(String path) {
+ if (path == null) return "";
int dot = path.lastIndexOf('.');
if (dot < 0) return "";
return path.substring(dot);
}
+
+ private String calcBasePath(String fullpath) {
+ if (!fullpath.contains(SERVLET_PATH)) return "/";
+ return fullpath.substring(0, fullpath.indexOf(SERVLET_PATH) + SERVLET_PATH.length()) + "/";
+ }
+
+
/**
+ * Returns a relative path, starting from a given base.
+ * @param full The full path to be truncated.
+ * @return The new relative path.
+ */
+ private String relPath(String full) {
+ if (full.startsWith(basePath)) {
+ log("Calculating relpath for: " + full + " | " + basePath);
+ String path = full.substring(basePath.length());
+ return path.startsWith("/") ? path : "/" + path;
+ }
+ log("Path does not start with base: " + full + " | " + basePath);
+ return full;
+ }
+
+
+ /**
* Registerable Interpreter. This contains a factory for an interpreter, plus the name it should
* be registered under.
*/
Modified: trunk/src/jar/web/java/org/mulgara/webquery/Template.java
===================================================================
--- trunk/src/jar/web/java/org/mulgara/webquery/Template.java 2009-04-06 16:34:43 UTC (rev 1657)
+++ trunk/src/jar/web/java/org/mulgara/webquery/Template.java 2009-04-06 17:47:48 UTC (rev 1658)
@@ -55,6 +55,9 @@
/** The tag to replace in the template file for the user-set graph URI. */
public static final String GRAPH_TAG = "graph";
+ /** The tag to replace in the template file for the base path of the application. */
+ public static final String BASE_PATH_TAG = "base";
+
/** The amount of indenting to use for the rows in the template. */
public static final int ROW_INDENT = 8;
Modified: trunk/src/jar/web/resources/debug.html
===================================================================
--- trunk/src/jar/web/resources/debug.html 2009-04-06 16:34:43 UTC (rev 1657)
+++ trunk/src/jar/web/resources/debug.html 2009-04-06 17:47:48 UTC (rev 1658)
@@ -9,7 +9,7 @@
<div id="wrapper">
<div id="header">
<div id="logo">
- <a href="http://mulgara.org/"><img src="images/logo.jpg" alt="Mulgara - Semantic Store" border="0" /></a>
+ <a href="http://mulgara.org/"><img src="@@base@@images/logo.jpg" alt="Mulgara - Semantic Store" border="0" /></a>
</div>
</div>
<div id="content">
Modified: trunk/src/jar/web/resources/template.html
===================================================================
--- trunk/src/jar/web/resources/template.html 2009-04-06 16:34:43 UTC (rev 1657)
+++ trunk/src/jar/web/resources/template.html 2009-04-06 17:47:48 UTC (rev 1658)
@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Mulgara Viewer</title>
- <link href="styles/ui.css" rel="stylesheet" type="text/css" />
+ <link href="@@base@@styles/ui.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript">
<!--
// Validate the form and submit it if all is OK
@@ -47,7 +47,7 @@
<div id="wrapper">
<div id="header">
<div id="logo">
- <a href="http://mulgara.org/"><img src="images/logo.jpg" alt="Mulgara - Semantic Store" border="0" /></a>
+ <a href="http://mulgara.org/"><img src="@@base@@images/logo.jpg" alt="Mulgara - Semantic Store" border="0" /></a>
</div>
</div>
<div id="content">
@@ -55,7 +55,7 @@
<tr>
<td>
<table class="queryTable" summary="Enter a query">
- <form action="@@execute@@" method="post" name="QueryForm">
+ <form action="@@base@@@@execute@@" method="post" name="QueryForm">
<tr>
<td><strong>Graph URI:</strong> </td>
<td><input name="GraphURI" size="60" type="text" value=""/> </td>
Modified: trunk/src/jar/web/resources/template_head.html
===================================================================
--- trunk/src/jar/web/resources/template_head.html 2009-04-06 16:34:43 UTC (rev 1657)
+++ trunk/src/jar/web/resources/template_head.html 2009-04-06 17:47:48 UTC (rev 1658)
@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Mulgara Viewer</title>
- <link href="styles/ui.css" rel="stylesheet" type="text/css" />
+ <link href="@@base@@styles/ui.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript">
<!--
// Validate the form and submit it if all is OK
@@ -47,7 +47,7 @@
<div id="wrapper">
<div id="header">
<div id="logo">
- <a href="http://mulgara.org/"><img src="images/logo.jpg" alt="Mulgara - Semantic Store" border="0" /></a>
+ <a href="http://mulgara.org/"><img src="@@base@@images/logo.jpg" alt="Mulgara - Semantic Store" border="0" /></a>
</div>
</div>
<div id="content">
@@ -55,7 +55,7 @@
<tr>
<td>
<table class="queryTable" summary="Enter a query">
- <form action="@@execute@@.html" method="post" name="QueryForm">
+ <form action="@@base@@@@execute@@.html" method="post" name="QueryForm">
<tr>
<td><strong>Graph URI:</strong> </td>
<td><input name="GraphURI" size="60" type="text" value="@@graph@@"/> </td>
Modified: trunk/src/jar/web/resources/tutorial.html
===================================================================
--- trunk/src/jar/web/resources/tutorial.html 2009-04-06 16:34:43 UTC (rev 1657)
+++ trunk/src/jar/web/resources/tutorial.html 2009-04-06 17:47:48 UTC (rev 1658)
@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Mulgara Tutorial</title>
- <link href="styles/ui.css" rel="stylesheet" type="text/css" />
+ <link href="@@base@@styles/ui.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript">
<!--
// Put the selected example query into the query text area. The graph
@@ -47,14 +47,14 @@
<div id="wrapper">
<div id="header">
<div id="logo">
- <a href="http://mulgara.org/"><img src="images/logo.jpg" alt="Mulgara - Semantic Store" border="0" /></a>
+ <a href="http://mulgara.org/"><img src="@@base@@images/logo.jpg" alt="Mulgara - Semantic Store" border="0" /></a>
</div>
</div>
<div id="content">
<table class="formatTable" summary="">
<tr>
<td>
- <form action="@@execute@@" method="post" name="QueryForm">
+ <form action="@@base@@@@execute@@" method="post" name="QueryForm">
<table class="queryTable" summary="Enter a query">
<tr>
<td><strong>Graph URI:</strong> </td>
Modified: trunk/src/jar/web/resources/tutorial_head.html
===================================================================
--- trunk/src/jar/web/resources/tutorial_head.html 2009-04-06 16:34:43 UTC (rev 1657)
+++ trunk/src/jar/web/resources/tutorial_head.html 2009-04-06 17:47:48 UTC (rev 1658)
@@ -6,7 +6,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Mulgara Tutorial</title>
- <link href="styles/ui.css" rel="stylesheet" type="text/css" />
+ <link href="@@base@@styles/ui.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript">
<!--
// Put the selected example query into the query text area. The graph
@@ -47,14 +47,14 @@
<div id="wrapper">
<div id="header">
<div id="logo">
- <a href="http://mulgara.org/"><img src="images/logo.jpg" alt="Mulgara - Semantic Store" border="0" /></a>
+ <a href="http://mulgara.org/"><img src="@@base@@images/logo.jpg" alt="Mulgara - Semantic Store" border="0" /></a>
</div>
</div>
<div id="content">
<table class="formatTable" summary="">
<tr>
<td>
- <form action="@@execute@@.html" method="post" name="QueryForm">
+ <form action="@@base@@@@execute@@.html" method="post" name="QueryForm">
<table class="queryTable" summary="Enter a query">
<tr>
<td><strong>Graph URI:</strong> </td>
More information about the Mulgara-svn
mailing list