cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing properties files in Action

rohit_chakrabor
Champ on-the-rise
Champ on-the-rise
Hi,

Is there a way to access properties files in a custom action? I can use
ResourceBundle resourceBundle = getResources();
in a Java webscript but it throws an error in my custom action.
Any help will be appreciated.
3 REPLIES 3

steven_okennedy
Star Contributor
Star Contributor
Hi

I assume your are talking about properties that exist within your global properties file/standard OOTB Alfresco properties files?  The easiest way to do this is just inject the properties you need into the Spring bean that represents your action using ${} notation. E.g.

<bean id="script" class="org.alfresco.repo.action.executer.ScriptActionExecuter" parent="action-executer">
<!– The service registry is needed as ScriptAction needs it –>
  <property name="serviceRegistry">
    <ref bean="ServiceRegistry" />
  </property>
  <property name="personService">
    <ref bean="personService" />
  </property>
  <property name="storeUrl">
     <value>${spaces.store}</value>
  </property>
  <property name="companyHomePath">
     <value>/${spaces.company_home.childname}</value>
  </property>
  <property name="sysAdminParams">
     <ref bean="sysAdminParams" />
  </property>
</bean>


All you would need to do is create the instance variable in your class to hold the value (usually a String) and define an appropriate setter for it.

Alternatively if you need to dynamically look up properties, you could inject the entire Global Properties object itself e.g.

<property name="properties">
  <ref bean="global-properties"/>
</property>


In this case your "properties" instance variable would need to be of type java.util.Properties

Regards

Steven

Thanks but how do I access the properties file in the Java action class?

steven_okennedy
Star Contributor
Star Contributor
Hi

If you've injected the global properties in your action's spring bean like


<property name="properties">
  <ref bean="global-properties"/>
</property>


Then all you do is call
properties.getProperty("<prop name>")
- it's just a java.util.Properties object, look at the Javadocs.

Realistically though unless your action needs to figure out what property to look for at runtime, then it's far easier just to inject the actual property values you need using the ${prop.name} notation as shown above

Regards

Steven
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.