timeLabels ){
if ( params.update || ( timeLabels.size()!=pngFilenameArrayBig.size() ) ) {
logger.info("skipping create HTML step because of partial run");
return;
}
String filePath= params.outputFolder+""+ params.product + ".html";
//String filePath = "pngImagePage2.html";
File f= new File(filePath);
String htmlOpen= "\n";
String htmlHead="\tPNG Gallery "+params.product+"\n";
String htmlBody="\t\n";
String htmlClose1= "\t\t\n";
String htmlClose2= "\t\n";
String htmlClose3= "";
//String pageHeaderOpen= "\t\t\n\t\t\t"
// + "" + params.product + "_"+ params.timeFormat + "\n" + "\t\t
\n";
String pageHeaderOpen= "\t\t\n\t\t\t"
+ "" + "PNG WALK" + "\n" + "\t\t
\n";
String addImageString;
String htmlAnchorStringOpen = "\t\t\t\t\n";
String htmlImageStringOpen = "\t\t\t\t\n";
String htmlImageCaptionOpen = "\t\t\t\t";
String htmlImageCaptionClose = "\t\t\t\t\n";
String htmlImageContainer = "\t\t\n";
String htmlFigureOpen = "\t\t\t\n";
String currentPngFilename;
String currentPngFilenameBIG;
String fileNameToDisplay;
String bigImageLink;
String fullImageCaption;
int count=0;
try ( BufferedWriter bw = new BufferedWriter(new FileWriter(f)) ) {
bw.write(htmlOpen);
bw.write(htmlHead);
bw.write(htmlBody);
bw.write(pageHeaderOpen);
bw.write(htmlImageContainer);
for (String pngFilenameArray1 : pngFilenameArrayThumbs) {
currentPngFilename = pngFilenameArray1;
//System.out.println("image file path: " + currentPngFilename);
currentPngFilenameBIG = pngFilenameArrayBig.get(count);
fileNameToDisplay= timeLabels.get(count);
count++;
bigImageLink= htmlAnchorStringOpen + currentPngFilenameBIG + htmlAnchorStringClose;
addImageString= htmlImageStringOpen+currentPngFilename+htmlImageStringClose; //insert image into html code
fullImageCaption= htmlImageCaptionOpen + fileNameToDisplay + htmlImageCaptionClose; //insert corresponding date for image into html code
bw.write(htmlFigureOpen);
bw.write(bigImageLink);
bw.write(addImageString);
bw.write(fullImageCaption);
bw.write(htmlFigureClose);
}
bw.write(htmlClose1);
bw.write(htmlClose2);
bw.write(htmlClose3);
} catch (IOException e) {
logger.log( Level.WARNING, e.getMessage(), e );
}
}
/**
* command-line support for creating PNGWalks. When PNGWalks are created
* interactively in Autoplot, this is used as well.
* @param args see the code for the argument list.
* @throws InterruptedException
* @throws ParseException
* @throws IOException
*/
public static void main( String[] args ) throws InterruptedException, ParseException, IOException {
System.err.println("CreatePngWalk 20200819");
final ArgumentList alm = new ArgumentList("CreatePngWalk");
alm.addOptionalSwitchArgument( "timeFormat", "f", "timeFormat", "$Y$m$d", "timeformat for png files, e.g. $Y is year, $j is day of year");
alm.addOptionalSwitchArgument( "timeRange", "r", "timeRange", "", "time range to cover, e.g. 2011 through 2012" );
alm.requireOneOf( new String[] { "timeRange","batchUri" } );
alm.addOptionalSwitchArgument( "batchUri", "b", "batchUri", "", "optionally provide list of timeranges" );
alm.addOptionalSwitchArgument( "batchUriName", null, "batchUriName", "", "use $o to use the filename in the batch file" );
alm.addOptionalSwitchArgument( "createThumbs", "t", "createThumbs", "y", "create thumbnails, y (default) or n" );
alm.addOptionalSwitchArgument( "product", "n", "product", "product", "product name in each filename (default=product)");
alm.addOptionalSwitchArgument( "outputFolder", "o", "outputFolder", "pngwalk", "location of root of pngwalk");
alm.addOptionalSwitchArgument( "outputFormat", null, "outputFormat", "png", "output format png or pdf");
alm.addOptionalSwitchArgument( "vap", "v", "vap", null, "vap file to plot");
alm.addOptionalSwitchArgument( "uri", "u", "uri", null, "single URI plotted");
alm.requireOneOf(new String[] { "vap","uri" } );
alm.addOptionalSwitchArgument( "rescalex", null, "rescalex", "0%,100%", "rescale factor, such as '0%-1hr,100%+1hr', to provide context to each image");
alm.addOptionalSwitchArgument( "version", null, "version", null, "additional version string to add to each filename, like v1.0");
alm.addBooleanSwitchArgument( "autorange", null, "autorange", "rerange dependent dimensions Y and Z");
alm.addBooleanSwitchArgument( "autorangeFlags", null, "autorangeFlags", "only autorange axes with autorange=true");
alm.addBooleanSwitchArgument( "update", null, "update", "only calculate missing images");
alm.addBooleanSwitchArgument( "removeNoData", null, "removeNoData", "don't produce images which have no visible data.");
alm.addBooleanSwitchArgument( "testException", null, "testException", "throw a runtime exception to test exit code");
if ( !alm.process(args) ) {
System.exit( alm.getExitCode() );
}
if ( alm.getBooleanValue("testException") ) {
throw new RuntimeException("--textException on command line, throwing exception");
// verified, 20130627.
// java -cp autoplot.jar org.autoplot.pngwalk.CreatePngWalk --vap=x --testException
// echo $? -> 1
// Note, no files found does not yeild non-zero exit code!
}
if ( System.getProperty( "noCheckCertificate","true").equals("true") ) {
logger.fine("disabling HTTP certificate checks.");
try {
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[0];
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) { }
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) { }
}
};
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
} catch (NoSuchAlgorithmException | KeyManagementException ex) {
logger.log(Level.SEVERE, ex.getMessage(), ex);
}
}
Params params= new Params();
params.createThumbs= alm.getValue("createThumbs").equals("y");
params.outputFolder= alm.getValue("outputFolder");
params.product= alm.getValue("product");
params.timeFormat= alm.getValue("timeFormat");
params.timeRangeStr= alm.getValue("timeRange");
params.rescalex= alm.getValue("rescalex");
params.version= alm.getValue("version");
params.autorange= alm.getBooleanValue("autorange");
params.autorangeFlags= alm.getBooleanValue("autorangeFlags");
params.update= alm.getBooleanValue("update");
params.batchUri= alm.getValue("batchUri");
params.removeNoData= alm.getBooleanValue("removeNoData");
if ( params.batchUri!=null && params.batchUri.length()>0 ) {
params.useBatchUri= true;
params.batchUriName= alm.getValue("batchUriName");
}
params.outputFormat= alm.getValue("outputFormat");
Application dom;
String vap= alm.getValue("vap");
if ( vap!=null ) {
if ( ( vap.length()>2 && vap.charAt(1)==':' ) ) {
logger.fine("reference appears to be absolute (Windows)");
} else {
vap= URISplit.makeAbsolute(new File(".").getAbsolutePath(),vap);
}
dom = (Application) StatePersistence.restoreState(new File(vap));
} else {
String uri = alm.getValue("uri");
ScriptContext.setCanvasSize( 800, 600 );
ScriptContext.plot(uri);
dom = ScriptContext.getDocumentModel();
}
if ( vap!=null && vap.contains(params.outputFolder) ) {
params.writeVap= false;
}
int status= doIt( dom, params );
System.exit(status); // something starts up thread that prevents java from exiting.
}
}