1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package edu.internet2.middleware.grouperInstaller.morphString;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.util.Properties;
26
27 import edu.internet2.middleware.grouperInstaller.util.GrouperInstallerUtils;
28
29
30
31
32 public class Morph {
33
34
35
36
37 public static final String ENCRYPT_KEY = "encrypt.key";
38
39
40
41
42
43
44
45 public static String stripPrefix(String string, String prefix) {
46 if (string == null || prefix == null) {
47 return string;
48 }
49 if (string.startsWith(prefix)) {
50 return string.substring(prefix.length(), string.length());
51 }
52 return string;
53 }
54
55
56
57
58
59
60
61
62
63 public static String readFileIntoStringUtf8(File file) {
64
65 if (file == null) {
66 return null;
67 }
68 try {
69 return GrouperInstallerUtils.readFileToString(file, "UTF-8");
70 } catch (IOException ioe) {
71 throw new RuntimeException(ioe);
72 }
73 }
74
75
76 public static String readFromFileIfFileUtf8(String in, boolean disableExternalFileLookup) {
77
78 if (in == null || "".equals(in)) {
79 return in;
80 }
81
82 boolean isFile = false;
83 if (in.startsWith("file:")) {
84 isFile = true;
85 in = stripPrefix(in, "file:");
86 File file = new File(in);
87 if (!file.exists() || !file.isFile()) {
88 throw new RuntimeException("Cant find or read file: '" + in + "'");
89 }
90 } else {
91 if (!disableExternalFileLookup) {
92 File file = new File(in);
93 if (file.exists() && file.isFile()) {
94 isFile = true;
95 }
96 }
97 }
98
99
100 if (isFile) {
101
102 return readFileIntoStringUtf8(new File(in));
103 }
104 return in;
105
106 }
107
108
109 public static String testMorphKey = null;
110
111
112
113
114 private Morph() {
115 }
116
117 }