KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > directory > ldapstudio > browser > core > internal > model > JNDIUtils


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  * http://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
21 package org.apache.directory.ldapstudio.browser.core.internal.model;
22
23
24 import javax.naming.NamingException JavaDoc;
25 import javax.naming.directory.SearchResult JavaDoc;
26
27 import org.apache.directory.ldapstudio.browser.core.model.DN;
28 import org.apache.directory.ldapstudio.browser.core.model.NameException;
29
30
31 public class JNDIUtils
32 {
33
34     public static DN getDn( SearchResult sr, String JavaDoc base, JNDIConnectionContext context ) throws NamingException JavaDoc,
35         NameException, NoSuchFieldException JavaDoc
36     {
37         String JavaDoc dn = sr.getNameInNamespace();
38         dn = unescapeJndiName( dn );
39         return new DN( dn );
40     }
41
42
43     /**
44      * Correct some JNDI encodings...
45      *
46      * @param name
47      * @return
48      */

49     public static String JavaDoc unescapeJndiName( String JavaDoc name )
50     {
51
52         if ( name.startsWith( "\"" ) && name.endsWith( "\"" ) ) { //$NON-NLS-1$ //$NON-NLS-2$
53
name = name.substring( 1, name.length() - 1 );
54         }
55
56         name = name.replaceAll( "\\\\\\\\\"", "\\\\\"" ); //$NON-NLS-1$ //$NON-NLS-2$
57
name = name.replaceAll( "\\\\2C", "\\\\," ); //$NON-NLS-1$ //$NON-NLS-2$
58
name = name.replaceAll( "\\\\3B", "\\\\;" ); //$NON-NLS-1$ //$NON-NLS-2$
59
name = name.replaceAll( "\\\\22", "\\\\\"" ); //$NON-NLS-1$ //$NON-NLS-2$
60
name = name.replaceAll( "\\\\3C", "\\\\<" ); //$NON-NLS-1$ //$NON-NLS-2$
61
name = name.replaceAll( "\\\\3E", "\\\\>" ); //$NON-NLS-1$ //$NON-NLS-2$
62
name = name.replaceAll( "\\\\2B", "\\\\+" ); //$NON-NLS-1$ //$NON-NLS-2$
63
name = name.replaceAll( "\\\\5C", "\\\\\\\\" ); //$NON-NLS-1$ //$NON-NLS-2$
64

65         return name;
66     }
67
68 }
69
Popular Tags