Hi Tullio,
> However I prefere an external, technical file in order to read properties,
> like magnolia.properties.
> Is there any way to read such file (say axioma.properties) using standard
> magnolia mechanisms (not java file io)
Ok, I'll try to help you as best as I can regarding getting properties from
magnolia.properties, someone else please chime in here if there's a better
way.
Afaik, the easiest way to do this would be to use
info.magnolia.cms.core.SystemProperty.
Example class would be something like this (note: I haven't tested this, so
it may be a little off):
package my.company.module.foobar.service;
import info.magnolia.cms.core.SystemProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyService {
private Logger log = LoggerFactory.getLogger(MyService.class.getName()
);
public static void getSomeSystemProperties() {
try {
log.info("Prop1 is " +
SystemProperty.getProperty("my.foobar.prop1") );
log.info("Prop2 is " +
SystemProperty.getProperty("my.foobar.prop2") );
log.info("Prop3 is " +
SystemProperty.getProperty("my.foobar.prop3") );
} catch(Exception e) {
e.printStackTrace();
}
}
}
> Another option could be to add new nodes to the module configuration I
> worked but I wasn't able to read it, how should I do ?
Yes, indeed, that would be your other option. Once you have the properties
in your module's config node, you can grab them using the Magnolia API.
Again, see the Technical Guide for more info on this, in particular the
Magnolia API section here:
http://documentation.magnolia-cms.com/technical-guide/api.html
You can use the HierarchyManager to get your module's config node, for
example, something like this:
package my.company.module.foobar.service;
import info.magnolia.cms.beans.config.ContentRepository;
import info.magnolia.cms.core.Content;
import info.magnolia.cms.core.HierarchyManager;
import info.magnolia.cms.util.NodeDataUtil;
import info.magnolia.context.MgnlContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyService {
private Logger log = LoggerFactory.getLogger(MyService.class.getName()
);
private static String prop1 = "";
private boolean enabled;
public static String getProp1() {
HierarchyManager hm = MgnlContext.getHierarchyManager(
ContentRepository.CONFIG);
try {
Content content = hm.getContent("/modules/my-foobar/config");
prop1 = NodeDataUtil.getString(content, "prop1");
log.debug("Found 'prop1' with a value of '" + prop1 + "' in My
Foobar Module config");
} catch(Exception e) {
log.error("Could not find 'prop1' in My Foobar Module config");
}
return prop1 ;
}
public static boolean isEnabled() {
HierarchyManager hm = MgnlContext.getHierarchyManager(
ContentRepository.CONFIG);
try {
Content content = hm.getContent("/modules/my-foobar/config");
String enabled = NodeDataUtil.getString(content, "enabled");
log.debug("Found 'enabled' with a value of '" + enabled + "' in
My Foobar Module config");
if (enabled.equals("true") ) {
return true;
}
} catch(Exception e) {
log.error("Could not find 'enabled' in My Foobar Module
config");
}
// return false unless we can verify that it is true
return false;
}
}
HTH,
Matt
> From: Tullio Bettinazzi <[email protected]>
> Reply-To: Magnolia User-List <[email protected]>
> Date: Sun, 28 Nov 2010 06:48:03 -0800
> To: <[email protected]>
> Subject: Re: Re[magnolia-user] ading properties
>
>
>
> Tks for Your help.
> I'll try.
> However I prefere an external, technical file in order to read properties,
> like magnolia.properties.
> Is there any way to read such file (say axioma.properties) using standard
> magnolia mechanisms (not java file io)
> Another option could be to add new nodes to the module configuration I
> worked but I wasn't able to read it, how should I do ?
> Tks
> Tullio
> --
> View this message in context:
> http://old.nabble.com/Reading-properties-tp30317530p30323790.html
> Sent from the Magnolia - User mailing list archive at Nabble.com.
>
>
>
> ----------------------------------------------------------------
> For list details see
> http://www.magnolia-cms.com/home/community/mailing-lists.html
> To unsubscribe, E-mail to: <[email protected]>
> ----------------------------------------------------------------
>
----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------