1 | //NAME:Caleb Bird
|
---|
2 | //ID: 1289680
|
---|
3 | //??References??
|
---|
4 | //https://stackoverflow.com/questions/13796451/how-to-extract-a-string-between-two-delimiters
|
---|
5 |
|
---|
6 | import java.io.BufferedReader;
|
---|
7 | import java.io.FileReader;
|
---|
8 | import java.io.FileWriter;
|
---|
9 |
|
---|
10 | public class TabProcMetaListGen {
|
---|
11 | public static void main(String[] args) {
|
---|
12 | try{
|
---|
13 |
|
---|
14 |
|
---|
15 | if (args.length != 2) {
|
---|
16 | System.out.println("Usage: TabProcMetaListGen <inputFilename> <listFilename>");
|
---|
17 | }
|
---|
18 | else {
|
---|
19 | //Variables
|
---|
20 | String inputFilename = args[0];
|
---|
21 | String listFilename = args[1];
|
---|
22 | FileReader fileReader = new FileReader(inputFilename);
|
---|
23 | BufferedReader buf = new BufferedReader(fileReader);
|
---|
24 | FileWriter listWriter = new FileWriter(listFilename, true);
|
---|
25 | String line = null;
|
---|
26 | String[] item;
|
---|
27 |
|
---|
28 | String idLine = null;
|
---|
29 | String id = null;
|
---|
30 | String numpages = null;
|
---|
31 |
|
---|
32 | System.out.println("Processing: " + inputFilename);
|
---|
33 |
|
---|
34 | //Splits into each record
|
---|
35 | while ((line = buf.readLine()) != null) {
|
---|
36 | if(line.contains("<id>")){
|
---|
37 | //Isoclate and store the id from the line
|
---|
38 | idLine = line.substring(line.indexOf(">")+1, line.indexOf("</"));
|
---|
39 | id = idLine.substring(idLine.lastIndexOf("meta/")+5);
|
---|
40 |
|
---|
41 | }
|
---|
42 | if(line.contains("<htd:numpages>")){
|
---|
43 | //Iscolate and store the page number
|
---|
44 | numpages = line.substring(line.indexOf(">")+1, line.lastIndexOf("<"));
|
---|
45 |
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | //Check if there are more than 10 pages
|
---|
50 | if(Integer.parseInt(numpages) >= 10){
|
---|
51 | //Add extracted metadata to output list
|
---|
52 | listWriter.write(id + '\t' + numpages + '\n');
|
---|
53 | }
|
---|
54 | buf.close();
|
---|
55 | listWriter.close();
|
---|
56 | }
|
---|
57 | }catch(Exception e){
|
---|
58 | e.printStackTrace();
|
---|
59 | }
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | //REFERNECES
|
---|
64 | //https://www.javatpoint.com/java-filewriter-class
|
---|
65 | //https://docs.oracle.com/javase/8/docs/api/index.html?java/io/FileWriter.html
|
---|