List of usage examples for org.springframework.web.context.support ServletContextResource ServletContextResource
public ServletContextResource(ServletContext servletContext, String path)
From source file:org.jnap.core.assets.LessAssetsHandler.java
@Override public void handle() { LessEngine less = new LessEngine(getOptions()); try {//w w w .ja va 2 s . c om Resource sourceRes = new ServletContextResource(servletContext, source); Resource destRes = new ServletContextResource(servletContext, destination); resetResource(destRes); less.compile(sourceRes.getFile(), destRes.getFile()); } catch (Exception e) { logger.error("Error compiling LESS file!", e); } }
From source file:org.jnap.core.assets.YuiCompressorAssetsHandler.java
@Override protected Resource doCompression(Resource resource) throws IOException { File sourceFile = resource.getFile(); Resource minifiedResource = new ServletContextResource(servletContext, format(((ServletContextResource) this.path).getPath() + compressedFilename, FilenameUtils.getBaseName(sourceFile.getName()), FilenameUtils.getExtension(sourceFile.getName()))); resetResource(minifiedResource);/*from w w w . j a v a 2 s . c o m*/ runYuiCompressor(sourceFile, minifiedResource.getFile()); return minifiedResource; }
From source file:com.scf.web.context.WebContext.java
/** * * @return// w w w . j a va 2 s . co m */ public String getWebRootPath() { if (WEB_ROOT_PATH == null) { try { Resource resource = new ServletContextResource(getServletContext(), "/"); WEB_ROOT_PATH = resource.getFile().getAbsolutePath(); if (WEB_ROOT_PATH == null) { WEB_ROOT_PATH = resource.getFile().getAbsoluteFile().getAbsolutePath(); } WEB_ROOT_PATH = FileUtilies.fixPath(WEB_ROOT_PATH); WEB_ROOT_PATH += "/"; } catch (NullPointerException e1) { throw new IllegalAccessError("Can not init system root path. please check."); } catch (IOException e2) { throw new IllegalAccessError("Can not init system root path. please check."); } } return WEB_ROOT_PATH; }
From source file:org.jnap.core.assets.HandlebarsAssetsHandler.java
@Override public void handle() { final Handlebars handlebars = new Handlebars(); try {/*from w w w .j ava2s . c o m*/ Resource[] resources = this.resourceResolver.getResources(source); Resource destRes = new ServletContextResource(servletContext, destination); resetResource(destRes); BufferedWriter writer = new BufferedWriter( new FileWriterWithEncoding(destRes.getFile(), this.encoding, true)); writer.write("(function() {"); writer.write(IOUtils.LINE_SEPARATOR); writer.write("var template = Handlebars.template, "); writer.write("templates = Handlebars.templates = Handlebars.templates || {};"); writer.write(IOUtils.LINE_SEPARATOR); final Set<String> templateNames = new TreeSet<String>(); for (Resource resource : resources) { Template template = handlebars .compile(StringUtils.trimToEmpty(IOUtils.toString(resource.getInputStream()))); final String templateName = FilenameUtils.getBaseName(resource.getFilename()); templateNames.add(templateName); writer.write("templates[\"" + templateName + "\"] = "); writer.write("template("); writer.write(template.toJavaScript()); writer.write(");"); writer.write(IOUtils.LINE_SEPARATOR); } writer.write(IOUtils.LINE_SEPARATOR); if (this.bindToBackboneView) { writer.write("$(function() {"); writer.write(IOUtils.LINE_SEPARATOR); for (String templateName : templateNames) { writer.write(format("if (window[\"{0}\"]) {0}.prototype.template " + "= templates[\"{0}\"];", templateName)); writer.write(IOUtils.LINE_SEPARATOR); } writer.write("});"); writer.write(IOUtils.LINE_SEPARATOR); } writer.write("})();"); IOUtils.closeQuietly(writer); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.wisemapping.webmvc.ApplicationContextInitializer.java
public void initialize(@NotNull ConfigurableWebApplicationContext ctx) { try {/*from w w w. j a v a 2 s . co m*/ final Resource resource = new ServletContextResource(ctx.getServletContext(), "/WEB-INF/app.properties"); final ResourcePropertySource resourcePropertySource = new ResourcePropertySource(resource); ctx.getEnvironment().getPropertySources().addFirst(resourcePropertySource); } catch (IOException e) { throw new IllegalStateException(e); } }
From source file:de.contentreich.extensions.webscripts.servlet.mvc.GrailsResourceController.java
@Override public boolean dispatchResource(final String path, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { boolean resolved = false; // final boolean debug = logger.isDebugEnabled(); // serve back the resource from the web application (if it exists) if (pluginPrefix != null) { String pathWithPrefix = pluginPrefix + "/" + path; ServletContextResource resource = new ServletContextResource(getServletContext(), "/" + pathWithPrefix); if (resource.exists()) { // dispatch to resource if (logger.isDebugEnabled()) logger.debug("...dispatching resource from web application ServletContext."); commitResponse(pathWithPrefix, resource, request, response); resolved = true;//w ww . j a va2 s . com } } if (resolved) { return resolved; } return super.dispatchResource(path, request, response); }
From source file:javawars.server.servlets.Register.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request// w w w . ja v a2 s .co m * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // resource and factory necessary to access the rpc servlet's dispatcher beans Resource resource = new ServletContextResource(getServletContext(), "/WEB-INF/rpc-servlet.xml"); BeanFactory factory = new XmlBeanFactory(resource); // getting access to services ServiceProvider serviceProvider = (ServiceProvider) factory.getBean("serviceProvider"); String login = request.getParameter("login"); String password = request.getParameter("password"); String repeatedPassword = request.getParameter("repeatedPassword"); String studentID = request.getParameter("studentID"); try { if (password.equals(repeatedPassword) == false) throw new IncorrectParameterException(Parameter.PASSWORD, javawars.domain.exceptions.Enum.Error.MALFORMED); Long userID = serviceProvider.newUser(login, password, "", studentID, request.getRemoteAddr(), false); // Getting the full user data from the database UserDAO userDAO = (UserDAO) factory.getBean("userDAO"); User currentUser = userDAO.getUser(userID); // Putting 'em into the SessionConstants object... SessionConstants sessionConstants = new SessionConstants(currentUser); // When the SessionConstants object is put into the user's session // the rest of the application knows that it is dealing with a logged-in // user; request.getSession(true).setAttribute("sessionConstants", sessionConstants); // index.jsp will recognise that the user is logged in and will redirect // him further, to the proper application response.sendRedirect(""); /* response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // printing information about an error out.println("<html><body>"); out.println("Twoje konto zostao utworzone - poczekaj na aktywacj konta przez administratora"); out.println("</body></html>"); out.close(); */ } catch (IncorrectParameterException ex) { // setting up all the variables necessary for // printing the output response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // printing information about an error out.println("<html><body>"); out.println("error: " + ex.getParameter() + ", " + ex.getError() + "."); out.println("</body></html>"); out.close(); } }
From source file:inti.ws.spring.resource.template.TemplateResource.java
public TemplateResource(ServletContext ctx, String moduleName, String containerLocation, String templateLocation, List<WebResource> files, Map<String, Object> parameters, Minifier minifier, boolean minify) throws Exception { super(ctx, containerLocation, null, minifier, minify); ServletContextResource resource;/*w ww .j a va 2 s . c o m*/ InputStream inputStream; this.moduleName = moduleName; this.parameters = parameters; if (files != null) { this.files.addAll(files); } if (templateLocation != null) { resource = new ServletContextResource(ctx, templateLocation); inputStream = resource.getInputStream(); try { template = IOUtils.toString(inputStream, StandardCharsets.UTF_8); } finally { inputStream.close(); } } }
From source file:javawars.server.servlets.Login.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request/*from www . ja v a2 s . co m*/ * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // resource and factory necessary to access the rpc servlet's dispatcher beans Resource resource = new ServletContextResource(getServletContext(), "/WEB-INF/rpc-servlet.xml"); BeanFactory factory = new XmlBeanFactory(resource); // getting access to services ServiceProvider serviceProvider = (ServiceProvider) factory.getBean("serviceProvider"); String login = request.getParameter("login"); String password = request.getParameter("password"); try { Long userID = serviceProvider.login(login, password, request.getRemoteAddr()); // Getting the full user data from the database UserDAO userDAO = (UserDAO) factory.getBean("userDAO"); User currentUser = userDAO.getUser(userID); // Putting 'em into the SessionConstants object... SessionConstants sessionConstants = new SessionConstants(currentUser); // for debug purposes; it might solve the problems with session... // request.getSession(true).invalidate(); // When the SessionConstants object is put into the user's session // the rest of the application knows that it is dealing with a logged-in // user; request.getSession(true).setAttribute("sessionConstants", sessionConstants); // index.jsp will recognise that the user is logged in and will redirect // him further, to the proper application response.sendRedirect(""); } catch (InactiveAccountException ex) { // setting up all the variables necessary for // printing the output response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // printing information about an error out.println("<html><body>"); out.println( "Twoje konto nie zostao jeszcze aktywowane - zaczekaj a administrator aktywuje Twoje konto."); out.println("</body></html>"); out.close(); } catch (AuthenticationException ex) { // setting up all the variables necessary for // printing the output response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // printing information about an error out.println("<html><body>"); out.println("error: incorrect username or password"); out.println("</body></html>"); out.close(); } }
From source file:javawars.server.servlets.Guest.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request//from ww w.j ava 2 s . c o m * @param response servlet response */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // resource and factory necessary to access the rpc servlet's dispatcher beans Resource resource = new ServletContextResource(getServletContext(), "/WEB-INF/rpc-servlet.xml"); BeanFactory factory = new XmlBeanFactory(resource); // getting access to services ServiceProvider serviceProvider = (ServiceProvider) factory.getBean("serviceProvider"); Long id = new Date().getTime(); String login = "guest" + id; String password = "g" + id + "pass"; String repeatedPassword = "g" + id + "pass"; String studentID = "000000"; try { if (password.equals(repeatedPassword) == false) throw new IncorrectParameterException(Parameter.PASSWORD, javawars.domain.exceptions.Enum.Error.MALFORMED); Long userID = serviceProvider.newUser(login, password, "", studentID, request.getRemoteAddr(), true); // Getting the full user data from the database UserDAO userDAO = (UserDAO) factory.getBean("userDAO"); User currentUser = userDAO.getUser(userID); // Putting 'em into the SessionConstants object... SessionConstants sessionConstants = new SessionConstants(currentUser); // When the SessionConstants object is put into the user's session // the rest of the application knows that it is dealing with a logged-in // user; request.getSession(true).setAttribute("sessionConstants", sessionConstants); // index.jsp will recognise that the user is logged in and will redirect // him further, to the proper application response.sendRedirect(""); /* response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // printing information about an error out.println("<html><body>"); out.println("Twoje konto zostao utworzone - poczekaj na aktywacj konta przez administratora"); out.println("</body></html>"); out.close(); */ } catch (IncorrectParameterException ex) { // setting up all the variables necessary for // printing the output response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); // printing information about an error out.println("<html><body>"); out.println("error: " + ex.getParameter() + ", " + ex.getError() + "."); out.println("</body></html>"); out.close(); } }