|
15 | 15 | * benefit from the abstraction |
16 | 16 | */ |
17 | 17 | public class DataUtilities { |
| 18 | + |
| 19 | + private static final String EMPTY_RESOURCE_FILE = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + |
| 20 | + "<root>\n" + |
| 21 | + " <xsd:schema id=\"root\" xmlns=\"\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\">\n" + |
| 22 | + " <xsd:import namespace=\"http://www.w3.org/XML/1998/namespace\" />\n" + |
| 23 | + " <xsd:element name=\"root\" msdata:IsDataSet=\"true\">\n" + |
| 24 | + " <xsd:complexType>\n" + |
| 25 | + " <xsd:choice maxOccurs=\"unbounded\">\n" + |
| 26 | + " <xsd:element name=\"metadata\">\n" + |
| 27 | + " <xsd:complexType>\n" + |
| 28 | + " <xsd:sequence>\n" + |
| 29 | + " <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" />\n" + |
| 30 | + " </xsd:sequence>\n" + |
| 31 | + " <xsd:attribute name=\"name\" use=\"required\" type=\"xsd:string\" />\n" + |
| 32 | + " <xsd:attribute name=\"type\" type=\"xsd:string\" />\n" + |
| 33 | + " <xsd:attribute name=\"mimetype\" type=\"xsd:string\" />\n" + |
| 34 | + " <xsd:attribute ref=\"xml:space\" />\n" + |
| 35 | + " </xsd:complexType>\n" + |
| 36 | + " </xsd:element>\n" + |
| 37 | + " <xsd:element name=\"assembly\">\n" + |
| 38 | + " <xsd:complexType>\n" + |
| 39 | + " <xsd:attribute name=\"alias\" type=\"xsd:string\" />\n" + |
| 40 | + " <xsd:attribute name=\"name\" type=\"xsd:string\" />\n" + |
| 41 | + " </xsd:complexType>\n" + |
| 42 | + " </xsd:element>\n" + |
| 43 | + " <xsd:element name=\"data\">\n" + |
| 44 | + " <xsd:complexType>\n" + |
| 45 | + " <xsd:sequence>\n" + |
| 46 | + " <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"1\" />\n" + |
| 47 | + " <xsd:element name=\"comment\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"2\" />\n" + |
| 48 | + " </xsd:sequence>\n" + |
| 49 | + " <xsd:attribute name=\"name\" type=\"xsd:string\" use=\"required\" msdata:Ordinal=\"1\" />\n" + |
| 50 | + " <xsd:attribute name=\"type\" type=\"xsd:string\" msdata:Ordinal=\"3\" />\n" + |
| 51 | + " <xsd:attribute name=\"mimetype\" type=\"xsd:string\" msdata:Ordinal=\"4\" />\n" + |
| 52 | + " <xsd:attribute ref=\"xml:space\" />\n" + |
| 53 | + " </xsd:complexType>\n" + |
| 54 | + " </xsd:element>\n" + |
| 55 | + " <xsd:element name=\"resheader\">\n" + |
| 56 | + " <xsd:complexType>\n" + |
| 57 | + " <xsd:sequence>\n" + |
| 58 | + " <xsd:element name=\"value\" type=\"xsd:string\" minOccurs=\"0\" msdata:Ordinal=\"1\" />\n" + |
| 59 | + " </xsd:sequence>\n" + |
| 60 | + " <xsd:attribute name=\"name\" type=\"xsd:string\" use=\"required\" />\n" + |
| 61 | + " </xsd:complexType>\n" + |
| 62 | + " </xsd:element>\n" + |
| 63 | + " </xsd:choice>\n" + |
| 64 | + " </xsd:complexType>\n" + |
| 65 | + " </xsd:element>\n" + |
| 66 | + " </xsd:schema>\n" + |
| 67 | + " <resheader name=\"resmimetype\">\n" + |
| 68 | + " <value>text/microsoft-resx</value>\n" + |
| 69 | + " </resheader>\n" + |
| 70 | + " <resheader name=\"version\">\n" + |
| 71 | + " <value>2.0</value>\n" + |
| 72 | + " </resheader>\n" + |
| 73 | + " <resheader name=\"reader\">\n" + |
| 74 | + " <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\n" + |
| 75 | + " </resheader>\n" + |
| 76 | + " <resheader name=\"writer\">\n" + |
| 77 | + " <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>\n" + |
| 78 | + " </resheader>\n" + |
| 79 | + "</data>"; |
| 80 | + |
18 | 81 | public static final String SINGLE_TRUTH_LOCALE = ""; |
19 | 82 |
|
20 | 83 | private static final String FILE_NAME_FORMAT = "%s%s.resx"; |
@@ -93,4 +156,22 @@ public static String getFileIdentifier(Path file) { |
93 | 156 | throw new IllegalArgumentException("The resx file does not match our permissive regex"); |
94 | 157 | } |
95 | 158 | } |
| 159 | + |
| 160 | + /** |
| 161 | + * Creates an empty resource file at the given path, assuming the file does not exist already |
| 162 | + * |
| 163 | + * @param path |
| 164 | + * The Path where the resource file needs to be created. |
| 165 | + */ |
| 166 | + public static void createEmptyResourceFile(Path path) { |
| 167 | + if (path.toFile().exists()) { |
| 168 | + return; |
| 169 | + } |
| 170 | + try { |
| 171 | + Files.createFile(path); |
| 172 | + Files.write(path, EMPTY_RESOURCE_FILE.getBytes()); |
| 173 | + } catch (IOException e) { |
| 174 | + e.printStackTrace(); |
| 175 | + } |
| 176 | + } |
96 | 177 | } |
0 commit comments