Another reason to host the YUI scripts locally is so that you can take
advantage of JavaScript combination (in Tapestry 5.1). That only works
if all of the individual script files are located on the server (in
the context, or on the classpath).

On Thu, Mar 26, 2009 at 11:48 AM, Geoffrey Wiseman
<geoffrey.wise...@gmail.com> wrote:
> On Thu, Mar 26, 2009 at 1:40 PM, Dave Greggory <davegregg...@yahoo.com>wrote:
>
>>
>> Just use RenderSupport.
>>
>> I just built my own component named asset attacher for this purpose.
>>
>
> And if anyone's curious what the other approach might look like:
>
> package com.tsg.tapestry;
>
> import java.io.IOException;
> import java.io.InputStream;
> import java.net.MalformedURLException;
> import java.net.URI;
> import java.net.URISyntaxException;
> import java.net.URL;
> import java.util.Locale;
>
> import org.apache.tapestry5.Asset;
> import org.apache.tapestry5.ioc.Resource;
> import org.apache.tapestry5.services.AssetFactory;
>
> public class UriAssetFactory implements AssetFactory {
>
>   �...@override
>    public Asset createAsset(Resource resource) {
>        return new UriAsset((UriResource) resource);
>    }
>
>   �...@override
>    public Resource getRootResource() {
>        return new UriResource();
>    }
>
>    private static class UriResource implements Resource {
>
>        private String path;
>        private URI uri;
>
>        public UriResource() {
>            // root uri resource
>            this.path = null;
>            this.uri = null;
>        }
>
>        public UriResource(String path) {
>            this.path = path;
>            try {
>                this.uri = new URI(path);
>            } catch (URISyntaxException e) {
>                uri = null;
>            }
>        }
>
>        private boolean isRoot() {
>            return path == null;
>        }
>
>       �...@override
>        public boolean exists() {
>            if (uri != null) {
>                return true;
>            } else {
>                return false;
>            }
>        }
>
>       �...@override
>        public Resource forFile(String relativePath) {
>            if (isRoot()) {
>                return new UriResource(relativePath);
>            } else {
>                return new UriResource(this.getFolder() + '/' +
> relativePath);
>            }
>        }
>
>        /**
>         * URI Resources can't be localized -- at least, not in any easy
> manner.
>         */
>       �...@override
>        public Resource forLocale(Locale locale) {
>            return this;
>        }
>
>       �...@override
>        public String getFile() {
>            if (isRoot()) {
>                return "";
>            } else {
>                int index = path.lastIndexOf('/');
>                if (index == -1) {
>                    return path;
>                } else {
>                    return path.substring(index + 1);
>                }
>            }
>        }
>
>       �...@override
>        public String getFolder() {
>            if (isRoot()) {
>                return "";
>            } else {
>                int index = path.lastIndexOf('/');
>                if (index == -1) {
>                    return "";
>                } else {
>                    return path.substring(0, index);
>                }
>            }
>        }
>
>       �...@override
>        public String getPath() {
>            return path;
>        }
>
>       �...@override
>        public InputStream openStream() throws IOException {
>            if (isRoot()) {
>                throw new IOException("Cannot open stream for root uri.");
>            } else if (uri == null) {
>                throw new IOException("Cannot open stream for malformed
> uri.");
>            } else {
>                return uri.toURL().openStream();
>            }
>        }
>
>       �...@override
>        public URL toURL() {
>            if (uri == null) {
>                try {
>                    return uri.toURL();
>                } catch (MalformedURLException e) {
>                    return null;
>                }
>            } else {
>                return null;
>            }
>        }
>
>       �...@override
>        public Resource withExtension(String extension) {
>            if (isRoot()) {
>                return this;
>            } else {
>                int index = path.lastIndexOf('.');
>                if (index == -1) {
>                    return new UriResource(path + '.' + extension);
>                } else {
>                    return new UriResource(path.substring(0, index + 1)
>                            + extension);
>                }
>            }
>        }
>
>    }
>
>    private static class UriAsset implements Asset {
>
>        private UriResource resource;
>
>        public UriAsset(UriResource resource) {
>            this.resource = resource;
>        }
>
>       �...@override
>        public Resource getResource() {
>            return resource;
>        }
>
>       �...@override
>        public String toClientURL() {
>            return resource.getPath();
>        }
>
>    }
>
> }
>
>
> package com.tsg.crystal.web.services;
>
> import org.apache.tapestry5.ioc.MappedConfiguration;
> import org.apache.tapestry5.services.AssetFactory;
>
> import com.tsg.tapestry.UriAssetFactory;
>
> public class TapestryModule {
>
>    public static void contributeAssetSource(
>            MappedConfiguration<String, AssetFactory> configuration) {
>        configuration.add("uri", new UriAssetFactory());
>    }
> }
>
>
>
> @IncludeStylesheet( {
>        "uri:
> http://yui.yahooapis.com/2.7.0/build/reset-fonts-grids/reset-fonts-grids.css
> ",
>        "uri:http://yui.yahooapis.com/2.7.0/build/base/base-min.css"; })
>
>
> --
> Geoffrey Wiseman
> http://www.geoffreywiseman.ca/
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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

Reply via email to