public class Transcoding extends Object
Transcoding deals with the encoding of arbitrary URIs within the syntax of short names. This is necessary when rendering arbitrary predicates into XML, since legal NCNames need not be legal shortnames, and there may be no prefix available for the namespace. (Allocating and remembering prefixes would be stateful and would mean that the set of legal shortnames would depend on what renderings had been done since the last server restart.)
What we do is to define the /light encoding/ as: leave the lower-case letters alone and prefix any upper-case letter or "_" with "_". The well-known special characters (:/.-?) are translated to a mnemonic upper-case letter, and the other special characters are translated to _HH where the HH are (lower-case) hex digits. Additionally, a leading :// is converted to X (because CSS looks wrong) and a Z is inserted before the first character of the encoded local name. This encoding is reversible.
For a URI N:L where N is the namespace and L is the local name, N has prefix P, and L is a legal shortname, we encode as P_L.
If L isn't a legal shortname, we encode as pre_P_L', where L' is the light encoding of L.
In the remaining case, where there's no prefix for N, we give up and generate unknown_N'L'.
This requisitions the two pseudo-prefix names 'pre' and 'unknown', but we'll have to live with that.
Constructor and Description |
---|
Transcoding() |
Modifier and Type | Method and Description |
---|---|
static String |
decode(com.hp.hpl.jena.shared.PrefixMapping pm,
String shortName)
Answer the decoding (expansion) of the given shortname if it is in
transcoded form "unknown_ENCODED" or "pre_APREFIX_ENCODED", or if it is
of the form prefixName_localName, or null if it is not.
|
static String |
decodeLightly(String encoded) |
static String |
decodeMaybePrefixed(com.hp.hpl.jena.shared.PrefixMapping pm,
String shortName) |
static String |
encode(com.hp.hpl.jena.shared.PrefixMapping pm,
String any)
Encode the URI string
any into a "short"name. |
public static String decode(com.hp.hpl.jena.shared.PrefixMapping pm, String shortName)
public static String decodeMaybePrefixed(com.hp.hpl.jena.shared.PrefixMapping pm, String shortName)
public static String encode(com.hp.hpl.jena.shared.PrefixMapping pm, String any)
any
into a "short"name.
If any can be expressed as a legal shortname pre_local where
pre is the prefix for any's namespace and local is the
local name of any, return that. Otherwise, if the local
name isn't a legal shortname but a prefix exists, return
pre_thatPrefix_localnameEncoded. Otherwise, return
uri_theEntireURIencoded.Copyright © 2014. All Rights Reserved.