use of org.apache.naming.resources.Resource in project Payara by payara.
the class DefaultServlet method findXsltInputStream.
/**
* Return a Source for the xsl template (if possible)
*/
protected Source findXsltInputStream(DirContext directory) throws IOException, ServletException {
if (localXsltFile != null) {
try {
Object obj = directory.lookup(localXsltFile);
if (obj != null && obj instanceof Resource) {
InputStream is = ((Resource) obj).streamContent();
if (is != null) {
if (Globals.IS_SECURITY_ENABLED) {
return secureXslt(is);
} else {
return new StreamSource(is);
}
}
}
} catch (Throwable e) {
;
/* Should only be IOException or NamingException
* can be ignored
*/
if (debug > 10)
log("localXsltFile '" + localXsltFile + "' not found", e);
return null;
}
}
if (contextXsltFile != null) {
InputStream is = getServletContext().getResourceAsStream(contextXsltFile);
if (is != null) {
if (Globals.IS_SECURITY_ENABLED) {
return secureXslt(is);
} else {
return new StreamSource(is);
}
}
if (debug > 10)
log("contextXsltFile '" + contextXsltFile + "' not found");
}
/* Open and read in file in one fell swoop to reduce chance
* chance of leaving handle open.
*/
if (globalXsltFile != null) {
File f = validateGlobalXsltFile();
if (f != null) {
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
long len = f.length();
byte[] b = new byte[(int) len];
/* danger! */
if (len != fis.read(b)) {
throw new IOException(MessageFormat.format(rb.getString(LogFacade.READ_FILE_EXCEPTION), f.getAbsolutePath()));
}
return new StreamSource(new ByteArrayInputStream(b));
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException ioe) {
if (debug > 10) {
log(ioe.getMessage(), ioe);
}
}
}
}
}
}
return null;
}
Aggregations