Package org.springframework.core.io

Examples of org.springframework.core.io.ResourceLoader


        // since 2.2 we add by default all flow scripts located in the ./flow directory
        // The default location can be overwritten by specifying the location attribute.
        final BeanFactory beanFactory = this.treeBuilder.getWebApplicationContext();
        if ( beanFactory instanceof ApplicationContext && node.getInterpreter().getScriptExtension() != null ) {
            final ResourceLoader resourceLoader = (ApplicationContext)beanFactory;
            final String scriptLocation = config.getAttribute("location", DEFAULT_FLOW_SCRIPT_LOCATION);
            if ( resourceLoader.getResource(scriptLocation).exists() ) {
                final ServletContextResourcePatternResolver resolver = new ServletContextResourcePatternResolver(resourceLoader);
                final Resource[] resources = resolver.getResources(scriptLocation + "/*" + node.getInterpreter().getScriptExtension());
                if ( resources != null ) {
                    for(int i=0; i < resources.length; i++) {
                        node.getInterpreter().register(ResourceUtils.getUri(resources[i]));
View Full Code Here


   * if none specified.
   */
  protected EntityResolver getEntityResolver() {
    if (this.entityResolver == null) {
      // Determine default EntityResolver to use.
      ResourceLoader resourceLoader = getResourceLoader();
      if (resourceLoader != null) {
        this.entityResolver = new ResourceEntityResolver(resourceLoader);
      }
      else {
        this.entityResolver = new DelegatingEntityResolver(getBeanClassLoader());
View Full Code Here

   * @see #getResourceLoader()
   * @see #loadBeanDefinitions(org.springframework.core.io.Resource)
   * @see #loadBeanDefinitions(org.springframework.core.io.Resource[])
   */
  public int loadBeanDefinitions(String location, Set actualResources) throws BeanDefinitionStoreException {
    ResourceLoader resourceLoader = getResourceLoader();
    if (resourceLoader == null) {
      throw new BeanDefinitionStoreException(
          "Cannot import bean definitions from location [" + location + "]: no ResourceLoader available");
    }

    if (resourceLoader instanceof ResourcePatternResolver) {
      // Resource pattern matching available.
      try {
        Resource[] resources = ((ResourcePatternResolver) resourceLoader).getResources(location);
        int loadCount = loadBeanDefinitions(resources);
        if (actualResources != null) {
          for (int i = 0; i < resources.length; i++) {
            actualResources.add(resources[i]);
          }
        }
        if (logger.isDebugEnabled()) {
          logger.debug("Loaded " + loadCount + " bean definitions from location pattern [" + location + "]");
        }
        return loadCount;
      }
      catch (IOException ex) {
        throw new BeanDefinitionStoreException(
            "Could not resolve bean definition resource pattern [" + location + "]", ex);
      }
    }
    else {
      // Can only load single resources by absolute URL.
      Resource resource = resourceLoader.getResource(location);
      int loadCount = loadBeanDefinitions(resource);
      if (actualResources != null) {
        actualResources.add(resource);
      }
      if (logger.isDebugEnabled()) {
View Full Code Here

*/
public class GenericWebContextLoader extends AbstractContextLoader {
  protected final MockServletContext servletContext;

  public GenericWebContextLoader(String warRootDir, boolean isClasspathRelative) {
    ResourceLoader resourceLoader = isClasspathRelative ? new DefaultResourceLoader() : new FileSystemResourceLoader();
    this.servletContext = initServletContext(warRootDir, resourceLoader);
  }
View Full Code Here

            }
        }
    }

    protected void handleImport(ParserContext parserContext, String uri) {
        final ResourceLoader resourceLoader = parserContext.getReaderContext().getReader().getResourceLoader();
        parserContext.getDelegate().getReaderContext().getReader().loadBeanDefinitions(resourceLoader.getResource(uri));
    }
View Full Code Here

    @Override
    protected ClassPathBeanDefinitionScanner configureScanner(ParserContext parserContext, Element element) {
        final ClassPathBeanDefinitionScanner scanner = super.configureScanner(parserContext, element);

        final ResourceLoader originalResourceLoader = parserContext.getReaderContext().getResourceLoader();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Scanning only this classloader:" + originalResourceLoader.getClassLoader());
        }

        ResourceLoader parentOnlyResourceLoader;
        try {
            parentOnlyResourceLoader = new ResourceLoader() {
                ClassLoader parentOnlyGetResourcesClassLoader = new ParentOnlyGetResourcesClassLoader(originalResourceLoader.getClassLoader());

                public Resource getResource(String location) {
                    return originalResourceLoader.getResource(location);
                }
View Full Code Here

    protected ResourceLoader defaultResourceLoader =  new FileSystemResourceLoader();
    protected GrailsPluginManager pluginManager;
    protected boolean warDeployed = Environment.isWarDeployed();

    public void setSearchLocation(String searchLocation) {
        ResourceLoader resourceLoader = getDefaultResourceLoader();
        patchMatchingResolver = new PathMatchingResourcePatternResolver(resourceLoader);
        initializeForSearchLocation(searchLocation);
    }
View Full Code Here

   * @throws Exception
   */
  public void setResourcePaths(List<String> paths) throws Exception{
    getLog().info("set resource paths to ", paths);
   
    ResourceLoader resourceLoader = new BoostedDefaultResourceLoader();
    for (String path: paths){
      if (resourcePathTransformation != null){
        path = resourcePathTransformation.value(path);
      }
      Resource resource = resourceLoader.getResource(path);
      Document doc = DomUtils.read(resource.getInputStream());
      Node schemaNode = DomUtils.getNode(true, doc, "schema");
      for (Node simpleType: DomUtils.getNodes(true, schemaNode, "simpleType")){
        //Use defined format
        for (Node annotation: DomUtils.getNodes(true, simpleType, "annotation")){
View Full Code Here

        logInBothServletAndLoggingSystem("Initializing filter: " + getFilterName());

        try {
            PropertyValues pvs = new FilterConfigPropertyValues(getFilterConfig(), requiredProperties);
            BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
            ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());
            bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader));
            initBeanWrapper(bw);
            bw.setPropertyValues(pvs, true);
        } catch (Exception e) {
            throw new ServletException("Failed to set bean properties on filter: " + getFilterName(), e);
View Full Code Here

        Map<String, Object> inputVariables = scriptInputs.isEmpty() ? inputs : scriptInputs.pop();
        inputVariables.forEach((k, v) -> {
            variables.put(k, v);
        });

        ResourceLoader loader = new DefaultResourceLoader();

        for (Script script : scripts) {
            NamespacedBinding binding = create();
            // Bind inputs.
            for (String key : variables.keySet()) {
                binding.setVariable(key, variables.get(key));
            }
            binding.startCapture();

            String filename = Strings.isNullOrEmpty(scriptDirectory) ? script.getName() : scriptDirectory
                    + File.separator + script.getName();
            try (InputStream stream = loader.getResource(filename).getInputStream()) {
                List<String> lines = IOUtils.readLines(stream);
                String content = String.join("\n", lines);

                transaction.exec(() -> execute(content, binding));
            } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.springframework.core.io.ResourceLoader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.