<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>
\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
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;
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.
* @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(!)
}
- /**
- * @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)
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;
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");
}
}
\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
\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
--- /dev/null
+/**
+ * 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());
+ }
+
+
+}
\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
\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
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;
*/
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;
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
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
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
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
T datasource = beanFactory.getBean(beanName, requiredType);\r
dataSources.put(beanName, datasource);\r
}\r
- return (Map<String, T>) dataSources;\r
+ return dataSources;\r
}\r
\r
}
\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
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
import org.jdom.Document;
-import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
/**
* 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
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
/**
* 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.
*/
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
/*
* (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(
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);
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;
/**
* 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 {
.getLogger(Cdm2MediawikiExporter.class);
private PublishConfigurator configurator = PublishConfigurator.NewRemoteInstance();
-
+
private IXMLEntityFactory factory;
// where the mediawiki xml code is stored
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,
/**
* does the whole export process: runs cdm export to mediawiki xml-file and
* wiki import of this file
- *
+ *
* @param serviceUrl
* @param taxonName
* @param wikiUrl
* - 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
// 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
//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,
// 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
}
// 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);
if ((usePublisher && !deleteOutputFiles) || importImages) {
// the cdm output where we want to fetch the urls of the
// images:
- cdmOutputDocument = ((MediawikiOutputModule) wikiOutputModule)
+ cdmOutputDocument = wikiOutputModule
.getInputDocument();
}
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)");
}
/**
- *
+ *
*/
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.");
*/
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));
//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();
/**
* 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
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
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);
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();
// 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) {
}
}
- // logout
+ // logout
myBot.logout();
logger.info("all images uploaded to mediawiki "+wikiUrl+" and logged out.");
}
//// 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];
}
private Document getDocument(String filePath) {
- SAXBuilder saxBuilder = new SAXBuilder();
-
+ SAXBuilder saxBuilder = new SAXBuilder();
+
File file = new File(filePath);
Document document = null;
FileInputStream fileis;
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());
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;
*/
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;
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) +
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;
/**
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());
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
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
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;
/**
*
// 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);
}