MCPcopy Create free account
hub / github.com/BaseXdb/basex / uri2path

Method uri2path

basex-core/src/main/java/org/basex/util/Strings.java:355–385  ·  view source on GitHub ↗

Converts a URI to a directory path. See https://docs.basex.org/wiki/Repository#URI_Rewriting for details. @param uri namespace URI @return converted path

(final String uri)

Source from the content-addressed store, hash-verified

353 * @return converted path
354 */
355 public static String uri2path(final String uri) {
356 String path = uri;
357 try {
358 final URI u = new URI(uri);
359 final TokenBuilder tb = new TokenBuilder();
360 if(u.isOpaque()) {
361 tb.add(u.getScheme()).add('/').add(u.getSchemeSpecificPart().replace(':', '/'));
362 } else {
363 final String auth = u.getAuthority();
364 if(auth != null) {
365 // reverse authority, replace dots by slashes. example: basex.org → org/basex
366 final String[] comp = split(auth, '.');
367 for(int c = comp.length - 1; c >= 0; c--) tb.add('/').add(comp[c]);
368 }
369 // add remaining path
370 final String p = u.getPath();
371 tb.add(p == null || p.isEmpty() ? "/" : p.replace('.', '/'));
372 }
373 path = tb.toString();
374 } catch(final URISyntaxException ex) {
375 Util.debug(ex);
376 }
377
378 // replace special characters with dashes; remove multiple slashes
379 path = path.replaceAll("[^\\w.-/]+", "-").replaceAll("//+", "/");
380 // add "index" string
381 if(endsWith(path, '/')) path += "index";
382 // remove heading slash
383 if(startsWith(path, '/')) path = path.substring(1);
384 return path;
385 }
386
387 /**
388 * Canonicalizes a string: heuristic CP437/UTF-8 mojibake fix followed by Unicode normalization.

Callers 7

uri2PathMethod · 0.95
repoFilePathMethod · 0.95
getMethod · 0.95
installXQMethod · 0.95
writeMethod · 0.95
addImportMethod · 0.95
jarUrlsMethod · 0.95

Calls 10

addMethod · 0.95
splitMethod · 0.95
toStringMethod · 0.95
debugMethod · 0.95
endsWithMethod · 0.95
startsWithMethod · 0.95
addMethod · 0.65
replaceMethod · 0.45
isEmptyMethod · 0.45
substringMethod · 0.45

Tested by 1

uri2PathMethod · 0.76