Acosix / alfresco-utility

Project to consolidate abstract utility features and enhancements / safe fixes that may be used by multiple Alfresco addons
Apache License 2.0
12 stars 11 forks source link

Question on the use of the share-global-properties on Share #2

Closed p4535992 closed 7 years ago

p4535992 commented 7 years ago

Hi, a question about the use of the share-global-properties on Share-Tier, the properties on the file tomcat/shared/classes/share-global.properties, i can read them like i read the alfresco-global.properties, with a bean right? for example with this piece of code:

<bean class="bee.alfresco.ReadProperty" id="webscript.org.alfresco.bee.readproperty.get" parent="webscript">
    <property name="properties">
        <ref bean="global-properties"></ref>
    </property> 
</bean> 

......
 <bean abstract="true" id="global-properties" class="org.alfresco.config.JndiPropertiesFactoryBean">
        <property name="locations">
            <list>
                <value>classpath*:alfresco/share-global.properties</value>
                <value>classpath*:alfresco/enterprise/share-global.properties</value>
                <value>classpath*:alfresco/module/*/share-global.properties</value>
                <value>classpath*:share-global.properties</value>
            </list>
        </property>
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="propertiesPersister">
            <bean class="org.alfresco.config.AlfrescoPropertiesPersister" />
        </property>
    </bean>
public class ReadProperty extends AbstractWebScript{

 protected Properties properties;

 public void setProperties(Properties properties) {
  this.properties = properties;
 }

 @Override
 public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException{
  String repositoryName = properties.getProperty("my_property_name");

  System.out.println(repositoryName);

 }
}

Now i use multiple amp_share with custom surf extensions on my project, my question is "can i use the same share-global-properties in my other amps surf extensions; i just need to call the properties file with the same id of the bean "global-properties" like in the code i show before?

i'm asking because i'm not sure if these approach can work with the surf extensions in the specific if i can use the class ResourceBundleBootstrapComponent for retrieve these properties:

 <bean id="myresources"
          class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
        <property name="resourceBundles">
            <list>
                <!--
                 This is the reference to the share-global-properties
                 but this usually it is based on the classpath location where the file is located in
                 so not sure is it allowed
                  -->
                <value>classpath*:alfresco/share-global.properties</value>
                <value>classpath*:alfresco/enterprise/share-global.properties</value>
                <value>classpath*:alfresco/module/*/share-global.properties</value>
                <value>classpath*:share-global.properties</value>
            </list>
        </property>
    </bean>

or i can use the syntax ${....} like for the global.properties in the services-context.xml in my extensions xml files?

<!-- Return params from alfresco-global.properties -->
<bean id="webscript.es.keensoft.custom-actions.headerParams.get"
      class="es.keensoft.alfresco.action.webscript.HeaderParamsWebScript" parent="webscript">
    <property name="test1" value="${myPropertyName1}" />
    <property name="test2" value="${myPropertyName2}"/>
</bean>
public class HeaderParamsWebScript  extends AbstractWebScript {

    private String test1;
    private String test2;

    @SuppressWarnings("unchecked")
    @Override
    public void execute(WebScriptRequest request, WebScriptResponse response) throws IOException {

        JSONObject obj = new JSONObject();
        obj.put("customHeaderModuleHeight", test2);
        obj.put("customHeaderModuleUrl", test1);

        String jsonString = obj.toString();
        response.setContentEncoding("UTF-8");
        response.setContentType(MediaType.APPLICATION_JSON.toString());
        response.getWriter().write(jsonString);

    }

    public void setTest1(String test1) {
        this.test1 = test1;
    }

    public void setTest2(String test2) {
        this.test2 = test2;
    }

}

or both the cases are wrong usage?

AFaust commented 7 years ago

The support for share-global.properties is primarily intended to allow you to use the ${} syntax to directly inject property values into your Spring beans. You can also reference the bean as the complete Properties object just as in your first example. You can reference the same global properties from as many extension modules as you like - when enabled (which is the default) the bean will be available globally.

It does not make much sense to use the ResourceBundleBootstrapComponent to load the share-global.properties though - the ResourceBundleBootstrapComponent is meant for loading I18n data while the share-global.properties files are configuration files. Technically you could do that, and doing so would allow you to reference property values from JavaScript-backed web scripts via the message root object.

p4535992 commented 7 years ago

ty very much, just what i want to know