Re: asset expansion question
http://tapestry.apache.org/assets.html http://tapestry.1045711.n5.nabble.com/T5-Assets-resources-and-file-path-td2416655.html -- View this message in context: http://tapestry.1045711.n5.nabble.com/asset-expansion-question-tp3697610p3834582.html Sent from the Tapestry - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
asset expansion question
Hallo,I have a new question! I'm writing a asset expansion like this lmg src=${asset:uri:http://people.apache.org/~uli/images/tapestry.png} / I implememt a Resource using URI, and add a asset configure,It works well Now I want to change it like this img src=${asset:uri:images/tapestry.png}/img I want the server root path http://people.apache.org/~uli/ to be configurable ,so it can be configured using tapestry symbols.I tried this using AssetFactory,URIResource,and symbols,but failed Can anyone help me?
Re: asset expansion question
I want the server root path http://people.apache.org/~uli/ to be configurable ,so it can be configured using tapestry symbols.I tried this using AssetFactory,URIResource,and symbols,but failed Can anyone help me? Please define failed? What is the error, or what does the generated HTML look like? On Tue, Mar 15, 2011 at 4:13 AM, jqzone jqz...@gmail.com wrote: Hallo,I have a new question! I'm writing a asset expansion like this lmg src=${asset:uri:http://people.apache.org/~uli/images/tapestry.png} / I implememt a Resource using URI, and add a asset configure,It works well Now I want to change it like this img src=${asset:uri:images/tapestry.png}/img I want the server root path http://people.apache.org/~uli/ to be configurable ,so it can be configured using tapestry symbols.I tried this using AssetFactory,URIResource,and symbols,but failed Can anyone help me? - To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org
Re: asset expansion question
Here is my code. TemplateResource.java public class TemplateResource implements Resource{ private URI uri; public TemplateResource(String uri) { try { this.uri = new URI(uri); } catch (URISyntaxException e) { throw new RuntimeException(e); } } public TemplateResource(URI uri) throws MalformedURLException { this.uri = uri; } public TemplateResource(File file) throws MalformedURLException { this(file.toURI()); } public TemplateResource(URL url) throws URISyntaxException, MalformedURLException { this(url.toURI()); } protected Resource newResource(String uri) { return new TemplateResource(uri); } @Override public boolean exists() { InputStream is = null; try { is = uri.toURL().openStream(); int i = is.read(); return true; } catch (Exception e) { return false; } finally { try { if (is != null) is.close(); } catch (Exception e) { // do nothing } } } @Override public Resource forFile(String relativePath) { return createResource(relativePath); } @Override public Resource forLocale(Locale locale) { for (String path : new LocalizedNameGenerator(this.uri.toString(), locale)) { Resource potential = createResource(path); if (potential.exists()) return potential; } return null; } private Resource createResource(String path) { if (this.uri.toString().equals(path)) return this; return newResource(path); } @Override public String getFile() { String fileName = ; String completePath = toURL().getPath(); if (completePath != null) { if (completePath.lastIndexOf('/') 0) fileName = completePath.substring(completePath.lastIndexOf('/') + 1); else fileName = completePath; } return fileName; } @Override public String getFolder() { String folderName = ; String completePath = toURL().getPath(); if (completePath != null) { int lastSlash = completePath.lastIndexOf('/'); if (lastSlash 0) folderName = completePath.substring(0, lastSlash); } return folderName; } @Override public String getPath() { return toURL().toExternalForm(); } @Override public InputStream openStream() throws IOException { return uri.toURL().openStream(); } @Override public URL toURL() { try { if (exists()) return uri.toURL(); } catch (Exception e) { // do nothing } return null; } @Override public Resource withExtension(String extension) { throw new RuntimeException(not implemented yet!); } @Override public boolean equals(Object obj) { if (obj == null) return false; if (obj == this) return true; if (obj.getClass() != getClass()) return false; TemplateResource other = (TemplateResource) obj; return other.getPath().equals(getPath()); } } TemplateAssetFactory.java public class TemplateAssetFactory implements AssetFactory { private final boolean invariant; private Resource rootResource; public TemplateAssetFactory() { this.invariant = true; } @Override public Asset createAsset(final Resource resource) { return new AbstractAsset(invariant) { @Override public String toClientURL() { return resource.getPath(); } @Override public Resource getResource() { return resource; } }; } @Override public Resource getRootResource() { rootResource = new TemplateResource(/); return rootResource; } } TemplateProvider.java @Target({ ElementType.PARAMETER, ElementType.FIELD, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface TemplateProvider { } TemplateAssetConstants.java public class TemplateAssetConstants extends AssetConstants { public static final String TEMPLATE = template; } Some config in AppModule.java @Marker(TemplateProvider.class) public AssetFactory buildTemplateAssetFactory() { return new TemplateAssetFactory(); } public void contributeAssetSource( MappedConfigurationString, AssetFactory configuration, @TemplateProvider AssetFactory templateAssetFactory) { configuration .add(TemplateAssetConstants.TEMPLATE, templateAssetFactory); } some code in tml : x:dynamic template=asset:template: http://192.168.1.105:8080/dynamic2.html; It works well. Now I wnat to change it like this x:dynamic template=asset:template:dynamic2.html I want the server root path http://192.168.1.105:8080/ is configurable using tapestry symbols,so how can i change my code ?