/* * [ProbeForSkus.java] * * Summary: finds tags for electronic fields that are missing. * * Copyright: (c) 2012-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2016-01-19 initial version */ package com.mindprod.stores; import com.mindprod.common18.EIO; import com.mindprod.common18.Misc; import com.mindprod.common18.ST; import com.mindprod.htmlmacros.macro.Global; import com.mindprod.htmlmacros.support.ConfigurationForMindprod; import com.mindprod.hunkio.HunkIO; import java.io.File; import java.io.IOException; import static java.lang.System.*; /** * finds tags for electronic fields that are missing. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2016-01-19 initial version * @see SkuStore * @since 2016-01-19 */ public class ProbeForSkus extends ManipulateMacros { /** * how to use from command line. run only on book dir. */ private static final String USAGE = "\nProbeForSkus.exe"; /** * where current website files are kept */ private static File currentElectronicDir; /** * contents of the Electronic file */ private static String currentBig; /** * File access to Electronic file */ private static File currentFile; /** * true if contents of Electric file has changed */ private static boolean changed; /** * add a new sku the log and to the Electronic file * * @param skuName name of the sku field * @param skuValue sku part number */ private static void addSku( final String skuName, final String skuValue ) { if ( skuValue != null ) { final String line = skuName + "=" + skuValue + "\n"; out.print( line ); int p = currentBig.indexOf( "price=" ); if ( p < 0 ) { throw new IllegalArgumentException( "missing price=" ); } currentBig = currentBig.substring( 0, p ) + line + currentBig.substring( p ); changed = true; } } /** * tidy electronic macros in e:\mindprod\electronic. Correct ElectronicHead * * @param args * * @throws IOException if trouble reading or writing files containing Book macros. */ public static void main( String[] args ) throws IOException { Global.installConfiguration( new ConfigurationForMindprod() ); final File webrootDir = new File( Global.configuration.getLocalWebrootWithSlashes() ); currentElectronicDir = new File( webrootDir, "electronic" ); final String[] files = currentElectronicDir.list( new ElectronicMacroFileFilter() ); int j = 0; for ( String fileName : files ) { j++; currentFile = new File( currentElectronicDir, fileName ); currentBig = HunkIO.readEntireFile( currentFile, HunkIO.UTF8 ); changed = false; try { final String electronicMacro = findFirstMacroContents( currentBig, "Electronic" ); if ( electronicMacro == null ) { err.println( "missing