2323import org .httprpc .sierra .VerticalAlignment ;
2424
2525import javax .swing .Icon ;
26+ import javax .swing .JComponent ;
2627import javax .swing .JMenu ;
2728import javax .swing .JMenuBar ;
2829import javax .swing .JPanel ;
3435import java .awt .Color ;
3536import java .awt .Font ;
3637import java .awt .Image ;
37- import java .io .File ;
38- import java .io .FileOutputStream ;
3938import java .io .IOException ;
4039import java .io .Writer ;
40+ import java .nio .file .Files ;
41+ import java .nio .file .Path ;
4142import java .util .ArrayList ;
4243import java .util .Comparator ;
4344import java .util .HashMap ;
4445import java .util .HashSet ;
4546import java .util .List ;
4647import java .util .Map ;
48+ import java .util .Properties ;
4749
4850import static org .httprpc .sierra .UILoader .*;
4951
@@ -251,6 +253,12 @@ private void declareAttributeList(String tag, Class<?> type, Writer writer) thro
251253 }
252254
253255 public static void main (String [] args ) throws Exception {
256+ var workingPath = Path .of (System .getProperty ("user.dir" ));
257+
258+ if (args .length > 0 ) {
259+ applyBindings (workingPath .resolve (args [0 ]));
260+ }
261+
254262 var typeSet = new HashSet <Class <?>>();
255263
256264 var tags = new HashMap <Class <?>, String >();
@@ -271,15 +279,29 @@ public static void main(String[] args) throws Exception {
271279
272280 typeList .sort (Comparator .comparing (DTDEncoder ::getDepth ).thenComparing (Class ::getCanonicalName ));
273281
274- var dtdEncoder = new DTDEncoder (typeList , tags );
282+ try (var outputStream = Files .newOutputStream (workingPath .resolve ("sierra.dtd" ))) {
283+ var dtdEncoder = new DTDEncoder (typeList , tags );
275284
276- var file = new File (new File (System .getProperty ("user.dir" )), "sierra.dtd" );
277-
278- try (var outputStream = new FileOutputStream (file )) {
279285 dtdEncoder .write (null , outputStream );
280286 }
281287 }
282288
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+
283305 private static int getDepth (Class <?> type ) {
284306 var depth = 0 ;
285307
0 commit comments