Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5a17df64ff2e5916d0d5128a7e0dfe79dd06eb25 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
 * @author: Manel Fredj - CEA
 * This class enables to change the namespace of di2 metamodel from
 * replace  http://www.papyrusuml.org into http://www.papyrusuml.org/di2
 */

package org.eclipse.papyrus.conversion.di2todi.popupactions;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;

public class PapyrusNamespace
{
	/////////////////////////////////////////////////////////////////////////////////////////////
	//replace  http://www.papyrusuml.org -- by -- http://www.papyrusuml.org/di2
	
	public static void replaceNamespace(String absolutepath)
	{
		try {
			String oldNameSpace = "di2=\"http://www.papyrusuml.org\""; 
			String newNameSpace="di2=\"http://www.papyrusuml.org/di2\"";
			String  oldtext =readFileAsString(absolutepath);
			// replace the namespace in the di2 file
			String newtext = oldtext.replaceAll (oldNameSpace, newNameSpace);
	            
			FileWriter writer = new FileWriter(absolutepath);
			writer.write(newtext);writer.close();
		}
		catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}
	
	public static void restoreDi2Namespace(String absolutepath)
	{
		try {
			String oldNameSpace="di2=\"http://www.papyrusuml.org/di2\"";
			String newNameSpace = "di2=\"http://www.papyrusuml.org\""; 
			
			String  oldtext =readFileAsString(absolutepath);
			// replace the namespace in the di2 file
			String newtext = oldtext.replaceAll (oldNameSpace, newNameSpace);
	            
			FileWriter writer = new FileWriter(absolutepath);
			writer.write(newtext);writer.close();
		}
		catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}
	
    /**
     * @param filePath the name of the file to open. Not sure if it can accept 
     *    cccURLs or just filenames. Path handling could be better, and buffer
     *    sizes are hardcoded
     */ 
	private static String readFileAsString (String filePath)
		throws java.io.IOException
	{
		byte[] buffer = new byte[(int) new File(filePath).length()];
		BufferedInputStream f = null;
		try {
			f = new BufferedInputStream(new FileInputStream(filePath));
			f.read(buffer);
		}
		finally {
			if (f != null) {
				try {
					f.close();
				}
				catch (IOException ignored) {
				}
			}
		}
		return new String(buffer);
	}
}

Back to the top