public static void printPrefixes(Prologue prologue, IndentedWriter out) { if (prologue.getPrefixMapping() == null) return; Map<String, String> pmap = null; if (prologue.getPrefixMapping() instanceof PrefixMapping2) { PrefixMapping2 pm2 = (PrefixMapping2) prologue.getPrefixMapping(); pmap = pm2.getNsPrefixMap(false); } else { Map<String, String> _pmap = prologue.getPrefixMapping().getNsPrefixMap(); pmap = _pmap; } if (pmap.size() > 0) { // boolean first = true ; for (String k : pmap.keySet()) { String v = pmap.get(k); out.print("PREFIX "); out.print(k); out.print(':'); out.print(' ', 4 - k.length()); // Include at least one space out.print(' '); out.print(FmtUtils.stringForURI(v)); out.newline(); } } }
// c.f. FmtUtils.stringForURI // Uses PrefixMap, not PrefixMapping static String stringForURI(String uri, String base, PrefixMap mapping) { if (mapping != null) { String pname = mapping.abbreviate(uri); if (pname != null) return pname; } if (base != null) { String x = FmtUtils.abbrevByBase(uri, base); if (x != null) return "<" + x + ">"; } return FmtUtils.stringForURI(uri); }
private void outputStringAsURI(String uriStr) { String x = FmtUtils.stringForURI(uriStr, sCxt); out.print(x); }