Example usage for org.springframework.core.io DefaultResourceLoader DefaultResourceLoader

List of usage examples for org.springframework.core.io DefaultResourceLoader DefaultResourceLoader

Introduction

In this page you can find the example usage for org.springframework.core.io DefaultResourceLoader DefaultResourceLoader.

Prototype

public DefaultResourceLoader() 

Source Link

Document

Create a new DefaultResourceLoader.

Usage

From source file:org.craftercms.deployer.impl.TargetServiceImplTest.java

private Handlebars createHandlebars() {
    SpringTemplateLoader templateLoader = new SpringTemplateLoader(new DefaultResourceLoader());
    templateLoader.setPrefix("classpath:templates/targets");
    templateLoader.setSuffix("-target-template.yaml");

    Handlebars handlebars = new Handlebars(templateLoader);
    handlebars.prettyPrint(true);/*  ww  w. j  ava 2  s . c om*/

    return handlebars;
}

From source file:org.dataconservancy.cos.osf.client.model.AbstractMockServerTest.java

/**
 * Starts mock HTTP servers on the port specified by the OSF client configuration and the Waterbutler client
 * configuration//from  w w  w.j  a v a  2 s. c om
 */
@Before
public void startMockServer() throws Exception {
    final ObjectMapper mapper = new ObjectMapper();

    final JacksonConfigurer<OsfClientConfiguration> osfConfigurer = new DefaultOsfJacksonConfigurer<>();
    final JacksonConfigurer<WbClientConfiguration> wbConfigurer = new DefaultWbJacksonConfigurer<>();

    final ResourceLoader loader = new DefaultResourceLoader();

    final Resource configuration = loader.getResource(getOsfServiceConfigurationResource());
    assertTrue("Unable to resolve configuration resource: '" + getOsfServiceConfigurationResource() + "'",
            configuration.exists());

    mockServer = ClientAndServer.startClientAndServer(
            osfConfigurer.configure(mapper.readTree(IOUtils.toString(configuration.getURL(), "UTF-8")), mapper,
                    OsfClientConfiguration.class).getPort());

    wbMockServer = ClientAndServer.startClientAndServer(
            wbConfigurer.configure(mapper.readTree(IOUtils.toString(configuration.getURL(), "UTF-8")), mapper,
                    WbClientConfiguration.class).getPort());

    /* Sets up the expectations of the mock http server.
     *
     * Invokes the NodeResponseCallback when the HTTP header "X-Response-Resource" is present.
     * The header value is a classpath resource to the JSON document to be serialized for the
     * response.
     */
    mockServer.when(request().withHeader(X_RESPONSE_RESOURCE))
            .callback(callback().withCallbackClass(NodeResponseCallback.class.getName()));
    wbMockServer.when(request().withHeader(X_RESPONSE_RESOURCE))
            .callback(callback().withCallbackClass(NodeResponseCallback.class.getName()));
}

From source file:org.eclipse.gemini.blueprint.test.FilteringProbeBuilder.java

private void appendManifest(TinyBundle bundle) throws IOException {

    DefaultResourceLoader loader = new DefaultResourceLoader();
    Manifest manifest = new Manifest(loader.getResource(manifestLocation).getInputStream());
    Attributes attr = manifest.getMainAttributes();
    for (Object key : attr.keySet()) {
        String k = key.toString();
        String v = attr.getValue(k);

        // append optional import for org.ops4j.pax.exam
        if (k.equalsIgnoreCase(Constants.IMPORT_PACKAGE)) {
            if (StringUtils.hasText(v)) {
                v = v + ",";
            }/*w w w .  j a va2s .c  om*/
        }
        v = v + "org.ops4j.pax.exam;resolution:=optional";
        bundle.set(k, v);
    }
}

From source file:org.guess.generate.Generate.java

public static void main(String[] args) {

    // ==========  ?? ====================

    // ??????//from  w  ww. ja v  a  2 s .  c o m
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}

    // packageName
    // ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?
    String packageName = "net.iharding.modulesmeta";

    String moduleName = "meta"; // ???sys
    String className = "project"; // ??user
    String classAuthor = "Joe.zhang"; // 
    String functionName = "??"; // ??

    List<Field> fields = new ArrayList<Field>();
    fields.add(new Field("projectCode", "?", "String"));
    fields.add(new Field("projectName", "??", "String"));
    fields.add(new Field("remark", "", "String"));
    fields.add(new Field("createDate", "", "Date"));
    fields.add(new Field("updateDate", "", "Date"));
    fields.add(new Field("createId", "", "createId"));
    fields.add(new Field("updateId", "", "updateId"));

    // ???
    Boolean isEnable = true;

    // ==========  ?? ====================

    if (!isEnable) {
        logger.error("????isEnable = true");
        return;
    }

    if (StringUtils.isBlank(moduleName) || StringUtils.isBlank(moduleName) || StringUtils.isBlank(className)
            || StringUtils.isBlank(functionName)) {
        logger.error("??????????????");
        return;
    }

    // ?
    String separator = File.separator;

    // ?
    File projectPath = null;
    try {
        projectPath = new DefaultResourceLoader().getResource("").getFile();
        //         File projectPath = new File("D:/template");
        while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) {
            projectPath = projectPath.getParentFile();
        }
        logger.info("Project Path: {}", projectPath);

        // ?
        String tplPath = StringUtils.replace(
                projectPath.getAbsolutePath() + "/src/test/java/org/guess/generate/temp", "/", separator);
        logger.info("Template Path: {}", tplPath);

        // Java
        String javaPath = StringUtils.replaceEach(
                projectPath.getAbsolutePath() + "/src/main/java/" + StringUtils.lowerCase(packageName),
                new String[] { "/", "." }, new String[] { separator, separator });
        //         String javaPath = "D:/template";
        logger.info("Java Path: {}", javaPath);

        String viewPath = StringUtils.replace(
                projectPath + "/src/main/webapp/WEB-INF/content/" + moduleName + "/" + className, "/",
                separator);
        //         String viewPath = "D:/template";

        // ???
        Configuration cfg = new Configuration();
        FileUtils.isFolderExitAndCreate(tplPath);
        cfg.setDirectoryForTemplateLoading(new File(tplPath));

        // ???
        Map<String, Object> model = Maps.newHashMap();
        model.put("packageName", StringUtils.lowerCase(packageName));
        model.put("moduleName", StringUtils.lowerCase(moduleName));
        model.put("className", StringUtils.uncapitalize(className));
        model.put("ClassName", StringUtils.capitalize(className));
        model.put("classAuthor", StringUtils.isNotBlank(classAuthor) ? classAuthor : "Generate Tools");
        model.put("classVersion", DateUtil.getCurrenDate());
        model.put("functionName", functionName);
        model.put("tableName", model.get("moduleName") + "_" + model.get("className"));

        model.put("fields", fields);

        // ? Entity
        Template template = cfg.getTemplate("entity.ftl");
        String content = FreeMarkers.renderTemplate(template, model);
        String filePath = javaPath + separator + model.get("moduleName") + separator + "model" + separator
                + model.get("ClassName") + ".java";
        //         writeFile(content, filePath);
        logger.info("Entity: {}", filePath);

        // ? Dao
        template = cfg.getTemplate("dao.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator
                + model.get("ClassName") + "Dao.java";
        writeFile(content, filePath);
        logger.info("Dao: {}", filePath);

        // ? DaoImpl
        template = cfg.getTemplate("daoImpl.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator + "impl"
                + separator + model.get("ClassName") + "DaoImpl.java";
        writeFile(content, filePath);
        logger.info("Dao: {}", filePath);

        // ? Service
        template = cfg.getTemplate("service.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator
                + model.get("ClassName") + "Service.java";
        writeFile(content, filePath);
        logger.info("Service: {}", filePath);

        // ? Service
        template = cfg.getTemplate("serviceImpl.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator + "impl"
                + separator + model.get("ClassName") + "ServiceImpl.java";
        writeFile(content, filePath);
        logger.info("Service: {}", filePath);

        // ? Controller
        template = cfg.getTemplate("controller.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "controller" + separator
                + model.get("ClassName") + "Controller.java";
        writeFile(content, filePath);
        logger.info("Controller: {}", filePath);

        /*   // ? list.jsp
           template = cfg.getTemplate("list.ftl");
           content = FreeMarkers.renderTemplate(template, model);
           filePath = viewPath + separator + "list.jsp";
           writeFile(content, filePath);
           logger.info("Controller: {}", filePath);
                   
           // ? edit.jsp
           template = cfg.getTemplate("edit.ftl");
           content = FreeMarkers.renderTemplate(template, model);
           filePath = viewPath + separator + "edit.jsp";
           writeFile(content, filePath);
           logger.info("Controller: {}", filePath);*/

        logger.info("Generate Success.");
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:org.impalaframework.config.SimplePropertiesLoader.java

protected ResourceLoader getResourceLoader() {
    return new DefaultResourceLoader();
}

From source file:org.jumpmind.metl.core.util.DatabaseScriptContainer.java

public DatabaseScriptContainer(String scriptLocation, IDatabasePlatform platform) {
    try {// w w w . ja  va 2s.  com
        this.scriptLocation = scriptLocation;
        this.platform = platform;
        this.jdbcTemplate = new JdbcTemplate(platform.getDataSource());

        replacementTokens = new HashMap<String, String>();
        // Add any replacement tokens

        Resource[] resources = ResourcePatternUtils.getResourcePatternResolver(new DefaultResourceLoader())
                .getResources(String.format("classpath*:%s/*.sql", scriptLocation));
        for (Resource r : resources) {
            DatabaseScript script = new DatabaseScript(r.getFilename());
            script.setResource(r);

            if (script.getWhen() == DatabaseScript.WHEN_PREINSTALL) {
                preInstallScripts.add(script);
            } else if (script.getWhen() == DatabaseScript.WHEN_POSTINSTALL) {
                postInstallScripts.add(script);
            }
        }
    } catch (IOException e) {
        throw new IoException(e);
    }
}

From source file:org.jumpmind.metl.core.util.DatabaseScriptContainer.java

protected void executeImports(Resource resource) throws IOException {
    BufferedReader reader = null;
    try {// ww w. j  a v a2s . c o m
        reader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
        String line = reader.readLine();
        while (line != null) {
            if (line.startsWith(IMPORT_PREFIX)) {
                String file = line.substring(IMPORT_PREFIX.length()).trim();
                Resource[] resources = ResourcePatternUtils
                        .getResourcePatternResolver(new DefaultResourceLoader())
                        .getResources(String.format("classpath*:%s/%s", scriptLocation, file));
                for (Resource resource2 : resources) {
                    execute(resource2.getURL());
                }
            }
            line = reader.readLine();
        }
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:org.kuali.kra.infrastructure.TestUtilities.java

License:asdf

public static String getContentsAsString(String fileLoc) throws Exception {
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    String data = "";
    BufferedReader reader = null;
    try {//w w  w  . j av  a 2s  . c o m
        reader = new BufferedReader(
                new InputStreamReader(resourceLoader.getResource(fileLoc).getInputStream()));
        String line = "";
        while ((line = reader.readLine()) != null) {
            data += line + "\r\n ";
        }
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception e) {
                LOG.error(e);
            }
        }

    }
    return data;
}

From source file:org.kuali.rice.core.api.impex.xml.LocationXmlDoc.java

static Resource getResource(String location) {
    if (isExistingFile(location)) {
        return new FileSystemResource(location);
    } else {/*from  w  w  w .  j  av  a  2 s .c o m*/
        ResourceLoader loader = new DefaultResourceLoader();
        return loader.getResource(location);
    }
}

From source file:org.kuali.rice.ken.test.SQLDataLoader.java

private String getContentsAsString(String fileLoc) throws Exception {
    DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
    String data = "";
    BufferedReader reader = null;
    try {// ww  w . j a  v a2s . c  o  m
        reader = new BufferedReader(
                new InputStreamReader(resourceLoader.getResource(fileLoc).getInputStream()));
        String line = "";
        while ((line = reader.readLine()) != null) {
            // discard comments...commented single line statements
            // will result in errors when executed because there are no
            // results
            if (!line.trim().startsWith(SQL_LINE_COMMENT_PREFIX)) {
                data += line + " ";
            }
        }
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception e) {
                LOG.error(e);
            }
        }

    }
    return data;
}