Example usage for com.google.gwt.resources.ext ResourceContext deploy

List of usage examples for com.google.gwt.resources.ext ResourceContext deploy

Introduction

In this page you can find the example usage for com.google.gwt.resources.ext ResourceContext deploy.

Prototype

String deploy(URL resource, String mimeType, boolean forceExternal) throws UnableToCompleteException;

Source Link

Document

Cause a specific collection of bytes to be available in the program's compiled output.

Usage

From source file:org.cruxframework.crux.plugin.bootstrap.rebind.font.FontResourceGenerator.java

License:Apache License

private void writeSrc(TreeLogger logger, ResourceContext context, JMethod method, SourceWriter sw, URL[] urls)
        throws UnableToCompleteException {
    for (URL url : urls) {
        String lower = url.getPath().toLowerCase();
        if (lower.endsWith(".ttf") || lower.endsWith(".otf")) {
            String outputUrlExpression = context.deploy(url, "application/x-font-ttf", false);

            sw.print("src:url('\" + ");
            sw.print(outputUrlExpression);
            sw.print(" + \"') format('truetype');");
        }//from  www  . j  av a2 s .co  m
    }
}

From source file:org.cruxframework.crux.plugin.bootstrap.rebind.font.FontResourceGenerator.java

License:Apache License

private void writeSrcIE(TreeLogger logger, ResourceContext context, JMethod method, SourceWriter sw, URL[] urls)
        throws UnableToCompleteException {
    for (URL url : urls) {
        if (url.getPath().toLowerCase().endsWith(".eot")) {
            String outputUrlExpression = context.deploy(url, "application/vnd.ms-fontobject", false);

            sw.print("src:url('\" + ");
            sw.print(outputUrlExpression);
            sw.print(" + \"');");
        }/*ww  w.  java  2 s .c  om*/
    }
}

From source file:org.rstudio.core.rebind.StaticDataResourceGenerator.java

License:Open Source License

@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {

    URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method);

    if (resources.length != 1) {
        logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", null);
        throw new UnableToCompleteException();
    }//www.j a va2  s.  co m

    URL resource = resources[0];
    String outputUrlExpression = context.deploy(resource, null, true);

    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + StaticDataResource.class.getName() + "() {");
    sw.indent();

    // Convenience when examining the generated code.
    sw.println("// " + resource.toExternalForm());

    sw.println("public String getUrl() {");
    sw.indent();
    sw.println("return " + outputUrlExpression + ";");
    sw.outdent();
    sw.println("}");

    sw.println("public com.google.gwt.safehtml.shared.SafeUri getSafeUri() {");
    sw.indent();
    sw.println("return new org.rstudio.core.client.SafeUriStringImpl(" + outputUrlExpression + ");");
    sw.outdent();
    sw.println("}");

    sw.println("public String getName() {");
    sw.indent();
    sw.println("return \"" + method.getName() + "\";");
    sw.outdent();
    sw.println("}");

    sw.outdent();
    sw.println("}");

    return sw.toString();
}