Hi,

Try that (thanks Gabriel Nossier):

public class CssServlet extends HttpServlet {
private static final long serialVersionUID = 2545846261709821197L;

private static final String path1 = "./";
private static final String path2 = "webapps/styles/";

/*
 * (non-Javadoc)
 *
 * @see
 *
javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest
 * , javax.servlet.http.HttpServletResponse)
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
}

/*
 * (non-Javadoc)
 *
 * @see
 *
javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest
 * , javax.servlet.http.HttpServletResponse)
 */
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/css");

PrintWriter out = resp.getWriter();
out.println("@CHARSET \"ISO-8859-1\";");
generateMonoliticCssFile(out);
out.close();
}

private void generateMonoliticCssFile(PrintWriter out) throws IOException {
File dir = new File(path1);
if (dir.exists()) {
listFolder(out, dir);
} else {
dir = new File(path2);
if (dir.exists()) {
listFolder(out, dir);
} else {
out.println("Paths '" + path1 + "' and ' " + path2 + "' doesn't exists");
File local = new File(".");
out.println("Local path:" + local.getAbsolutePath());
}
}
}

private void listFolder(PrintWriter out, File dir) throws IOException {
for (File file : getAllCssFiles(dir)) {
process(out, file);
}
}

/**
 * @param out
 * @param file
 * @throws IOException
 */
private void process(PrintWriter out, File file) throws IOException {
out.println("");
out.println("/******  file:" + file.getName() + "  *******/");
out.println("");

BufferedReader fileReader = new BufferedReader(new FileReader(file));

String aLine = null;
while ((aLine = fileReader.readLine()) != null) {
if (!aLine.startsWith("@CHARSET")) {
out.println(aLine);
}
}

out.println("");
}

/**
 * @param dir
 * @return
 */

private List<File> getAllCssFiles(File dir) {
List<File> rv = new LinkedList<File>();

FilenameFilter filenameFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".css");
}
};

for (File file : dir.listFiles(filenameFilter)) {
rv.add(file);
}

return rv;
}
}


2011/2/23 Deepak Singh <[email protected]>

> Hi,
>
> After compiling our gwt project we get one statndard.css file which loads
> to the client consuming 1 http request.
> We also have our application specific style.css file which loads consuming
> 1 seperate http request.
>
> To reduce the number of http requests, how should i combine them into 1 css
> file ?
>
> Also, we have many application specific images which loads to the client
> using 1 http request for 1 image. If i create 1 ImageBundle and put all
> images into this bundle, how do i get this bundle loaded to the client in
> just 1 http request at the application start up time ?
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to