Reputation: 46543
I'd like to access share-config-custom.xml
data from a Java bean in the Share webapp.
What is the equivalent to the following javascript syntax (which access the config root object) but in a Java context:
config.scoped['RepositoryLibrary']['root-node']
Is the share-config-custom translated to a bean itself? Or is there an API to read it from Java?
Upvotes: 2
Views: 840
Reputation: 1839
I know this is already answered, but Andreas' answer only got me halfway there. The configuration class is actually the XMLConfigService now.
Here's a code snippet that worked with Enterprise 4.1.* Alfresco:
Java class
import org.springframework.extensions.config.xml.XMLConfigService;
public class PDFValidate extends BaseJavaDelegate implements ExecutionListener
{
protected XMLConfigService configService;
public void setConfigService( XMLConfigService scriptConfigModel )
{
this.configService = scriptConfigModel;
}
Bean registration:
<bean id="AbstractWorkflowDelegate" parent="baseJavaDelegate" abstract="true" depends-on="activitiBeanRegistry" />
<bean id="PDFValidate" parent="AbstractWorkflowDelegate" class="com.epnet.alfresco.metadata.listener.PDFValidate">
<property name="repository" ref="repositoryHelper" />
<property name="configService" ref="web.config" />
</bean>
And from there, you can use the configService in your java code to get the config values. The XMLConfigService is located in the spring-surf-core-configservice-1.2.0-SNAPSHOT.jar for my version of Alfresco.
Upvotes: 1
Reputation: 6159
First, there is no "reasonable" way to use this API "looking" at one XML config file. In gen eral, the ConfigService
creates a configuration merging from various sources. But looking directly at the XML should not be needed anyways.
That being said, the Javascript object config
actually is a org.springframework.extensions.webscripts.ScriptConfigModel
.
To get something equivalent in Java get yourself a reference to the ConfigService
. To obtain the reference, let spring inject it in your custom bean:
<property name="configService" ref="web.config" />
Calling configService.getGlobalConfig()
should get you the equivalent of config.scoped
.
Upvotes: 4