You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScssServlet.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package com.vaadin.sass;
  2. import java.io.BufferedOutputStream;
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.io.OutputStream;
  6. import java.io.OutputStreamWriter;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServlet;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. public class ScssServlet extends HttpServlet {
  12. @Override
  13. protected void doGet(HttpServletRequest req, HttpServletResponse resp)
  14. throws ServletException, IOException {
  15. String cssPath = req.getRequestURI();
  16. if (cssPath.endsWith(".css")) {
  17. File cssFile = new File(cssPath);
  18. if (cssFile.exists()) {
  19. } else {
  20. String scssPath = cssPath.replace(".css", ".scss");
  21. File scssFile = new File(scssPath);
  22. if (scssFile.exists()) {
  23. ScssStylesheet scss = ScssStylesheet.get(new File(cssPath));
  24. try {
  25. scss.compile();
  26. } catch (Exception e) {
  27. e.printStackTrace();
  28. }
  29. resp.setContentType("text/css");
  30. OutputStream fout = resp.getOutputStream();
  31. OutputStream bos = new BufferedOutputStream(fout);
  32. OutputStreamWriter outputwriter = new OutputStreamWriter(
  33. bos);
  34. outputwriter.write(scss.toString());
  35. }
  36. }
  37. }
  38. }
  39. }