Example usage for com.google.gwt.resources.converter Css2Gss toGss

List of usage examples for com.google.gwt.resources.converter Css2Gss toGss

Introduction

In this page you can find the example usage for com.google.gwt.resources.converter Css2Gss toGss.

Prototype

public String toGss() throws UnableToCompleteException 

Source Link

Usage

From source file:com.github.jdramaix.server.servlet.ConverterServlet.java

License:Apache License

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    StringWriter logWriter = new StringWriter();

    Map<String, List<BlobKey>> files = blobstoreService.getUploads(req);
    List<BlobKey> blobKeys = files.get(FILE_FIELD);

    if (blobKeys == null || blobKeys.size() != 1) {
        throw new IllegalStateException("Unexpected file");
    }//from   w w w.j a  v  a2  s .  c om

    BlobKey fileKey = blobKeys.get(0);

    // TODO improve that !!
    String url = req.getRequestURL().append("?").append(FileServlet.BLOB_KEY).append("=")
            .append(fileKey.getKeyString()).toString().replace("/convert", "/file");

    URL urlFile = new URL(url);

    Css2Gss converter = new Css2Gss(urlFile, new PrintWriterTreeLogger(new PrintWriter(logWriter)), false,
            Predicates.<String>alwaysFalse());

    String result;

    try {
        result = converter.toGss();
    } catch (UnableToCompleteException e) {
        result = "UnableToCompleteException: " + e.getMessage();
    } catch (Css2GssConversionException e) {
        result = "Css2GssConversionException: " + e.getMessage();
    } finally {
        deleteFile(fileKey);
    }

    writeResponse(result, logWriter.toString(), resp);
}