-
Notifications
You must be signed in to change notification settings - Fork 415
OAK-10952: improve autogenerated namespace prefixes - test with prototype #2237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Conversation
…type
Commit-Check ✔️ |
|
SHA-1 would be 160 bits, thus 20 bytes, right? That's not always less than the actual namespace name. I could however special case that case.
That's a separate issue. I believe we already found out that it can be done using the namespace registry, although risky. The point of this is to reduce the number of cases where it actually comes up. |
I was thinking of something like the |
-> 7024038 |
re valid prefixes: the JCR spec allows many characters here; but checking exactly might be hard and overkill. As valid URIs, strictly speaking, are only ASCII, we should filter out all non-ASCII. That would leaves with a short "allow" list of characters. |
…ix - starting with 7 chars
+1, |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good, some minor remarks only.
|
||
// public API: suggest an available prefix for the provided namespace | ||
// (while considering pre-existing mappings) | ||
private static @NotNull String suggestPrefix(@NotNull String namespace, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest is a bit fuzzy to me, why not getUnusedPrefix(...)
String prefix = namespace.toLowerCase(Locale.ENGLISH); | ||
|
||
// https://www.w3.org/guide/editor/namespaces.html | ||
if (prefix.startsWith("http://www.w3c.org/ns/")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let us use String constants and their length method to get rid of the magical size.
// in the namespace name | ||
// (while considering pre-existing mappings) | ||
private static @NotNull String makeUpPrefix(@NotNull String namespace, | ||
@NotNull Function<String, String> lookupNamespace) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lookupNamespace
is hard to grasp why not getRegisteredNamespaceForPrefix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be rather named getRegisteredPrefix() here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this returns a namespace URI for a given prefix (not the other way around). But this definitely calls for a non ambiguous name.
I would place this in |
PoC, hopefully illustrating the idea.
(needs more documentation and support for edge cases, final location in project to be decided)