001/*
002 * (C) Copyright 2009 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 */
017package org.nuxeo.ecm.directory.ldap;
018
019import javax.naming.directory.SearchControls;
020
021/**
022 * Helper for translating ldap search scope from string to integer
023 *
024 * @author Anahide Tchertchian
025 */
026public class LdapScope {
027
028    /**
029     * Returns the associated integer for scope, comparing lower case. Returns null if not one of "object", "onelevel"
030     * or "subtree".
031     */
032    public static Integer getIntegerScope(String scopeString) {
033        if (scopeString != null) {
034            scopeString = scopeString.toLowerCase();
035            if ("object".equals(scopeString)) {
036                return Integer.valueOf(SearchControls.OBJECT_SCOPE);
037            } else if ("onelevel".equals(scopeString)) {
038                return Integer.valueOf(SearchControls.ONELEVEL_SCOPE);
039            } else if ("subtree".equals(scopeString)) {
040                return SearchControls.SUBTREE_SCOPE;
041            }
042        }
043        return null;
044    }
045
046}