當前位置: 首頁>>代碼示例>>Java>>正文


Java DirContext.lookup方法代碼示例

本文整理匯總了Java中javax.naming.directory.DirContext.lookup方法的典型用法代碼示例。如果您正苦於以下問題:Java DirContext.lookup方法的具體用法?Java DirContext.lookup怎麽用?Java DirContext.lookup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.naming.directory.DirContext的用法示例。


在下文中一共展示了DirContext.lookup方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getReadme

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * Get the readme file as a string.
 */
protected String getReadme(DirContext directory)
    throws IOException, ServletException {

    if (readmeFile != null) {
        try {
            Object obj = directory.lookup(readmeFile);
            if ((obj != null) && (obj instanceof Resource)) {
                StringWriter buffer = new StringWriter();
                InputStream is = ((Resource) obj).streamContent();
                copyRange(new InputStreamReader(is),
                        new PrintWriter(buffer));
                return buffer.toString();
            }
        } catch (NamingException e) {
            if (debug > 10)
                log("readme '" + readmeFile + "' not found", e);

            return null;
        }
    }

    return null;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:DefaultServlet.java

示例2: getResourceAsStream

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * Return the requested resource as an <code>InputStream</code>.  The
 * path must be specified according to the rules described under
 * <code>getResource</code>.  If no such resource can be identified,
 * return <code>null</code>.
 *
 * @param path The path to the desired resource.
 */
public InputStream getResourceAsStream(String path) {

    if (path == null || (Globals.STRICT_SERVLET_COMPLIANCE && !path.startsWith("/")))
        return (null);

    path = RequestUtil.normalize(path);
    if (path == null)
        return (null);

    DirContext resources = context.getResources();
    if (resources != null) {
        try {
            Object resource = resources.lookup(path);
            if (resource instanceof Resource)
                return (((Resource) resource).streamContent());
        } catch (Exception e) {
        }
    }
    return (null);

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:30,代碼來源:ApplicationContext.java

示例3: determineMethodsAllowed

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * Determines the methods normally allowed for the resource.
 *
 */
private StringBuilder determineMethodsAllowed(DirContext dirContext,
                                             HttpServletRequest req) {

    StringBuilder methodsAllowed = new StringBuilder();
    boolean exists = true;
    Object object = null;
    try {
        String path = getRelativePath(req);

        object = dirContext.lookup(path);
    } catch (NamingException e) {
        exists = false;
    }

    if (!exists) {
        methodsAllowed.append("OPTIONS, MKCOL, PUT, LOCK");
        return methodsAllowed;
    }

    methodsAllowed.append("OPTIONS, GET, HEAD, POST, DELETE, TRACE");
    methodsAllowed.append(", PROPPATCH, COPY, MOVE, LOCK, UNLOCK");

    if (listings) {
        methodsAllowed.append(", PROPFIND");
    }

    if (!(object instanceof DirContext)) {
        methodsAllowed.append(", PUT");
    }

    return methodsAllowed;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:37,代碼來源:WebdavServlet.java

示例4: getObjectDn

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * Low level method: Retrieves a serialized Java Object,
 * using the specified dn/pswd for authorization.
 * See {@link #storeObjectDn storeObjectDn}.
 *
 * @param authDn   the authorized dn (distinguished name) of the caller
 * @param password the password associated with authDn
 * @param objectDn the dn of the object.
 */

public Object getObjectDn(
	String authDn,
	String password,
	String objectDn)
throws LdapException
{
	chkstg( "object dn", objectDn);

	Object obj = null;
	DirContext dirctx = getDirContext( authDn, password);
	try {
		obj = dirctx.lookup( objectDn);
		if (bugs >= 1 && obj instanceof Context) {
			Context ctx = (Context) obj;
			prtln("getObjectDn: got Context: " + ctx.getNameInNamespace());
		}
	}
	catch( NamingException nexc) {
		if (bugs >= 1) {
			prtln("getObjectDn: nexc: " + nexc);
			nexc.printStackTrace();
			prtln();
			prtln("authDn: \"" + authDn + "\"");
			prtln("password: \"" + password + "\"");
			prtln("objectDn: \"" + objectDn + "\"");
			prtln();
		}
		throw new LdapException("getObjectDn: exception", nexc);
	}
	return obj;
}
 
開發者ID:NCAR,項目名稱:joai-project,代碼行數:42,代碼來源:LdapClient.java

示例5: determineMethodsAllowed

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * Determines the methods normally allowed for the resource.
 *
 */
private StringBuffer determineMethodsAllowed(DirContext resources,
                                             HttpServletRequest req) {

    StringBuffer methodsAllowed = new StringBuffer();
    boolean exists = true;
    Object object = null;
    try {
        String path = getRelativePath(req);

        object = resources.lookup(path);
    } catch (NamingException e) {
        exists = false;
    }

    if (!exists) {
        methodsAllowed.append("OPTIONS, MKCOL, PUT, LOCK");
        return methodsAllowed;
    }

    methodsAllowed.append("OPTIONS, GET, HEAD, POST, DELETE, TRACE");
    methodsAllowed.append(", PROPPATCH, COPY, MOVE, LOCK, UNLOCK");

    if (listings) {
        methodsAllowed.append(", PROPFIND");
    }

    if (!(object instanceof DirContext)) {
        methodsAllowed.append(", PUT");
    }

    return methodsAllowed;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:37,代碼來源:WebdavServlet.java

示例6: doOptions

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * OPTIONS Method.
 */
protected void doOptions(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {

    String path = getRelativePath(req);

    resp.addHeader("DAV", "1,2");
    String methodsAllowed = null;

    // Retrieve the resources
    DirContext resources = getResources();

    if (resources == null) {
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
    }

    boolean exists = true;
    Object object = null;
    try {
        object = resources.lookup(path);
    } catch (NamingException e) {
        exists = false;
    }

    if (!exists) {
        methodsAllowed = "OPTIONS, MKCOL, PUT, LOCK";
        resp.addHeader("Allow", methodsAllowed);
        return;
    }

    methodsAllowed = "OPTIONS, GET, HEAD, POST, DELETE, TRACE, "
        + "PROPFIND, PROPPATCH, COPY, MOVE, LOCK, UNLOCK";
    if (!(object instanceof DirContext)) {
        methodsAllowed += ", PUT";
    }

    resp.addHeader("Allow", methodsAllowed);

    resp.addHeader("MS-Author-Via", "DAV");

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:45,代碼來源:WebdavServlet.java

示例7: getResource

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * Return the URL to the resource that is mapped to a specified path.
 * The path must begin with a "/" and is interpreted as relative to the
 * current context root.
 *
 * @param path The path to the desired resource
 *
 * @exception MalformedURLException if the path is not given
 *  in the correct form
 */
public URL getResource(String path)
    throws MalformedURLException {

    DirContext resources = context.getResources();
    if (resources != null) {
        String fullPath = context.getName() + path;

        // this is the problem. Host must not be null
        String hostName = context.getParent().getName();

        try {
            resources.lookup(path);
            if( System.getSecurityManager() != null ) {
                try {
                    PrivilegedGetResource dp =
                        new PrivilegedGetResource
                            (hostName, fullPath, resources);
                    return (URL)AccessController.doPrivileged(dp);
                } catch( PrivilegedActionException pe) {
                    throw pe.getException();
                }
            } else {
                return new URL
                    ("jndi", null, 0, getJNDIUri(hostName, fullPath),
                     new DirContextURLStreamHandler(resources));
            }
        } catch (Exception e) {
            //e.printStackTrace();
        }
    }
    return (null);

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:44,代碼來源:ApplicationContext.java

示例8: getResourceAsStream

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * Return the requested resource as an <code>InputStream</code>.  The
 * path must be specified according to the rules described under
 * <code>getResource</code>.  If no such resource can be identified,
 * return <code>null</code>.
 *
 * @param path The path to the desired resource.
 */
public InputStream getResourceAsStream(String path) {

    DirContext resources = context.getResources();
    if (resources != null) {
        try {
            Object resource = resources.lookup(path);
            if (resource instanceof Resource)
                return (((Resource) resource).streamContent());
        } catch (Exception e) {
        }
    }
    return (null);

}
 
開發者ID:c-rainstorm,項目名稱:jerrydog,代碼行數:23,代碼來源:ApplicationContext.java

示例9: determineMethodsAllowed

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * Determines the methods normally allowed for the resource.
 *
 */
private StringBuilder determineMethodsAllowed(DirContext dirContext, HttpServletRequest req) {

	StringBuilder methodsAllowed = new StringBuilder();
	boolean exists = true;
	Object object = null;
	try {
		String path = getRelativePath(req);

		object = dirContext.lookup(path);
	} catch (NamingException e) {
		exists = false;
	}

	if (!exists) {
		methodsAllowed.append("OPTIONS, MKCOL, PUT, LOCK");
		return methodsAllowed;
	}

	methodsAllowed.append("OPTIONS, GET, HEAD, POST, DELETE");
	// Trace - assume disabled unless we can prove otherwise
	if (req instanceof RequestFacade && ((RequestFacade) req).getAllowTrace()) {
		methodsAllowed.append(", TRACE");
	}
	methodsAllowed.append(", PROPPATCH, COPY, MOVE, LOCK, UNLOCK");

	if (listings) {
		methodsAllowed.append(", PROPFIND");
	}

	if (!(object instanceof DirContext)) {
		methodsAllowed.append(", PUT");
	}

	return methodsAllowed;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:40,代碼來源:WebdavServlet.java

示例10: resourcesStart

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * Allocate resources, including proxy.
 * Return <code>true</code> if initialization was successfull,
 * or <code>false</code> otherwise.
 */
public boolean resourcesStart() {

    boolean ok = true;

    Hashtable<String, String> env = new Hashtable<String, String>();
    if (getParent() != null)
        env.put(ProxyDirContext.HOST, getParent().getName());
    env.put(ProxyDirContext.CONTEXT, getName());

    try {
        ProxyDirContext proxyDirContext =
            new ProxyDirContext(env, webappResources);
        if (webappResources instanceof FileDirContext) {
            filesystemBased = true;
            ((FileDirContext) webappResources).setAllowLinking
                (isAllowLinking());
        }
        if (webappResources instanceof BaseDirContext) {
            ((BaseDirContext) webappResources).setDocBase(getBasePath());
            ((BaseDirContext) webappResources).setCached
                (isCachingAllowed());
            ((BaseDirContext) webappResources).setCacheTTL(getCacheTTL());
            ((BaseDirContext) webappResources).setCacheMaxSize
                (getCacheMaxSize());
            ((BaseDirContext) webappResources).allocate();
            // Alias support
            ((BaseDirContext) webappResources).setAliases(getAliases());
            
            if (effectiveMajorVersion >=3 && addWebinfClassesResources) {
                try {
                    DirContext webInfCtx =
                        (DirContext) webappResources.lookup(
                                "/WEB-INF/classes");
                    // Do the lookup to make sure it exists
                    webInfCtx.lookup("META-INF/resources");
                    ((BaseDirContext) webappResources).addAltDirContext(
                            webInfCtx);
                } catch (NamingException e) {
                    // Doesn't exist - ignore and carry on
                }
            }
        }
        // Register the cache in JMX
        if (isCachingAllowed() && proxyDirContext.getCache() != null) {
            String contextName = getName();
            if (!contextName.startsWith("/")) {
                contextName = "/" + contextName;
            }
            ObjectName resourcesName = 
                new ObjectName(this.getDomain() + ":type=Cache,host=" 
                               + getHostname() + ",context=" + contextName);
            Registry.getRegistry(null, null).registerComponent
                (proxyDirContext.getCache(), resourcesName, null);
        }
        this.resources = proxyDirContext;
    } catch (Throwable t) {
        ExceptionUtils.handleThrowable(t);
        log.error(sm.getString("standardContext.resourcesStart"), t);
        ok = false;
    }

    return (ok);

}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:70,代碼來源:StandardContext.java

示例11: doLookupWithoutNNFE

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
private Object doLookupWithoutNNFE(String name) throws NamingException {
    if (!aliases.isEmpty()) {
        AliasResult result = findAlias(name);
        if (result.dirContext != null) {
            return result.dirContext.lookup(result.aliasName);
        }
    }

    // Next do a standard lookup
    Object obj = doLookup(name);

    if (obj != null) {
        return obj;
    }

    // Class files may not be loaded from the alternate locations so don't
    // waste cycles looking.
    if (name.endsWith(".class")) {
        return null;
    }
    
    // Check the alternate locations (Resource JARs)
    String resourceName = "/META-INF/resources" + name;
    for (DirContext altDirContext : altDirContexts) {
        if (altDirContext instanceof BaseDirContext) {
            obj = ((BaseDirContext) altDirContext)
                    .doLookupWithoutNNFE(resourceName);
        } else {
            try {
                obj = altDirContext.lookup(resourceName);
            } catch (NamingException ex) {
                // ignore
            }
        }
        if (obj != null) {
            return obj;
        }
    }

    // Return null instead
    return null;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:43,代碼來源:BaseDirContext.java

示例12: resourcesStart

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
/**
 * Allocate resources, including proxy. Return <code>true</code> if
 * initialization was successfull, or <code>false</code> otherwise.
 */
public boolean resourcesStart() {

	boolean ok = true;

	Hashtable<String, String> env = new Hashtable<String, String>();
	if (getParent() != null)
		env.put(ProxyDirContext.HOST, getParent().getName());
	env.put(ProxyDirContext.CONTEXT, getName());

	try {
		ProxyDirContext proxyDirContext = new ProxyDirContext(env, webappResources);
		if (webappResources instanceof FileDirContext) {
			filesystemBased = true;
			((FileDirContext) webappResources).setAllowLinking(isAllowLinking());
		}
		if (webappResources instanceof BaseDirContext) {
			((BaseDirContext) webappResources).setDocBase(getBasePath());
			((BaseDirContext) webappResources).setCached(isCachingAllowed());
			((BaseDirContext) webappResources).setCacheTTL(getCacheTTL());
			((BaseDirContext) webappResources).setCacheMaxSize(getCacheMaxSize());
			((BaseDirContext) webappResources).allocate();
			// Alias support
			((BaseDirContext) webappResources).setAliases(getAliases());

			if (effectiveMajorVersion >= 3 && addWebinfClassesResources) {
				try {
					DirContext webInfCtx = (DirContext) webappResources.lookup("/WEB-INF/classes");
					// Do the lookup to make sure it exists
					webInfCtx.lookup("META-INF/resources");
					((BaseDirContext) webappResources).addAltDirContext(webInfCtx);
				} catch (NamingException e) {
					// Doesn't exist - ignore and carry on
				}
			}
		}
		// Register the cache in JMX
		if (isCachingAllowed() && proxyDirContext.getCache() != null) {
			String contextName = getName();
			if (!contextName.startsWith("/")) {
				contextName = "/" + contextName;
			}
			ObjectName resourcesName = new ObjectName(
					this.getDomain() + ":type=Cache,host=" + getHostname() + ",context=" + contextName);
			Registry.getRegistry(null, null).registerComponent(proxyDirContext.getCache(), resourcesName, null);
		}
		this.resources = proxyDirContext;
	} catch (Throwable t) {
		ExceptionUtils.handleThrowable(t);
		log.error(sm.getString("standardContext.resourcesStart"), t);
		ok = false;
	}

	return (ok);

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:60,代碼來源:StandardContext.java

示例13: doLookupWithoutNNFE

import javax.naming.directory.DirContext; //導入方法依賴的package包/類
private Object doLookupWithoutNNFE(String name) throws NamingException {
	if (!aliases.isEmpty()) {
		AliasResult result = findAlias(name);
		if (result.dirContext != null) {
			return result.dirContext.lookup(result.aliasName);
		}
	}

	// Next do a standard lookup
	Object obj = doLookup(name);

	if (obj != null) {
		return obj;
	}

	// Class files may not be loaded from the alternate locations so don't
	// waste cycles looking.
	if (name.endsWith(".class")) {
		return null;
	}

	// Check the alternate locations (Resource JARs)
	String resourceName = "/META-INF/resources" + name;
	for (DirContext altDirContext : altDirContexts) {
		if (altDirContext instanceof BaseDirContext) {
			obj = ((BaseDirContext) altDirContext).doLookupWithoutNNFE(resourceName);
		} else {
			try {
				obj = altDirContext.lookup(resourceName);
			} catch (NamingException ex) {
				// ignore
			}
		}
		if (obj != null) {
			return obj;
		}
	}

	// Return null instead
	return null;
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:42,代碼來源:BaseDirContext.java


注:本文中的javax.naming.directory.DirContext.lookup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。