From: Egon W. <eg...@us...> - 2004-01-14 15:44:46
|
Update of /cvsroot/woc/woc/source/wocjava/source/com/egonw/woc/tools In directory sc8-pr-cvs1:/tmp/cvs-serv24845/source/wocjava/source/com/egonw/woc/tools Modified Files: SimpleAddItem.java Log Message: Final tweaks. I can now add one item reasonably easy. See woc website: 1-butoxy-2-propanol Index: SimpleAddItem.java =================================================================== RCS file: /cvsroot/woc/woc/source/wocjava/source/com/egonw/woc/tools/SimpleAddItem.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** SimpleAddItem.java 14 Jan 2004 13:07:57 -0000 1.4 --- SimpleAddItem.java 14 Jan 2004 15:44:43 -0000 1.5 *************** *** 7,12 **** import java.util.*; import com.egonw.woc.*; - import com.egonw.woc.files.*; import com.egonw.woc.util.*; import com.egonw.woc.predicate.*; import com.egonw.woc.exception.*; --- 7,12 ---- import java.util.*; import com.egonw.woc.*; import com.egonw.woc.util.*; + import com.egonw.woc.files.*; import com.egonw.woc.predicate.*; import com.egonw.woc.exception.*; *************** *** 15,18 **** --- 15,22 ---- import org.openscience.dadml.tools.*; + /** + * @author egonw + * @created January 14, 2004 + */ class SimpleAddItem { *************** *** 20,153 **** private static String title = "WOC.SimpleAddItem"; ! private static String version = "1.4"; ! private static String date = "23-02-2001"; private static Path repository; private static String module = ""; ! public static void main(String[] args) { ! System.out.println(title + " v." + version + " (" + date + ")"); ! int length = args.length; ! ! String reposdeffile = "file:///vol/www/woc/bin/repository_def.xml"; ! String repos = "woc"; ! ! if (length > 0) { ! String f = ""; ! if (length > 1) { ! System.out.println("Parsing arguments..."); ! for (int i = 0; i < length; i++) { ! if (args[i].equals("-r") && ((i+1) < length)) { ! i++; ! System.out.println(" repository: " + args[i]); ! repos = args[i]; ! } else if (args[i].equals("-R") && ((i+1) < length)) { ! i++; ! reposdeffile = args[i]; ! System.out.println(" reposdeffile: " + reposdeffile); ! } else if (args[i].equals("-m") && ((i+1) < length)) { ! i++; ! module = args[i]; ! System.out.println(" module: " + args[i]); ! } } ! // file is considered the last argument ! f = args[length-1]; ! } else { ! f = args[0]; ! } // setting default repository ! String url = "file://" + reposdeffile; repository = new Path(repos, url); ! WocEngine we = new WocEngine(repository); ! we.setWoordTable(new WoordTable()); ! try { ! we.setWocReportFile(new WocReportFile("WMLreport.txt")); ! } catch (IOException e) { ! System.out.println(e); ! } ! System.out.println("Reading data..."); ! if (!(f.endsWith(".xml"))) { ! f = f + ".xml"; ! } ! WMLReadFile rf = new WMLReadFile(repository, f); ! we.setReadFile((FileReadAble)rf); ! we.read(); ! ! System.out.println("Downloading DADML database definitions..."); ! DBDEFLIST dbdeflist = new DBDEFLIST(); ! DBLIST dblist = new DBLIST(); ! String superXML = "http://www.woc.sci.kun.nl/super.xml"; ! try { ! System.err.println("Downloading: " + superXML); ! dblist = DBLISTFileReader.read(superXML, pClass); ! } catch (Exception supererror) { ! System.err.println(supererror.toString()); ! return; ! } ! Enumeration dbases = dblist.databases(); ! while (dbases.hasMoreElements()) { ! DATABASE db = (DATABASE)dbases.nextElement(); ! String dburl = db.getURL()+db.getDefinition(); ! DBDEF dbdef = new DBDEF(); ! try { ! System.err.println("Downloading: " + dburl); ! dbdef = DBDEFFileReader.read(dburl, pClass); ! dbdeflist.addDBDEF(dbdef); ! } catch (Exception deferror) { ! System.err.println(deferror.toString()); ! return; ! } ! } ! ! ! System.out.println("Expanding item..."); ! we.setConvertAble(new Expander()); ! we.convert(); ! ! // System.out.println("Marking up items..."); ! // if (module.length() > 0) { ! // try { ! // Class c = Woord.class.getClassLoader().loadClass("com.egonw.woc.util." + module); ! // we.setConvertAble((ConvertAble)c.newInstance()); ! // we.convert(); ! // } catch (ClassCastException e) { ! // System.out.println("Object " + module + " is not a module!"); ! // } catch (ClassNotFoundException e) { ! // System.out.println("Module " + module + " not found!"); ! // } catch (Exception e) { ! // System.out.println("Error: " + e); ! // } ! // } ! ! System.out.print("Writing data..."); ! Enumeration values = we.getWTElements(); ! while (values.hasMoreElements()) { ! Item i = (Item)values.nextElement(); ! System.out.println("Processing: " +(String)i.get(Item.NAME)); ! we.setFilterPredicate( ! new BindSecondPredicate( new IsName(), ! (String)i.get(Item.NAME) ) ); try { ! String filename = repository.getPhysicalRoot() + ! repository.getItemFileSubDir() + ! (String)i.get(Item.ANCHOR) + ".shtml"; ! System.out.println("Filename: " + filename); ! ItemWriteFile iwf = new ItemWriteFile(repository, filename, ! ItemFile.LONG, dbdeflist); ! we.setWriteFile((FileWriteAble)iwf); ! we.write(); ! iwf.close(); ! } catch (IOException e) { System.out.println(e); ! }; ! }; ! System.out.println(); ! } else { ! System.out.println("syntax: java SimpleAddItem [-r repository] <item.xml>"); } - } } --- 24,136 ---- private static String title = "WOC.SimpleAddItem"; ! private static String version = "1.0.0"; ! private static String date = "2004-01-14"; + private static String path = "woc"; private static Path repository; private static String module = ""; ! ! /** ! * The main program for the SimpleAddItem class. ! * ! * @param args The command line arguments ! */ ! public static void main(String[] args) { ! ! String reposdeffile = "file:///vol/www/woc/woc3/bin/wml2html/repository_def.xml"; ! String repos = "woc"; ! ! System.out.println(title + " v." + version + " (" + date + ")"); ! int length = args.length; ! if (length > 1) { ! System.out.println("Parsing arguments..."); ! for (int i = 0; i < length - 1; i++) { ! if (args[i].equals("-r") && ((i + 1) < length)) { ! i++; ! path = args[i]; ! System.out.println(" repository: " + args[i]); ! } else if ("-R".equals(args[i]) && ((i + 1) < length)) { ! reposdeffile = args[i + 1]; ! System.out.println(" reposdeffile: " + args[i + 1]); ! i++; ! } else { ! System.out.println("Unknown option: " + args[i]); ! System.exit(1); ! } ! } } ! String code = args[args.length - 1]; // setting default repository ! String url = reposdeffile; repository = new Path(repos, url); ! WocEngine we = new WocEngine(repository); ! we.setWoordTable(new WoordTable()); try { ! we.setWocReportFile(new WocReportFile("WMLreport.txt")); ! } catch (IOException e) { System.out.println(e); ! } ! String readfile = "woclist.xml"; ! System.out.println("Reading " + readfile + "..."); ! WocListReadFile rf = new WocListReadFile(repository, readfile); ! we.setReadFile((FileReadAble) rf); ! we.read(); ! ! System.out.println("Downloading DADML database definitions..."); ! DBDEFLIST dbdeflist = new DBDEFLIST(); ! DBLIST dblist = new DBLIST(); ! String superXML = "http://www.woc.sci.kun.nl/super.xml"; ! try { ! // System.err.println("Downloading: " + superXML); ! dblist = DBLISTFileReader.read(superXML, pClass); ! } catch (Exception supererror) { ! System.err.println(supererror.toString()); ! return; ! } ! Enumeration dbases = dblist.databases(); ! while (dbases.hasMoreElements()) { ! DATABASE db = (DATABASE)dbases.nextElement(); ! String dburl = db.getURL()+db.getDefinition(); ! DBDEF dbdef = new DBDEF(); ! try { ! // System.err.println("Downloading: " + dburl); ! dbdef = DBDEFFileReader.read(dburl, pClass); ! dbdeflist.addDBDEF(dbdef); ! } catch (Exception deferror) { ! System.err.println(deferror.toString()); ! return; ! } ! } ! ! System.out.println("Adding group items..."); ! we.setConvertAble(new GroupAdder()); ! we.convert(); ! System.out.print("Writing data..."); ! we.setFilterPredicate( ! new BindSecondPredicate(new IsCode(), code) ! ); ! Enumeration values = we.getWTElements(); ! while (values.hasMoreElements()) { ! Item i = (Item)values.nextElement(); ! if (i.get(XItem.XCODE).equals(code)) { ! try { ! System.out.println(" " + (String) i.get(Item.NAME) + " -> " + (String) i.get(XItem.XFILENAME)); ! ItemWriteFile iwf = new ItemWriteFile(repository, ! repository.getPhysicalRoot() + repository.getItemFileSubDir() + ! (String) i.get(XItem.XFILENAME) + ".shtml", ItemFile.LONG, ! dbdeflist); ! we.setWriteFile((FileWriteAble) iwf); ! we.write(); ! iwf.close(); ! } catch (IOException e) { ! System.out.println(e); ! } ! } ! } } } + |