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:com.pactera.edg.am.metamanager.extractor.util.ExtractorContext.java

/**
 * ????XSLT//  www  .  j a va 2 s  . co m
 * 
 * @return the xsltTemplate throws Exception ?XLST
 */
public Templates getXsltTemplate(String xslt) throws IOException, TransformerConfigurationException {
    // if (!this.templates.containsKey(xslt)) {
    InputStream in = new DefaultResourceLoader().getResource(xslt).getInputStream();
    Source xsltSource = new SAXSource(new InputSource(in));
    TransformerFactory factory = TransformerFactory.newInstance();
    factory.setAttribute(FeatureKeys.DTD_VALIDATION, Boolean.FALSE); //TODO DTD?
    factory.setAttribute(FeatureKeys.SCHEMA_VALIDATION, 4);
    Templates xsltTemplate = factory.newTemplates(xsltSource);
    // this.templates.put(xslt, xsltTemplate);
    if (in != null)
        in.close();
    // }
    return xsltTemplate;
}

From source file:com.surveypanel.view.FreemarkerManager.java

/**
 * Create the instance of the freemarker Configuration object.
 * <p/>/* w w w. ja va2s  .c  o m*/
 * this implementation
 * <ul>
 * <li>obtains the default configuration from Configuration.getDefaultConfiguration()
 * <li>sets up template loading from a ClassTemplateLoader and a WebappTemplateLoader
 * <li>sets up the object wrapper to be the BeansWrapper
 * <li>loads settings from the classpath file /freemarker.properties
 * </ul>
 * @param form 
 *
 * @param servletContext
 */
protected static Configuration createConfiguration(Form form) throws TemplateException {
    Configuration configuration = new Configuration();
    configuration.setTemplateLoader(new MultiTemplateLoader(new TemplateLoader[] { form.getTemplateLoader(),
            new SpringTemplateLoader(new DefaultResourceLoader(), "") }));
    configuration.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
    if (mruMaxStrongSize > 0) {
        configuration.setSetting(freemarker.template.Configuration.CACHE_STORAGE_KEY,
                "strong:" + mruMaxStrongSize);
    }
    if (encoding != null) {
        configuration.setDefaultEncoding(encoding);
    }
    loadSettings(configuration);

    configuration.setWhitespaceStripping(true);
    configuration.setSharedVariable("a", new Anchor());
    configuration.setSharedVariable("input", new Input());
    configuration.setSharedVariable("text", new I18nTag(form.getQuestionnaire()));

    return configuration;
}

From source file:apm.generate.Generate.java

public static void parameters(String packageName, String moduleName, String className, String classAuthor,
        String functionName, String tableName, String entityContent, String flag) throws Exception {
    // ==========  ?? ====================
    // ??????//from   w  w  w . j  av  a2 s  . c  om
    // ?{packageName}/{moduleName}/{dao,entity,service,web}/{subModuleName}/{className}
    // packageName ????applicationContext.xmlsrping-mvc.xml?base-package?packagesToScan?4?

    //String packageName = "lms.modules";//???

    //String moduleName = "test";         //???sys
    String subModuleName = ""; // ?????? 
    //String className = "test";         // ??user
    //String classAuthor = "htd";         // ThinkGem
    //String functionName = "";         //??

    // ???
    Boolean isEnable = true;

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

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

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

    // ?
    String separator = File.separator;

    // ?
    File projectPath = new DefaultResourceLoader().getResource("").getFile();
    while (!new File(projectPath.getPath() + separator + "src" + separator + "main").exists()) {
        projectPath = projectPath.getParentFile();
    }
    //logger.info("Project Path: {}", projectPath);
    System.out.println("-------------------------------------------------");
    System.out.println(":" + projectPath);
    // ?
    String tplPath = StringUtils.replace(projectPath + "/src/main/java/apm/generate/template", "/", separator);
    //logger.info("Template Path: {}", tplPath);
    System.out.println("?:" + tplPath);
    // Java
    String javaPath = StringUtils.replaceEach(
            projectPath + "/src/main/java/" + StringUtils.lowerCase(packageName), new String[] { "/", "." },
            new String[] { separator, separator });
    //logger.info("Java Path: {}", javaPath);
    System.out.println("Java:" + javaPath);
    // 
    String viewPath = StringUtils.replace(projectPath + "/src/main/webapp/WEB-INF/views", "/", separator);
    //logger.info("View Path: {}", viewPath);
    System.out.println(":" + viewPath);
    // ???
    Configuration cfg = new Configuration();
    cfg.setDirectoryForTemplateLoading(new File(tplPath));

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

    model.put("urlPrefix", "/" + model.get("className"));
    model.put("viewUrlPrefix", "/" + model.get("moduleName"));
    model.put("returnPrefix", "modules" + //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("viewUrlPrefix") + "/" + model.get("className"));
    model.put("viewPrefix", //StringUtils.substringAfterLast(model.get("packageName"),".")+"/"+
            model.get("urlPrefix"));

    model.put("permissionPrefix", model.get("className"));
    String[] strs = entityContent.split("##");
    model.put("columnContent", strs[0]);
    model.put("entityContent", strs[1]);

    System.out.println("-------------------------?------------------------");
    Template template = null;
    String content = null;
    String filePath = null;
    if (flag.indexOf("entity") != -1 || flag.length() == 0) {
        // ? Entity
        template = cfg.getTemplate("entity.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "entity" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + ".java";
        writeFile(content, filePath);
        System.out.println("? Entity:" + filePath);
    }

    if (flag.indexOf("dao") != -1 || flag.length() == 0) {

        // ? Dao
        template = cfg.getTemplate("dao.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "dao" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Dao.java";
        writeFile(content, filePath);
        System.out.println("? Dao:" + filePath);

    }

    if (flag.indexOf("service") != -1 || flag.length() == 0) {

        // ? Service
        template = cfg.getTemplate("service.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "service" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Service.java";
        writeFile(content, filePath);
        System.out.println("? Service:" + filePath);

    }

    if (flag.indexOf("controler") != -1 || flag.length() == 0) {

        // ? Controller
        template = cfg.getTemplate("controller.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = javaPath + separator + model.get("moduleName") + separator + "web" + separator
                + StringUtils.lowerCase(subModuleName) + model.get("ClassName") + "Controller.java";
        writeFile(content, filePath);
        System.out.println("? Controller:" + filePath);

    }

    if (flag.indexOf("form") != -1 || flag.length() == 0) {

        // ? ViewForm
        template = cfg.getTemplate("viewForm.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".")
                + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName)
                + model.get("className") + "Form.jsp";
        writeFile(content, filePath);
        System.out.println("? ViewForm:" + filePath);

    }

    if (flag.indexOf("list") != -1 || flag.length() == 0) {

        // ? ViewList
        template = cfg.getTemplate("viewList.ftl");
        content = FreeMarkers.renderTemplate(template, model);
        filePath = viewPath + separator + StringUtils.substringAfterLast(model.get("packageName"), ".")
                + separator + model.get("moduleName") + separator + StringUtils.lowerCase(subModuleName)
                + model.get("className") + "List.jsp";
        writeFile(content, filePath);
        System.out.println("? ViewList:" + filePath);

    }

}

From source file:com.baomidou.framework.log.LogbackConfigListener.java

@Override
public void contextInitialized(ServletContextEvent event) {
    try {//from w ww .ja  v a2  s . c  o m
        String location = event.getServletContext().getInitParameter(CONFIG_LOCATION_PARAM);
        Resource resource = new DefaultResourceLoader().getResource(location);
        Map<Object, Object> context = new HashMap<Object, Object>();
        context.put("env", getRunEnvironment());
        StringWriter writer = new StringWriter();
        BufferedReader br = new BufferedReader(new InputStreamReader(resource.getInputStream(), getCharset()));
        Velocity.evaluate(new VelocityContext(context), writer, "LogbackConfigListener", br);
        this.initLogging(new ByteArrayInputStream(writer.toString().getBytes(getCharset())));
    } catch (Exception e) {
        throw new SpringWindException(e);
    }
}

From source file:com.xyxy.platform.modules.nosql.redis.JedisScriptExecutor.java

/**
 * Lua Script, ?Spring Resource?./*  w  w  w .j  av  a 2s .com*/
 */
public void loadFromFile(final String scriptPath) throws JedisDataException {
    String scriptContent;
    try {
        Resource resource = new DefaultResourceLoader().getResource(scriptPath);
        scriptContent = FileUtils.readFileToString(resource.getFile());
    } catch (IOException e) {
        throw new IllegalArgumentException(scriptPath + " is not exist.", e);
    }

    load(scriptContent);
}

From source file:com.saysth.commons.quartz.ResourceLoaderClassLoadHelper.java

public void initialize() {
    if (this.resourceLoader == null) {
        this.resourceLoader = SchedulerFactoryBean.getConfigTimeResourceLoader();
        if (this.resourceLoader == null) {
            this.resourceLoader = new DefaultResourceLoader();
        }/*from   w w  w  .  j  a  v a2s .c o  m*/
    }
}

From source file:com.github.mjeanroy.springmvc.view.mustache.nashorn.NashornCompilerTest.java

@Before
public void setUp() throws Exception {
    this.model = new HashMap<String, Object>();
    this.model.put("name", "foo");
    this.model.put("zero", 0);
    this.model.put("emptyString", "");

    writer = new StringWriter();

    ResourceLoader resourceLoader = new DefaultResourceLoader();
    templateLoader = new DefaultTemplateLoader(resourceLoader);
    mustacheEngine = new MustacheEngine(templateLoader);
    nashornCompiler = new NashornCompiler(templateLoader, mustacheEngine);
}

From source file:com.github.mjeanroy.springmvc.view.mustache.mustachejava.MustacheJavaCompilerTest.java

@Before
public void setUp() throws Exception {
    this.model = new HashMap<String, Object>();
    this.model.put("name", "foo");
    this.model.put("zero", 0);
    this.model.put("emptyString", "");

    writer = new StringWriter();

    ResourceLoader resourceLoader = new DefaultResourceLoader();
    templateLoader = new DefaultTemplateLoader(resourceLoader);
    mustacheJavaCompiler = new MustacheJavaCompiler(templateLoader);
}

From source file:com.github.mjeanroy.springmvc.view.mustache.jmustache.JMustacheCompilerTest.java

@Before
public void setUp() throws Exception {
    this.model = new HashMap<String, Object>();
    this.model.put("name", "foo");
    this.model.put("zero", 0);
    this.model.put("emptyString", "");

    writer = new StringWriter();

    ResourceLoader resourceLoader = new DefaultResourceLoader();
    templateLoader = new DefaultTemplateLoader(resourceLoader);
    Compiler compiler = Mustache.compiler().zeroIsFalse(true).emptyStringIsFalse(true);

    mustacheCompiler = new JMustacheCompiler(compiler, templateLoader);
}

From source file:com.zaubersoftware.mule.module.jenkins.JenkinsCloudConnector.java

/** Creates the JenkinsCloudConnector. */
public JenkinsCloudConnector() {
    loader = new DefaultResourceLoader();
    new ResourceEditorRegistrar(loader).registerCustomEditors(new PropertyEditorRegistrySupport());
}