I don't know much about the details how you contribute your FilesystemAssetFactory. Never had time to take a briefer look at tapestry-ioc.

Please note: in the previous example the AssetFactory is injected like this:

@Inject @ClasspathProvider
private AssetFactory assetFactory;


The @ClasspathProvider is necessary, so that tapestry-ioc knows, which of the 
different implementations to inject.

Maybe, in order to make your solution work, you need to give a hint like that, 
too?


Andy










Peter Kanze schrieb:
Hi Andy,

Thanks for adding this to Jira.
See below my code what I have produced so far. The problem is that I now see
the complete filepath in my html source (<img src="
C:/tmp/pictures/8/71/1001/thumb1.jpg" alt=""/>)
I don't want the complete file url in my html source. How can I fix this.
And how do I map the html url to the file url?
The last problem is that the file url is correct, but the image is not shown
in my html page.
What am I doing wrong?


--Quick Example Code Below---

<img src="${ThumbnailPath}" alt="" />

public String getThumbnailPath() {
         Asset asset = assetSource.getAsset(null,
"file:/8/71/1001/thumb1.jpg", null);
         return asset.toClientURL();
}

public class FileSystemResource extends AbstractResource {

    private static final int PRIME = 37;

    public FileSystemResource(String path) {
        super(path);
    }

    @Override
    protected Resource newResource(String path) {
        return new FileSystemResource(path);
    }

    @Override
    public URL toURL() {
        String filePath = getPath();
        File file = new File(filePath);

        if (file != null && file.exists()) {
            try {
                return file.toURL();
            }
            catch (MalformedURLException ex) {
                throw new RuntimeException(ex);
            }
        }
        return null;
    }
}

public class FileSystemAssetFactory implements AssetFactory {

    private static final String assetPath = "/images/";

    public FileSystemAssetFactory() {

    }

   @Override
    public Resource getRootResource() {
        return new FileSystemResource("C:/tmp/pictures/");
    }

    @Override
    public Asset createAsset(final Resource resource) {
        final String filePath =  resource.getPath();

        return new Asset()
        {
            public Resource getResource()
            {
                return resource;
            }

            public String toClientURL()
            {
                return filePath;
            }

            /**
             * Returns the client URL, which is essiential to allow informal
parameters of type
             * Asset to generate a proper value.
             */
            @Override
            public String toString()
            {
                return toClientURL();
            }
        };
    }



}

//In AppModule.java
public AssetFactory buildfileSystemAssetFactory() {
        return new FileSystemAssetFactory();
    }

    public void contributeAssetSource(MappedConfiguration<String,
AssetFactory> configuration,
            @InjectService("fileSystemAssetFactory") AssetFactory
fileSystemAssetFactory) {
        configuration.add("file", fileSystemAssetFactory);
    }



On Tue, Mar 10, 2009 at 3:28 PM, Andy Pahne <andy.pa...@googlemail.com>wrote:

There is a ClasspathAssetFactory and a ContextAssetFactory. A useful
addition to the framework would be a FilesystemAssetFactory. I am going to
fill an JIRA issue about it.

The way I did it for classpath resources was very simple, see below. Only
the first two lines of renderIcon() are relevant for construction an asset.

 @BeginRender
  public void renderIcon(MarkupWriter writer) {

      Resource iconResource = new ClasspathResource(BASE_PATH + src);
                  if(assetFactory == null) {
          LOG.warn("assertFactory is null");
      }
            if(iconResource == null) {
          LOG.warn("iconResource is null");
      }
      Asset icon = assetFactory.createAsset(iconResource);

      if(icon != null) {

          writer.element("img",
              "src", icon.toClientURL(),
              "alt", getAlt());

          resources.renderInformalParameters(writer);

          writer.end();

      } else {

          writer.writeRaw(getAlt());

      }

  }



  @Inject @ClasspathProvider
  private AssetFactory assetFactory;

  @BeginRender
  public void renderIcon(MarkupWriter writer) {

      Resource iconResource = new ClasspathResource(BASE_PATH + src);
     Asset icon = assetFactory.createAsset(iconResource);

      if(icon != null) {

          writer.element("img",
              "src", icon.toClientURL(),
              "alt", getAlt());

          resources.renderInformalParameters(writer);

          writer.end();

      } else {

          writer.writeRaw(getAlt());

      }

  }








Peter Kanze schrieb:

 The documentation (http://tapestry.apache.org/tapestry5/guide/assets.html
)
tells me to define a new AssetFactory and contribute it to the AssetSource
service configuration.
Yes okay, but how do I implement an AssetFactory? Is there any
documentation?

What do I need to do with public Resource getRootResource() and public
Asset
createAsset(Resource resource);
I also looked at ClasspathAssetFactory but don't understand it. The
comment
is too minimal.

Can someone help me with this?

Thanks,
Peter!

On Tue, Mar 10, 2009 at 1:59 PM, Peter Kanze <peterka...@gmail.com>
wrote:



Oke thank you.

But how do I map between the web http:// and the file D:/ urls?
Can you give me some (pseudo) code examples how to do this?

Thanks!
Peter




On Tue, Mar 10, 2009 at 1:56 PM, Thiago H. de Paula Figueiredo <
thiag...@gmail.com> wrote:



On Tue, Mar 10, 2009 at 9:51 AM, Peter Kanze <peterka...@gmail.com>
wrote:


I already searched the archive and found the question, but it is not


clear


to me.
There are no examples in it with a dynamic path..


You'll use AssetSource for that.

--
Thiago

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to