cancel
Showing results for 
Search instead for 
Did you mean: 

Can one split (or import an other xml to) share-config-custom.xml ?

sunquanbin
Champ on-the-rise
Champ on-the-rise
Hi all,

I have made many customisation in Share so the share-config-custom.xml is quite large now.

Just wandering is it possible to split this share-config-custom.xml into several smaller xml files. e.g.

share-config-custom.xml, plus
additional_1.xml, additional_2.xm. etc.

Is there a naming convention for those additional xml files or they can be imported into share-config-custom.xml via something like "/<import>"?

Thanks,

Sun
6 REPLIES 6

kaynezhang
World-Class Innovator
World-Class Innovator
Yes you can ,you have several options :
1.cut part content of share-config-custom.xml to  share-config-custom-dev.xml,share-config-custom-dev.xml is in the same location with share-config-custom.xml.
2.create several file named share-config-custom.xml,and split settings in these files ,and package each file in a jar under /META-INF/share-config-custom.xml,and place these jars under shared lib.

Many thanks for the reply.

But I am not very clear with your second step. I am using maven sdk for development. All the changes to share is taken place in an AMP project. The share-config-custom.xml is defaultly located at: /src/main/amp/config/alfresco/web-extension/share-config-custom.xml.

Would you please be more specific how I can split share-config-custom.xml?

regards,

Sun

tomoconnell
Champ in-the-making
Champ in-the-making
I have split my share-config-custom up into a file for each content model.
So at the moment I have around 6.

Naming wise I have used
web-extension/companyname-modelname-share-config-custom.xml
web-extension/companyname-modelname-custom-slingshot-context.xml

kaynezhang
World-Class Innovator
World-Class Innovator
following code is  Share custom config search path,you have many options to choose as you wish

            <value>classpath:alfresco/web-extension/share-config-custom.xml</value>
            <value>jar:*!/META-INF/share-config-custom.xml</value>
            <value>classpath:alfresco/web-extension/share-config-custom-dev.xml</value>
            <value>jar:*!/META-INF/share-config-custom-dev.xml</value>

sunquanbin
Champ on-the-rise
Champ on-the-rise
Many thanks for the replies, but I cannot get things work as I might not fully understand your guys' answers..(Am I too dumb?)

I will try to describe my problem more clearly.

Say my current share-config-custom.xml has define the following to custom forms:


   <config evaluator="model-type" condition="my:type1">
      <forms>
         <!– Create form –>
         <form>
                           …
         </form>
      </forms>
   </config>

       <config evaluator="model-type" condition="my:type2">
      <forms>
         <!– Create form –>
         <form>
                           …
         </form>
      </forms>
   </config>


Now I want to move the definition of "my:type2" into another  .xml file, say "share-config-custom_1.xml".
The files are look like:

In "share-config-custom.xml", it has:

   <config evaluator="model-type" condition="my:type1">
      <forms>
         <!– Create form –>
         <form>
                           …
         </form>
      </forms>
   </config>


In "share-config-custom_1.xml", it has:


       <config evaluator="model-type" condition="my:type2">
      <forms>
         <!– Create form –>
         <form>
                           …
         </form>
      </forms>
   </config>


However, the form in this additional file is not loaded when I create "my:type2" in share. So I can solve this?

Regards,

army81
Champ in-the-making
Champ in-the-making
I found the solution:
in alfresco/web-extension create a xml file "custom-slingshot-application-context.xml" as:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<bean id="customConfig" class="com.mypackage.CustomConfigBootstrap"
         init-method="register">
      <property name="configService" ref="web.config" />
      <property name="configs">
         <list>
            <value>classpath:alfresco/model-form.xml</value>
         </list>
      </property>
   </bean>
</beans>


Create a file "model-form.xml" in the same folder (you can create an arbitrary number of xml, you must remember to add it to the list of previous values ​​of the bean)

Create the java class CustomConfigBootstrap.java:
<java>package com.mypackage;



/**
* The Class CustomConfigBootstrap.
*/
public class CustomConfigBootstrap
  implements BeanNameAware, ConfigDeployer
{
 
 
  /** The Constant logger. */
  private static final Log logger = LogFactory.getLog(CustomConfigBootstrap.class);
 
  /** The bean name. */
  private String beanName;
 
  /** The config service. */
  protected ConfigService configService;
 
  /** The configs. */
  protected List<String> configs;
 
  public void setBeanName(String name)
  {
    this.beanName = name;
  }
 
  /**
   * Sets the configs.
   *
   * @param configs the new configs
   */
  public void setConfigs(List<String> configs)
  {
    this.configs = configs;
  }
 
  /**
   * Sets the config service.
   *
   * @param configService the new config service
   */
  public void setConfigService(ConfigService configService)
  {
    this.configService = configService;
  }
 
  /* (non-Javadoc)
   * @see org.springframework.extensions.config.ConfigDeployer#initConfig()
   */
  public List<ConfigDeployment> initConfig()
  {
    List<ConfigDeployment> deployed = null;
    if ((this.configService != null) && (this.configs != null) && (!this.configs.isEmpty()))
    {
      List<String> configsToAdd = processWildcards(this.configs);
      if ((configsToAdd != null) && (!configsToAdd.isEmpty()))
      {
        UrlConfigSource configSource = new UrlConfigSource(configsToAdd,true);
        deployed = this.configService.appendConfig(configSource);
      }
    }
    return deployed;
  }
 
  /**
   * Process wildcards.
   *
   * @param configs the configs
   * @return the list
   */
  private List<String> processWildcards(List<String> configs)
  {
    List<String> ret = new ArrayList<String>();
    for (String config : configs) {
      ret.addAll(processWidlCards(config));
    }
    return ret;
  }
 
  /**
   * Process widl cards.
   *
   * @param sourceString the source string
   * @return the list
   */
  private List<String> processWidlCards(String sourceString)
  {
    String separator = System.getProperty("file.separator");
   
    List<String> ret = new ArrayList<String>();
    if ((sourceString != null) && (sourceString.startsWith("file:")) && (sourceString.indexOf("*") != -1) && (sourceString.indexOf(separator) != -1))
    {
      logger.debug("processWildCards: " + sourceString);
      File dir = new File(sourceString.substring(5, sourceString.lastIndexOf(separator)));
      if ((dir != null) && (dir.exists()))
      {
        FileFilter fileFilter = new WildcardFileFilter(sourceString.substring(sourceString.lastIndexOf(separator) + 1));
        File[] files = dir.listFiles(fileFilter);
        if (files != null) {
          for (int i = 0; i < files.length; i++)
          {
            logger.debug("Add config file : file:" + files.getAbsolutePath());
            ret.add("file:" + files.getAbsolutePath());
          }
        }
      }
    }
    else
    {
      logger.debug("Add config file : " + sourceString);
      ret.add(sourceString);
    }
    return ret;
  }
 
  /* (non-Javadoc)
   * @see org.springframework.extensions.config.ConfigDeployer#register()
   */
  public void register()
  {
    if (this.configService == null) {
      throw new ConfigException("Config service must be provided");
    }
    this.configService.addDeployer(this);
  }
 
  /* (non-Javadoc)
   * @see org.springframework.extensions.config.ConfigDeployer#getSortKey()
   */
  public String getSortKey()
  {
    return this.beanName;
  }
}


</java>