public static String toString(UID uid) { return "<" + NTriplesUtil.escapeString(uid.getValue()) + ">"; }
public static String escapeString(String label) { int labelLength = label.length(); StringBuilder sb = new StringBuilder(2 * labelLength); for (int i = 0; i < labelLength; i++) { char c = label.charAt(i); int cInt = c; if (c == '\\') { sb.append("\\\\"); } else if (c == '"') { sb.append("\\\""); } else if (c == '\n') { sb.append("\\n"); } else if (c == '\r') { sb.append("\\r"); } else if (c == '\t') { sb.append("\\t"); } else if (cInt >= 0x0 && cInt <= 0x8 || cInt == 0xB || cInt == 0xC || cInt >= 0xE && cInt <= 0x1F || cInt >= 0x7F && cInt <= 0xFFFF) { sb.append("\\u"); sb.append(toHexString(cInt, 4)); } else if (cInt >= 0x10000 && cInt <= 0x10FFFF) { sb.append("\\U"); sb.append(toHexString(cInt, 8)); } else { sb.append(c); } } return sb.toString(); }
protected void appendPrefixed(UID uid) throws IOException { String prefix = prefixes.get(uid.ns()); if (prefix != null) { appendable.append(prefix).append(":").append(uid.ln()); } else { appendable.append("<").append(NTriplesUtil.escapeString(uid.getId())).append(">"); } }
@Override protected void appendPrefixed(UID uid) throws IOException { String prefix = prefixes.get(uid.ns()); if (prefix == null) { prefix = Namespaces.DEFAULT.get(uid.ns()); if (prefix == null) { prefix = "ns" + (prefixes.size() + 1); } prefixes.put(uid.ns(), prefix); prefixesString.append("@prefix " + prefix + ": <" + NTriplesUtil.escapeString(uid.ns()) + "> .\n"); } appendable.append(prefix).append(":").append(uid.ln()); }
@Override protected void append(UID uid) { String prefix = prefixes.get(uid.ns()); if (prefix == null) { prefix = Namespaces.DEFAULT.get(uid.ns()); if (prefix == null) { prefix = "ns" + (prefixes.size() + 1); } prefixes.put(uid.ns(), prefix); prefixesString.append("PREFIX " + prefix + ": <" + NTriplesUtil.escapeString(uid.ns()) + ">\n"); } try { appendable.append(prefix).append(":").append(uid.ln()); } catch (IOException e) { throw new RepositoryException(e); } }
public static String toString(LIT lit) { String value = "\"" + NTriplesUtil.escapeString(lit.getValue()) + "\""; if (lit.getLang() != null) { return value + "@" + LocaleUtil.toLang(lit.getLang()); } else { return value + "^^" + toString(lit.getDatatype()); } }