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

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

Introduction

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

Prototype

boolean supportsDataUrls();

Source Link

Document

Indicates if the runtime context supports data: urls.

Usage

From source file:cc.alcina.framework.entity.gen.SimpleCssResourceGenerator.java

License:Apache License

@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method)
        throws UnableToCompleteException {
    try {/*  w w  w  .  j  av a2 s .  c om*/
        ConfigurationProperty cp = context.getGeneratorContext().getPropertyOracle()
                .getConfigurationProperty(IGNORE_DATA_URLS);
        logMissingUrlResources = !Boolean.valueOf(cp.getValues().get(0));
    } catch (BadPropertyValueException e1) {
        e1.printStackTrace();
    }
    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();
    }
    URL resource = resources[0];
    SourceWriter sw = new StringSourceWriter();
    // Write the expression to create the subtype.
    sw.println("new " + SimpleCssResource.class.getName() + "() {");
    sw.indent();
    if (!AbstractResourceGenerator.STRIP_COMMENTS) {
        // Convenience when examining the generated code.
        sw.println("// " + resource.toExternalForm());
    }
    sw.println("public String getText() {");
    sw.indent();
    String toWrite = Util.readURLAsString(resource);
    if (context.supportsDataUrls()) {
        try {
            toWrite = replaceWithDataUrls(context, toWrite);
        } catch (Exception e) {
            logger.log(Type.ERROR, "css data url gen", e);
            throw new UnableToCompleteException();
        }
    }
    if (toWrite.length() > MAX_STRING_CHUNK) {
        writeLongString(sw, toWrite);
    } else {
        sw.println("return \"" + Generator.escape(toWrite) + "\";");
    }
    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();
}