本文整理汇总了Java中org.apache.naming.resources.Resource类的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于org.apache.naming.resources包,在下文中一共展示了Resource类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getReadme
import org.apache.naming.resources.Resource; //导入依赖的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;
}
示例2: getResourceAsStream
import org.apache.naming.resources.Resource; //导入依赖的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);
}
示例3: getReadme
import org.apache.naming.resources.Resource; //导入依赖的package包/类
/**
* Get the readme file as a string.
*
* @param directory Description of the Parameter
* @return The readme value
*/
protected String getReadme(DirContext directory) {
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 (Throwable e) {
;
/*
* Should only be IOException or NamingException
* can be ignored
*/
}
}
return null;
}
示例4: populateFileBindings
import org.apache.naming.resources.Resource; //导入依赖的package包/类
/**
* Description of the Method
*
* @param db Description of the Parameter
* @throws SQLException Description of the Exception
* @throws FileNotFoundException Description of the Exception
*/
private void populateFileBindings(Connection db) throws SQLException, FileNotFoundException {
FileItemList files = new FileItemList();
files.setLinkModuleId(linkModuleId);
files.setLinkItemId(linkItemId);
files.setFolderId(folderId);
files.setFileLibraryPath(path);
files.buildList(db);
Iterator j = files.iterator();
while (j.hasNext()) {
FileItem thisFile = (FileItem) j.next();
//TODO: determine if the user has permission to view this File Item
// If he has then include it in the binding list
File file = new File(thisFile.getFullFilePath());
Resource resource = new Resource(new FileInputStream(file));
bindings.put(thisFile.getClientFilename(), resource);
//build properties
buildProperties(thisFile.getClientFilename(), thisFile.getEntered(),
thisFile.getModified(), new Integer(thisFile.getSize()));
}
}
示例5: populateFileBindings
import org.apache.naming.resources.Resource; //导入依赖的package包/类
/**
* Description of the Method
*
* @param db Description of the Parameter
* @throws SQLException Description of the Exception
* @throws FileNotFoundException Description of the Exception
*/
private void populateFileBindings(Connection db) throws SQLException, FileNotFoundException {
FileItemList files = new FileItemList();
files.setLinkModuleId(linkModuleId);
files.setLinkItemId(linkItemId);
files.setTopLevelOnly(true);
files.setFileLibraryPath(path);
files.buildList(db);
Iterator j = files.iterator();
while (j.hasNext()) {
FileItem thisFile = (FileItem) j.next();
// TODO: determine if the user has permission to view this File Item
// If he has then include it in the binding list
File file = new File(thisFile.getFullFilePath());
Resource resource = new Resource(new FileInputStream(file));
bindings.put(thisFile.getClientFilename(), resource);
//build properties
buildProperties(thisFile.getClientFilename(), thisFile.getEntered(),
thisFile.getModified(), new Integer(thisFile.getSize()));
}
}
示例6: getReadme
import org.apache.naming.resources.Resource; //导入依赖的package包/类
/**
* Get the readme file as a string.
*/
protected String getReadme(DirContext directory)
throws IOException {
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;
}
示例7: getResourceAsStream
import org.apache.naming.resources.Resource; //导入依赖的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);
}
示例8: getResourceStream
import org.apache.naming.resources.Resource; //导入依赖的package包/类
@Override
public InputStream getResourceStream(String name, Context context) throws IOException {
try {
return ((Resource) context.getResources().lookup(name)).streamContent();
} catch (NamingException ex) {
logger.trace("", ex);
throw new RuntimeException(ex);
}
}
示例9: resourceStream
import org.apache.naming.resources.Resource; //导入依赖的package包/类
/**
* Resource stream.
*
* @throws IOException Signals that an I/O exception has occurred.
* @throws NamingException Signals that a Naming exception has occurred.
*/
@Test
public void resourceStream() throws IOException, NamingException {
Assert.assertNotNull(new Expectations() {
{
resource.lookup(this.anyString);
this.result = new Resource();
}
});
final Tomcat70ContainerAdapter adapter = new Tomcat70ContainerAdapter();
adapter.getResourceStream("name", context);
}
示例10: connect
import org.apache.naming.resources.Resource; //导入依赖的package包/类
/**
* Connect to the DirContext, and retrive the bound object, as well as
* its attributes. If no object is bound with the name specified in the
* URL, then an IOException is thrown.
*
* @throws IOException Object not found
*/
public void connect()
throws IOException {
if (!connected) {
try {
date = System.currentTimeMillis();
String path = getURL().getFile();
if (context instanceof ProxyDirContext) {
ProxyDirContext proxyDirContext =
(ProxyDirContext) context;
String hostName = proxyDirContext.getHostName();
String contextName = proxyDirContext.getContextName();
if (hostName != null) {
if (!path.startsWith("/" + hostName + "/"))
return;
path = path.substring(hostName.length()+ 1);
}
if (contextName != null) {
if (!path.startsWith(contextName + "/")) {
return;
} else {
path = path.substring(contextName.length());
}
}
}
object = context.lookup(path);
attributes = context.getAttributes(path);
if (object instanceof Resource)
resource = (Resource) object;
if (object instanceof DirContext)
collection = (DirContext) object;
} catch (NamingException e) {
// Object not found
}
connected = true;
}
}
示例11: handleContext
import org.apache.naming.resources.Resource; //导入依赖的package包/类
protected ModelAndView handleContext(String contextName, Context context,
HttpServletRequest request, HttpServletResponse response) throws Exception {
String jspName = ServletRequestUtils.getStringParameter(request, "source", null);
boolean highlight = ServletRequestUtils.getBooleanParameter(request, "highlight", true);
Summary summary = (Summary) (request.getSession() != null ?
request.getSession().getAttribute(DisplayJspController.SUMMARY_ATTRIBUTE) : null);
if (jspName != null && summary != null && contextName.equals(summary.getName())) {
Item item = (Item) summary.getItems().get(jspName);
if (item != null) {
//
// replace "\" with "/"
//
jspName = jspName.replaceAll("\\\\", "/");
//
// remove cheeky "../" from the path to avoid exploits
//
while (jspName.indexOf("../") != -1) {
jspName = jspName.replaceAll("\\.\\./", "");
}
Resource jsp = (Resource) context.getResources().lookup(jspName);
if (jsp != null) {
ServletContext sctx = context.getServletContext();
ServletConfig scfg = (ServletConfig) context.findChild("jsp");
Options opt = new EmbeddedServletOptions(scfg, sctx);
String descriptorPageEncoding = opt.getJspConfig().findJspProperty(jspName).getPageEncoding();
if (descriptorPageEncoding != null && descriptorPageEncoding.length() > 0) {
item.setEncoding(descriptorPageEncoding);
} else {
//
// we have to read the JSP twice, once to figure out the content encoding
// the second time to read the actual content using the correct encoding
//
item.setEncoding(Utils.getJSPEncoding(jsp.streamContent()));
}
if (highlight) {
request.setAttribute("highlightedContent", Utils.highlightStream(jspName, jsp.streamContent(),
"xhtml", item.getEncoding()));
} else {
request.setAttribute("content", Utils.readStream(jsp.streamContent(), item.getEncoding()));
}
} else {
logger.error(jspName + " does not exist");
}
request.setAttribute("item", item);
} else {
logger.error("jsp name passed is not in the summary, ignored");
}
} else {
if (jspName == null) {
logger.error("Passed empty \"source\" parameter");
}
if (summary == null) {
logger.error("Session has expired or there is no summary");
}
}
return new ModelAndView(getViewName());
}