1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * https://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.api.ldap.model.name; 21 22 23 import java.io.StringReader; 24 import java.util.List; 25 26 import org.apache.directory.api.ldap.model.exception.LdapInvalidDnException; 27 import org.apache.directory.api.ldap.model.message.ResultCodeEnum; 28 import org.apache.directory.api.ldap.model.schema.SchemaManager; 29 30 31 /** 32 * A Dn parser that is able to parse complex DNs. This is an Antlr based parser. 33 * 34 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 35 */ 36 /* No protection*/class ComplexDnParser 37 { 38 39 /** 40 * Parses an Dn. 41 * 42 * @param schemaManager The SchemaManager 43 * @param name the string representation of the distinguished name 44 * @param rdns the (empty) list where parsed RDNs are put to 45 * @return The normalized Dn 46 * 47 * @throws LdapInvalidDnException the invalid name exception 48 */ 49 /* No protection*/String parseDn( SchemaManager schemaManager, String name, List<Rdn> rdns ) throws LdapInvalidDnException 50 { 51 AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name ) ) ); 52 53 try 54 { 55 return dnParser.relativeDistinguishedNames( schemaManager, rdns ); 56 } 57 catch ( Exception e ) 58 { 59 throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, e.getMessage(), e ); 60 } 61 } 62 63 64 /** 65 * Parses an Rdn. 66 * 67 * @param schemaManager The SchemaManager 68 * @param name the string representation of the relative distinguished name 69 * @param rdn the (empty) Rdn where parsed ATAVs are put into 70 * 71 * @throws LdapInvalidDnException the invalid name exception 72 */ 73 /* No protection*/void parseRdn( SchemaManager schemaManager, String name, Rdn rdn ) throws LdapInvalidDnException 74 { 75 AntlrDnParser dnParser = new AntlrDnParser( new AntlrDnLexer( new StringReader( name ) ) ); 76 77 try 78 { 79 dnParser.relativeDistinguishedName( schemaManager, rdn ); 80 } 81 catch ( Exception e ) 82 { 83 throw new LdapInvalidDnException( ResultCodeEnum.INVALID_DN_SYNTAX, e.getMessage(), e ); 84 } 85 } 86 }