org.nsdl.mptstore.util
Class NTriplesUtil

java.lang.Object
  extended by org.nsdl.mptstore.util.NTriplesUtil

public abstract class NTriplesUtil
extends java.lang.Object

Utility for parsing, validating, and printing strings in N-Triples format.

Author:
cwilper@cs.cornell.edu

Method Summary
static java.lang.String consumeURIReference(java.io.Reader reader, int pos)
          Consume the next URI reference.
static int consumeWhitespace(java.io.Reader reader, int pos)
          Move the reader to the first non-whitespace character and return the number of whitespaces encountered.
static java.lang.String escapeLiteralValue(java.lang.String s)
          Escape a string to N-Triples literal format.
static Literal parseLiteral(java.lang.String s)
          Parse an RDF literal in N-Triples format.
static Node parseNode(java.lang.String ntNode)
          Parse an RDF node in N-Triples format.
static ObjectNode parseObject(java.lang.String ntObject)
          Parse an RDF object in N-Triples format.
static PredicateNode parsePredicate(java.lang.String ntPredicate)
          Parse an RDF predicate in N-Triples format.
static SubjectNode parseSubject(java.lang.String ntSubject)
          Parse an RDF subject in N-Triples format.
static Triple parseTriple(java.lang.String ntTriple)
          Parse an RDF triple in N-Triples format.
static URIReference parseURIReference(java.lang.String s)
          Parse an RDF URI reference in N-Triples format.
static java.lang.String unescapeLiteralValue(java.lang.String s)
          Unescape an N-Triples-escaped string.
static void validateLanguage(java.lang.String language)
          Validate the given language tag according to RFC3066.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

consumeURIReference

public static java.lang.String consumeURIReference(java.io.Reader reader,
                                                   int pos)
                                            throws java.io.IOException,
                                                   java.text.ParseException
Consume the next URI reference. This will advance the reader through the next '>' character.

Parameters:
reader - the reader to get characters from.
pos - the current position in the overall input.
Returns:
all characters up to an including the terminal, '>'.
Throws:
java.io.IOException - if there's an I/O error reading the input.
java.text.ParseException - if the reader is exhausted before the terminal is encountered.

consumeWhitespace

public static int consumeWhitespace(java.io.Reader reader,
                                    int pos)
                             throws java.io.IOException,
                                    java.text.ParseException
Move the reader to the first non-whitespace character and return the number of whitespaces encountered.

Parameters:
reader - the reader.
pos - the current position in the reader.
Returns:
the number of whitespaces encountered.
Throws:
java.io.IOException - if there is an error reading.
java.text.ParseException - if the first character is not a whitespace or EOF is reached before a non-whitespace char.

parseTriple

public static Triple parseTriple(java.lang.String ntTriple)
                          throws java.text.ParseException
Parse an RDF triple in N-Triples format.

Parameters:
ntTriple - the input string.
Returns:
the parsed triple.
Throws:
java.text.ParseException - if the input syntax is incorrect
See Also:
N-Triples triple syntax

parseSubject

public static SubjectNode parseSubject(java.lang.String ntSubject)
                                throws java.text.ParseException
Parse an RDF subject in N-Triples format.

Parameters:
ntSubject - the input string.
Returns:
the parsed subject.
Throws:
java.text.ParseException - if the input syntax is incorrect
See Also:
N-Triples subject syntax

parsePredicate

public static PredicateNode parsePredicate(java.lang.String ntPredicate)
                                    throws java.text.ParseException
Parse an RDF predicate in N-Triples format.

Parameters:
ntPredicate - the input string.
Returns:
the parsed predicate.
Throws:
java.text.ParseException - if the input syntax is incorrect
See Also:
N-Triples predicate syntax

parseObject

public static ObjectNode parseObject(java.lang.String ntObject)
                              throws java.text.ParseException
Parse an RDF object in N-Triples format.

Parameters:
ntObject - the input string.
Returns:
the parsed predicate.
Throws:
java.text.ParseException - if the input syntax is incorrect
See Also:
N-Triples object syntax

parseNode

public static Node parseNode(java.lang.String ntNode)
                      throws java.text.ParseException
Parse an RDF node in N-Triples format.

Parameters:
ntNode - the input string.
Returns:
the parsed node.
Throws:
java.text.ParseException - if the input syntax is incorrect

parseLiteral

public static Literal parseLiteral(java.lang.String s)
                            throws java.text.ParseException
Parse an RDF literal in N-Triples format.

Parameters:
s - the input string.
Returns:
the parsed literal.
Throws:
java.text.ParseException - if the input syntax is incorrect

parseURIReference

public static URIReference parseURIReference(java.lang.String s)
                                      throws java.text.ParseException
Parse an RDF URI reference in N-Triples format.

Parameters:
s - the input string.
Returns:
the parsed URI reference.
Throws:
java.text.ParseException - if the input syntax is incorrect

unescapeLiteralValue

public static java.lang.String unescapeLiteralValue(java.lang.String s)
                                             throws java.text.ParseException
Unescape an N-Triples-escaped string.

Parameters:
s - The input string.
Returns:
The unescaped string.
Throws:
java.text.ParseException - if the input syntax is incorrect

escapeLiteralValue

public static java.lang.String escapeLiteralValue(java.lang.String s)
Escape a string to N-Triples literal format.

Parameters:
s - The input string.
Returns:
The escaped string.

validateLanguage

public static void validateLanguage(java.lang.String language)
                             throws java.text.ParseException
Validate the given language tag according to RFC3066. The grammar for a language tag is:
   LANGUAGE-TAG   = PRIMARY-SUBTAG ("-" SUBTAG)*
   PRIMARY-SUBTAG = 1-8(ALPHA)
   SUBTAG         = 1-8(ALPHA/DIGIT)
 

Parameters:
language - the language to validate.
Throws:
java.text.ParseException - if the language is syntactically invalid.