[Mulgara-svn] r1489 - in trunk/src/jar: content-mbox/java/org/mulgara/content/mbox content-mbox/java/org/mulgara/content/mbox/parser/model/impl content-mp3/java/org/mulgara/content/mp3 content-rdfxml/java/org/mulgara/content/rdfxml resolver/java/org/mulgara/resolver resolver-spi/java/org/mulgara/content
pag at mulgara.org
pag at mulgara.org
Fri Feb 13 07:05:37 UTC 2009
Author: pag
Date: 2009-02-12 23:05:36 -0800 (Thu, 12 Feb 2009)
New Revision: 1489
Modified:
trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxContentHandler.java
trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxStatements.java
trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxStatementsUnitTest.java
trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/parser/model/impl/MBoxImpl.java
trunk/src/jar/content-mp3/java/org/mulgara/content/mp3/MP3ContentHandler.java
trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/Parser.java
trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLContentHandler.java
trunk/src/jar/resolver-spi/java/org/mulgara/content/ContentResolver.java
trunk/src/jar/resolver/java/org/mulgara/resolver/ContentHandlerManagerImpl.java
Log:
Safe printing of content URIs and at fixups
Modified: trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxContentHandler.java
===================================================================
--- trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxContentHandler.java 2009-02-13 06:58:23 UTC (rev 1488)
+++ trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxContentHandler.java 2009-02-13 07:05:36 UTC (rev 1489)
@@ -30,12 +30,7 @@
// Java 2 standard packages
import java.io.*;
import java.net.URI;
-import java.util.Map;
-// Java 2 enterprise packages
-import javax.activation.MimeType;
-import javax.activation.MimeTypeParseException;
-
// Third party packages
import org.apache.log4j.Logger; // Apache Log4J
@@ -72,23 +67,7 @@
/** Logger. */
private static Logger log = Logger.getLogger(MBoxContentHandler.class);
- /**
- * The MIME type of MBoxes.
- */
- private static final MimeType TEXT_MAILBOX;
- static {
-
- try {
-
- // Create the mime type to represent mailboxes
- TEXT_MAILBOX = new MimeType("text", "mailbox");
- } catch (MimeTypeParseException e) {
-
- throw new ExceptionInInitializerError(e);
- }
- }
-
/**
* Parses the messages of an mbox file pointed to by the content object which
* are then converted to a statements object.
@@ -113,7 +92,7 @@
} catch (TuplesException tuplesException) {
throw new ContentHandlerException("Unable to create statements object from " +
- "content object: " + content.getURI().toString(),
+ "content object: " + content.getURIString(),
tuplesException);
}
@@ -127,52 +106,43 @@
public boolean canParse(Content content) throws NotModifiedException {
if (content.getClass().getName().equals("org.mulgara.resolver.StreamContent")) {
-
log.info("Unable to parse streaming content in mbox content handler.");
-
return false;
}
- // Get the mime type of the content object
- MimeType contentType = content.getContentType();
+ // Ignoring the MIME type
- //if (contentType != null && TEXT_MAILBOX.match(contentType)) {
+ // Container for our input stream from the mbox file
+ InputStream inputStream = null;
- // If the mime type matches an mbox then check the first line to see if it
- // is a valid format
+ try {
- // Container for our input stream from the mbox file
- InputStream inputStream = null;
+ // Obtain the input stream to our file
+ inputStream = content.newInputStream();
+ } catch (NotModifiedException e) {
+ // Not only CAN we parse this, we already have
+ return true;
+ } catch (IOException ioException) {
- try {
+ // If we can't obtain an input stream, chances are our mbox file has
+ // problems and is most likely invalid and non-parsable
+ return false;
+ }
- // Obtain the input stream to our file
- inputStream = content.newInputStream();
- } catch (NotModifiedException e) {
- // Not only CAN we parse this, we already have
- return true;
- } catch (IOException ioException) {
+ try {
- // If we can't obtain an input stream, chances are our mbox file has
- // problems and is most likely invalid and non-parsable
- return false;
- }
+ // Attempt to validate the inputStream to the file in order to validate
+ // that we are working with an MBox
+ validate(inputStream, content.getURI());
+ } catch (InvalidMBoxException invalidMBoxException) {
- try {
+ // If the mbox is in an invalid format then we can't use it so state
+ // that we can't parse it
+ return false;
+ }
- // Attempt to validate the inputStream to the file in order to validate
- // that we are working with an MBox
- validate(inputStream, content.getURI());
- } catch (InvalidMBoxException invalidMBoxException) {
-
- // If the mbox is in an invalid format then we can't use it so state
- // that we can't parse it
- return false;
- }
-
- return true;
- //}
+ return true;
}
/**
@@ -202,11 +172,12 @@
private void validate(InputStream stream, URI uri) throws InvalidMBoxException {
if (stream == null) {
-
// The mbox file cannot be null
throw new InvalidMBoxException("Cannot parse null mbox objects.");
}
+ String file = (uri == null) ? "<<stream>>" : uri.toString();
+
// Create an input stream reader
InputStreamReader inputReader = new InputStreamReader(stream);
@@ -226,7 +197,7 @@
} catch (IOException ioException) {
// We could not read the mbox file
- throw new InvalidMBoxException("MBox file [" + uri.toString() +
+ throw new InvalidMBoxException("MBox file [" + file +
"] was not able to be read from.",
ioException);
}
@@ -234,7 +205,7 @@
if (!line.toLowerCase().startsWith("from ")) {
// The mbox is not RFC822 compliant
- throw new InvalidMBoxException("MBox file [" + uri.toString() +
+ throw new InvalidMBoxException("MBox file [" + file +
"] was not a valid RFC822 mbox.");
} else {
@@ -245,7 +216,7 @@
} catch (IOException ioException) {
// We could not read the mbox file
- throw new InvalidMBoxException("MBox file [" + uri.toString() +
+ throw new InvalidMBoxException("MBox file [" + file +
"] was not able to be read from.",
ioException);
}
@@ -253,7 +224,7 @@
!line.split(" ")[0].endsWith(":")) {
// The mbox is not RFC822 compliant if the next line is not a header
- throw new InvalidMBoxException("MBox file [" + uri.toString() +
+ throw new InvalidMBoxException("MBox file [" + file +
"] was not a valid RFC822 mbox.");
}
}
Modified: trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxStatements.java
===================================================================
--- trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxStatements.java 2009-02-13 06:58:23 UTC (rev 1488)
+++ trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxStatements.java 2009-02-13 07:05:36 UTC (rev 1489)
@@ -28,35 +28,23 @@
package org.mulgara.content.mbox;
// Java 2 standard packages
-import java.io.*;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
import java.net.MalformedURLException;
+import java.net.URL;
import java.util.*;
-import org.xml.sax.*;
// Third party packages
import org.jrdf.graph.*;
-import org.jrdf.graph.mem.*;
import org.apache.log4j.Logger; // Apache Log4J
-import org.jrdf.graph.*; // JRDF
-import org.jrdf.util.ClosableIterator; // JRDF
-import org.jrdf.graph.*; // JRDF
// Locally written packages
import org.mulgara.content.*;
import org.mulgara.content.mbox.parser.model.*;
import org.mulgara.content.mbox.parser.model.exception.*;
-import org.mulgara.query.Constraint;
-import org.mulgara.query.QueryException;
import org.mulgara.query.TuplesException;
import org.mulgara.query.Variable;
-import org.mulgara.query.rdf.*;
import org.mulgara.resolver.spi.LocalizeException;
import org.mulgara.resolver.spi.ResolverSession;
import org.mulgara.resolver.spi.Statements;
-import org.mulgara.store.StoreException;
import org.mulgara.store.tuples.AbstractTuples;
import org.mulgara.store.tuples.Tuples;
@@ -96,9 +84,6 @@
/** The session used to globalize the RDF nodes from the stream. */
private ResolverSession resolverSession;
- /** The queue of triples generated by the MBox parser. */
- private ArrayList triples;
-
/** The number of statements in the MBox data. */
private long rowCount;
@@ -114,11 +99,8 @@
/** The location of the MBox file. */
private URL url;
- /** The model which will store the content of parsed mbox files */
- private Graph model;
-
/** The mapping of blank nodes to their localised value */
- protected static HashMap blankNodeMap;
+ protected static HashMap<Node,Long> blankNodeMap;
/** The content object containing information about the mbox file */
private Content content;
@@ -154,9 +136,12 @@
}
// Initialize fields
- this.url = url;
+ try {
+ this.url = content.getURI() == null ? null : content.getURI().toURL();
+ } catch (MalformedURLException e) {
+ this.url = null;
+ }
this.resolverSession = resolverSession;
- this.triples = new ArrayList();
// Store the content object
this.content = content;
@@ -172,7 +157,7 @@
}
// Initialise blank node map
- blankNodeMap = new HashMap();
+ blankNodeMap = new HashMap<Node,Long>();
// Load in the RDF conversion of the given mbox url
loadMBox();
@@ -188,104 +173,75 @@
*/
private void loadMBox() throws NotModifiedException, TuplesException {
- if (logger.isInfoEnabled()) {
+ if (logger.isInfoEnabled()) logger.info("!! Loading in mbox data");
- logger.info("!! Loading in mbox data");
- }
-
- // Discard any existing statements
- triples.clear();
-
- // Initialise the blank node map
- //blankNodeMap = new HashMap();
-
if (mboxManager == null) {
// Container for the model factory
ModelFactory factory = null;
try {
-
factory = ModelFactory.getInstance();
} catch (FactoryException factoryException) {
-
- throw new TuplesException(
- "Unable to initialise factory to create MBox " +
- "parser.", factoryException);
+ throw new TuplesException("Unable to initialise factory to create MBox parser.", factoryException);
}
try {
-
// Initialise the mbox object using the factory
mboxManager = factory.createMBoxManager();
} catch (FactoryException factoryException) {
-
- throw new TuplesException("Unable to create a new mbox manager.",
- factoryException);
+ throw new TuplesException("Unable to create a new mbox manager.", factoryException);
}
}
try {
-
// Get the mbox for our contentStream
mbox = mboxManager.getMBox(content);
} catch (ModelException modelException) {
-
+ if (content.getURI() == null) {
+ throw new TuplesException("Failed to create/retrieve MBox with content type " +
+ content.getContentType(), modelException);
+ }
throw new TuplesException("Failed to create/retrieve MBox for URI " +
content.getURI().toString(), modelException);
}
try {
-
// Perform the parsing and prepare for reading triples
mbox.start();
} catch (ModelException modelException) {
-
- throw new TuplesException("Failed to parse mbox file: " +
- content.getURI().toString(), modelException);
+ if (content.getURI() == null) {
+ throw new TuplesException("Failed to parse mbox data of type: " + content.getContentType(), modelException);
+ }
+ throw new TuplesException("Failed to parse mbox file: " + content.getURI().toString(), modelException);
} catch (InvalidMBoxException invalidMBoxException) {
+ logger.warn("MBox '" + content.getURI().toString() + "' was an invalid mbox file.", invalidMBoxException);
- logger.warn("MBox '" + content.getURI().toString() + "' was an invalid" +
- " mbox file.", invalidMBoxException);
-
try {
-
// Remove the mbox from the cache
mboxManager.delete(mbox);
} catch (ModelException modelException) {
-
// With the current implementation this shouldn't happen, but we
// should still throw an exception just in case
- throw new TuplesException("Failed to delete invalid mbox from manager.",
- modelException);
+ throw new TuplesException("Failed to delete invalid mbox from manager.", modelException);
}
// Since we can't use the file, throw a tuples exception and stop parsing
throw new TuplesException("MBox '" + content.getURI().toString() +
- "' was an invalid mbox file.",
- invalidMBoxException);
+ "' was an invalid mbox file.", invalidMBoxException);
} catch (VocabularyException vocabularyException) {
-
- throw new TuplesException("Unable to set up vocabulary for mbox parsing.",
- vocabularyException);
+ throw new TuplesException("Unable to set up vocabulary for mbox parsing.", vocabularyException);
}
try {
-
// Initialize the metadata now that we know the statements
rowCount = mbox.getGraph().getNumberOfTriples();
} catch (GraphException graphException) {
-
- throw new TuplesException(
- "Unable to retrieve number of triples in graph.",
- graphException);
+ throw new TuplesException("Unable to retrieve number of triples in graph.",graphException);
}
- if (logger.isDebugEnabled()) {
-
- logger.debug("Parsed MBox");
- }
+ if (logger.isDebugEnabled()) logger.debug("Parsed MBox");
}
//
@@ -300,7 +256,6 @@
* @throws TuplesException
*/
public long getSubject() throws TuplesException {
-
return getColumnValue(SUBJECT);
}
@@ -312,7 +267,6 @@
* @throws TuplesException
*/
public long getPredicate() throws TuplesException {
-
return getColumnValue(PREDICATE);
}
@@ -324,7 +278,6 @@
* @throws TuplesException
*/
public long getObject() throws TuplesException {
-
return getColumnValue(OBJECT);
}
@@ -340,23 +293,16 @@
*
* @throws TuplesException
*/
- public void beforeFirst(long[] prefix, int suffixTruncation) throws
- TuplesException {
+ public void beforeFirst(long[] prefix, int suffixTruncation) throws TuplesException {
try {
-
// Reset the mbox
mbox.reset();
} catch (ModelException modelException) {
-
- throw new TuplesException("Unable to reset the MBox graph.",
- modelException);
+ throw new TuplesException("Unable to reset the MBox graph.", modelException);
}
- if (logger.isDebugEnabled()) {
-
- logger.debug("-- Getting the before first value");
- }
+ if (logger.isDebugEnabled()) logger.debug("-- Getting the before first value");
}
public Object clone() {
@@ -369,9 +315,6 @@
cloned.tripleStatement = tripleStatement;
cloned.url = url;
- // Copy mutable fields by value
- cloned.triples = (ArrayList) triples.clone();
-
return cloned;
}
@@ -379,10 +322,8 @@
* Close the RDF/XML formatted input stream.
*/
public void close() throws TuplesException {
-
resolverSession = null;
tripleStatement = null;
- triples = null;
url = null;
}
@@ -396,25 +337,18 @@
switch (column) {
case SUBJECT:
-
// Try creating the node with a URI reference
node = tripleStatement.getSubject();
-
break;
case PREDICATE:
-
// Try to create a URI reference node to represent the predicate
node = tripleStatement.getPredicate();
-
break;
case OBJECT:
-
// Create a literal node with the value for objects
node = tripleStatement.getObject();
-
break;
default:
-
throw new TuplesException("No such column " + column);
}
assert node != null;
@@ -423,20 +357,15 @@
Long result = null;
if (blankNodeMap.containsKey(node)) {
-
// If the node is already mapped then get the value
- result = (Long) blankNodeMap.get(node);
+ result = blankNodeMap.get(node);
} else {
+ // If we haven't mapped the node already then create a new value and store it
- // If we haven't mapped the node already then create a new value and
- // store it
-
// Localize the node and store the long object value
try {
-
result = new Long(resolverSession.localize(node));
} catch (LocalizeException e) {
-
throw new TuplesException("Couldn't get column " + column + " value", e);
}
@@ -444,21 +373,16 @@
blankNodeMap.put(node, result);
}
- if (column == SUBJECT && logger.isInfoEnabled()) {
+ if (column == SUBJECT && logger.isInfoEnabled()) logger.info("!! Using node value of: " + result.longValue());
- logger.info("!! Using node value of: " + result.longValue());
- }
-
return result.longValue();
}
- public List getOperands() {
-
- return Collections.EMPTY_LIST;
+ public List<Tuples> getOperands() {
+ return Collections.emptyList();
}
public long getRowCount() throws TuplesException {
-
// Since we don't know how many messages and how many triples within a
// message we can't accurately determine the number of messages so we just
// give the highest number we can to cater for large messages and mboxes
@@ -466,55 +390,37 @@
}
public long getRowUpperBound() throws TuplesException {
-
return getRowCount();
}
public boolean hasNoDuplicates() throws TuplesException {
-
return false;
}
public boolean isColumnEverUnbound(int column) throws TuplesException {
-
switch (column) {
-
case 0:
-
case 1:
-
case 2:
-
return false;
default:
-
throw new TuplesException("No such column " + column);
}
}
public boolean next() throws TuplesException {
-
try {
-
// Get the next statement in the iterator
tripleStatement = mbox.nextTriple();
} catch (ModelException modelException) {
-
- throw new TuplesException("Failed to read next triple from mbox",
- modelException);
+ throw new TuplesException("Failed to read next triple from mbox", modelException);
}
if (tripleStatement != null) {
-
- if (logger.isInfoEnabled()) {
-
- logger.info("-- Getting next statement: " + tripleStatement.toString());
- }
-
+ if (logger.isInfoEnabled()) logger.info("-- Getting next statement: " + tripleStatement.toString());
// If there is a value for the triple then we have more data
return true;
} else {
-
// There is no more data to navigate
return false;
}
Modified: trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxStatementsUnitTest.java
===================================================================
--- trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxStatementsUnitTest.java 2009-02-13 06:58:23 UTC (rev 1488)
+++ trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/MBoxStatementsUnitTest.java 2009-02-13 07:05:36 UTC (rev 1489)
@@ -174,8 +174,8 @@
"data" + File.separator + "mbox"), "Trash");
// Containers for construction of content object
- Class contentClass = null;
- Constructor constructor = null;
+ Class<?> contentClass = null;
+ Constructor<?> constructor = null;
Content content = null;
try {
@@ -255,19 +255,19 @@
} catch (NotModifiedException notModifiedException) {
// Log the exception
- log.error("Failed to parse out [" + content.getURI() + "] into " +
+ log.error("Failed to parse out [" + content.getURIString() + "] into " +
"statements.", notModifiedException);
// Fail the test
- fail("Failed to parse out [" + content.getURI() + "] into statements.");
+ fail("Failed to parse out [" + content.getURIString() + "] into statements.");
} catch (TuplesException tuplesException) {
// Log the exception
- log.error("Failed to parse out [" + content.getURI() + "] into " +
+ log.error("Failed to parse out [" + content.getURIString() + "] into " +
"statements.", tuplesException);
// Fail the test
- fail("Failed to parse out [" + content.getURI() + "] into statements.");
+ fail("Failed to parse out [" + content.getURIString() + "] into statements.");
}
// Check the statements objects was really created
@@ -286,8 +286,8 @@
"data" + File.separator + "mbox"), "Trash");
// Containers for construction of content object
- Class contentClass = null;
- Constructor constructor = null;
+ Class<?> contentClass = null;
+ Constructor<?> constructor = null;
Content content = null;
try {
@@ -367,19 +367,19 @@
} catch (NotModifiedException notModifiedException) {
// Log the exception
- log.error("Failed to parse out [" + content.getURI() + "] into " +
+ log.error("Failed to parse out [" + content.getURIString() + "] into " +
"statements.", notModifiedException);
// Fail the test
- fail("Failed to parse out [" + content.getURI() + "] into statements.");
+ fail("Failed to parse out [" + content.getURIString() + "] into statements.");
} catch (TuplesException tuplesException) {
// Log the exception
- log.error("Failed to parse out [" + content.getURI() + "] into " +
+ log.error("Failed to parse out [" + content.getURIString() + "] into " +
"statements.", tuplesException);
// Fail the test
- fail("Failed to parse out [" + content.getURI() + "] into statements.");
+ fail("Failed to parse out [" + content.getURIString() + "] into statements.");
}
// Check the statements objects was really created
@@ -400,7 +400,7 @@
content.getURI() + "].", tuplesException);
// Fail the test
- fail("Unable to retrieve number of statements for [" + content.getURI() +
+ fail("Unable to retrieve number of statements for [" + content.getURIString() +
"].");
}
@@ -425,8 +425,8 @@
"data" + File.separator + "mbox"), "Trash");
// Containers for construction of content object
- Class contentClass = null;
- Constructor constructor = null;
+ Class<?> contentClass = null;
+ Constructor<?> constructor = null;
Content content = null;
try {
@@ -506,19 +506,19 @@
} catch (NotModifiedException notModifiedException) {
// Log the exception
- log.error("Failed to parse out [" + content.getURI() + "] into " +
+ log.error("Failed to parse out [" + content.getURIString() + "] into " +
"statements.", notModifiedException);
// Fail the test
- fail("Failed to parse out [" + content.getURI() + "] into statements.");
+ fail("Failed to parse out [" + content.getURIString() + "] into statements.");
} catch (TuplesException tuplesException) {
// Log the exception
- log.error("Failed to parse out [" + content.getURI() + "] into " +
+ log.error("Failed to parse out [" + content.getURIString() + "] into " +
"statements.", tuplesException);
// Fail the test
- fail("Failed to parse out [" + content.getURI() + "] into statements.");
+ fail("Failed to parse out [" + content.getURIString() + "] into statements.");
}
// Check the statements objects was really created
@@ -550,8 +550,8 @@
"data" + File.separator + "mbox"), "Trash");
// Containers for construction of content object
- Class contentClass = null;
- Constructor constructor = null;
+ Class<?> contentClass = null;
+ Constructor<?> constructor = null;
Content content = null;
try {
@@ -631,19 +631,19 @@
} catch (NotModifiedException notModifiedException) {
// Log the exception
- log.error("Failed to parse out [" + content.getURI() + "] into " +
+ log.error("Failed to parse out [" + content.getURIString() + "] into " +
"statements.", notModifiedException);
// Fail the test
- fail("Failed to parse out [" + content.getURI() + "] into statements.");
+ fail("Failed to parse out [" + content.getURIString() + "] into statements.");
} catch (TuplesException tuplesException) {
// Log the exception
- log.error("Failed to parse out [" + content.getURI() + "] into " +
+ log.error("Failed to parse out [" + content.getURIString() + "] into " +
"statements.", tuplesException);
// Fail the test
- fail("Failed to parse out [" + content.getURI() + "] into statements.");
+ fail("Failed to parse out [" + content.getURIString() + "] into statements.");
}
// Check the statements objects was really created
@@ -690,11 +690,11 @@
log.debug("Globalized values of first entry: [" +
resolverSession.globalize(statements.getColumnValue(
- statements.SUBJECT)) + ", " +
+ MBoxStatements.SUBJECT)) + ", " +
resolverSession.globalize(statements.getColumnValue(
- statements.PREDICATE)) + ", " +
+ MBoxStatements.PREDICATE)) + ", " +
resolverSession.globalize(statements.getColumnValue(
- statements.OBJECT)) + "]");
+ MBoxStatements.OBJECT)) + "]");
} catch (TuplesException tuplesException) {
// Ignore the exception as we are debugging
@@ -712,7 +712,7 @@
try {
// Get the subject node id
- subject = statements.getColumnValue(statements.SUBJECT);
+ subject = statements.getColumnValue(MBoxStatements.SUBJECT);
} catch (TuplesException tuplesException) {
// Log the exception
@@ -728,7 +728,7 @@
try {
// Get the predicate node id
- predicate = statements.getColumnValue(statements.PREDICATE);
+ predicate = statements.getColumnValue(MBoxStatements.PREDICATE);
} catch (TuplesException tuplesException) {
// Log the exception
@@ -744,7 +744,7 @@
try {
// Get the object node id
- object = statements.getColumnValue(statements.OBJECT);
+ object = statements.getColumnValue(MBoxStatements.OBJECT);
} catch (TuplesException tuplesException) {
// Log the exception
@@ -842,8 +842,8 @@
"data"), "camera.owl");
// Containers for construction of content object
- Class contentClass = null;
- Constructor constructor = null;
+ Class<?> contentClass = null;
+ Constructor<?> constructor = null;
Content content = null;
try {
@@ -913,6 +913,7 @@
ResolverSession resolverSession = new TestResolverSession();
// Container for our statements object
+ @SuppressWarnings("unused")
MBoxStatements statements = null;
// Boolean to show we failed to initialise (assumed false)
@@ -1063,19 +1064,19 @@
} catch (NotModifiedException notModifiedException) {
// Log the exception
- log.error("Failed to parse out [" + content.getURI() + "] into " +
+ log.error("Failed to parse out [" + content.getURIString() + "] into " +
"statements.", notModifiedException);
// Fail the test
- fail("Failed to parse out [" + content.getURI() + "] into statements.");
+ fail("Failed to parse out [" + content.getURIString() + "] into statements.");
} catch (TuplesException tuplesException) {
// Log the exception
- log.error("Failed to parse out [" + content.getURI() + "] into " +
+ log.error("Failed to parse out [" + content.getURIString() + "] into " +
"statements.", tuplesException);
// Fail the test
- fail("Failed to parse out [" + content.getURI() + "] into statements.");
+ fail("Failed to parse out [" + content.getURIString() + "] into statements.");
}
// Check the statements objects was really created
Modified: trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/parser/model/impl/MBoxImpl.java
===================================================================
--- trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/parser/model/impl/MBoxImpl.java 2009-02-13 06:58:23 UTC (rev 1488)
+++ trunk/src/jar/content-mbox/java/org/mulgara/content/mbox/parser/model/impl/MBoxImpl.java 2009-02-13 07:05:36 UTC (rev 1489)
@@ -28,10 +28,7 @@
package org.mulgara.content.mbox.parser.model.impl;
import java.io.*;
-import java.net.URL;
-import java.net.MalformedURLException;
import java.net.URI;
-import java.net.URISyntaxException;
import java.util.Properties;
import java.util.List;
import java.util.Date;
@@ -53,7 +50,6 @@
import org.mulgara.content.mbox.parser.model.exception.InvalidMBoxException;
import org.mulgara.content.mbox.parser.model.exception.ModelException;
import org.mulgara.content.mbox.parser.model.exception.VocabularyException;
-import org.mulgara.util.TempDir;
/**
* implementation of the MBox object interface which representes an MBox along
@@ -84,17 +80,11 @@
private Graph graph;
/** The iterator to use for iterating the graph */
- private ClosableIterator iterator;
+ private ClosableIterator<Triple> iterator;
- /** Indicator as to whether we are parsing one file or a directory */
- private boolean singleFile;
-
/** The tool to perform the actual parsing of an mbox into message beans */
private MimeMessageToPart mimeMessageToPart;
- /** The name of the cached file */
- private String cachedFileName;
-
/** The content object this object represents */
private Content mBoxContent;
@@ -104,9 +94,6 @@
*/
public MBoxImpl(Content content) {
- // Always assume a single file
- singleFile = true;
-
// Instantiate our parsing tool
mimeMessageToPart = new MimeMessageToPart();
@@ -120,7 +107,6 @@
* @return The location of the mbox as an URI
*/
public URI getURI() {
-
return mBoxContent.getURI();
}
@@ -146,7 +132,6 @@
* @return The graph object that the mbox is using to store its content
*/
public Graph getGraph() {
-
return graph;
}
@@ -156,7 +141,6 @@
* @param graph The graph object the mbox should use to store its content
*/
public void setGraph(Graph graph) {
-
// Store the new graph
this.graph = graph;
}
@@ -177,7 +161,7 @@
if (iterator.hasNext()) {
// Get the next triple in the iterator
- nextTriple = (Triple) iterator.next();
+ nextTriple = iterator.next();
} else {
try {
@@ -205,7 +189,7 @@
// Get the next triple in the iterator if we have any, as the message
// we just finished with may have been the last
- nextTriple = (Triple) iterator.next();
+ nextTriple = iterator.next();
} else {
// If we could not find any more messages then end the triple search
@@ -287,7 +271,7 @@
} catch (IOException ioException) {
throw new ModelException("Failed to open stream to original resource: " +
- getURI().toString(), ioException);
+ getUriString(), ioException);
}
// Validate the file
@@ -311,7 +295,7 @@
} catch (IOException ioException) {
throw new ModelException("Failed to reopen stream to original resource: " +
- getURI().toString(), ioException);
+ getUriString(), ioException);
}
try {
@@ -356,7 +340,7 @@
// exceptions, otherwise we just ignore the mbox because we don't
// want to interrupt processing
throw new ModelException(
- "Unable to process mbox '" + getURI().toString() +
+ "Unable to process mbox '" + getUriString() +
"' into parts due to I/O failure.", ioProcessingException);
} catch (UnsupportedEncodingProcessingException
unsupportedEncodingProcessingException) {
@@ -431,7 +415,7 @@
} catch (IOException ioException) {
// We could not read the mbox file
- throw new InvalidMBoxException("MBox file [" + getURI().toString() +
+ throw new InvalidMBoxException("MBox file [" + getUriString() +
"] was not able to be read from.",
ioException);
}
@@ -439,7 +423,7 @@
if (line == null || !line.toLowerCase().startsWith("from ")) {
// The mbox is not RFC822 compliant
- throw new InvalidMBoxException("MBox file [" + getURI().toString() +
+ throw new InvalidMBoxException("MBox file [" + getUriString() +
"] was not a valid RFC822 mbox.");
} else {
@@ -450,7 +434,7 @@
} catch (IOException ioException) {
// We could not read the mbox file
- throw new InvalidMBoxException("MBox file [" + getURI().toString() +
+ throw new InvalidMBoxException("MBox file [" + getUriString() +
"] was not able to be read from.",
ioException);
}
@@ -463,7 +447,7 @@
// We require a check for either a blank line or an invalid header
// The mbox is not RFC822 compliant if the next line is not a header
- throw new InvalidMBoxException("MBox file [" + getURI().toString() +
+ throw new InvalidMBoxException("MBox file [" + getUriString() +
"] was not a valid RFC822 mbox.");
}
}
@@ -478,8 +462,7 @@
* @throws ModelException
* @throws VocabularyException
*/
- private void storeBeansRDF(MimeMessageToPartBean bean) throws
- ModelException, VocabularyException {
+ private void storeBeansRDF(MimeMessageToPartBean bean) throws ModelException, VocabularyException {
// Create the vocabulary for the graph
Properties vocab = EmailVocab.createVocabulary(graph);
@@ -490,23 +473,18 @@
// Container for our subject node
SubjectNode subject = null;
- if (log.isDebugEnabled()) {
+ if (log.isDebugEnabled()) log.debug("Creating graph nodes for bean: " + bean);
- log.debug("Creating graph nodes for bean: " + bean);
- }
-
try {
-
// Create a subject blank node
subject = factory.createResource();
} catch (GraphElementFactoryException graphElementFactoryException) {
-
throw new ModelException("Unable to create resource node for subject.",
graphElementFactoryException);
}
// Get the list of bccs
- List bccList = bean.getBCCAddresses();
+ List<QuollEmailAddress> bccList = bean.getBCCAddresses();
for (int j = 0; j < bccList.size(); j++) {
@@ -523,7 +501,7 @@
} catch (GraphElementFactoryException graphElementFactoryException) {
throw new ModelException("Failed to create literal for mbox: " +
- getURI().toString(),
+ getUriString(),
graphElementFactoryException);
}
@@ -536,7 +514,7 @@
throw new ModelException("Failed to add BCC address '" +
address.getAddress() + "' to mbox: " +
- getURI().toString(), graphException);
+ getUriString(), graphException);
}
if (log.isDebugEnabled()) {
@@ -548,13 +526,8 @@
}
// Get the list of ccs
- List ccList = bean.getCCAddresses();
+ for (QuollEmailAddress address: bean.getCCAddresses()) {
- for (int j = 0; j < ccList.size(); j++) {
-
- // Retrieve the next address
- QuollEmailAddress address = (QuollEmailAddress) ccList.get(j);
-
// Container for our object node
ObjectNode objectNode = null;
@@ -565,7 +538,7 @@
} catch (GraphElementFactoryException graphElementFactoryException) {
throw new ModelException("Failed to create literal for mbox: " +
- getURI().toString(),
+ getUriString(),
graphElementFactoryException);
}
@@ -578,7 +551,7 @@
throw new ModelException("Failed to add CC address '" +
address.getAddress() + "' to mbox: " +
- getURI().toString(), graphException);
+ getUriString(), graphException);
}
if (log.isDebugEnabled()) {
@@ -589,14 +562,8 @@
}
}
- // Get the list of tos
- List toList = bean.getToAddresses();
+ for (QuollEmailAddress address: bean.getToAddresses()) {
- for (int j = 0; j < toList.size(); j++) {
-
- // Retrieve the next address
- QuollEmailAddress address = (QuollEmailAddress) toList.get(j);
-
// Container for our object node
ObjectNode objectNode = null;
@@ -607,7 +574,7 @@
} catch (GraphElementFactoryException graphElementFactoryException) {
throw new ModelException("Failed to create literal for mbox: " +
- getURI().toString(),
+ getUriString(),
graphElementFactoryException);
}
@@ -620,7 +587,7 @@
throw new ModelException("Failed to add TO address '" +
address.getAddress() + "' to mbox: " +
- getURI().toString(), graphException);
+ getUriString(), graphException);
}
if (log.isDebugEnabled()) {
@@ -642,26 +609,18 @@
if (from != null) {
try {
-
// Create a literal out of the address
objectNode = factory.createLiteral(from.getAddress());
} catch (GraphElementFactoryException graphElementFactoryException) {
-
- throw new ModelException("Failed to create literal for mbox: " +
- getURI().toString(),
- graphElementFactoryException);
+ throw new ModelException("Failed to create literal for mbox: " + getUriString(), graphElementFactoryException);
}
try {
-
// Add the triple to the graph
- graph.add(subject, (PredicateNode) vocab.get(EmailVocab.FROM),
- objectNode);
+ graph.add(subject, (PredicateNode) vocab.get(EmailVocab.FROM), objectNode);
} catch (GraphException graphException) {
-
- throw new ModelException("Failed to add from address '" +
- from.getAddress() + "' to mbox: " +
- getURI().toString(), graphException);
+ throw new ModelException("Failed to add from address '" + from.getAddress() + "' to mbox: " +
+ getUriString(), graphException);
}
}
@@ -671,25 +630,21 @@
if (date != null) {
try {
-
// Create a literal out of the date
objectNode = factory.createLiteral(formatDateTime(date));
} catch (GraphElementFactoryException graphElementFactoryException) {
-
throw new ModelException("Failed to create literal for mbox: " +
- getURI().toString(),
+ getUriString(),
graphElementFactoryException);
}
try {
// Add the triple to the graph
- graph.add(subject, (PredicateNode) vocab.get(EmailVocab.DATE),
- objectNode);
+ graph.add(subject, (PredicateNode) vocab.get(EmailVocab.DATE), objectNode);
} catch (GraphException graphException) {
-
throw new ModelException("Failed to add date '" + formatDateTime(date) +
- "' to mbox: " + getURI().toString(),
+ "' to mbox: " + getUriString(),
graphException);
}
}
@@ -706,7 +661,7 @@
} catch (GraphElementFactoryException graphElementFactoryException) {
throw new ModelException("Failed to create literal for mbox: " +
- getURI().toString(),
+ getUriString(),
graphElementFactoryException);
}
@@ -718,7 +673,7 @@
} catch (GraphException graphException) {
throw new ModelException("Failed to add ID '" + id + "' to mbox: " +
- getURI().toString(), graphException);
+ getUriString(), graphException);
}
if (log.isDebugEnabled()) {
@@ -731,34 +686,22 @@
}
// Retrieve the references of the message
- List references = bean.getReferences();
-
- for (int j = 0; j < references.size(); j++) {
-
- // Retrieve the next reference
- String reference = (String) references.get(j);
-
+ for (String reference: bean.getReferences()) {
try {
-
// Create a literal out of the reference
objectNode = factory.createLiteral(reference);
} catch (GraphElementFactoryException graphElementFactoryException) {
-
throw new ModelException("Failed to create literal for mbox: " +
- getURI().toString(),
+ getUriString(),
graphElementFactoryException);
}
try {
-
// Add the triple to the graph
- graph.add(subject, (PredicateNode) vocab.get(EmailVocab.REFERENCES),
- objectNode);
+ graph.add(subject, (PredicateNode) vocab.get(EmailVocab.REFERENCES), objectNode);
} catch (GraphException graphException) {
-
throw new ModelException("Failed to add reference '" + reference +
- "' to mbox: " + getURI().toString(),
- graphException);
+ "' to mbox: " + getUriString(), graphException);
}
}
@@ -766,28 +709,21 @@
String subjectString = bean.getSubject();
if (subjectString != null) {
-
try {
-
// Create a literal out of the subject
objectNode = factory.createLiteral(subjectString);
} catch (GraphElementFactoryException graphElementFactoryException) {
-
throw new ModelException("Failed to create literal for mbox: " +
- getURI().toString(),
+ getUriString(),
graphElementFactoryException);
}
try {
-
// Add the triple to the graph
- graph.add(subject, (PredicateNode) vocab.get(EmailVocab.SUBJECT),
- objectNode);
+ graph.add(subject, (PredicateNode) vocab.get(EmailVocab.SUBJECT), objectNode);
} catch (GraphException graphException) {
-
throw new ModelException("Failed to add subject '" + subjectString +
- "' to mbox: " +
- getURI().toString(), graphException);
+ "' to mbox: " + getUriString(), graphException);
}
}
@@ -795,35 +731,23 @@
PredicateNode typePredicate = null;
try {
-
// Create a predicate for type
typePredicate = factory.createResource(RDF.TYPE);
} catch (GraphElementFactoryException graphElementFactoryException) {
-
- throw new ModelException("Failed to create type predicate: " + RDF.TYPE,
- graphElementFactoryException);
+ throw new ModelException("Failed to create type predicate: " + RDF.TYPE, graphElementFactoryException);
}
try {
-
// Add the type triple to the graph
- graph.add(subject, typePredicate,
- (ObjectNode) vocab.get(EmailVocab.MESSAGE));
+ graph.add(subject, typePredicate, (ObjectNode) vocab.get(EmailVocab.MESSAGE));
} catch (GraphException graphException) {
-
throw new ModelException("Failed to add type '" + RDF.TYPE +
- "' to mbox: " +
- getURI().toString(), graphException);
+ "' to mbox: " + getUriString(), graphException);
}
- // Retrieve the attachments of the message
- Attachment[] attachments = bean.getParts();
-
- for (int j = 0; j < attachments.length; j++) {
-
+ for (Attachment attachment: bean.getParts()) {
// Add the next attachment to the resource
- addAttachment(subject, attachments[j], vocab);
-
+ addAttachment(subject, attachment, vocab);
}
}
@@ -997,6 +921,14 @@
}
/**
+ * Gets a string representation of the URI.
+ * @return A String for the URI of the content.
+ */
+ private String getUriString() {
+ return mBoxContent.getURIString();
+ }
+
+ /**
* Calculates whether the given object is equal to the current mbox. Only the
* file is required to be the same as the class is the encapsulation of a file
* handle and will always have the same content for a particular handle.
@@ -1022,15 +954,17 @@
MBox mbox = null;
try {
-
// Cast the object to an MBox
mbox = (MBox) object;
} catch (ClassCastException classCastException) {
-
// If the object is not of the right cast then it is not equal
return false;
}
+ if (mbox.getURI() == null) {
+ return getURI() == null;
+ }
+
if (mbox.getURI().compareTo(getURI()) == 0) {
// If the file handles of the mboxes are equal then they match
Modified: trunk/src/jar/content-mp3/java/org/mulgara/content/mp3/MP3ContentHandler.java
===================================================================
--- trunk/src/jar/content-mp3/java/org/mulgara/content/mp3/MP3ContentHandler.java 2009-02-13 06:58:23 UTC (rev 1488)
+++ trunk/src/jar/content-mp3/java/org/mulgara/content/mp3/MP3ContentHandler.java 2009-02-13 07:05:36 UTC (rev 1489)
@@ -28,11 +28,9 @@
package org.mulgara.content.mp3;
// Java 2 standard packages
-import java.io.InputStream;
+// Java 2 enterprise packages
import java.net.URI;
-import java.util.Map;
-// Java 2 enterprise packages
import javax.activation.MimeType;
import javax.activation.MimeTypeParseException;
@@ -69,8 +67,8 @@
public class MP3ContentHandler implements ContentHandler {
/** Logger. */
- private static Logger logger =
- Logger.getLogger(MP3ContentHandler.class.getName());
+ @SuppressWarnings("unused")
+ private static Logger logger = Logger.getLogger(MP3ContentHandler.class.getName());
/**
* The MIME type of RDF/XML.
@@ -80,8 +78,7 @@
static {
try {
AUDIO_MPEG = new MimeType("audio", "mpeg");
- }
- catch (MimeTypeParseException e) {
+ } catch (MimeTypeParseException e) {
throw new ExceptionInInitializerError(e);
}
}
@@ -108,10 +105,13 @@
// Attempt to create the MP3 statements
statements = new MP3Statements(content, resolverSession);
} catch (TuplesException tuplesException) {
-
- throw new ContentHandlerException("Unable to create statements object from " +
- "content object: " + content.getURI().toString(),
- tuplesException);
+ URI u = content.getURI();
+ if (u == null) {
+ throw new ContentHandlerException("Unable to create statements object from stream with type" +
+ content.getContentType(), tuplesException);
+ }
+ throw new ContentHandlerException("Unable to create statements object from content object: " +
+ content.getURI().toString(), tuplesException);
}
return statements;
@@ -128,8 +128,7 @@
return true;
}
- if (content.getURI() == null)
- {
+ if (content.getURI() == null) {
return false;
}
Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/Parser.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/Parser.java 2009-02-13 06:58:23 UTC (rev 1488)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/Parser.java 2009-02-13 07:05:36 UTC (rev 1489)
@@ -34,6 +34,8 @@
import java.net.URISyntaxException;
import java.util.LinkedList;
+import javax.activation.MimeType;
+
// logging
import org.apache.log4j.Logger;
@@ -48,6 +50,7 @@
import org.mulgara.query.TuplesException;
import org.mulgara.query.rdf.BlankNodeImpl;
import org.mulgara.query.rdf.LiteralImpl;
+import org.mulgara.query.rdf.Mulgara;
import org.mulgara.query.rdf.URIReferenceImpl;
import org.mulgara.resolver.spi.LocalizeException;
import org.mulgara.resolver.spi.ResolverSession;
@@ -169,6 +172,9 @@
*/
private URI baseURI;
+ /** The data type on the stream provided. If provided then this should be application/rdf+xml. */
+ private MimeType contentType;
+
/**
* The context in which to localize incoming RDF nodes.
*/
@@ -208,7 +214,7 @@
}
// Initialize fields
- this.baseURI = content.getURI();
+ this.baseURI = content.getURI() != null ? content.getURI() : URI.create(Mulgara.NAMESPACE);
try {
this.blankNodeNameMap = new StringToLongMap();
this.blankNodeIdMap = IntFile.open(
@@ -222,9 +228,9 @@
try {
this.inputStream = content.newInputStream();
} catch (IOException e) {
- throw new TuplesException("Unable to obtain input stream from " + baseURI,
- e);
+ throw new TuplesException("Unable to obtain input stream from " + baseURI, e);
}
+ this.contentType = content.getContentType();
this.resolverSession = resolverSession;
// Configure the RDF/XML parser
@@ -288,7 +294,7 @@
Throwable t = null;
try {
- arp.load(inputStream, baseURI.toString());
+ arp.load(inputStream, baseURI == null ? "" : baseURI.toString());
if (logger.isDebugEnabled()) {
logger.debug("Parsed RDF/XML");
}
@@ -486,6 +492,7 @@
queue.clear();
headIndex = 0;
headBuffer = null;
+ if (baseURI == null) throw new TuplesException("Exception while reading stream of type: " + contentType, exception);
throw new TuplesException("Exception while reading " + baseURI, exception);
}
}
Modified: trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLContentHandler.java
===================================================================
--- trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLContentHandler.java 2009-02-13 06:58:23 UTC (rev 1488)
+++ trunk/src/jar/content-rdfxml/java/org/mulgara/content/rdfxml/RDFXMLContentHandler.java 2009-02-13 07:05:36 UTC (rev 1489)
@@ -106,8 +106,7 @@
// We're breaking the WWW architectural principle of URI Opacity by doing
// so (see http://www.w3.org/TR/webarch/#uri-opacity).
- if (content.getURI() == null)
- {
+ if (content.getURI() == null) {
return false;
}
@@ -132,8 +131,8 @@
public void serialize(Statements statements,
Content content,
ResolverSession resolverSession)
- throws ContentHandlerException, ModifiedException
- {
+ throws ContentHandlerException, ModifiedException {
+
RDFXMLWriter rdfXmlWriter = new RDFXMLWriter();
try {
rdfXmlWriter.write(
@@ -141,16 +140,10 @@
resolverSession,
new OutputStreamWriter(content.newOutputStream(), "utf-8")
);
+ } catch (QueryException e) {
+ throw new ContentHandlerException("Failed to serialize RDF/XML to " + content.getURIString(), e);
+ } catch (IOException e) {
+ throw new ContentHandlerException("Failed to serialize RDF/XML to " + content.getURIString(), e);
}
- catch (QueryException e) {
- throw new ContentHandlerException(
- "Failed to serialize RDF/XML to " + content.getURI(), e
- );
- }
- catch (IOException e) {
- throw new ContentHandlerException(
- "Failed to serialize RDF/XML to " + content.getURI(), e
- );
- }
}
}
Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/ContentHandlerManagerImpl.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/ContentHandlerManagerImpl.java 2009-02-13 06:58:23 UTC (rev 1488)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/ContentHandlerManagerImpl.java 2009-02-13 07:05:36 UTC (rev 1489)
@@ -112,9 +112,13 @@
}
if (defaultHandler == null) {
- throw new ContentHandlerException(
- "Unable to determine content type for " + content.getURI()
- );
+ if (content.getURI() != null) {
+ throw new ContentHandlerException("Unable to determine content type for " + content.getURI());
+ }
+ if (content.getContentType() != null) {
+ throw new ContentHandlerException("Unknown content type: " + content.getContentType());
+ }
+ throw new ContentHandlerException("Attempting to parse invalid content.");
}
assert defaultHandler != null;
@@ -133,9 +137,13 @@
}
if (defaultHandler == null) {
- throw new ContentHandlerException(
- "Unable to determine type of " + content.getURI()
- );
+ if (content.getContentType() != null) {
+ throw new ContentHandlerException("Unrecognized content type: " + content.getContentType());
+ }
+ if (content.getURI() != null) {
+ throw new ContentHandlerException("Unable to determine type of " + content.getURI());
+ }
+ throw new ContentHandlerException("Attempted to parse invalid content");
}
assert defaultHandler != null;
Modified: trunk/src/jar/resolver-spi/java/org/mulgara/content/ContentResolver.java
===================================================================
--- trunk/src/jar/resolver-spi/java/org/mulgara/content/ContentResolver.java 2009-02-13 06:58:23 UTC (rev 1488)
+++ trunk/src/jar/resolver-spi/java/org/mulgara/content/ContentResolver.java 2009-02-13 07:05:36 UTC (rev 1489)
@@ -78,16 +78,16 @@
* Map from the {@link URIReference} of each document ever parsed by this
* resolver to the corresponding {@link Content}.
*/
- protected final Map contentMap = new HashMap();
+ protected final Map<URIReference,Content> contentMap = new HashMap<URIReference,Content>();
protected final ContentHandlerManager contentManager;
/** Current system resolver */
+ @SuppressWarnings("unused")
private final Resolver systemResolver;
/** Logger. */
- private static Logger logger =
- Logger.getLogger(ContentResolver.class.getName());
+ private static Logger logger = Logger.getLogger(ContentResolver.class.getName());
//
// Constructors
@@ -96,7 +96,7 @@
/**
* Construct a ContentResolver.
*
- * @param resolverSession the session this resolver is associated with
+ * @param resolverSession the session this resolver is associated with - unused for now.
* @param contentManager the available {@link ContentHandler}s
* @throws IllegalArgumentException if <var>resolverSession</var> is
* <code>null</code>
@@ -131,38 +131,25 @@
*
* @param model {@inheritDoc}. In this case it should always be a URL
* referencing {@link Content} outside the database.
- *
- * @param modelTypeURI {@inheritDoc}. This field is ignored, because the
- * {@link Content} is external.
+ * @param modelTypeURI {@inheritDoc}. This field is ignored, because the {@link Content} is external.
*/
- public void createModel(long model,
- URI modelTypeURI) throws ResolverException {
- if (logger.isDebugEnabled()) {
- logger.debug("Create content model " + model);
- }
-
- throw new ResolverException(
- "Creation of external documents not implemented"
- );
+ public void createModel(long model, URI modelTypeURI) throws ResolverException {
+ if (logger.isDebugEnabled()) logger.debug("Create content model " + model);
+ throw new ResolverException("Creation of external documents not implemented");
}
/**
* @return a {@link DummyXAResource} with a 10 second transaction timeout
*/
public XAResource getXAResource() {
- return new DummyXAResource(
- 10 // seconds before transaction timeout
- );
+ return new DummyXAResource(10); // seconds before transaction timeout
}
/**
* Insert or delete RDF statements from a model stored in a file.
*/
- public void modifyModel(long model, Statements statements,
- boolean occurs) throws ResolverException {
- if (logger.isDebugEnabled()) {
- logger.debug("Modify external document model " + model);
- }
+ public void modifyModel(long model, Statements statements, boolean occurs) throws ResolverException {
+ if (logger.isDebugEnabled()) logger.debug("Modify external document model " + model);
Content content = toContent(model);
assert content != null;
@@ -170,45 +157,36 @@
try {
ContentHandler contentHandler = contentManager.getContentHandler(content);
contentHandler.serialize(statements, content, resolverSession);
+ } catch (RuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ URI u = content.getURI();
+ if (u != null) throw new ResolverException("Unable to serialize " + content.getURI(), e);
+ try {
+ throw new ResolverException("Unable to serialize stream with type: " + content.getContentType(), e);
+ } catch (NotModifiedException e1) {
+ throw new ResolverException("Unable to serialize stream", e);
+ }
}
- catch (ModifiedException e) {
- throw new ResolverException("Unable to serialize " + content.getURI(), e);
- }
- catch (NotModifiedException e) {
- throw new ResolverException("Unable to serialize " + content.getURI(), e);
- }
- catch (ContentHandlerException e) {
- throw new ResolverException("Unable to serialize " + content.getURI(), e);
- }
}
/**
* Remove the file containing the model.
*/
public void removeModel(long model) throws ResolverException {
- if (logger.isDebugEnabled()) {
- logger.debug("Remove model " + model);
- }
-
- throw new ResolverException(
- "Deletion of external documents not implemented"
- );
+ if (logger.isDebugEnabled()) logger.debug("Remove model " + model);
+ throw new ResolverException("Deletion of external documents not implemented");
}
/**
* Resolve a constraint against an RDF/XML document.
- *
* Resolution is by filtration of a stream, and thus very slow.
*/
public Resolution resolve(Constraint constraint) throws QueryException {
- if (logger.isDebugEnabled()) {
- logger.debug("Resolve " + constraint);
- }
+ if (logger.isDebugEnabled()) logger.debug("Resolve " + constraint);
// Validate parameters
- if (constraint == null) {
- throw new IllegalArgumentException("constraint null");
- }
+ if (constraint == null) throw new IllegalArgumentException("constraint null");
else if (!(constraint.getModel() instanceof LocalNode)) {
throw new QueryException("Constraint model can't be variable");
}
@@ -234,7 +212,7 @@
assert modelURIReference != null;
// Find or create the Content instance representing this external document
- Content content = (Content) contentMap.get(modelURIReference);
+ Content content = contentMap.get(modelURIReference);
if (content == null) {
try {
content = toContent(modelNode);
@@ -272,15 +250,12 @@
try {
ContentHandler contentHandler = contentManager.getContentHandler(content);
return contentHandler.parse(content, resolverSession);
- }
- catch (NotModifiedException e) {
- throw new QueryException("Unable to parse " + content.getURI(), e);
- }
- catch (CorruptContentException e) {
+ } catch (NotModifiedException e) {
+ throw new QueryException("Unable to parse " + out(content), e);
+ } catch (CorruptContentException e) {
// This is the right content type, but the content is corrupt
- throw new QueryException("Unable to parse " + content.getURI(), e);
- }
- catch (ContentHandlerException contentHandlerException) {
+ throw new QueryException("Unable to parse " + out(content), e);
+ } catch (ContentHandlerException contentHandlerException) {
// Continue trying other content handlers
}
@@ -289,27 +264,40 @@
try {
// Attempt to parse the content of the file into statements
return contentManager.blindParse(content, resolverSession);
- }
- catch (NotModifiedException e) {
- throw new QueryException("Unable to parse " + content.getURI(), e);
- }
- catch (CorruptContentException e) {
+ } catch (NotModifiedException e) {
+ throw new QueryException("Unable to parse " + out(content), e);
+ } catch (CorruptContentException e) {
// This is the right content type, but the content is corrupt
- throw new QueryException("Unable to parse " + content.getURI(), e);
- }
- catch (ContentHandlerException e) {
+ throw new QueryException("Unable to parse " + out(content), e);
+ } catch (ContentHandlerException e) {
// Continue trying other content handlers
}
// Couldn't obtain a content handler for this URI
- throw new QueryException("Unable to parse " + content.getURI());
+ throw new QueryException("Unable to parse " + out(content));
}
+
public void abort() {
// I don't believe there is anything to do here. It is possible that we may
// need to close file handles or clear caches.
}
+
+ /**
+ * Creates a label for the content.
+ * @param content The content to describe.
+ * @return A string containing a description of what can be found in the content.
+ */
+ private String out(Content content) {
+ try {
+ return content.getURI() == null ? "stream of type: " + content.getContentType() : content.getURI().toString();
+ } catch (NotModifiedException e) {
+ return "stream of unknown type";
+ }
+ }
+
+
//
// SPI methods
//
More information about the Mulgara-svn
mailing list