CssFileBuilder.java 1.92 KB
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  javax.jcr.Session
 *  org.apache.commons.io.IOUtils
 *  org.apache.jackrabbit.util.Text
 */
package com.adobe.granite.ui.clientlibs.impl;

import com.adobe.granite.ui.clientlibs.LibraryType;
import com.adobe.granite.ui.clientlibs.impl.AbstractBuilder;
import com.adobe.granite.ui.clientlibs.script.ScriptResource;
import com.adobe.granite.ui.clientlibs.script.Utils;
import java.io.IOException;
import java.io.Reader;
import java.util.Collection;
import javax.jcr.Session;
import org.apache.commons.io.IOUtils;
import org.apache.jackrabbit.util.Text;

public class CssFileBuilder
extends AbstractBuilder {
    private final String[] libPath;
    private final Session session;
    private final long maxDataUriSize;

    public CssFileBuilder(String libraryPath, Session session, long maxDataUriSize) {
        super(libraryPath);
        this.libPath = Text.explode((String)libraryPath, (int)47);
        this.session = session;
        this.maxDataUriSize = maxDataUriSize;
    }

    @Override
    public LibraryType getType() {
        return LibraryType.CSS;
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    @Override
    protected String concatenate(Collection<ScriptResource> resources) throws IOException {
        StringBuilder out = new StringBuilder();
        for (ScriptResource resource : resources) {
            String src;
            Reader r = resource.getReader();
            try {
                src = IOUtils.toString((Reader)r);
            }
            finally {
                IOUtils.closeQuietly((Reader)r);
            }
            String[] filePath = Text.explode((String)resource.getName(), (int)47);
            out.append(Utils.rewriteUrlsInCss(this.libPath, filePath, src, this.session, this.maxDataUriSize));
            out.append("\n");
        }
        return out.toString();
    }
}