Project

General

Profile

Revision b8516771

IDb8516771377dcce421c1f0e9b6d29404d57a4a59
Parent 6c211528
Child d57c0094

Added by Andreas Müller about 12 years ago

Copy File problem solved

View differences:

.gitattributes
764 764
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/common/IdentifiableDaoBaseTest.java -text
765 765
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImplTest.java -text
766 766
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/function/Datasource.java -text
767
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/function/TestCdmApplicationUtils.java -text
767 768
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/function/TestDatabase.java -text
768 769
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/function/TestPersistence.java -text
769 770
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/function/TestSessionFactory.java -text
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationUtils.java
19 19
import org.jdom.output.Format;
20 20

  
21 21
import eu.etaxonomy.cdm.common.CdmUtils;
22
import eu.etaxonomy.cdm.common.FileCopy;
22 23
import eu.etaxonomy.cdm.common.XmlHelp;
23 24
import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
24 25

  
......
27 28
	
28 29
	//directory of the resources (configfiles etc.)
29 30
	static File fileResourceDir;
30
	static final String MUST_EXIST_FILE = CdmPersistentDataSource.DATASOURCE_FILE_NAME;
31
	static final String MUST_EXIST_FILE = CdmPersistentDataSource.DATASOURCE_PATH + CdmPersistentDataSource.DATASOURCE_FILE_NAME;
31 32

  
32 33
//	static final String MUST_EXIST_FILE = "persistence.xml";
33 34
//	static final String MUST_EXIST_FILE = "applicationContext.xml";
......
41 42
		//compute only once
42 43
		if (fileResourceDir == null){
43 44
			//workaround to find out in which environment the library is executed
44
			URL url = CdmUtils.class.getResource("/eu/etaxonomy/cdm/"+ MUST_EXIST_FILE);
45
			URL url = CdmUtils.class.getResource(MUST_EXIST_FILE);
45 46
			if (url != null){
46 47
				File file = new File(url.getPath()); 
47 48
				if (file.exists()){
......
71 72
	 * @param directory
72 73
	 * @param resourceFileName
73 74
	 */
74
	static private void copyResource(File directory, String resourceFileName){
75
	static private boolean copyResource(File directory, String resourceFileName){
75 76
		try {
76
			File fileToCopy = new File(directory + File.separator + resourceFileName);
77
			if (fileToCopy.createNewFile()){
78
				InputStream isDataSource = CdmUtils.class.getResourceAsStream("/"+ resourceFileName);
79
				XmlHelp.saveToXml(XmlHelp.getBeansRoot(isDataSource).getDocument(), new FileOutputStream(fileToCopy), Format.getPrettyFormat());
77
			InputStream isDataSource = CdmUtils.class.getResourceAsStream(CdmPersistentDataSource.DATASOURCE_PATH + resourceFileName);
78
			if (isDataSource != null){
79
				File fileToCopy = new File(directory + File.separator + resourceFileName);
80
				if (fileToCopy.createNewFile()){
81
					FileOutputStream outStream = new FileOutputStream(fileToCopy);
82
					FileCopy.copy(isDataSource, outStream);
83
					//XmlHelp.saveToXml(XmlHelp.getBeansRoot(isDataSource).getDocument(), outStream, Format.getPrettyFormat());
84
				}
85
				return true;
86
			}else{
87
				logger.error("Input datasource file "  + resourceFileName + " + could not be found");
80 88
			}
81 89
		} catch (IOException e) {
82 90
			logger.error("File "  + resourceFileName + " + could not be created");
83 91
		}
92
		return false;
84 93
	}
85 94
	
86 95

  
cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/CdmPersistentDataSource.java
52 52
	
53 53
	public static final String DATASOURCE_BEAN_POSTFIX = "DataSource";
54 54
	public final static String DATASOURCE_FILE_NAME = "cdm.datasources.xml";
55
	public final static String DATASOURCE_PATH = "/eu/etaxonomy/cdm/";
56
	
55 57
	private final static Format format = Format.getPrettyFormat(); 
56 58

  
57 59
	public enum DbProperties{
cdmlib-persistence/src/test/java/eu/etaxonomy/cdm/test/function/TestCdmApplicationUtils.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.cdm.test.function;
11

  
12
import org.apache.log4j.Logger;
13

  
14
import eu.etaxonomy.cdm.api.application.CdmApplicationUtils;
15

  
16
/**
17
 * @author a.mueller
18
 * @created 20.11.2008
19
 * @version 1.0
20
 */
21
public class TestCdmApplicationUtils {
22
	private static final Logger logger = Logger.getLogger(TestCdmApplicationUtils.class);
23

  
24
	private boolean testWritableResourceDirectory(){
25
		CdmApplicationUtils.getWritableResourceDir();
26
		return true;
27
	}
28
	
29
	/**
30
	 * @param args
31
	 */
32
	public static void main(String[] args) {
33
		TestCdmApplicationUtils me = new TestCdmApplicationUtils();
34
		me.testWritableResourceDirectory();
35

  
36
	}
37
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)