version 1.13, 2001/09/19 20:41:34
|
version 1.14, 2001/09/24 17:01:04
|
Line 70 import java.net.MalformedURLException;
|
Line 70 import java.net.MalformedURLException;
|
import java.net.URL; |
import java.net.URL; |
import java.util.StringTokenizer; |
import java.util.StringTokenizer; |
import java.util.Enumeration; |
import java.util.Enumeration; |
|
import java.util.Hashtable; |
import javax.servlet.*; |
import javax.servlet.*; |
import javax.servlet.http.*; |
import javax.servlet.http.*; |
|
|
Line 179 public class ARPServlet extends HttpServ
|
Line 180 public class ARPServlet extends HttpServ
|
// Name for the DOT file title |
// Name for the DOT file title |
private static final String DOT_TITLE = "dotfile"; |
private static final String DOT_TITLE = "dotfile"; |
|
|
|
// The string to use for to prefix anonymous nodes. |
|
private static final String ANON_NODE = "genid:"; |
|
|
// The string to use for a namespace name when no |
// The string to use for a namespace name when no |
// namespace is available - e.g. for the RDF that is |
// namespace is available - e.g. for the RDF that is |
// directly entered into the input form. |
// directly entered into the input form. |
private static final String DEFAULT_NAMESPACE = "genid:"; |
private static final String DEFAULT_NAMESPACE = "online:"; |
|
|
/* |
/* |
* Create a File object in the m_ServletTmpDir directory |
* Create a File object from the given directory and file names |
* |
* |
*@param directory the file's directory |
*@param directory the file's directory |
*@param prefix the file's prefix name (not its directory) |
*@param prefix the file's prefix name (not its directory) |
Line 249 public class ARPServlet extends HttpServ
|
Line 253 public class ARPServlet extends HttpServ
|
* This is only done if the servlet is explictly asked to save |
* This is only done if the servlet is explictly asked to save |
* the RDF to a file. |
* the RDF to a file. |
* |
* |
*@param dir the file's directory |
*@param tmpDir the file's directory |
*@param rdf the string of RDF |
*@param rdf the string of RDF |
*/ |
*/ |
private void copyRDFStringToFile(String tmpDir, String rdf) |
private void copyRDFStringToFile(String tmpDir, String rdf) |
Line 308 public class ARPServlet extends HttpServ
|
Line 312 public class ARPServlet extends HttpServ
|
* |
* |
*@param dotFileName the name of the DOT data file |
*@param dotFileName the name of the DOT data file |
*@param outputFileName the name of the output data file |
*@param outputFileName the name of the output data file |
|
*@param graphFormat the graph's format |
*@return true if success; false if any failure occurs |
*@return true if success; false if any failure occurs |
*/ |
*/ |
private boolean generateGraphFile(String dotFileName, |
private boolean generateGraphFile(String dotFileName, |
Line 336 public class ARPServlet extends HttpServ
|
Line 341 public class ARPServlet extends HttpServ
|
* value. |
* value. |
* |
* |
*@param req a Servlet request |
*@param req a Servlet request |
|
*@param param the name of the parameter |
|
*@param defString the string returned if the param is not found |
*@return if the request contains the specfied parameter its value |
*@return if the request contains the specfied parameter its value |
* in the request is returned; otherwise its default value is |
* in the request is returned; otherwise its default value is |
* returned |
* returned |
Line 352 public class ARPServlet extends HttpServ
|
Line 359 public class ARPServlet extends HttpServ
|
* to the graph consumer for handling |
* to the graph consumer for handling |
* |
* |
*@param req the response |
*@param req the response |
|
*@param pw the PrintWriter |
*@param consumer the GraphViz consumer |
*@param consumer the GraphViz consumer |
*/ |
*/ |
private void processGraphParameters (HttpServletRequest req, PrintWriter pw) |
private void processGraphParameters (HttpServletRequest req, PrintWriter pw) |
{ |
{ |
// Print the graph header |
// Print the graph header |
pw.println("digraph " + DOT_TITLE + "{ " ); |
pw.println("digraph " + DOT_TITLE + "{ " ); |
Line 646 public class ARPServlet extends HttpServ
|
Line 654 public class ARPServlet extends HttpServ
|
* |
* |
*@param out the servlet's output stream |
*@param out the servlet's output stream |
*@param rdf the RDF code |
*@param rdf the RDF code |
|
*@param needCR if true, add a CarriageReturn to the output; if false, |
|
* do not add it |
*/ |
*/ |
private void printListing (ServletOutputStream out, String rdf, |
private void printListing (ServletOutputStream out, String rdf, |
boolean needCR) |
boolean needCR) |
Line 685 public class ARPServlet extends HttpServ
|
Line 695 public class ARPServlet extends HttpServ
|
* Print the header for the triple listing |
* Print the header for the triple listing |
* |
* |
*@param out the servlet's output stream |
*@param out the servlet's output stream |
|
*@param nTriples if true, output is N-Triples syntax |
*/ |
*/ |
private void printTripleTableHeader (ServletOutputStream out, boolean nTriples) |
private void printTripleTableHeader (ServletOutputStream out, boolean nTriples) |
{ |
{ |
Line 713 public class ARPServlet extends HttpServ
|
Line 724 public class ARPServlet extends HttpServ
|
* Print the footer info for the triple listing |
* Print the footer info for the triple listing |
* |
* |
*@param out the servlet's output stream |
*@param out the servlet's output stream |
|
*@param nTriples if true, output is N-Triples syntax |
*/ |
*/ |
private void printTripleTableFooter (ServletOutputStream out, |
private void printTripleTableFooter (ServletOutputStream out, |
boolean nTriples) |
boolean nTriples) |
Line 953 public class ARPServlet extends HttpServ
|
Line 965 public class ARPServlet extends HttpServ
|
* Create a HTML anchor from the URI or anonNode of the |
* Create a HTML anchor from the URI or anonNode of the |
* given Resource |
* given Resource |
* |
* |
*@param s the string |
*@param r the Resource |
*@return the string as an HTML anchor |
*@return the string as an HTML anchor |
*/ |
*/ |
static private String addAnchor(AResource r) |
static private String addAnchor(AResource r) |
{ |
{ |
if (r.isAnonymous()) |
if (r.isAnonymous()) |
return DEFAULT_NAMESPACE + r.getAnonymousID(); |
return ANON_NODE + r.getAnonymousID(); |
else |
else |
return "<a href='" + r.getURI() + "'>" + r.getURI() + "</a>"; |
return "<a href='" + r.getURI() + "'>" + r.getURI() + "</a>"; |
} |
} |
Line 1005 public class ARPServlet extends HttpServ
|
Line 1017 public class ARPServlet extends HttpServ
|
boolean printTriples; |
boolean printTriples; |
boolean printGraph; |
boolean printGraph; |
boolean anonNodesEmpty; |
boolean anonNodesEmpty; |
int numStatements = 0; |
int numStatements; |
int numLiterals = 0; |
int numLiterals; |
|
Hashtable subjects; |
|
int numSubjects; |
|
|
/* |
/* |
* Constructuor for the StatementHandler. The primary |
* Constructuor for the StatementHandler. The primary |
Line 1029 public class ARPServlet extends HttpServ
|
Line 1043 public class ARPServlet extends HttpServ
|
this.printTriples = printTriples; |
this.printTriples = printTriples; |
this.printGraph = printGraph; |
this.printGraph = printGraph; |
this.anonNodesEmpty = anonNodesEmpty; |
this.anonNodesEmpty = anonNodesEmpty; |
|
|
|
this.numStatements = 0; |
|
this.numLiterals = 0; |
|
|
|
this.subjects = new Hashtable(); |
|
this.numSubjects = 0; |
} |
} |
|
|
/* |
/* |
Line 1110 public class ARPServlet extends HttpServ
|
Line 1130 public class ARPServlet extends HttpServ
|
*/ |
*/ |
public void printFirstPart(AResource subj) |
public void printFirstPart(AResource subj) |
{ |
{ |
if (subj.isAnonymous()) { |
if (subj.isAnonymous()) { |
if (this.anonNodesEmpty) { |
if (this.anonNodesEmpty) { |
this.pw.println("\"" + DEFAULT_NAMESPACE + |
Integer n = (Integer) subjects.get(subj.getAnonymousID()); |
subj.getAnonymousID() + "\" [label=\" \"];"); |
if (n == null) { |
|
this.numSubjects++; |
|
subjects.put(subj.getAnonymousID(), new Integer(this.numSubjects)); |
|
this.pw.println("\"" + ANON_NODE + |
|
subj.getAnonymousID() + "\" [label=\" \"];"); |
|
} |
} |
} |
this.pw.print("\"" + DEFAULT_NAMESPACE + subj.getAnonymousID()); |
this.pw.print("\"" + ANON_NODE + subj.getAnonymousID()); |
} else { |
} else { |
this.pw.println("\"" + subj.getURI() + "\" [URL=\"" + |
this.pw.println("\"" + subj.getURI() + "\" [URL=\"" + |
subj.getURI() + "\"];"); |
subj.getURI() + "\"];"); |
Line 1123 public class ARPServlet extends HttpServ
|
Line 1148 public class ARPServlet extends HttpServ
|
} |
} |
} |
} |
|
|
/* |
|
* Print the second part of a triple's Dot file. See below for |
|
* more info. This is the same regardless if the triple's |
|
* object is a Resource or a Literal |
|
* |
|
*@param pred the subject |
|
*/ |
|
public void printSecondPart(AResource pred) |
|
{ |
|
if (pred.isAnonymous()) { |
|
// Anonymous predicates? Nothing in the M&S spec |
|
// prohibits them so handle it just in case ... |
|
if (this.anonNodesEmpty) { |
|
this.pw.println("\"" + DEFAULT_NAMESPACE + |
|
pred.getAnonymousID() + "\" [label=\" \"];"); |
|
} else { |
|
this.pw.println("\" [label=\"" + DEFAULT_NAMESPACE + |
|
pred.getAnonymousID() + "\"];"); |
|
} |
|
} else { |
|
this.pw.println("\" [label=\"" + pred.getURI() + "\",URL=\"" + |
|
pred.getURI() + "\"];"); |
|
} |
|
} |
|
|
|
/* |
/* |
* Handler for a Resource/Resource/Resource triple (S/P/O). |
* Handler for a Resource/Resource/Resource triple (S/P/O). |
* Outputs the given triple using Dot syntax. |
* Outputs the given triple using Dot syntax. |
Line 1175 public class ARPServlet extends HttpServ
|
Line 1175 public class ARPServlet extends HttpServ
|
|
|
if (obj.isAnonymous()) { |
if (obj.isAnonymous()) { |
if (this.anonNodesEmpty) { |
if (this.anonNodesEmpty) { |
this.pw.println("\"" + DEFAULT_NAMESPACE + |
this.pw.println("\"" + ANON_NODE + |
obj.getAnonymousID() + "\" [label=\" \"];"); |
obj.getAnonymousID() + "\" [label=\" \"];"); |
} else { |
} else { |
this.pw.print("\"" + DEFAULT_NAMESPACE + obj.getAnonymousID()); |
this.pw.println("\"" + ANON_NODE + obj.getAnonymousID() + "\";"); |
} |
} |
} else { |
} else { |
this.pw.print("\"" + obj.getURI()); |
this.pw.println("\"" + obj.getURI() + "\" [label=\"" + |
} |
pred.getURI() + "\",URL=\"" + pred.getURI() + "\"];"); |
|
|
printSecondPart(pred); |
|
|
|
if (obj.isAnonymous()) { |
|
if (this.anonNodesEmpty) { |
|
this.pw.println("\"" + DEFAULT_NAMESPACE + |
|
obj.getAnonymousID() + "\" [label=\" \"];"); |
|
} else { |
|
this.pw.println("\"" + DEFAULT_NAMESPACE + |
|
obj.getAnonymousID() + "\";"); |
|
} |
|
} else { |
|
this.pw.println("\"" + obj.getURI() + "\" [URL=\"" + |
this.pw.println("\"" + obj.getURI() + "\" [URL=\"" + |
obj.getURI() + "\"];"); |
obj.getURI() + "\"];"); |
} |
} |
} |
} |
|
|
/* |
/* |
Line 1251 public class ARPServlet extends HttpServ
|
Line 1239 public class ARPServlet extends HttpServ
|
String tmpName = "Literal_" + Integer.toString(this.numLiterals); |
String tmpName = "Literal_" + Integer.toString(this.numLiterals); |
this.pw.print("\" -> \"" + tmpName); |
this.pw.print("\" -> \"" + tmpName); |
|
|
printSecondPart(pred); |
this.pw.println("\" [label=\"" + pred.getURI() + |
|
"\",URL=\"" + pred.getURI() + "\"];"); |
|
|
this.pw.println("\"" + tmpName + "\" [shape=box,label=\"" + tmpObject + "\"];"); |
this.pw.println("\"" + tmpName + "\" [shape=box,label=\"" + tmpObject + "\"];"); |
} |
} |