| | |
| | | * </table> |
| | | */ |
| | | final class DnTemplate { |
| | | private static final Pattern TEMPLATE_KEY_RE = Pattern.compile("\\{([^}]+)\\}"); |
| | | private static final Pattern TEMPLATE_VARIABLE_RE = Pattern.compile("\\{([^}]+)\\}"); |
| | | private final String template; |
| | | private final String formatString; |
| | | private final List<String> variables; |
| | | /** A value of -1 means that this DN template is absolute. */ |
| | | private final int relativeOffset; |
| | | |
| | | /** |
| | |
| | | |
| | | /** |
| | | * Compiles a DN template which will resolve LDAP entries relative to the root DSE by default, but MAY include |
| | | * relative RDNs indicating that that the DN template will be resolved against current routing state |
| | | * instead. |
| | | * relative RDNs indicating that the DN template will be resolved against current routing state instead. |
| | | * |
| | | * @param template |
| | | * The string representation of the DN template. |
| | |
| | | } |
| | | |
| | | final List<String> templateVariables = new ArrayList<>(); |
| | | final Matcher matcher = TEMPLATE_KEY_RE.matcher(trimmedTemplate); |
| | | final Matcher matcher = TEMPLATE_VARIABLE_RE.matcher(trimmedTemplate); |
| | | final StringBuffer buffer = new StringBuffer(trimmedTemplate.length()); |
| | | while (matcher.find()) { |
| | | matcher.appendReplacement(buffer, "%s"); |
| | |
| | | // First determine the base DN based on the context DN and the relative offset. |
| | | DN baseDn = null; |
| | | if (relativeOffset >= 0 && context.containsContext(RoutingContext.class)) { |
| | | baseDn = context.asContext(RoutingContext.class).getDn().parent(relativeOffset); |
| | | final RoutingContext routingContext = context.asContext(RoutingContext.class); |
| | | baseDn = routingContext.getDn().parent(routingContext.isCollection() ? relativeOffset - 1 : relativeOffset); |
| | | } |
| | | if (baseDn == null) { |
| | | baseDn = DN.rootDN(); |
| | |
| | | return value; |
| | | } |
| | | if (!uriRouterContext.getParent().containsContext(UriRouterContext.class)) { |
| | | throw new IllegalStateException("DN template parameter " + parameter + " cannot be resolved"); |
| | | throw new IllegalStateException("DN template parameter \"" + parameter + "\" cannot be resolved"); |
| | | } |
| | | uriRouterContext = uriRouterContext.getParent().asContext(UriRouterContext.class); |
| | | } |