当前位置: 首页>>代码示例>>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;未经允许,请勿转载。