4 Replies Latest reply on Sep 6, 2012 3:03 PM by aykay

    Solder / getWebResource to all files in a folder - How?

    aykay

      Hi there.

       

      Solder makes it easy to get access to a server resource.

       

      WebResourceLocator locator = new WebResourceLocator();

      InputStream inputStream = locator.getWebResource("/WEB-INF/standard_resources/legalnote.txt");

       

      But what if I want to have access to ALL files residing in /WEB-INF/standard_resources dynamically ?? Means, regardless of what's been put inside /WEB-INF/standard_resources each file gets processed. In that case I don't know the file names.

       

      One way, of course, would be to use

      File folder = new File("../standalone/deployments/PROJECTNAME.war/WEB-INF/standard_resources");

      But this stinks.

       

      Is there a way to get access to all resources dynamically in a given folder using Solder?

      Thank you !!

        • 1. Re: Solder / getWebResource to all files in a folder - How?
          lightguard

          We never had that use case come up when we designed the feature. As far as I know, there isn't a way to do this with Solder.

          • 2. Re: Solder / getWebResource to all files in a folder - How?
            aykay

            Thanks!

             

            In fact I programmed a solution meanwhile which I'll post a soon as I can spare some time.

             

            Cheers, and keep up the great stuff you're doing.

            • 3. Re: Solder / getWebResource to all files in a folder - How?
              davisonri_k12

              Great. I was looking to do something similar to load up multiple seam-beans.xml files (broken down into smaller more meaningful parts from the big seam-beans.xml that I initially had). it would be great if you can post your solution. Thanks

              • 4. Re: Solder / getWebResource to all files in a folder - How?
                aykay

                Hi Dave.

                 

                Terribly sorry about my late respone.

                 

                In the mean time project demands had altered in a way that my solution simply doesn't fit the original question anymore. When mentioning it I wasn't aware of this. Now I could spare some time to figure out how I'd solve my original request. Please bear with me that I again sticked to using java.io.File to get hold of all file names residing in a parcticular web folder. In order to input stream and process all of them I did:

                 

                import javax.faces.context.FacesContext;
                import javax.servlet.ServletContext;
                ...
                public void processAllResources(String folderInWebContext) throws IOException
                {
                     ServletContext servletContext = (ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext();
                
                     if (folderInWebContext.charAt(0) != '/') // Add global web root
                          folderInWebContext = "/" + folderInWebContext;
                
                     File webRootFolder = new File(servletContext.getRealPath(folderInWebContext));
                     File[] files = webRootFolder.listFiles();
                
                     if (files != null)
                          for (File file : files)
                          {
                               String fileName = file.getName();
                               String resourceTerm = folderInWebContext + "/" + fileName;
                               WebResourceLocator locator = new WebResourceLocator();
                               InputStream inputStream = locator.getWebResource(resourceTerm);
                               // Process this input stream
                               // ...
                               inputStream.close();
                          }
                }
                

                 

                As always, code can surely be improved and I welcome hints. Of course, I tested it successfully.

                Cheers

                AyKay