Skip to content

Commit da135e5

Browse files
author
atla5
committed
[refactor] minor stringutils, printout improvements
1 parent f0fa1f3 commit da135e5

File tree

5 files changed

+14
-51
lines changed

5 files changed

+14
-51
lines changed

main/java/dc_metadata/Contributor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static Contributor createContributor(String qualifierText, String fullNam
7373
String qualifier = determineContributorQualifier(qualifierText);
7474
String value = determineName(fullName).trim();
7575

76-
LOGGER.info(String.format("CONTRIBUTOR created | qualifier: %s, value: %s.", qualifier, value));
76+
//LOGGER.info(String.format("CONTRIBUTOR created | qualifier: %s, value: %s.", qualifier, value));
7777

7878
return new Contributor(qualifier, value);
7979
}

main/java/export/CSVExporter.java

+4-19
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package export;
22

3+
import com.sun.deploy.util.StringUtils;
34
import dc_metadata.Element;
45
import main.Item;
56

67
import java.io.File;
7-
import java.util.ArrayList;
8-
import java.util.List;
98

109
/**
1110
* Export to CSV file for use with `DSpace/SAFBuildier`
@@ -23,27 +22,13 @@ public CSVExporter(){
2322

2423
@Override
2524
protected String processHeader(){
26-
27-
ArrayList<String> lsElements = new ArrayList<String>();
28-
lsElements.addAll(this.lsUniqueElementNames);
29-
30-
String toReturn = ""; int i;
31-
for (i = 0; i < lsElements.size() - 1; i++)
32-
toReturn += lsElements.get(i) + ",";
33-
34-
return toReturn + lsElements.get(i) + "\n";
25+
return StringUtils.join(this.lsUniqueElementNames,",") + "\n";
3526
}
3627

3728
@Override
3829
protected String processItemHeader(Item item){
39-
String toReturn = "\"" + item.id + "\",";
40-
41-
List<String> filenames = item.lsFilenames; int i;
42-
toReturn += "\"";
43-
for(i = 0; i < filenames.size()-1; i++)
44-
toReturn += filenames.get(i) + "||";
45-
46-
return toReturn + filenames.get(i) + "\",";
30+
String filenames = StringUtils.join(item.lsFilenames, "||");
31+
return String.format("%d,\"%s\",", item.id, filenames);
4732

4833
}
4934

main/java/export/TXTExporter.java

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package export;
22

3+
import com.sun.deploy.util.StringUtils;
34
import dc_metadata.Element;
45
import main.Item;
56

@@ -10,15 +11,7 @@ public class TXTExporter extends main.Exporter {
1011

1112
@Override
1213
protected String processItemHeader(Item item){
13-
String toReturn = "---- Item " + item.id + ": ";
14-
15-
//list filenames
16-
int i = 0;
17-
for(i = 0; i < item.lsFilenames.size()-1; i++){
18-
toReturn += item.lsFilenames.get(i) + ", ";
19-
} toReturn += item.lsFilenames.get(i);
20-
21-
return toReturn + " ----\n";
14+
return String.format("---- Item %d: %s ----", item.id, StringUtils.join(item.lsFilenames, ", "));
2215
}
2316

2417
@Override

main/java/main/Main.java

+7-22
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,24 @@
1111
import java.util.logging.Logger;
1212
import java.util.logging.SimpleFormatter;
1313

14-
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
15-
1614
/**
1715
* main.Main user-facing class. Directs all actions.
1816
*/
1917
public class Main {
2018

2119
//delimiters
22-
public static String DELIM_SHARED = "|";
2320
public static String DIRECTORY_PATH_IN = "./main/sample_data/"; //TODO allow custom path
2421
public static String DIRECTORY_PATH_CONF = "./main/config/"; //TODO allow custom path
2522
public static String DIRECTORY_PATH_OUT = "../output/"; //TODO allow custom path
26-
private String EXPORT_FILENAME = "export"; //name of each exported file in 'output/' (collection name)
23+
private String EXPORT_FILENAME = "export"; //name of each exported file in 'output/' (collection name)
2724

2825
// configure logger
2926
private static Logger LOGGER = Logger.getLogger(Main.class.getName());
3027

3128

32-
// - public facing back end
33-
3429
/**
3530
* Main function responsible for taking in user input at the command line,
3631
* handling flags, and directing overall behavior of the program.
37-
* @param args list of files (?)
3832
* @throws IOException
3933
* @throws ParseException
4034
*/
@@ -43,7 +37,7 @@ public static void main(String[] args) throws IOException, ParseException {
4337
// - get input from the user command line - //
4438
String header = "A cataloguing tool for converting specially formatted text files containing dublin " +
4539
"core metadata into various formats\n";
46-
String footer = "";
40+
String footer = "-- developed by @atla5 on behalf of RIT Wallace and BU Mugar libraries.";
4741
CommandLineParser posixParser = new PosixParser();
4842
Options options = new Options();
4943

@@ -101,13 +95,6 @@ public static void main(String[] args) throws IOException, ParseException {
10195
System.exit(0);
10296
}
10397

104-
//display help information for dublin core
105-
if(commandLine.hasOption('d')) {
106-
throw new NotImplementedException();
107-
//System.exit(0);
108-
}
109-
110-
11198
/* - run the program in the absence of these tags */
11299

113100
//instantiate a new parser
@@ -141,16 +128,14 @@ public static void main(String[] args) throws IOException, ParseException {
141128

142129
int id = 1;
143130
//foreach file in the directory...
131+
File folder = new File(DIRECTORY_PATH_IN);
132+
File[] lsFiles = folder.listFiles();
144133

145-
String waldo = "sample-metadata-file.txt";
146-
String sample= "1990-v123n04.txt";
147-
String[] lsFiles = { waldo, sample };
148-
149-
for(String filename : lsFiles) {
150-
String path = DIRECTORY_PATH_IN + filename;
134+
for(File filename : lsFiles) {
135+
String path = filename.getAbsolutePath();
151136

152137
//todo: harvest metadata from file and use it to populate provenance information
153-
p.processMetadataFile(processFileIntoStringArray(DIRECTORY_PATH_IN + filename), id);
138+
p.processMetadataFile(processFileIntoStringArray(path), id);
154139
id++;
155140
}
156141
//end foreach file in directory...
Binary file not shown.

0 commit comments

Comments
 (0)