Re: [Wicket-user] [Spam] Re: CSS background images
I hope something like this will be included in wicket soon. I have an issue "hard-coding" the path in my css. Since I use wicket-bench for testing, my tests have a different servlet path than my actual application instance.On 8/1/06, cowwoc <[EMAIL PROTECTED]> wrote: Upon first glance, looks good ;) Maybe you guys should roll it up intocore GiliAl Maw wrote:> Igor Vaynberg wrote:>> i guess it is not something that we support right now, but something >> that is cleary needed. we need to build a resource that can load a css>> file, parse for images, replace them, and then serve the altered content. i know almaw has been working on something like this but i dont know how >> far he got. a patch would be welcome, if not then i guess you will have>> to wait until one of the core devels has the time.>> Sorry for the late reply - been on holiday. Please find attached > something that might be useful.>> You'll need to change CssResource#getResourceStream() to understand how> to tell if your app is in debug mode or not (see discussion on the dev> list a week or two ago about that). >> Best regards,>> Al Maw>>> >> package foo.wicket.resources;>> import wicket.Application ;> import wicket.AttributeModifier;> import wicket.Component;> import wicket.ResourceReference;> import wicket.SharedResources;> import wicket.markup.ComponentTag;> import wicket.markup.html.WebMarkupContainer ;> import wicket.model.IModel;> import wicket.model.Model;> import wicket.util.value.ValueMap;>> /**> * Created on 03-May-2006.> * @author Alastair Maw> */> public class CssReference extends WebMarkupContainer { >> private static final long serialVersionUID = 1L;>> /**> * Construct.> * @param id component id> * @param referer the class that is refering; is used as the relative > * root for gettting the resource> * @param file reference as a string> */> public CssReference(final String id, final Class referer, final String file) {> this(id, referer, new Model(file)); > }>> public CssReference(final String id, final Class referer, final IModel file) {> super(id);> IModel srcReplacement = new Model() {> private static final long serialVersionUID = 1L; >> public Object getObject(Component component) {>> Object o = file.getObject(component);> if (o == null) {> throw new IllegalArgumentException("The model must provide a non-null object (component == " + component + ")");> }> if (!(o instanceof String)) {> throw new IllegalArgumentException("The model must provide an instance of String");> }>> String f = (String)component.getConverter().convert(file.getObject(component), String.class);> final SharedResources sharedResources = Application.get().getSharedResources();> CssResource resource = (CssResource)sharedResources.get(referer, f, getLocale(), getStyle(), true);> if (resource == null) {> resource = new CssResource(getRequestCycle(), referer, file.getObject(component).toString());> sharedResources.add(referer, f, null, null, resource);> }>> String url = "" ResourceReference(referer, f)).toString();> return url;>> }> };> add(new AttributeModifier("href", true, srcReplacement));> }>> /** > * @see wicket.Component#onComponentTag(wicket.markup.ComponentTag)> */> protected void onComponentTag(ComponentTag tag) {> // Must be attached to a style tag> checkComponentTag(tag, "link"); > ValueMap attributes = tag.getAttributes();> attributes.put("rel", "stylesheet");> attributes.put("type", "text/css");> } >> }>>> >> package foo.wicket.resources;>> import java.io.BufferedReader;> import java.io.IOException ;> import java.io.InputStreamReader;>> import org.apache.commons.logging.Log;> import org.apache.commons.logging.LogFactory;>> import wicket.Application;> import wicket.RequestCycle ;> import wicket.Resource;> import wicket.ResourceReference;> import wicket.WicketRuntimeException;> import wicket.markup.html.PackageResourceReference;> import wicket.markup.html.WebResource ;> import wicket.util.lang.Packages;> import wicket.util.resource.IResourceStream;> import wicket.util.resource.ResourceStreamNotFoundException;> import wicket.util.resource.StringBufferResourceStream ;> import wicket.util.resource.locator.IResourceStreamLocator;> import wicket.util.time.Time;>> /**> * Created on 03-May-2006.> * @author Alastair Maw> */> public class CssResource extends WebResource { >> private static final long serialVersionUID = 1L;>> private stati
Re: [Wicket-user] [Spam] Re: CSS background images
Upon first glance, looks good ;) Maybe you guys should roll it up into core Gili Al Maw wrote: > Igor Vaynberg wrote: >> i guess it is not something that we support right now, but something >> that is cleary needed. we need to build a resource that can load a css >> file, parse for images, replace them, and then serve the altered content. >> >> i know almaw has been working on something like this but i dont know how >> far he got. a patch would be welcome, if not then i guess you will have >> to wait until one of the core devels has the time. > > Sorry for the late reply - been on holiday. Please find attached > something that might be useful. > > You'll need to change CssResource#getResourceStream() to understand how > to tell if your app is in debug mode or not (see discussion on the dev > list a week or two ago about that). > > Best regards, > > Al Maw > > > > > package foo.wicket.resources; > > import wicket.Application; > import wicket.AttributeModifier; > import wicket.Component; > import wicket.ResourceReference; > import wicket.SharedResources; > import wicket.markup.ComponentTag; > import wicket.markup.html.WebMarkupContainer; > import wicket.model.IModel; > import wicket.model.Model; > import wicket.util.value.ValueMap; > > /** > * Created on 03-May-2006. > * @author Alastair Maw > */ > public class CssReference extends WebMarkupContainer { > > private static final long serialVersionUID = 1L; > > /** > * Construct. > * @param id component id > * @param referer the class that is refering; is used as the relative > * root for gettting the resource > * @param file reference as a string > */ > public CssReference(final String id, final Class referer, final String > file) { > this(id, referer, new Model(file)); > } > > public CssReference(final String id, final Class referer, final IModel > file) { > super(id); > IModel srcReplacement = new Model() { > private static final long serialVersionUID = 1L; > > public Object getObject(Component component) { > > Object o = file.getObject(component); > if (o == null) { > throw new IllegalArgumentException("The model must > provide a non-null object (component == " + component + ")"); > } > if (!(o instanceof String)) { > throw new IllegalArgumentException("The model must > provide an instance of String"); > } > > String f = > (String)component.getConverter().convert(file.getObject(component), > String.class); > final SharedResources sharedResources = > Application.get().getSharedResources(); > CssResource resource = > (CssResource)sharedResources.get(referer, f, getLocale(), getStyle(), true); > if (resource == null) { > resource = new CssResource(getRequestCycle(), referer, > file.getObject(component).toString()); > sharedResources.add(referer, f, null, null, resource); > } > > String url = getRequestCycle().urlFor(new > ResourceReference(referer, f)).toString(); > return url; > > } > }; > add(new AttributeModifier("href", true, srcReplacement)); > } > > /** > * @see wicket.Component#onComponentTag(wicket.markup.ComponentTag) > */ > protected void onComponentTag(ComponentTag tag) { > // Must be attached to a style tag > checkComponentTag(tag, "link"); > ValueMap attributes = tag.getAttributes(); > attributes.put("rel", "stylesheet"); > attributes.put("type", "text/css"); > } > > } > > > > > package foo.wicket.resources; > > import java.io.BufferedReader; > import java.io.IOException; > import java.io.InputStreamReader; > > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > > import wicket.Application; > import wicket.RequestCycle; > import wicket.Resource; > import wicket.ResourceReference; > import wicket.WicketRuntimeException; > import wicket.markup.html.PackageResourceReference; > import wicket.markup.html.WebResource; > import wicket.util.lang.Packages; > import wicket.util.resource.IResourceStream; > import wicket.util.resource.ResourceStreamNotFoundException; > import wicket.util.resource.StringBufferResourceStream; > import wicket.util.resource.locator.IResourceStreamLocator; > import wicket.util.time.Time; > > /** > * Created on 03-May-2006. > * @author Alastair Maw > */ > public class CssResource extends WebResource { > > private static final long serialVersionUID = 1L; > > private static Log log = LogFacto