And, in case anyone's interested, here's a new WIKI page for it:

http://cwiki.apache.org/confluence/display/WICKET/Dynamically+Generate+a+CSS+Stylesheet

On Wed, Nov 19, 2008 at 12:48 PM, jwcarman <[EMAIL PROTECTED]> wrote:
>
> Well, I came up with a way to do it.  I wrote a new class called
> TextTemplateResourceReference, which you can use along with a
> StyleSheetReference.  Basically, you just pass it in a model for the
> variables to plugin.  I don't know about that lastModifiedTime()
> implementation, but its overridable if anyone wants to do something
> different.  If anyone wants the code to turn a java.awt.Color object into a
> hex string appropriate for CSS stylesheets, let me know.  I've got that
> floating around somewhere.
>
> import org.apache.wicket.IClusterable;
> import org.apache.wicket.Resource;
> import org.apache.wicket.ResourceReference;
> import org.apache.wicket.model.IDetachable;
> import org.apache.wicket.model.IModel;
> import org.apache.wicket.util.resource.IResourceStream;
> import org.apache.wicket.util.resource.StringResourceStream;
> import org.apache.wicket.util.template.PackagedTextTemplate;
> import org.apache.wicket.util.template.TextTemplate;
> import org.apache.wicket.util.time.Time;
>
> import java.util.Map;
>
> /**
>  * @author James Carman
>  */
> public class TextTemplateResourceReference extends ResourceReference
> implements IClusterable, IDetachable
> {
> //**********************************************************************************************************************
> // Fields
> //**********************************************************************************************************************
>
>    private static final long serialVersionUID = 1L;
>    private final TextTemplate textTemplate;
>    private final IModel<Map<String,Object>> variablesModel;
>
> //**********************************************************************************************************************
> // Constructors
> //**********************************************************************************************************************
>
>    public TextTemplateResourceReference(final Class<?> scope, final String
> name, IModel<Map<String,Object>> variablesModel)
>    {
>        super(scope, name);
>        this.textTemplate = new PackagedTextTemplate(scope, name);
>        this.variablesModel = variablesModel;
>    }
>
>    public TextTemplateResourceReference(final Class<?> scope, final String
> name, final String contentType, IModel<Map<String,Object>> variablesModel)
>    {
>        super(scope, name);
>        this.textTemplate = new PackagedTextTemplate(scope, name,
> contentType);
>        this.variablesModel = variablesModel;
>    }
>
>    public TextTemplateResourceReference(final Class<?> scope, final String
> name, final String contentType, final String encoding,
> IModel<Map<String,Object>> variablesModel)
>    {
>        super(scope, name);
>        this.textTemplate = new PackagedTextTemplate(scope, name,
> contentType, encoding);
>        this.variablesModel = variablesModel;
>    }
>
> //**********************************************************************************************************************
> // IDetachable Implementation
> //**********************************************************************************************************************
>
>    public void detach()
>    {
>        variablesModel.detach();
>    }
>
> //**********************************************************************************************************************
> // Other Methods
> //**********************************************************************************************************************
>
>    protected Resource newResource()
>    {
>        return new Resource()
>        {
>            private static final long serialVersionUID = 1L;
>
>            public IResourceStream getResourceStream()
>            {
>                return new
> StringResourceStream(textTemplate.asString(variablesModel.getObject()));
>            }
>
>
>        };
>    }
>
>    public Time lastModifiedTime()
>    {
>        return textTemplate.lastModifiedTime();
>    }
> }
>
>
> jwcarman wrote:
>>
>> Perhaps if it's that beneficial to folks, I'll put a wiki page out
>> there in the "how to" section.
>>
>> On Mon, Nov 17, 2008 at 6:40 AM, Ernesto Reinaldo Barreiro
>> <[EMAIL PROTECTED]> wrote:
>>> Tanks James! At the moment I do not need that code myself but maybe it
>>> could
>>> be useful to others...
>>> Best,
>>>
>>> Ernesto
>>>
>>> On Mon, Nov 17, 2008 at 12:20 PM, James Carman
>>> <[EMAIL PROTECTED]>wrote:
>>>
>>>> We're going to go with the "generate the CSS" route.  I'm going to
>>>> implement that today.  If you want me to send you some code after I'm
>>>> done, I can do that.
>>>>
>>>> On Mon, Nov 17, 2008 at 5:27 AM, Ernesto Reinaldo Barreiro
>>>> <[EMAIL PROTECTED]> wrote:
>>>> > Why don't you just generate the CSS or parse it if that's not
>>>> possible...
>>>> > With the  former approach you will have the color before hand, with
>>>> the
>>>> > latter you will have to locate it "somewhere" on the CSS. So, what is
>>>> the
>>>> > best solution will  depend on how you manage CSS on your
>>>> application...
>>>> > Best,
>>>> >
>>>> > Ernesto
>>>> >
>>>> > On Mon, Nov 17, 2008 at 9:21 AM, Eyal Golan <[EMAIL PROTECTED]>
>>>> wrote:
>>>> >
>>>> >> Stephen,
>>>> >> I need this the same reason James needs it.
>>>> >> We generate an image (a JFreeChart image) and we want it to have the
>>>> same
>>>> >> background color as the one specified in the CSS file.
>>>> >>
>>>> >>
>>>> >> Eyal Golan
>>>> >> [EMAIL PROTECTED]
>>>> >>
>>>> >> Visit: http://jvdrums.sourceforge.net/
>>>> >> LinkedIn: http://www.linkedin.com/in/egolan74
>>>> >>
>>>> >> P  Save a tree. Please don't print this e-mail unless it's really
>>>> necessary
>>>> >>
>>>> >>
>>>> >> On Sun, Nov 16, 2008 at 4:09 PM, James Carman <
>>>> [EMAIL PROTECTED]
>>>> >> >wrote:
>>>> >>
>>>> >> > I have the same sort of need in my application.  I need to do an
>>>> >> > "overlay" on an existing image using the same colors that are
>>>> defined
>>>> >> > in a CSS document.  I guess I could dynamically generate the CSS,
>>>> but
>>>> >> > I have no idea how to go about that. :)
>>>> >> >
>>>> >> > On Sun, Nov 16, 2008 at 7:02 AM, Swinsburg, Stephen
>>>> >> > <[EMAIL PROTECTED]> wrote:
>>>> >> > >
>>>> >> > > What do you need it for? Why can't you just make another class
>>>> with
>>>> >> just
>>>> >> > the attribute in it and AttributeAppender that in?
>>>> >> > >
>>>> >> > >
>>>> >> > >
>>>> >> > > -----Original Message-----
>>>> >> > > From: egolan74 [mailto:[EMAIL PROTECTED]
>>>> >> > > Sent: Sun 11/16/2008 10:42 AM
>>>> >> > > To: users@wicket.apache.org
>>>> >> > > Subject: RE: Reading an attribute that is set in a CSS file as a
>>>> class
>>>> >> > >
>>>> >> > >
>>>> >> > >
>>>> >> > >
>>>> >> > > Steve Swinsburg-2 wrote:
>>>> >> > >>
>>>> >> > >> On your component attach an AttributeAppender or
>>>> AttributeModifier,
>>>> >> set
>>>> >> > >> the "class" attribute to be the name of your class. Done :)
>>>> >> > >>
>>>> >> > >
>>>> >> > > Thanks Steve but this is not what I meant.
>>>> >> > > Adding a class as an attribute to a component is a pretty basic
>>>> stuff.
>>>> >> > >
>>>> >> > > What I want is, getting a value of an attribute of a class in a
>>>> CSS
>>>> >> file.
>>>> >> > >
>>>> >> > > -----
>>>> >> > > Eyal Golan
>>>> >> > > [EMAIL PROTECTED]
>>>> >> > >
>>>> >> > > Visit:  http://jvdrums.sourceforge.net/ JVDrums
>>>> >> > > LinkedIn:  http://www.linkedin.com/in/egolan74 LinkedIn
>>>> >> > > --
>>>> >> > > View this message in context:
>>>> >> >
>>>> >>
>>>> http://www.nabble.com/Reading-an-attribute-that-is-set-in-a-CSS-file-as-a-class-tp20523855p20524044.html
>>>> >> > > Sent from the Wicket - User mailing list archive at Nabble.com.
>>>> >> > >
>>>> >> > >
>>>> >> > >
>>>> ---------------------------------------------------------------------
>>>> >> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> >> > > For additional commands, e-mail: [EMAIL PROTECTED]
>>>> >> > >
>>>> >> > >
>>>> >> > >
>>>> >> > >
>>>> >> > >
>>>> ---------------------------------------------------------------------
>>>> >> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> >> > > For additional commands, e-mail: [EMAIL PROTECTED]
>>>> >> > >
>>>> >> >
>>>> >> >
>>>> ---------------------------------------------------------------------
>>>> >> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> >> > For additional commands, e-mail: [EMAIL PROTECTED]
>>>> >> >
>>>> >> >
>>>> >>
>>>> >
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>
>>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>>
>
> --
> View this message in context: 
> http://www.nabble.com/Reading-an-attribute-that-is-set-in-a-CSS-file-as-a-class-tp20523855p20585276.html
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to