[ https://issues.apache.org/jira/browse/JCR-5140?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Julian Reschke updated JCR-5140: -------------------------------- Description: There are a few use cases where a new namespace prefix needs to be computed for a given namespace name (this list may not be exhaustive): - when mapping expanded names to JCR names when the namespace name (URI) is not known in the repository (yet) - when importing content where namespace names (URIs) are known, but no prefixes are known - when registering a new namespace, but the specified prefix is already in use Automatically generating the prefixes has several commons problems: - consistency: generating prefixes in different places and/or based on previous state of the registry (incrementing counters until new prefix found) causes prefix inconsistency across systems for no good reason - conciseness and readability: for certain namespaces, there are commonly used prefixes (such as in DC, XMPP etc), and it would be good to just use those when possible Proposal: have a single place that offers help for generating prefixes (this ticket is in JCR space as jackrabbit-commons already has NamespaceHelper, but of course the location can be discussed). Blue print: {code:java} // Suggests a prefix for the given namespace, based on // well-known XML namespaces, or alternatively derived // from the namespace name. public static String suggestPrefix(String namespace); // as above, but will take exisiting prefixes into account // this would be for the case where the prefix already exists // but is mapped to a different namespace name. // Lookup for existing prefix so that we can abstract out the // actual JCR interface (to be discussed) public static String suggestPrefix(String namespace, Function<String, String> getNamespaceForPrefix); // maybe more helpers: public static boolean isValidNamespace(String namespace); public static Map.Entry<String, String> extractPrefixAndNamespace(String jcrName, Function<String, String> getNamespaceForPrefix);{code} We'd also need a hook to account for "internal", unless we want to hard-wire that into this. was: There are a few use cases where a new namespace prefix needs to be computed for a given namespace name (this list may not be exhaustive): - when mapping expanded names to JCR names when the namespace name (URI) is not known in the repository (yet) - when importing content where namespace names (URIs) are known, but no prefixes are known - when registering a new namespace, but the specified prefix is already in use Automatically generating the prefixes has several commons problems: - consistency: generating prefixes in different places and/or based on previous state of the registry (incrementing counters until new prefix found) causes prefix inconsistency across systems for no good reason - conciseness and readability: for certain namespaces, there are commonly used prefixes (such as in DC, XMPP etc), and it would be good to just use those when possible Proposal: have a single place that offers help for generating prefixes (this ticket is in JCR space as jackrabbit-commons already has NamespaceHelper, but of course the location can be discussed). Blue print: {code:java} // Suggests a prefix for the given namespace, based on // well-known XML namespaces, or alternatively derived // from the namespace name. public static String suggestPrefix(String namespace); // as above, but will take exisiting prefixes into account // this would be for the case where the prefix already exists // but is mapped to a different namespace name. // Lookup for existing prefix so that we can abstract out the // actual JCR interface (to be discussed) public static String suggestPrefix(String namespace, Function<String, String> getNamespaceForPrefix); // maybe more helpers: public static boolean isValidNamespace(String namespace); public static Map.Entry<String, String> extractPrefixAndNamespace(String jcrName, Function<String, String> getNamespaceForPrefix);{code} > Improve support for generating namespace prefixes > ------------------------------------------------- > > Key: JCR-5140 > URL: https://issues.apache.org/jira/browse/JCR-5140 > Project: Jackrabbit Content Repository > Issue Type: Task > Components: jackrabbit-jcr-commons > Reporter: Julian Reschke > Priority: Major > > There are a few use cases where a new namespace prefix needs to be computed > for a given namespace name (this list may not be exhaustive): > - when mapping expanded names to JCR names when the namespace name (URI) is > not known in the repository (yet) > - when importing content where namespace names (URIs) are known, but no > prefixes are known > - when registering a new namespace, but the specified prefix is already in > use > Automatically generating the prefixes has several commons problems: > - consistency: generating prefixes in different places and/or based on > previous state of the registry (incrementing counters until new prefix found) > causes prefix inconsistency across systems for no good reason > - conciseness and readability: for certain namespaces, there are commonly > used prefixes (such as in DC, XMPP etc), and it would be good to just use > those when possible > Proposal: have a single place that offers help for generating prefixes (this > ticket is in JCR space as jackrabbit-commons already has NamespaceHelper, but > of course the location can be discussed). > Blue print: > {code:java} > // Suggests a prefix for the given namespace, based on > // well-known XML namespaces, or alternatively derived > // from the namespace name. > public static String suggestPrefix(String namespace); > // as above, but will take exisiting prefixes into account > // this would be for the case where the prefix already exists > // but is mapped to a different namespace name. > // Lookup for existing prefix so that we can abstract out the > // actual JCR interface (to be discussed) > public static String suggestPrefix(String namespace, Function<String, String> > getNamespaceForPrefix); > // maybe more helpers: > public static boolean isValidNamespace(String namespace); > public static Map.Entry<String, String> extractPrefixAndNamespace(String > jcrName, Function<String, String> getNamespaceForPrefix);{code} > We'd also need a hook to account for "internal", unless we want to hard-wire > that into this. -- This message was sent by Atlassian Jira (v8.20.10#820010)