3535import java .awt .Color ;
3636import java .awt .Font ;
3737import java .awt .Image ;
38- import java .io .File ;
39- import java .io .FileInputStream ;
40- import java .io .FileOutputStream ;
4138import java .io .IOException ;
4239import java .io .Writer ;
40+ import java .nio .file .Files ;
41+ import java .nio .file .Path ;
4342import java .util .ArrayList ;
4443import java .util .Comparator ;
4544import java .util .HashMap ;
@@ -253,24 +252,11 @@ private void declareAttributeList(String tag, Class<?> type, Writer writer) thro
253252 writer .append (";>\n " );
254253 }
255254
256- @ SuppressWarnings ("unchecked" )
257255 public static void main (String [] args ) throws Exception {
258- if (args .length > 0 ) {
259- var bindings = new Properties ();
260-
261- var directory = new File (System .getProperty ("user.dir" ));
262- var file = new File (directory , args [0 ]);
263-
264- try (var inputStream = new FileInputStream (file )) {
265- bindings .load (inputStream );
266- }
256+ var workingPath = Path .of (System .getProperty ("user.dir" ));
267257
268- for (var entry : bindings .entrySet ()) {
269- var tag = (String )entry .getKey ();
270- var type = (Class <? extends JComponent >)Class .forName ((String )entry .getValue ());
271-
272- UILoader .bind (tag , type , () -> null );
273- }
258+ if (args .length > 0 ) {
259+ applyBindings (workingPath .resolve (args [0 ]));
274260 }
275261
276262 var typeSet = new HashSet <Class <?>>();
@@ -293,15 +279,29 @@ public static void main(String[] args) throws Exception {
293279
294280 typeList .sort (Comparator .comparing (DTDEncoder ::getDepth ).thenComparing (Class ::getCanonicalName ));
295281
296- var dtdEncoder = new DTDEncoder (typeList , tags );
297-
298- var file = new File (new File (System .getProperty ("user.dir" )), "sierra.dtd" );
282+ try (var outputStream = Files .newOutputStream (workingPath .resolve ("sierra.dtd" ))) {
283+ var dtdEncoder = new DTDEncoder (typeList , tags );
299284
300- try (var outputStream = new FileOutputStream (file )) {
301285 dtdEncoder .write (null , outputStream );
302286 }
303287 }
304288
289+ @ SuppressWarnings ("unchecked" )
290+ private static void applyBindings (Path path ) throws IOException , ClassNotFoundException {
291+ var bindings = new Properties ();
292+
293+ try (var inputStream = Files .newInputStream (path )) {
294+ bindings .load (inputStream );
295+ }
296+
297+ for (var entry : bindings .entrySet ()) {
298+ var tag = (String )entry .getKey ();
299+ var type = (Class <? extends JComponent >)Class .forName ((String )entry .getValue ());
300+
301+ UILoader .bind (tag , type , () -> null );
302+ }
303+ }
304+
305305 private static int getDepth (Class <?> type ) {
306306 var depth = 0 ;
307307
0 commit comments