ref #8189 moving folder funstins from CdmUtils to ConfigFileUtil
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Thu, 21 Mar 2019 12:36:44 +0000 (13:36 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 15 Apr 2019 13:53:01 +0000 (15:53 +0200)
18 files changed:
cdmlib-commons/pom.xml
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/AccountStore.java
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/CdmUtils.java
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/ConfigFileUtil.java
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/CdmUtilsTest.java
cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/ConfigFileUtilTest.java [new file with mode: 0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/TermMapping.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/term/init/TermLoader.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationUtils.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/DataSourceBeanLoader.java
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v31_33/TermVocabularyRepresentationUpdater.java
cdmlib-print/src/main/java/eu/etaxonomy/cdm/print/out/IPublishOutputModule.java
cdmlib-print/src/main/java/eu/etaxonomy/cdm/print/out/PublishOutputModuleBase.java
cdmlib-print/src/main/java/eu/etaxonomy/cdm/print/out/mediawiki/Cdm2MediawikiExporter.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/opt/config/DataSourceConfigurer.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/opt/config/EhCacheDiskStoreConfiguration.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/config/AbstractWebApplicationConfigurer.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/config/MultiWebSecurityConfiguration.java

index ac08b870297c3e7754c75f91b11f16256642f532..7503f2750af814bf282f3db47aafd4f011e791e0 100644 (file)
   <description>EDIT CDM library - Commons</description>
   
   <dependencies>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-test</artifactId>
index ea599e28262b481e57bb5dc03b03d71773994c70..c8221161d95816848c146aa2361bef7646284d61 100644 (file)
@@ -24,7 +24,7 @@ public class AccountStore {
 \r
     private static Logger logger = Logger.getLogger(AccountStore.class);\r
 \r
-    public final static File accountsFile = new File(CdmUtils.perUserCdmFolder + File.separator + ".dbaccounts.properties");\r
+    public final static File accountsFile = new File(ConfigFileUtil.perUserCdmFolder() + File.separator + ".dbaccounts.properties");\r
 \r
     public static String getAccountsFileName(){\r
         try {\r
index 608d284e6cc5a099be80f54a28f7958ea8359d92..2b7899e58df4386ebf15013b66d7c7c6bd29c833 100644 (file)
@@ -10,7 +10,6 @@
 package eu.etaxonomy.cdm.common;
 
 import java.io.BufferedReader;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -31,8 +30,6 @@ import java.util.regex.Pattern;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.log4j.Logger;
-import org.springframework.context.EnvironmentAware;
-import org.springframework.core.env.Environment;
 
 /**
  * Util class for consistent access to and creation of per instance application configuration files.
@@ -40,109 +37,10 @@ import org.springframework.core.env.Environment;
  * @author a.mueller
  * @author a.kohlbecker
  */
-public class CdmUtils implements EnvironmentAware {
+public class CdmUtils {
 
     private static final Logger logger = Logger.getLogger(CdmUtils.class);
 
-    // ============= TODO externalize into CdmFileUtils class ? ========== //
-
-    private static String userHome = null;
-
-    /**
-     * The per user cdm folder name: ".cdmLibrary"
-     */
-    private static final String CDM_FOLDER_NAME = ".cdmLibrary";
-
-    /**
-     * The per user cdm folder "~/.cdmLibrary"
-     */
-    public static File perUserCdmFolder = null;
-
-    /**
-     * suggested sub folder for web app related data and configurations.
-     * Each webapp instance should use a dedicated subfolder or file
-     * which is named by the data source bean id.
-     */
-    public static final String SUBFOLDER_WEBAPP = "remote-webapp";
-
-    static final String MUST_EXIST_FILE = "MUST-EXIST.txt";
-
-    //folder separator
-    static String folderSeparator;
-
-    protected Environment env;
-
-    @Override
-    public void setEnvironment(Environment environment) {
-        this.env = environment;
-        if(userHome == null){
-            CdmUtils.userHome = env.getRequiredProperty("user.home");
-            CdmUtils.perUserCdmFolder = new File(userHome + File.separator + CDM_FOLDER_NAME );
-            logger.info("user.home is set to " + CdmUtils.userHome);
-        }
-    }
-
-    public static File getCdmHomeDir() {
-        return new File(perUserCdmFolder + File.separator);
-    }
-
-       /**
-        * Returns specified the sub folder of  {@link #CDM_FOLDER_NAME}.
-        * If the sub folder does not exist it will be created.
-        *
-        * @param subFolderName
-        * @return the sub folder or null in case the folder did not exist ant the attempt to create it has failed.
-        *
-        * @see {@link #SUBFOLDER_WEBAPP}
-        */
-       public static File getCdmHomeSubDir(String subFolderName) {
-
-               File parentFolder = getCdmHomeDir();
-        return ensureSubfolderExists(parentFolder, subFolderName);
-       }
-
-       /**
-     * Returns an instance specific folder folder in  {@link #CDM_FOLDER_NAME}/<code>subFolderName</code>
-     * Non existing folders will be created.
-     *
-     * @param subFolderName
-     *      The name of a subfolded. In most cases this will be {@link #SUBFOLDER_WEBAPP}
-     * @param instanceName
-     *      The name of the application instance. The name should be related to the data source id.
-     * @return the sub folder or null in case the folder did not exist ant the attempt to create it has failed.
-     *
-     * @see {@link #SUBFOLDER_WEBAPP}
-     */
-    public static File getCdmInstanceSubDir(String subFolderName, String instanceName) {
-
-        File subfolder = ensureSubfolderExists(getCdmHomeDir(), subFolderName);
-        return ensureSubfolderExists(subfolder, instanceName);
-    }
-
-    /**
-     * @param subFolderName
-     * @param parentFolder
-     * @return
-     */
-    private static File ensureSubfolderExists(File parentFolder, String subFolderName) {
-        if (!parentFolder.exists()){
-            if (!parentFolder.mkdir()) {
-                throw new RuntimeException("Parent folder could not be created: " + parentFolder.getAbsolutePath());
-            }
-        }
-
-        File subfolder = new File(parentFolder, subFolderName);
-               // if the directory does not exist, create it
-               if (!subfolder.exists()) {
-                       if (!subfolder.mkdir()) {
-                               throw new RuntimeException("Subfolder could not be created: " + subfolder.getAbsolutePath());
-                       }
-               }
-               return subfolder;
-    }
-
-       // ============= END of CdmFileUtils ========== //
-
     /**
      * Returns the an InputStream for a read-only source
      * @param resourceFileName the resources path within the classpath(!)
@@ -169,29 +67,6 @@ public class CdmUtils implements EnvironmentAware {
     }
 
 
-    /**
-     * @return
-     */
-    static public String getFolderSeperator(){
-        if (folderSeparator == null){
-            URL url = CdmUtils.class.getResource("/"+ MUST_EXIST_FILE);
-            if ( url != null && ! urlIsJarOrBundle(url) ){
-                folderSeparator =  File.separator;
-            }else{
-                folderSeparator = "/";
-            }
-        }
-        return folderSeparator;
-    }
-
-
-    /**
-     * @param url
-     * @return
-     */
-    static private boolean urlIsJarOrBundle(URL url){
-        return url.getProtocol().startsWith("jar") || url.getProtocol().startsWith("bundleresource");
-    }
 
     /**
      * Returns the file name for the file in which 'clazz' is to be found (helps finding according libraries)
index 973278150937bd260fcde83e34ddd1722ae0e90e..ab34218f86e1c53dd99c1f5ab47a639fe53256cf 100644 (file)
@@ -13,20 +13,148 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.net.URL;
 import java.nio.file.Files;
 import java.util.Properties;
 
+import org.apache.log4j.Logger;
+import org.springframework.context.EnvironmentAware;
+import org.springframework.core.env.Environment;
+
 /**
  *
  * @author a.kohlbecker
  * @since May 8, 2017
  *
  */
-public class ConfigFileUtil {
+public class ConfigFileUtil implements EnvironmentAware {
+
+    private static final Logger logger = Logger.getLogger(ConfigFileUtil.class);
+
+    private static String userHome = null;
+
+    /**
+     * The per user cdm folder name: ".cdmLibrary"
+     */
+    private static final String CDM_FOLDER_NAME = ".cdmLibrary";
+
+    /**
+     * The per user cdm folder "~/.cdmLibrary"
+     */
+    private static File perUserCdmFolder = null;
+
+    public static File perUserCdmFolder() {
+        return perUserCdmFolder;
+    }
+
+    /**
+     * suggested sub folder for web app related data and configurations.
+     * Each webapp instance should use a dedicated subfolder or file
+     * which is named by the data source bean id.
+     */
+    public static final String SUBFOLDER_WEBAPP = "remote-webapp";
+
+    static final String MUST_EXIST_FILE = "MUST-EXIST.txt";
+
+    //folder separator
+    static String folderSeparator;
+
+    protected Environment env;
+
+    @Override
+    public void setEnvironment(Environment environment) {
+        this.env = environment;
+        if(userHome == null){
+            ConfigFileUtil.userHome = env.getRequiredProperty("user.home");
+            ConfigFileUtil.perUserCdmFolder = new File(userHome + File.separator + CDM_FOLDER_NAME );
+            logger.info("user.home is set to " + ConfigFileUtil.userHome);
+        }
+    }
+
+
+    /**
+     * @return
+     */
+    static public String getFolderSeperator(){
+        if (folderSeparator == null){
+            URL url = CdmUtils.class.getResource("/"+ MUST_EXIST_FILE);
+            if ( url != null && ! urlIsJarOrBundle(url) ){
+                folderSeparator =  File.separator;
+            }else{
+                folderSeparator = "/";
+            }
+        }
+        return folderSeparator;
+    }
+
 
     /**
+     * @param url
+     * @return
+     */
+    static private boolean urlIsJarOrBundle(URL url){
+        return url.getProtocol().startsWith("jar") || url.getProtocol().startsWith("bundleresource");
+    }
+
+
+    public static File getCdmHomeDir() {
+        return new File(perUserCdmFolder + File.separator);
+    }
+
+    /**
+     * Returns specified the sub folder of  {@link #CDM_FOLDER_NAME}.
+     * If the sub folder does not exist it will be created.
+     *
+     * @param subFolderName
+     * @return the sub folder or null in case the folder did not exist ant the attempt to create it has failed.
+     *
+     * @see {@link #SUBFOLDER_WEBAPP}
+     */
+    public static File getCdmHomeSubDir(String subFolderName) {
+
+        File parentFolder = getCdmHomeDir();
+        return ensureSubfolderExists(parentFolder, subFolderName);
+    }
+
+    /**
+     * Returns an instance specific folder folder in  {@link #CDM_FOLDER_NAME}/<code>subFolderName</code>
+     * Non existing folders will be created.
+     *
+     * @param subFolderName
+     *      The name of a subfolded. In most cases this will be {@link #SUBFOLDER_WEBAPP}
+     * @param instanceName
+     *      The name of the application instance. The name should be related to the data source id.
+     * @return the sub folder or null in case the folder did not exist ant the attempt to create it has failed.
      *
+     * @see {@link #SUBFOLDER_WEBAPP}
+     */
+    public static File getCdmInstanceSubDir(String subFolderName, String instanceName) {
+
+        File subfolder = ensureSubfolderExists(getCdmHomeDir(), subFolderName);
+        return ensureSubfolderExists(subfolder, instanceName);
+    }
+
+    /**
+     * @param subFolderName
+     * @param parentFolder
+     * @return
      */
+    private static File ensureSubfolderExists(File parentFolder, String subFolderName) {
+        if (!parentFolder.exists()){
+            if (!parentFolder.mkdir()) {
+                throw new RuntimeException("Parent folder could not be created: " + parentFolder.getAbsolutePath());
+            }
+        }
+
+        File subfolder = new File(parentFolder, subFolderName);
+        // if the directory does not exist, create it
+        if (!subfolder.exists()) {
+            if (!subfolder.mkdir()) {
+                throw new RuntimeException("Subfolder could not be created: " + subfolder.getAbsolutePath());
+            }
+        }
+        return subfolder;
+    }
     public static final String CDM_CONFIGFILE_OVERRIDE = "cdm.configfile.override.";
 
     private Properties props = null;
@@ -70,7 +198,7 @@ public class ConfigFileUtil {
         if(override != null){
             return new File(override);
         } else {
-            File configFolder = CdmUtils.getCdmInstanceSubDir(CdmUtils.SUBFOLDER_WEBAPP, instanceName);
+            File configFolder = ConfigFileUtil.getCdmInstanceSubDir(ConfigFileUtil.SUBFOLDER_WEBAPP, instanceName);
             return new File(configFolder, propertiesSet + ".properties");
         }
     }
index 7838ec63e17998178681598dad521b045b4b486a..fac603184597f7796c2b9458bbb166a4aa1b24be 100644 (file)
@@ -9,11 +9,6 @@
 \r
 package eu.etaxonomy.cdm.common;\r
 \r
-import static org.junit.Assert.assertNotNull;\r
-\r
-import java.io.File;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
 import java.util.regex.Pattern;\r
 \r
 import org.apache.log4j.Level;\r
@@ -42,27 +37,6 @@ public class CdmUtilsTest {
 \r
 /************************** TESTS ****************************************/\r
 \r
-       @Test\r
-       public void testGetReadableResourceStream() {\r
-               String resourceFileName = CdmUtils.MUST_EXIST_FILE;\r
-               try {\r
-                       InputStream inputStream = CdmUtils.getReadableResourceStream(resourceFileName);\r
-                       assertNotNull(inputStream);\r
-               } catch (IOException e) {\r
-                       Assert.fail("IOException");\r
-               }\r
-       }\r
-\r
-       @Test\r
-       public void testGetFolderSeperator() {\r
-               Assert.assertEquals(File.separator, CdmUtils.getFolderSeperator());\r
-       }\r
-\r
-       @Test\r
-       public void testGetHomeDir() {\r
-               //Assert.assertEquals("", CdmUtils.getHomeDir());\r
-       }\r
-\r
        @Test\r
        public void testFindLibrary() {\r
                if (logger.isEnabledFor(Level.DEBUG)) {logger.debug(CdmUtils.findLibrary(CdmUtils.class));}\r
diff --git a/cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/ConfigFileUtilTest.java b/cdmlib-commons/src/test/java/eu/etaxonomy/cdm/common/ConfigFileUtilTest.java
new file mode 100644 (file)
index 0000000..3af1478
--- /dev/null
@@ -0,0 +1,48 @@
+/**
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
+
+package eu.etaxonomy.cdm.common;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+public class ConfigFileUtilTest {
+
+       @Test
+       public void testGetReadableResourceStream() {
+               String resourceFileName = ConfigFileUtil.MUST_EXIST_FILE;
+               try {
+                       InputStream inputStream = CdmUtils.getReadableResourceStream(resourceFileName);
+                       assertNotNull(inputStream);
+               } catch (IOException e) {
+                       Assert.fail("IOException");
+               }
+       }
+
+       @Test
+       public void testGetFolderSeperator() {
+               Assert.assertEquals(File.separator, ConfigFileUtil.getFolderSeperator());
+       }
+
+       @Test
+       @Ignore
+       public void testGetHomeDir() {
+               Assert.assertEquals("", ConfigFileUtil.getCdmHomeDir());
+       }
+
+
+}
index 30738debd9f82a507d7d138f582f682cea7c1f8e..7c7434aec632fefb72208a757c3e3a8b2c94b71c 100644 (file)
@@ -19,6 +19,7 @@ import org.apache.log4j.Logger;
 \r
 import au.com.bytecode.opencsv.CSVReader;\r
 import eu.etaxonomy.cdm.common.CdmUtils;\r
+import eu.etaxonomy.cdm.common.ConfigFileUtil;\r
 \r
 /**\r
  * @author a.mueller\r
@@ -44,7 +45,7 @@ public class TermMapping {
 \r
 \r
        private void readMapping(String filename) throws IOException {\r
-               String strResourceFileName = "mapping" + CdmUtils.getFolderSeperator() + filename;\r
+               String strResourceFileName = "mapping" + ConfigFileUtil.getFolderSeperator() + filename;\r
                InputStreamReader isr = CdmUtils.getUtf8ResourceReader(strResourceFileName);\r
                CSVReader reader = new CSVReader(isr, separator);\r
 \r
index 0615f44506afc964d223686ccb8ab4d1d1f668f4..39c0af930ca89def9f54c379b981a80995c50ebe 100644 (file)
@@ -24,6 +24,7 @@ import org.springframework.stereotype.Component;
 
 import au.com.bytecode.opencsv.CSVReader;
 import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.common.ConfigFileUtil;
 import eu.etaxonomy.cdm.model.term.DefinedTermBase;
 import eu.etaxonomy.cdm.model.term.OrderedTermBase;
 import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;
@@ -196,7 +197,7 @@ public class TermLoader implements ITermLoader {
         */
        private CSVReader getCsvReader(VocabularyEnum vocType) throws IOException {
                String filename = vocType.name()+".csv";
-               String strResourceFileName = "terms" + CdmUtils.getFolderSeperator() + filename;
+               String strResourceFileName = "terms" + ConfigFileUtil.getFolderSeperator() + filename;
                if (logger.isDebugEnabled()){logger.debug("strResourceFileName is " + strResourceFileName);}
                CSVReader reader = new CSVReader(CdmUtils.getUtf8ResourceReader(strResourceFileName));
                return reader;
index 398c738e97b6c8af6f51569c89052f9922b84bb9..33f480c15a2029ebc090fbc4cd3ce89cd8cab40e 100644 (file)
@@ -18,6 +18,7 @@ import java.net.URL;
 import org.apache.log4j.Logger;\r
 \r
 import eu.etaxonomy.cdm.common.CdmUtils;\r
+import eu.etaxonomy.cdm.common.ConfigFileUtil;\r
 import eu.etaxonomy.cdm.common.FileCopy;\r
 import eu.etaxonomy.cdm.config.CdmPersistentXMLSource;\r
 \r
@@ -51,7 +52,7 @@ public class CdmApplicationUtils {
                 if (file.exists()){\r
                     fileResourceDir = file.getParentFile();\r
                 }else{\r
-                    file = new File(CdmUtils.getCdmHomeDir(), "writableResources" );\r
+                    file = new File(ConfigFileUtil.getCdmHomeDir(), "writableResources" );\r
 \r
                     file.mkdirs();\r
                     copyResources(file);\r
index e1cb9c913029e3ca2f5fdb7b8d42b0c872dcb0b3..55baac653693b84f33ce0075500bab80ac111b4b 100644 (file)
@@ -8,7 +8,7 @@ import org.springframework.beans.factory.xml.XmlBeanFactory;
 import org.springframework.core.io.FileSystemResource;\r
 import org.springframework.stereotype.Component;\r
 \r
-import eu.etaxonomy.cdm.common.CdmUtils;\r
+import eu.etaxonomy.cdm.common.ConfigFileUtil;\r
 \r
 @Component\r
 public class DataSourceBeanLoader {\r
@@ -16,7 +16,7 @@ public class DataSourceBeanLoader {
     private static final Logger logger = Logger.getLogger(DataSourceBeanLoader.class);\r
 \r
     private static final String DATASOURCE_BEANDEF_FILE = "datasources.xml";\r
-    private static final String DATASOURCE_BEANDEF_PATH = CdmUtils.getCdmHomeDir().getPath();\r
+    private static final String DATASOURCE_BEANDEF_PATH = ConfigFileUtil.getCdmHomeDir().getPath();\r
 \r
     private static String userdefinedBeanDefinitionFile = null;\r
 \r
@@ -41,7 +41,7 @@ public class DataSourceBeanLoader {
             T datasource = beanFactory.getBean(beanName, requiredType);\r
             dataSources.put(beanName, datasource);\r
         }\r
-        return (Map<String, T>) dataSources;\r
+        return dataSources;\r
     }\r
 \r
 }
index 5bdae9805c7df37a5cd111674cb32985677b1703..c2b467ea88a619a87c7dfd1cf9792ef76427bf10 100644 (file)
@@ -17,6 +17,7 @@ import org.apache.log4j.Logger;
 \r
 import au.com.bytecode.opencsv.CSVReader;\r
 import eu.etaxonomy.cdm.common.CdmUtils;\r
+import eu.etaxonomy.cdm.common.ConfigFileUtil;\r
 import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;\r
 import eu.etaxonomy.cdm.database.ICdmDataSource;\r
 import eu.etaxonomy.cdm.database.update.CaseType;\r
@@ -66,7 +67,7 @@ public class TermVocabularyRepresentationUpdater
                        for(VocabularyEnum vocabularyEnum : VocabularyEnum.values()) {\r
                                //read vocabulary from terms files\r
                                String filename = vocabularyEnum.name()+".csv";\r
-                               CSVReader reader = new CSVReader(CdmUtils.getUtf8ResourceReader("terms" + CdmUtils.getFolderSeperator() + filename));\r
+                               CSVReader reader = new CSVReader(CdmUtils.getUtf8ResourceReader("terms" + ConfigFileUtil.getFolderSeperator() + filename));\r
                                String [] nextLine = reader.readNext();\r
                                TermVocabulary<?> voc = TermVocabulary.NewInstance(TermType.Unknown);\r
                                voc.readCsvLine(arrayedLine(nextLine));\r
index 441b7b91c3501def1eb8e7cf0b85c9b9cd23e9a2..61db61982b0ebb8a4e7607ff90c41f917800b44e 100644 (file)
@@ -15,7 +15,6 @@ import java.util.List;
 
 import org.jdom.Document;
 
-import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
 
 
@@ -49,7 +48,7 @@ public interface IPublishOutputModule {
 
     /**
      * Returns all available stylesheets for this output module.
-     * Search path will include the users {@link CdmUtils.perUserCdmFolder} directory to allow for custom stylesheets
+     * Search path will include the users {@link ConfigFileUtil.perUserCdmFolder()} directory to allow for custom stylesheets
      *
      * @return a set of xsl files
      * @throws IOException TODO
index aed26bbe892776856833f7dfc365a2bf5940fa9b..6907bbabbbf2546edf9fad6f8fbb6d615c5d7ef5 100644 (file)
@@ -25,14 +25,14 @@ import java.util.List;
 import org.apache.log4j.Logger;
 import org.jdom.Document;
 
-import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.common.ConfigFileUtil;
 import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
 
 /**
  * This abstract implementation of the {@link IPublishOutputModule} contains
  * convenience methods for file path generation. Clients should consider
  * extending this class.
- * 
+ *
  * @author n.hoffmann
  * @since Apr 20, 2010
  * @version 1.0
@@ -61,7 +61,7 @@ public abstract class PublishOutputModuleBase implements IPublishOutputModule {
        /**
         * Generates a string containing the current date followed by the given
         * name.
-        * 
+        *
         * @param name
         *            a string.
         * @return a string containing the current date followed by the given name.
@@ -95,21 +95,21 @@ public abstract class PublishOutputModuleBase implements IPublishOutputModule {
                 */
                if (filePath == null) {
                        filePath = getNewFilePath(outputFolder);
-               } 
+               }
                        return filePath;
        }
 
        /**
-        * @return the complete path to the output file 
+        * @return the complete path to the output file
         * @author s.buers
         */
        public String getFilePath() {
                return filePath;
        }
-       
+
        /**
         * creates new name for the output file based on the given output
-        * folder and actual timestamp. 
+        * folder and actual timestamp.
         * @author s.buers
         * @param outputFolder
         * @return
@@ -125,12 +125,13 @@ public abstract class PublishOutputModuleBase implements IPublishOutputModule {
 
        /*
         * (non-Javadoc)
-        * 
+        *
         * @see
         * eu.etaxonomy.printpublisher.out.IPublishOutputModule#output(org.jdom.
         * Document, java.io.File)
         */
-       public void output(Document document, File exportFolder,
+       @Override
+    public void output(Document document, File exportFolder,
                        IProgressMonitor progressMonitor) {
                if (progressMonitor == null) {
                        throw new IllegalArgumentException(
@@ -173,7 +174,7 @@ public abstract class PublishOutputModuleBase implements IPublishOutputModule {
                locationList.add(shippedStylesheetsDir);
 
                // TODO this should be configured in a central place, see #2387
-               File userdir = new File(CdmUtils.perUserCdmFolder + l + "stylesheets"
+               File userdir = new File(ConfigFileUtil.perUserCdmFolder() + l + "stylesheets"
                                + l + getOutputFileSuffix());
                locationList.add(userdir);
 
index 45c917ab43505f61398d8d6f368760a55c19ffcf..91291f2d7dab0aecd852d9cb76d0120e58e682dd 100644 (file)
@@ -24,7 +24,7 @@ import org.jdom.output.Format;
 import org.jdom.output.XMLOutputter;
 import org.jdom.xpath.XPath;
 
-import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.common.ConfigFileUtil;
 import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
 import eu.etaxonomy.cdm.print.IXMLEntityFactory;
 import eu.etaxonomy.cdm.print.PublishConfigurator;
@@ -34,11 +34,11 @@ import eu.etaxonomy.cdm.print.out.IPublishOutputModule;
 /**
  * fill in all parameters and you get a complete export from a cdm database to a
  * mediawiki
- * 
+ *
  * TODO would we move this class somewhere else and/or rename it?
- * 
+ *
  * @author s.buers, l.morris
- * 
+ *
  */
 public class Cdm2MediawikiExporter {
 
@@ -62,7 +62,7 @@ public class Cdm2MediawikiExporter {
                        .getLogger(Cdm2MediawikiExporter.class);
 
        private PublishConfigurator configurator = PublishConfigurator.NewRemoteInstance();
-                       
+
        private IXMLEntityFactory factory;
 
        // where the mediawiki xml code is stored
@@ -80,7 +80,7 @@ public class Cdm2MediawikiExporter {
 
        private List<String> localImages;
 
-       
+
        public void export(String serviceUrl, UUID taxonNodeUuid, UUID treeNodeUuid,  String wikiUrl,
                        String wikiLoginUid, String passwd, String wikiPageNamespace,
                        boolean import2Mediawiki, boolean deleteOutputFiles,
@@ -92,7 +92,7 @@ public class Cdm2MediawikiExporter {
        /**
         * does the whole export process: runs cdm export to mediawiki xml-file and
         * wiki import of this file
-        * 
+        *
         * @param serviceUrl
         * @param taxonName
         * @param wikiUrl
@@ -105,7 +105,7 @@ public class Cdm2MediawikiExporter {
         *            - prefix that, will be added to all pages null or "" will make
         *            no prefix
         * @throws MalformedURLException
-        * 
+        *
         *             TODO: make passwd "unplain" MAYDO: pass more parameters e.g.:
         *             alternative stylesheet layout parameters (that may force the
         *             use of different stylesheet) export folder - we use a
@@ -124,17 +124,17 @@ public class Cdm2MediawikiExporter {
                                // setup configurator
                setupConfigurator(serviceUrl);
                configurator.addSelectedTaxonNodeElements(factory.getTaxonNodesByName(taxonName, classificationName));
-               
-               
+
+
                export(portalUrl, serviceUrl, wikiUrl, wikiLoginUid, passwd,
                                wikiPageNamespace, import2Mediawiki, deleteOutputFiles,
                                importImages, true);
        }
        /**
-        * if you already have a cdm xml export in some file you put it in here 
+        * if you already have a cdm xml export in some file you put it in here
         * the mediawiki xml is created and imported to an mediawiki
         * does step 2 and 3 out of all 3 export steps
-        * 
+        *
         * @param filename
         * @param serviceUrl
         * @param taxonName
@@ -156,9 +156,9 @@ public class Cdm2MediawikiExporter {
 
                //put the document to a field:
                externalDocument = getDocument(filename);
-               
+
 //             setupConfigurator(serviceUrl);
-               
+
                // and run export with usePublisher=false:
                export(portalUrl, serviceUrl, wikiUrl, wikiLoginUid, passwd,
                                wikiPageNamespace, import2Mediawiki, deleteOutputFiles,
@@ -191,7 +191,7 @@ public class Cdm2MediawikiExporter {
                // page
                // then it will be the same as the username that is used for the actual
                // mediawiki import.
-               ((MediawikiOutputModule) wikiOutputModule).setUsername(wikiLoginUid);
+               wikiOutputModule.setUsername(wikiLoginUid);
 
                // if we actually export from the cdm and not from a file we run the
                // Publisher
@@ -215,7 +215,7 @@ public class Cdm2MediawikiExporter {
                }
 
                // we get the whole filename that the wikiOutputModule created
-               mediawikiFileWithPath = ((MediawikiOutputModule) wikiOutputModule)
+               mediawikiFileWithPath = wikiOutputModule
                                .getFilePath();
 
                logger.info("mediawiki xml file created and saved to"+mediawikiFileWithPath);
@@ -224,7 +224,7 @@ public class Cdm2MediawikiExporter {
                if ((usePublisher && !deleteOutputFiles) || importImages) {
                        // the cdm output where we want to fetch the urls of the
                        // images:
-                       cdmOutputDocument = ((MediawikiOutputModule) wikiOutputModule)
+                       cdmOutputDocument = wikiOutputModule
                                        .getInputDocument();
                }
 
@@ -245,11 +245,11 @@ public class Cdm2MediawikiExporter {
                else{
                        logger.info("did not get images!");
                }
-               
+
                if (import2Mediawiki && importImages && !(localImages.isEmpty())) {
                        uploadImagesToMediawiki(wikiUrl, wikiLoginUid, passwd);
                }
-               
+
                if (deleteOutputFiles) {
                        deleteOutputFiles();
                        logger.info("deleted temporary file(s)");
@@ -257,10 +257,10 @@ public class Cdm2MediawikiExporter {
        }
 
        /**
-        * 
+        *
         */
        private void createTemporaryExportFolder() {
-               temporaryExportFolder = CdmUtils.getCdmHomeSubDir(MEDIAWIKI_CDM_SUB_DIR);
+               temporaryExportFolder = ConfigFileUtil.getCdmHomeSubDir(MEDIAWIKI_CDM_SUB_DIR);
                if (temporaryExportFolder != null) {
                        logger.info("using " + temporaryExportFolder.getAbsolutePath()
                                        + " as temporary directory.");
@@ -277,15 +277,15 @@ public class Cdm2MediawikiExporter {
         */
        private void setupConfigurator(String serviceUrl)
                        throws MalformedURLException {
-               
+
                createTemporaryExportFolder();
-               
+
                configurator.setWebserviceUrl(serviceUrl);
                factory = configurator.getFactory();
 
                // get feature tree from taxon name/taxon node and pass it to the
                // configurator:
-               // TODO, get a feature tree name or uuid as method parameters 
+               // TODO, get a feature tree name or uuid as method parameters
                String featureTree = getDefaultFeatureTree();
                configurator.setFeatureTree(UUID.fromString(featureTree));
 
@@ -324,12 +324,12 @@ public class Cdm2MediawikiExporter {
                //JDOMParseException Invalid byte 2 of 3-byte UTF-8 sequence which occurs for e.g.
                //with German umlauts and French accents on characters
                format.setEncoding("ISO-8859-1");//"UTF-8");
-               XMLOutputter xmlOutput = new XMLOutputter(format);      
-               xmlOutput.setFormat(format);            
+               XMLOutputter xmlOutput = new XMLOutputter(format);
+               xmlOutput.setFormat(format);
 
                try {
-                       xmlOutput.output(cdmOutputDocument, new FileWriter(cdm_output_file));                   
-                    
+                       xmlOutput.output(cdmOutputDocument, new FileWriter(cdm_output_file));
+
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
@@ -353,7 +353,7 @@ public class Cdm2MediawikiExporter {
        /**
         * uploads a given mediawiki xml file to a mediawiki - does only third (last) step
         * of the whole export process
-        * 
+        *
         * @param inputFilePath
         * @param wikiUrl
         * @param wikiUser
@@ -372,10 +372,10 @@ public class Cdm2MediawikiExporter {
        private void uploadToMediawiki(String wikiUrl, String wikiLoginUid, String passwd) {
 
                // login to mediawiki
-               
+
                WikiBot myBot = getBotAndLogin(wikiUrl, wikiLoginUid, passwd);
 
-               
+
                try {
 
                        // parse wiki xml file and import pages one by one
@@ -437,15 +437,15 @@ public class Cdm2MediawikiExporter {
        private void downloadImages() {
                org.jdom.Document document = wikiOutputModule.getInputDocument();
                localImages = new ArrayList<String>();
-               
+
                try {
                        List<Element> media_uris = XPath.selectNodes(document, "//Taxon/media/e/representations/e/parts/e/uri");
-               
+
                        if(media_uris.isEmpty()){
                                logger.info("there are no images in the data.");
                                return;
                        }
-                       
+
                        for (Element urlEl : media_uris) {
                                String url=urlEl.getValue();
                                URL imageUrl = new URL(url);
@@ -456,11 +456,11 @@ public class Cdm2MediawikiExporter {
                                String filePath = temporaryExportFolder.getAbsolutePath()
                                                +FILESEPARATOR + IMAGES_FOLDER +FILESEPARATOR+ filename;
                                logger.info("downloading image " + url+" to "+filePath);
-                               
+
                                FileUtils.copyURLToFile(imageUrl, new File(filePath));
                                localImages.add(filePath);
                        }
-               
+
                } catch (JDOMException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
@@ -471,16 +471,16 @@ public class Cdm2MediawikiExporter {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
-               
+
        }
 
        private void uploadImagesToMediawiki(String wikiUrl, String wikiLoginUid, String passwd) {
-               WikiBot myBot = getBotAndLogin(wikiUrl, wikiLoginUid, passwd); 
+               WikiBot myBot = getBotAndLogin(wikiUrl, wikiLoginUid, passwd);
                // get published output file
-               
 
-                       for(String localUri : localImages){                                             
-                               
+
+                       for(String localUri : localImages){
+
                                try {
                                        uploadImage(myBot, localUri);
                                } catch (MalformedURLException e) {
@@ -492,7 +492,7 @@ public class Cdm2MediawikiExporter {
                                }
                        }
 
-                       // logout               
+                       // logout
                myBot.logout();
                logger.info("all images uploaded to mediawiki "+wikiUrl+" and logged out.");
        }
@@ -517,10 +517,10 @@ public class Cdm2MediawikiExporter {
 ////           System.out.println(filePath);
 //             File imageFile = new File(filePath);
 //             logger.info("downloading image " + url);
-               
+
 //             FileUtils.copyURLToFile(imageUrl, new File(filePath));
-               
-               
+
+
                File imageFile = new File(filePath);
                String[] arr = filePath.split("/");
                String filename = arr[arr.length - 1];
@@ -536,8 +536,8 @@ public class Cdm2MediawikiExporter {
        }
 
        private Document getDocument(String filePath) {
-               SAXBuilder saxBuilder = new SAXBuilder();               
-               
+               SAXBuilder saxBuilder = new SAXBuilder();
+
                File file = new File(filePath);
                Document document = null;
                FileInputStream fileis;
@@ -546,9 +546,9 @@ public class Cdm2MediawikiExporter {
                try {
                        //document = saxBuilder.build(file);
                        fileis = new FileInputStream(file);
-                       BufferedInputStream in = new BufferedInputStream(fileis); 
+                       BufferedInputStream in = new BufferedInputStream(fileis);
                        document = saxBuilder.build(in);
-                       
+
                } catch (JDOMException e) {
                        // TODO Auto-generated catch block
                        logger.error(e.getCause().getMessage());
index 64b919631cd81d34a493e57d3d8615cff703cbcd..11c4868fee3ff60cfd2cd26f68516552637080fa 100644 (file)
@@ -40,7 +40,7 @@ import org.springframework.jndi.JndiObjectFactoryBean;
 import com.mchange.v2.c3p0.ComboPooledDataSource;
 
 import eu.etaxonomy.cdm.api.config.CdmConfigurationKeys;
-import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.common.ConfigFileUtil;
 import eu.etaxonomy.cdm.database.WrappedCdmDataSource;
 import eu.etaxonomy.cdm.database.update.CdmUpdater;
 import eu.etaxonomy.cdm.model.metadata.CdmMetaData;
@@ -125,7 +125,7 @@ public class DataSourceConfigurer extends AbstractWebApplicationConfigurer {
      */
     public static final String ATTRIBUTE_FORCE_SCHEMA_UPDATE = "cdm.forceSchemaUpdate";
 
-    protected static final String DATASOURCE_BEANDEF_DEFAULT = CdmUtils.getCdmHomeDir().getPath() + File.separator + "datasources.xml";
+    protected static final String DATASOURCE_BEANDEF_DEFAULT = ConfigFileUtil.getCdmHomeDir().getPath() + File.separator + "datasources.xml";
 
     protected static String beanDefinitionFile = DATASOURCE_BEANDEF_DEFAULT;
 
@@ -345,7 +345,7 @@ public class DataSourceConfigurer extends AbstractWebApplicationConfigurer {
     public Properties hibernateProperties(){
         Properties props = getHibernateProperties();
         props.setProperty(HIBERNATE_DIALECT, inferHibernateDialectName());
-        String searchPath = CdmUtils.getCdmHomeSubDir(CdmUtils.SUBFOLDER_WEBAPP).getPath();
+        String searchPath = ConfigFileUtil.getCdmHomeSubDir(ConfigFileUtil.SUBFOLDER_WEBAPP).getPath();
         props.setProperty(HIBERNATE_SEARCH_DEFAULT_INDEX_BASE,
                 searchPath +
                 "/index/".replace("/", File.separator) +
index fd66b64067d43553785eaddacf5dbea627f06611..de0268e28d38b6edb943c7ce12ee3e518c0f5d2a 100644 (file)
@@ -15,7 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 
-import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.common.ConfigFileUtil;
 import net.sf.ehcache.config.DiskStoreConfiguration;
 
 /**
@@ -35,7 +35,7 @@ public class EhCacheDiskStoreConfiguration {
     public DiskStoreConfiguration diskStoreConfiguration(){
 
         DiskStoreConfiguration diskStoreConfiguration = new DiskStoreConfiguration();
-        File ehcacheFolder = CdmUtils.getCdmHomeSubDir("ehcache");
+        File ehcacheFolder = ConfigFileUtil.getCdmHomeSubDir("ehcache");
         String instanceName = dataSourceProperties.getCurrentDataSourceId();
         File instanceCacheFolder = new File(ehcacheFolder, instanceName);
         logger.debug("Setting ehcache diskstore location to " + instanceCacheFolder.getAbsolutePath());
index 17f2b2273f28cc9275868a1a18c2f74c0ac206b4..c19e4b38a54c0f917c57e2ff376b56c3c67d914f 100644 (file)
@@ -21,7 +21,7 @@ import org.springframework.context.ApplicationContext;
 import org.springframework.core.env.ConfigurableEnvironment;\r
 import org.springframework.web.context.WebApplicationContext;\r
 \r
-import eu.etaxonomy.cdm.common.CdmUtils;\r
+import eu.etaxonomy.cdm.common.ConfigFileUtil;\r
 \r
 /**\r
  * @author a.kohlbecker\r
@@ -51,7 +51,7 @@ public abstract class AbstractWebApplicationConfigurer {
             userDefinedProperties = new Properties();\r
             try {\r
                 InputStream in = new FileInputStream(\r
-                            CdmUtils.perUserCdmFolder\r
+                            ConfigFileUtil.perUserCdmFolder()\r
                             + java.io.File.separator\r
                             + CDMLIB_REMOTE_PROPERTIES\r
                     );\r
index f649764507014307a8951bd9953f465a3c688fab..60cd268f4c6d2669daf662b2d75f98aac7f866d8 100644 (file)
@@ -25,7 +25,7 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity;
 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
 
-import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.common.ConfigFileUtil;
 
 /**
  *
@@ -135,7 +135,7 @@ public class MultiWebSecurityConfiguration {
         // Add an inMemoryUserManager to  enable access to the global ROLE_MANAGE_CLIENTs.
         // This is the casue for the need to do the configuration explicitly.
         InMemoryUserDetailsManagerConfigurer<AuthenticationManagerBuilder> inMemoryAuthConf = auth.inMemoryAuthentication();
-        File managingUsersFile = new File(CdmUtils.getCdmHomeDir(), MANAGING_USERS_PROPERTIES);
+        File managingUsersFile = new File(ConfigFileUtil.getCdmHomeDir(), MANAGING_USERS_PROPERTIES);
         if(!managingUsersFile.exists()){
             makeManagingUsersPropertiesFile(managingUsersFile);
         }