org.openrdf.rio.ntriples
Class NTriplesUtil

java.lang.Object
  extended by org.openrdf.rio.ntriples.NTriplesUtil

public class NTriplesUtil
extends Object

Utility methods for N-Triples encoding/decoding.


Constructor Summary
NTriplesUtil()
           
 
Method Summary
static String escapeString(String label)
          Escapes a Unicode string to an all-ASCII character sequence.
static boolean isLetter(int c)
          Checks whether the supplied character is a letter according to the N-Triples specification.
static boolean isLetterOrNumber(int c)
          Checks whether the supplied character is a letter or number according to the N-Triples specification.
static boolean isNumber(int c)
          Checks whether the supplied character is a number according to the N-Triples specification.
static BNode parseBNode(String nTriplesBNode, ValueFactory valueFactory)
          Parses an N-Triples bNode, creates an object for it using the supplied ValueFactory and returns this object.
static Literal parseLiteral(String nTriplesLiteral, ValueFactory valueFactory)
          Parses an N-Triples literal, creates an object for it using the supplied ValueFactory and returns this object.
static Resource parseResource(String nTriplesResource, ValueFactory valueFactory)
          Parses an N-Triples resource, creates an object for it using the supplied ValueFactory and returns this object.
static URI parseURI(String nTriplesURI, ValueFactory valueFactory)
          Parses an N-Triples URI, creates an object for it using the supplied ValueFactory and returns this object.
static Value parseValue(String nTriplesValue, ValueFactory valueFactory)
          Parses an N-Triples value, creates an object for it using the supplied ValueFactory and returns this object.
static String toHexString(int decimal, int stringLength)
          Converts a decimal value to a hexadecimal string represention of the specified length.
static String toNTriplesString(BNode bNode)
          Creates an N-Triples string for the supplied bNode.
static String toNTriplesString(Literal lit)
          Creates an N-Triples string for the supplied literal.
static String toNTriplesString(Resource resource)
          Creates an N-Triples string for the supplied resource.
static String toNTriplesString(URI uri)
          Creates an N-Triples string for the supplied URI.
static String toNTriplesString(Value value)
          Creates an N-Triples string for the supplied value.
static String unescapeString(String s)
          Unescapes an escaped Unicode string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NTriplesUtil

public NTriplesUtil()
Method Detail

parseValue

public static Value parseValue(String nTriplesValue,
                               ValueFactory valueFactory)
                        throws IllegalArgumentException
Parses an N-Triples value, creates an object for it using the supplied ValueFactory and returns this object.

Parameters:
nTriplesValue - The N-Triples value to parse.
valueFactory - The ValueFactory to use for creating the object.
Returns:
An object representing the parsed value.
Throws:
IllegalArgumentException - If the supplied value could not be parsed correctly.

parseResource

public static Resource parseResource(String nTriplesResource,
                                     ValueFactory valueFactory)
                              throws IllegalArgumentException
Parses an N-Triples resource, creates an object for it using the supplied ValueFactory and returns this object.

Parameters:
nTriplesResource - The N-Triples resource to parse.
valueFactory - The ValueFactory to use for creating the object.
Returns:
An object representing the parsed resource.
Throws:
IllegalArgumentException - If the supplied resource could not be parsed correctly.

parseURI

public static URI parseURI(String nTriplesURI,
                           ValueFactory valueFactory)
                    throws IllegalArgumentException
Parses an N-Triples URI, creates an object for it using the supplied ValueFactory and returns this object.

Parameters:
nTriplesURI - The N-Triples URI to parse.
valueFactory - The ValueFactory to use for creating the object.
Returns:
An object representing the parsed URI.
Throws:
IllegalArgumentException - If the supplied URI could not be parsed correctly.

parseBNode

public static BNode parseBNode(String nTriplesBNode,
                               ValueFactory valueFactory)
                        throws IllegalArgumentException
Parses an N-Triples bNode, creates an object for it using the supplied ValueFactory and returns this object.

Parameters:
nTriplesBNode - The N-Triples bNode to parse.
valueFactory - The ValueFactory to use for creating the object.
Returns:
An object representing the parsed bNode.
Throws:
IllegalArgumentException - If the supplied bNode could not be parsed correctly.

parseLiteral

public static Literal parseLiteral(String nTriplesLiteral,
                                   ValueFactory valueFactory)
                            throws IllegalArgumentException
Parses an N-Triples literal, creates an object for it using the supplied ValueFactory and returns this object.

Parameters:
nTriplesLiteral - The N-Triples literal to parse.
valueFactory - The ValueFactory to use for creating the object.
Returns:
An object representing the parsed literal.
Throws:
IllegalArgumentException - If the supplied literal could not be parsed correctly.

toNTriplesString

public static String toNTriplesString(Value value)
Creates an N-Triples string for the supplied value.


toNTriplesString

public static String toNTriplesString(Resource resource)
Creates an N-Triples string for the supplied resource.


toNTriplesString

public static String toNTriplesString(URI uri)
Creates an N-Triples string for the supplied URI.


toNTriplesString

public static String toNTriplesString(BNode bNode)
Creates an N-Triples string for the supplied bNode.


toNTriplesString

public static String toNTriplesString(Literal lit)
Creates an N-Triples string for the supplied literal.


isLetterOrNumber

public static boolean isLetterOrNumber(int c)
Checks whether the supplied character is a letter or number according to the N-Triples specification.

See Also:
isLetter(int), isNumber(int)

isLetter

public static boolean isLetter(int c)
Checks whether the supplied character is a letter according to the N-Triples specification. N-Triples letters are A - Z and a - z.


isNumber

public static boolean isNumber(int c)
Checks whether the supplied character is a number according to the N-Triples specification. N-Triples numbers are 0 - 9.


escapeString

public static String escapeString(String label)
Escapes a Unicode string to an all-ASCII character sequence. Any special characters are escaped using backslashes (" becomes \", etc.), and non-ascii/non-printable characters are escaped using Unicode escapes (\uxxxx and \Uxxxxxxxx).


unescapeString

public static String unescapeString(String s)
Unescapes an escaped Unicode string. Any Unicode sequences (\uxxxx and \Uxxxxxxxx) are restored to the value indicated by the hexadecimal argument and any backslash-escapes (\", \\, etc.) are decoded to their original form.

Parameters:
s - An escaped Unicode string.
Returns:
The unescaped string.
Throws:
IllegalArgumentException - If the supplied string is not a correctly escaped N-Triples string.

toHexString

public static String toHexString(int decimal,
                                 int stringLength)
Converts a decimal value to a hexadecimal string represention of the specified length.

Parameters:
decimal - A decimal value.
stringLength - The length of the resulting string.


Copyright © 2001-2008 Aduna. All Rights Reserved.