View Javadoc

1   package org.catacomb.dataview;
2   
3   
4   
5   import org.catacomb.interlish.structure.Element;
6   import org.catacomb.report.E;
7   import org.catacomb.serial.ElementImporter;
8   import org.catacomb.util.FileUtil;
9   
10  import java.io.File;
11  
12  
13  public class BatchImageMaker {
14  
15  
16      File fsrc;
17      File fviewdir;
18      File fdestdir;
19  
20  
21      public static void main(String[] argv) {
22          BatchImageMaker bim = new BatchImageMaker(argv);
23          bim.process();
24          //      Element srcelt = ElementImporter.getElement(new File(argv[0]));
25      }
26  
27  
28  
29      public BatchImageMaker(String[] argv) {
30          fsrc = new File(argv[0]); // xml list of figures;
31  
32          fviewdir = new File(argv[1]);
33          fdestdir = new File(argv[2]);
34      }
35  
36  
37  
38      public void process() {
39  
40          E.info("about to read " + fsrc);
41  
42  
43          Element srcelt = ElementImporter.getElement(fsrc);
44  
45          Element[] elta = srcelt.getElementArray();
46  
47          for (int i = 0; i < elta.length; i++) {
48              Element elt = elta[i];
49  
50              if (elt.getName().equals("figure")) {
51                  makeFigure(elt);
52  
53              } else if (elt.getName().equals("movie")) {
54                  makeMovie(elt);
55  
56              } else {
57                  E.warning("unknown element type in figure list " + elt);
58              }
59          }
60      }
61  
62  
63  
64      public void makeFigure(Element elt) {
65          if (elt.hasAttribute("view")) {
66              // OK;
67          } else {
68              E.error("not processing element (no view attribute) " + elt);
69              return;
70          }
71          String sconf = elt.getAttribute("view");
72  
73          int ifr = -1;
74          if (elt.hasAttribute("frame")) {
75              ifr = Integer.parseInt(elt.getAttribute("frame"));
76          }
77  
78  
79          String sroot = elt.getAttribute("path") + elt.getAttribute("label");
80          if (ifr >= 0) {
81              sroot += "_" + ifr;
82          }
83          File fim = new File(fdestdir, sroot + ".png");
84          File ftn = new File(fdestdir, sroot + "-tn.png");
85          fim.getParentFile().mkdirs();
86  
87          if (fim.exists() && ftn.exists()) {
88              // nothing to do;
89          } else {
90  
91  
92              File fconf = new File(fviewdir, sconf + ".xml");
93              DataViewer dv = new DataViewer(fconf);
94              DataviewController dvc = dv.getController();
95  
96              if (!fim.exists()) {
97                  dvc.saveImage(fim, ifr);
98                  E.info("written image " + fim);
99              }
100             if (!ftn.exists()) {
101                 dvc.saveThumbnailImage(ftn, ifr);
102                 E.info("written image " + ftn);
103             }
104 
105             dvc.exit();
106         }
107     }
108 
109 
110 
111 
112     public void makeMovie(Element elt) {
113         if (elt.hasAttribute("view")) {
114             // OK;
115         } else {
116             E.error("not processing element (no view attribute) " + elt);
117             return;
118         }
119 
120         String sconf = elt.getAttribute("view");
121 
122 
123         String sroot = elt.getAttribute("path") + elt.getAttribute("label");
124 
125         File fmo = new File(fdestdir, sroot + ".gif");
126         File ftn = new File(fdestdir, sroot + "-tn.gif");
127 
128         File fsubdest = fmo.getParentFile();
129         fsubdest.mkdirs();
130 
131         if (fmo.exists() && ftn.exists()) {
132             // nothing to do;
133 
134         } else {
135 
136             File fconf = new File(fviewdir, sconf + ".xml");
137             DataViewer dv = new DataViewer(fconf);
138             DataviewController dvc = dv.getController();
139 
140             copyFiles(fconf, fsubdest);
141 
142             if (!fmo.exists()) {
143                 dvc.makeMovie(fmo);
144                 E.info("written movie " + fmo);
145             }
146             if (!ftn.exists()) {
147                 dvc.makeThumbnailMovie(ftn);
148                 E.info("written movie " + ftn);
149             }
150 
151             dvc.exit();
152         }
153     }
154 
155 
156 
157     private void copyFiles(File fconf, File fdd) {
158         File fpar = fconf.getParentFile();
159         String fnm = fconf.getName();
160         String sr = fnm.substring(0, fnm.lastIndexOf("."));
161 
162         String sr1 = sr + "-cache.bnd";
163         String sr2 = sr + ".sdj";
164         FileUtil.copyFile(fconf, new File(fdd, fconf.getName()));
165         FileUtil.copyFile(new File(fpar, sr1), new File(fdd, sr1));
166         FileUtil.copyFile(new File(fpar, sr2), new File(fdd, sr2));
167 
168     }
169 
170 
171 }