private static File populatedFrameworkBundles(final ServletContextFactory servletContextFactory) { final ServletContext servletContext = servletContextFactory.getServletContext(); final String osgiJarPath = servletContext.getRealPath(FRAMEWORK_BUNDLES_LOCATION); // JiraWebappStartupCheck ensures that getRealPath does not return null for / return new File(osgiJarPath); }
@Override public boolean exists(URI uri) { try { return servletContextFactory.getServletContext().getResource(uri.getPath()) != null; } catch (MalformedURLException e) { return false; } }
@Override public InputStream open(URI uri) throws IOException { InputStream is = servletContextFactory.getServletContext().getResourceAsStream(uri.getPath()); if (is == null) { throw new IOException(uri.getPath() + " does not exist in the servletContext"); } return is; }
@Override public String encodeState(URI uri) { URLConnection connection = null; try { URL url = servletContextFactory.getServletContext().getResource(uri.getPath()); connection = url.openConnection(); return String.valueOf(connection.getLastModified()); } catch (IOException e) { throw new IllegalStateException(e); } finally { if (connection != null) { try { connection.getInputStream().close(); } catch (IOException ignored) { } } } }
/** * Updates client-side location considering: * <ul> * <li>the last forwarded location</li> * </ul> * * @param writer writes the response to the client * @since 2.0.0 */ @Override public void updateLocation(final Writer writer) { forwarder.consumeLastLocation(lastLocation -> { final ServletContext context = contextFactory.getServletContext(); final String location = context.getContextPath() + lastLocation.toASCIIString(); renderer.render(writer, SOY_RESOURCE, SOY_TEMPLATE, singletonMap("location", location)); }); } }
String bundledPluginPath = servletContextFactory.getServletContext().getRealPath(BUNDLED_PLUGIN_LOCATION);
private URL getSoyResourceURL(ModuleDescriptor moduleDescriptor, ResourceDescriptor resource) { final String sourceParam = resource.getParameter("source"); if ("webContextStatic".equalsIgnoreCase(sourceParam)) { try { return servletContextFactory.getServletContext().getResource(resource.getLocation()); } catch (MalformedURLException e) { log.error("Ignoring soy resource. Could not locate soy with location: " + resource.getLocation()); return null; } } return moduleDescriptor.getPlugin().getResource(resource.getLocation()); }
/** * Returns stream for file with given location for given resource. */ public InputStream getStreamFor(Resource resource, String path) { if (resource instanceof ModuleResource) { return getPlugin(((ModuleResource) resource).getPluginKey()).getResourceAsStream(path); } else { ResourceLocation resourceLocation = resource.getResourceLocation(); String sourceParam = resourceLocation.getParameter(SOURCE_PARAM_NAME); final boolean isWebContextStatic = "webContextStatic".equalsIgnoreCase(sourceParam); if (isWebContextStatic) { // Tomcat 8 requires resource path to start with the slash. String pathWithSlash = path.startsWith("/") ? path : "/" + path; return servletContextFactory.getServletContext().getResourceAsStream(pathWithSlash); } else { return getPlugin(resource.getKey()).getResourceAsStream(path); } } }