for managed servers the datasource name is now converted into a valid XML type NCName
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Tue, 19 Jan 2016 07:33:08 +0000 (08:33 +0100)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 20 Jan 2016 10:00:21 +0000 (11:00 +0100)
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/server/CDMServerUtils.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmServerInfo.java

index 976d2a58b8a65985b4e8f3069b5bd33eb0ac314b..42bd28ba5144b5e9f9acbefaf4bcbe760f1a0c21 100644 (file)
@@ -47,7 +47,7 @@ public class CDMServerUtils {
         configStringBuilder.append(" </bean>" + System.lineSeparator());
 
         for(CdmPersistentDataSource dataSource : CdmPersistentDataSource.getAllDataSources()) {
-            String beanId = dataSource.getName();
+            String beanId = xmlNCNamefrom(dataSource.getName());
             String user = dataSource.getUsername();
             String password = dataSource.getPassword();
             String driverClass = dataSource.getCdmSourceProperty(CdmSourceProperties.DRIVER_CLASS);
@@ -65,6 +65,18 @@ public class CDMServerUtils {
         return configStringBuilder.toString();
     }
 
+    /**
+     * Assures that the datasource name is converted into a valid XML type NCName.
+     *
+     * Prefixes the string and replaces all forbidden characters by '_'.
+     *
+     * @param dataSource
+     * @return
+     */
+    public static String xmlNCNamefrom(String beanName) {
+        return "MGD_" + beanName.replaceAll("[^a-zA-Z0-9]", "_");
+    }
+
     public static File writeManagedServerConfig(String config, String fileName) throws IOException {
         File managedConfigFile = new File(CdmApplicationUtils.getWritableResourceDir(), fileName);
         if(managedConfigFile.exists()) {
index 952ceb9256b0a6a265ab22460e72ee8e886ee18e..17a128344cd104733c05a9de3c85d04fba82db06 100644 (file)
@@ -38,6 +38,7 @@ import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
 import eu.etaxonomy.cdm.database.ICdmDataSource;
 import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
 import eu.etaxonomy.taxeditor.remoting.server.CDMServerException;
+import eu.etaxonomy.taxeditor.remoting.server.CDMServerUtils;
 
 /**
  * @author cmathew
@@ -221,8 +222,9 @@ public class CdmServerInfo {
 
     public void addInstancesFromDataSourcesConfig() {
         for(ICdmDataSource dataSource : CdmPersistentDataSource.getAllDataSources()){
-            logger.info("Adding local instance " + dataSource.getName());
-            addInstance(dataSource.getName(), dataSource.getName());
+            String datasourceNCName = CDMServerUtils.xmlNCNamefrom(dataSource.getName());
+            logger.info("Adding local instance " + dataSource.getName() + " as " + datasourceNCName);
+            addInstance(datasourceNCName, datasourceNCName);
         }
     }