Re: Where to store site settings?

2012-03-30 Thread trsvax
I think I've done this differently on every project and every way has turned
out wrong. The way I do it now is objects in the environment. The great
thing about this way is you can set defaults for the entire site, override
them depending on development/production and override it at any point in the
page render cycle. For example the defaults are set this way in AppModule. 

@Contribute(EnvironmentSetup.class)
public static void provideEnvironmentSetup(MappedConfiguration configuration) {
configuration.add(FrameworkEnvironment.class, new
FrameworkValues(null).withName("tb"));
configuration.add(ButtonEnvironment.class, new 
ButtonValues(null));
configuration.add(FormEnvironment.class, new FormValues(null));
configuration.add(NavEnvironment.class, new NavValues(null));
configuration.add(TableEnvironment.class, new 
TableValues(null));
}

To override them 

@Contribute(EnvironmentSetup.class)
public static void provideEnvironmentSetup(MappedConfiguration configuration) {
configuration.override(TableEnvironment.class, new
TableValues(null).withType("table"));
configuration.override(FormEnvironment.class, new
FormValues(null).withType("form-horizontal"));
}


You'll need to set then in a markup filter

public void
contributeMarkupRenderer(OrderedConfiguration
configuration,
final Logger logger,
final EnvironmentSetup environmentSetup,
final Environment environment, 
final JavaScriptSupport javaScriptSupport, 
final ExcludeVisitor excludeVistior,
@InjectService(BootstrapVisitor.id)  final 
FrameworkVisitor
frameworkVisitor,
@InjectService("FrameworkProvider") final 
FrameworkProvider
frameworkProvider) {

MarkupRendererFilter bootstrapFilter = new 
MarkupRendererFilter() { 
public void renderMarkup(MarkupWriter writer, 
MarkupRenderer renderer) {
environmentSetup.push(); // push all the 
defaults
renderer.renderMarkup(writer);  

environmentSetup.pop(); // pop them after the 
render

Don't forget

public void
contributePartialMarkupRenderer(OrderedConfiguration
configuration,

Here is the service to push/pop them

@SuppressWarnings("rawtypes")
public class EnvironmentSetupImpl implements EnvironmentSetup {
private final Map setup;
private final Environment environment;

public EnvironmentSetupImpl(Map setup, Logger logger,
Environment environment) {
this.setup = setup;
this.environment = environment;
}

@SuppressWarnings("unchecked")
public void push() {
for ( Entry entry : setup.entrySet() ) {
environment.push(entry.getKey(), entry.getValue());
}
}
@SuppressWarnings("unchecked")
public void pop() {
for ( Entry entry : setup.entrySet() ) {
environment.pop(entry.getKey());
}
}

}


Now you can access them in pages/components/services. Plus by pushing new
ones you can override them at any point in the render cycle. I make the
constructor take the current one so you can chain them like this

environment.push(TableEnvironment.class, new
TableValues(environment.peekRequired(TableEnvironment.class)).withType("table-bordered"));

public class TableValues implements TableEnvironment {
private String type;
private boolean isInstrumented;
private String sortElement = "i";
private String[] sortElementAttributes = {"class","icon-random"};
private String prefix = "table";

public TableValues(TableEnvironment values) {
if ( values != null ) {
type = values.getType(null);
sortElement = values.getSortElement();
sortElementAttributes = 
values.getSortElementAttributes();
}
}

Finally I created an EnvironmentBinding so you can do this

${env:InterfaceName.property}

https://github.com/trsvax/tapestry-bootstrap/blob/master/src/main/java/com/trsvax/bootstrap/services/EnvironmentBindingFactory.java

While this might seem like a lot of code it's all pretty straight forward
and can be implemented as a module so you can just drop it into any project.



--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Where-to-store-site-settings-tp4849942p5607227.html
Sent from the Tapestry - U

Re: Where to store site settings?

2012-03-29 Thread ksrijith
You could access the properties as symbol.

You can refer the link below for an example:
http://wiki.apache.org/tapestry/Tapestry5HowToReadSymbolsFromPropertiesFile

This gives you the freedom to hold the configs in the property files rather
than as part of system properties or as init parameters in the web.xml

-
--
Don't Forget to Rate
--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Where-to-store-site-settings-tp4849942p5605548.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



Re: Where to store site settings?

2012-03-29 Thread Beat Durrer
We load a different hibernate.cfg.xml for each environment by adding a
HibernateSessionSource Service:

In our DevelopmentModule:

public static void
contributeApplicationDefaults(MappedConfiguration
configuration){
  // to prevent the default file to be loaded
  configuration.add(HibernateSymbols.DEFAULT_CONFIGURATION, "false");
}


public static void
contributeHibernateSessionSource(OrderedConfiguration
hibernateConfigurers, Logger logger){
 hibernateConfigurers.add("hibernate.cfg.file", new
FilebasedHibernateSetup(logger, "hibernate.cfg.DEV.xml"));
}


public class FilebasedHibernateSetup implements HibernateConfigurer{
 private final String hibernateFile;
 private final Logger logger;

 public FilebasedHibernateSetup(Logger aLogger, String anHibernateFile)
 {
  hibernateFile = anHibernateFile;
  logger = aLogger;
 }

 public void configure(Configuration configuration)
 {
  logger.info("Loading Hibernate config:" + hibernateFile);
  configuration.configure(hibernateFile);
 }
}


Have fun :)


2012/3/29 Jonathan Barker :
> I reference a JNDI datasource in my hibernate configuration, so each
> environment (server) just has a different configuration for a
> datasource of the same name.  It took a bit of experimenting to get
> something that worked well across Tomcat, Jetty and JBoss.
>
> I haven't hit upon the magic recipe for log4j yet.
>
> On Thu, Mar 29, 2012 at 9:46 AM, Earle Nietzel  
> wrote:
>> Quick question on this topic about configuration.
>>
>> Has anyone tried having separate configs for hibernate.cfg.xml and/or
>> log4j.properties i.e. production/QA/development?
>>
>> I was looking at commons-configuration and have it setup with spring
>> via tapestry-spring. Would like a way to move the configs mentioned
>> above into it as well?
>>
>> My next thought is to look at when log4j and hibernate are initialized
>> to inject them with a configuration from spring that way I can manage
>> all the config using commons-configuration.
>>
>> Thoughts or ideas are appreciated?
>> Earle
>>
>>
>> On Wed, Sep 28, 2011 at 12:53 PM, Kalle Korhonen
>>  wrote:
>>> I typically have a bunch of application specific symbols since they
>>> allow so much flexibility. Set the defaults in AppModule, override
>>> with jvm system properties, in your setup scripts for production
>>> environment etc.
>>>
>>> Kalle
>>>
>>>
>>> On Wed, Sep 28, 2011 at 9:47 AM, Tim  wrote:
 Can someone please tell me the best way to store site settings in a 
 Tapestry
 application?

 I would like to store the location of a certain directory (where Lucene 
 data
 is to be kept), and it is different in development and in production, so I
 don't want it hard coded into the code.  Where should I store this setting?
  In a properties file? (and if so, where do I store the location to the
 properties files?)   In the web.xml file as a context-param?  In
 app.properties?

 What do people out there do?

 I suspect the answer is probably app.properties, so how do I get access to
 this in a normal Java class?

 Thanks.

 --
 Tim Koop

 -
 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
>>
>
>
>
> --
> Jonathan Barker
> ITStrategic
>
> -
> 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



Re: Where to store site settings?

2012-03-29 Thread Jonathan Barker
I reference a JNDI datasource in my hibernate configuration, so each
environment (server) just has a different configuration for a
datasource of the same name.  It took a bit of experimenting to get
something that worked well across Tomcat, Jetty and JBoss.

I haven't hit upon the magic recipe for log4j yet.

On Thu, Mar 29, 2012 at 9:46 AM, Earle Nietzel  wrote:
> Quick question on this topic about configuration.
>
> Has anyone tried having separate configs for hibernate.cfg.xml and/or
> log4j.properties i.e. production/QA/development?
>
> I was looking at commons-configuration and have it setup with spring
> via tapestry-spring. Would like a way to move the configs mentioned
> above into it as well?
>
> My next thought is to look at when log4j and hibernate are initialized
> to inject them with a configuration from spring that way I can manage
> all the config using commons-configuration.
>
> Thoughts or ideas are appreciated?
> Earle
>
>
> On Wed, Sep 28, 2011 at 12:53 PM, Kalle Korhonen
>  wrote:
>> I typically have a bunch of application specific symbols since they
>> allow so much flexibility. Set the defaults in AppModule, override
>> with jvm system properties, in your setup scripts for production
>> environment etc.
>>
>> Kalle
>>
>>
>> On Wed, Sep 28, 2011 at 9:47 AM, Tim  wrote:
>>> Can someone please tell me the best way to store site settings in a Tapestry
>>> application?
>>>
>>> I would like to store the location of a certain directory (where Lucene data
>>> is to be kept), and it is different in development and in production, so I
>>> don't want it hard coded into the code.  Where should I store this setting?
>>>  In a properties file? (and if so, where do I store the location to the
>>> properties files?)   In the web.xml file as a context-param?  In
>>> app.properties?
>>>
>>> What do people out there do?
>>>
>>> I suspect the answer is probably app.properties, so how do I get access to
>>> this in a normal Java class?
>>>
>>> Thanks.
>>>
>>> --
>>> Tim Koop
>>>
>>> -
>>> 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
>



-- 
Jonathan Barker
ITStrategic

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



Re: Where to store site settings?

2012-03-29 Thread Earle Nietzel
Quick question on this topic about configuration.

Has anyone tried having separate configs for hibernate.cfg.xml and/or
log4j.properties i.e. production/QA/development?

I was looking at commons-configuration and have it setup with spring
via tapestry-spring. Would like a way to move the configs mentioned
above into it as well?

My next thought is to look at when log4j and hibernate are initialized
to inject them with a configuration from spring that way I can manage
all the config using commons-configuration.

Thoughts or ideas are appreciated?
Earle


On Wed, Sep 28, 2011 at 12:53 PM, Kalle Korhonen
 wrote:
> I typically have a bunch of application specific symbols since they
> allow so much flexibility. Set the defaults in AppModule, override
> with jvm system properties, in your setup scripts for production
> environment etc.
>
> Kalle
>
>
> On Wed, Sep 28, 2011 at 9:47 AM, Tim  wrote:
>> Can someone please tell me the best way to store site settings in a Tapestry
>> application?
>>
>> I would like to store the location of a certain directory (where Lucene data
>> is to be kept), and it is different in development and in production, so I
>> don't want it hard coded into the code.  Where should I store this setting?
>>  In a properties file? (and if so, where do I store the location to the
>> properties files?)   In the web.xml file as a context-param?  In
>> app.properties?
>>
>> What do people out there do?
>>
>> I suspect the answer is probably app.properties, so how do I get access to
>> this in a normal Java class?
>>
>> Thanks.
>>
>> --
>> Tim Koop
>>
>> -
>> 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



Re: Where to store site settings?

2011-10-03 Thread Mark
On Wed, Sep 28, 2011 at 11:47 AM, Tim  wrote:

> Can someone please tell me the best way to store site settings in a
> Tapestry application?
>
>
You can set a context parameter in web.xml like this:


 registration.properties-file
 misc/registration.properties

(I'm not sure, but putting things in app.properties may do the exact same
thing, but without the XML.)

I use Apache Common's to handle the properties in situations where I want
the users to be able to update them from the webapp and the values to be
saved to the properties file. So what you see above is how I set the name of
the properties file in the first place.

Then I get the value in a service using a constructor like:

 public ConfigurationImpl(@Value("${registration.properties-file}") String
fileName)

For handling the differences between test and production, my master branch
sets the registration.properties at one location and my deployment branches
set it in a different location. Before deploying I always merge everything I
need from master to the deployment branch and deploy from there.

I'm not saying that is the best way to handle it, but that is what I'm doing
for one of my applications and it seems to be working well. In particular,
it makes it easy for me to wipe out my database during testing without
losing all the configuration data.

Mark


Re: Where to store site settings?

2011-09-28 Thread Bob Harner
I like to have a simple "Settings" or "Config" table in the database,
having just VARCHAR "name" and "value" columns, and a simple Tapestry
IOC service that looks up and caches the values (either lazily or at
startup time). Another option is to have the settings in a property
file (outside the war), of course, but on the other hand having them
in the database makes it easier to later create crud interfaces for
those that may need to change at run time.

On Wed, Sep 28, 2011 at 12:53 PM, Kalle Korhonen
 wrote:
> I typically have a bunch of application specific symbols since they
> allow so much flexibility. Set the defaults in AppModule, override
> with jvm system properties, in your setup scripts for production
> environment etc.
>
> Kalle
>
>
> On Wed, Sep 28, 2011 at 9:47 AM, Tim  wrote:
>> Can someone please tell me the best way to store site settings in a Tapestry
>> application?
>>
>> I would like to store the location of a certain directory (where Lucene data
>> is to be kept), and it is different in development and in production, so I
>> don't want it hard coded into the code.  Where should I store this setting?
>>  In a properties file? (and if so, where do I store the location to the
>> properties files?)   In the web.xml file as a context-param?  In
>> app.properties?
>>
>> What do people out there do?
>>
>> I suspect the answer is probably app.properties, so how do I get access to
>> this in a normal Java class?
>>
>> Thanks.
>>
>> --
>> Tim Koop
>>
>> -
>> 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



Re: Where to store site settings?

2011-09-28 Thread Kalle Korhonen
I typically have a bunch of application specific symbols since they
allow so much flexibility. Set the defaults in AppModule, override
with jvm system properties, in your setup scripts for production
environment etc.

Kalle


On Wed, Sep 28, 2011 at 9:47 AM, Tim  wrote:
> Can someone please tell me the best way to store site settings in a Tapestry
> application?
>
> I would like to store the location of a certain directory (where Lucene data
> is to be kept), and it is different in development and in production, so I
> don't want it hard coded into the code.  Where should I store this setting?
>  In a properties file? (and if so, where do I store the location to the
> properties files?)   In the web.xml file as a context-param?  In
> app.properties?
>
> What do people out there do?
>
> I suspect the answer is probably app.properties, so how do I get access to
> this in a normal Java class?
>
> Thanks.
>
> --
> Tim Koop
>
> -
> 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



Where to store site settings?

2011-09-28 Thread Tim
Can someone please tell me the best way to store site settings in a 
Tapestry application?


I would like to store the location of a certain directory (where Lucene 
data is to be kept), and it is different in development and in 
production, so I don't want it hard coded into the code.  Where should I 
store this setting?  In a properties file? (and if so, where do I store 
the location to the properties files?)   In the web.xml file as a 
context-param?  In app.properties?


What do people out there do?

I suspect the answer is probably app.properties, so how do I get access 
to this in a normal Java class?


Thanks.

--
Tim Koop

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