Example usage for com.google.gwt.resources.ext ResourceGeneratorUtil addNamedFile

List of usage examples for com.google.gwt.resources.ext ResourceGeneratorUtil addNamedFile

Introduction

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

Prototype

public static void addNamedFile(String resourceName, File file) 

Source Link

Document

Publish or override resources named by Source annotations.

Usage

From source file:fr.onevu.gwt.uibinder.rebind.model.ImplicitCssResource.java

License:Apache License

private File getGeneratedFile() {
    if (body.length() == 0) {
        return null;
    }/*  ww w. j  a  v a  2s  . c  o  m*/

    if (generatedFile == null) {
        try {
            File f = File.createTempFile(String.format("uiBinder_%s_%s", packageName, className), ".css");
            f.deleteOnExit();

            BufferedWriter out = new BufferedWriter(new FileWriter(f));
            out.write(body);
            out.close();
            generatedFile = f;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        ResourceGeneratorUtil.addNamedFile(getBodyFileName(), generatedFile);
    }
    return generatedFile;
}

From source file:org.jboss.errai.ui.rebind.chain.TemplateChain.java

License:Apache License

private void writeDocumentToFile(Document document, String templateFileName) {
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer;/* www  .ja v a2s  .  c  o  m*/
    try {
        transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "html");
        final Node root;
        if (isTemplateFragment(templateFileName)) {
            root = document.getElementsByTagName("body").item(0).getFirstChild();
        } else {
            root = document;
        }
        DOMSource source = new DOMSource(root);
        final String baseName = StringUtils.rightPad(FilenameUtils.getBaseName(templateFileName), 4, 'a');
        final File tempFile = File.createTempFile(baseName, ".html");
        StreamResult result = new StreamResult(tempFile);
        transformer.transform(source, result);

        //make sure GWT finds the altered template file instead of the original one
        ResourceGeneratorUtil.addNamedFile(templateFileName, tempFile);
    } catch (Exception e) {
        throw new GenerationException("could not write document to file", e);
    }
}