All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sft.report.HtmlResources Maven / Gradle / Ivy

There is a newer version: 1.9
Show newest version
/*******************************************************************************
 * Copyright (c) 2013 Sylvain Lézier.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Sylvain Lézier - initial implementation
 *******************************************************************************/
package sft.report;


import sft.environment.FileSystem;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class HtmlResources {

    public static final String HTML_DEPENDENCIES_FOLDER = "sft-html-default";
    private FileSystem fileSystem = new FileSystem();
    private static List filesUsed;

    public HtmlResources ensureIsCreated() throws IOException {
//        if (filesUsed == null) {
            filesUsed = fileSystem.targetFolder.copyFromResources(HTML_DEPENDENCIES_FOLDER);
//        }
        return this;
    }

    public String convertIssue(Issue issue) {
        return issue.toString().toLowerCase();
    }

    public String getIncludeCssDirectives(Class useCaseClass) {
        RelativeHtmlPathResolver pathResolver = new RelativeHtmlPathResolver();
        String callerPath = pathResolver.getPathOf(useCaseClass, ".html");

        String includeCssDirectives = "";
        for (String cssToInclude : getCssToInclude()) {
            includeCssDirectives += "\n";
        }
        return  includeCssDirectives;
    }

    public String getIncludeJsDirectives(Class useCaseClass) {
        RelativeHtmlPathResolver pathResolver = new RelativeHtmlPathResolver();
        String callerPath = pathResolver.getPathOf(useCaseClass, ".html");

        String includeJsDirectives = "";
        for (String jsToInclude : getJsToInclude()) {
            includeJsDirectives += "\n";
        }
        return  includeJsDirectives;
    }

    private List getCssToInclude() {
        ArrayList cssFiles = new ArrayList();
        for (String file : filesUsed) {
            if( file.endsWith(".css")){
                cssFiles.add(file);
            }
        }
        return  cssFiles;
    }

    private List getJsToInclude() {
        ArrayList jsFiles = new ArrayList();
        for (String file : filesUsed) {
            if( file.endsWith(".js")){
                jsFiles.add(file);
            }
        }
        return  jsFiles;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy