Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
Migrate to git, fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
shred committed Oct 30, 2014
1 parent 7025cb6 commit 67ce9f4
Show file tree
Hide file tree
Showing 59 changed files with 528 additions and 600 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.classpath
.settings
target
18 changes: 0 additions & 18 deletions src/etc/header.txt

This file was deleted.

13 changes: 6 additions & 7 deletions src/main/java/org/shredzone/pdbconverter/CalendarFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
* {@link TimeZone}.
* <p>
* Instances are thread local, so different threads may have different time zone settings.
*
*
* @author Richard "Shred" Körber
* @version $Revision: 524 $
*/
public class CalendarFactory {

Expand All @@ -51,13 +50,13 @@ protected CalendarFactory initialValue() {
* Gets the singleton instance of the factory. The returned singleton is thread local
* and can only be used by the invoking thread. On the other hand, multiple threads
* can have individual time zone settings.
*
*
* @return {@link CalendarFactory} instance
*/
public static CalendarFactory getInstance() {
return INSTANCES.get();
}

/**
* The {@link TimeZone} to be used. Defaults to the system's time zone.
*/
Expand All @@ -66,7 +65,7 @@ public static CalendarFactory getInstance() {

/**
* Creates a new {@link Calendar} instance with the current time zone.
*
*
* @return {@link Calendar}
*/
public Calendar create() {
Expand All @@ -75,7 +74,7 @@ public Calendar create() {

/**
* Creates a new {@link Calendar} instance with the given time zone.
*
*
* @param tz
* {@link TimeZone} to be used
* @return {@link Calendar}
Expand All @@ -86,7 +85,7 @@ public Calendar createWithTimeZone(TimeZone tz) {

/**
* Creates a {@link Calendar} that is set to the PalmOS epoch.
*
*
* @return {@link Calendar} set to the PalmOS epoch.
*/
public Calendar createPalmEpoch() {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/org/shredzone/pdbconverter/ConverterRegister.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@
* A register of all available {@link ExportHandler}.
*
* @author Richard "Shred" Körber
* @version $Revision: 575 $
*/
public final class ConverterRegister {

private static final ExportHandler[] HANDLERS = {
new AddressXmlHandler(),
new ICalendarHandler(),
Expand All @@ -47,24 +46,24 @@ public final class ConverterRegister {
new VCardHandler(),
new ZipHandler(),
};

/**
* Utility class cannot be constructed.
*/
private ConverterRegister() {}

/**
* Gets all registered {@link ExportHandler}.
*
*
* @return Array of {@link ExportHandler}
*/
public static ExportHandler[] getHandlers() {
return HANDLERS;
}

/**
* Finds the {@link ExportHandler} for the given converter name.
*
*
* @param name
* Converter name
* @return {@link ExportHandler} or {@code null} if there is none.
Expand Down
33 changes: 16 additions & 17 deletions src/main/java/org/shredzone/pdbconverter/PdbConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@
* PdbConverter's main class.
*
* @author Richard "Shred" Körber
* @version $Revision: 524 $
*/
@SuppressWarnings("static-access")
public class PdbConverter {

private static final String OPT_CATEGORY = "category";
private static final String OPT_SPLIT = "split";
private static final String OPT_FROM = "from";
private static final String OPT_UNTIL = "until";

private static final DateFormat yearDateFmt = new SimpleDateFormat("yyyy");
private static final DateFormat monthDateFmt = new SimpleDateFormat("yyyy-MM");
private static final DateFormat dayDateFmt = new SimpleDateFormat("yyyy-MM-dd");
Expand All @@ -58,7 +57,7 @@ public class PdbConverter {
monthDateFmt.setLenient(true);
dayDateFmt.setLenient(true);
}

private static final Options CLI_OPTIONS = new Options();
static {
CLI_OPTIONS.addOption(OptionBuilder
Expand All @@ -74,7 +73,7 @@ public class PdbConverter {
.withDescription("converted output file")
.isRequired().hasArg()
.create("o"));

CLI_OPTIONS.addOption(OptionBuilder
.withArgName("converter")
.withLongOpt("converter")
Expand All @@ -88,7 +87,7 @@ public class PdbConverter {
.withDescription("only output records of this category")
.hasArg()
.create("t"));

CLI_OPTIONS.addOption(OptionBuilder
.withArgName(OPT_SPLIT)
.withLongOpt("split")
Expand Down Expand Up @@ -127,7 +126,7 @@ public static void main(String[] args) {
try {
CommandLineParser parser = new GnuParser();
CommandLine cmd = parser.parse(GUI_CLI_OPTIONS, args);

if (cmd.hasOption("gui")) {
new PdbConverterGui();
return;
Expand All @@ -139,34 +138,34 @@ public static void main(String[] args) {
try {
CommandLineParser parser = new GnuParser();
CommandLine cmd = parser.parse(CLI_OPTIONS, args);

if (cmd.hasOption("gui")) {
new PdbConverterGui();
return;
}

String infile = cmd.getOptionValue("input");
String outfile = cmd.getOptionValue("output");
String converter = cmd.getOptionValue("converter", "zip");

ExportHandler handler = ConverterRegister.findHandler(converter);
if (handler == null) {
System.err.println("Unknown converter: " + converter);
printHelp();
System.exit(1);
}

File in = new File(infile);
File out = new File(outfile);

ExportOptions options = new ExportOptions();
options.setSplit(cmd.hasOption(OPT_SPLIT));
options.setCategory(cmd.getOptionValue(OPT_CATEGORY));
options.setFrom(parseDate(cmd.getOptionValue(OPT_FROM)));
options.setUntil(parseDate(cmd.getOptionValue(OPT_UNTIL)));

handler.export(in, out, options);

} catch (IOException ex) {
System.err.println("Could not convert: " + ex.getMessage());

Expand All @@ -178,7 +177,7 @@ public static void main(String[] args) {

/**
* Parses a date string.
*
*
* @param str
* Date string to be parsed. May be {@code null}.
* @return {@link Calendar} object, or {@code null} if a null was passed in.
Expand All @@ -202,12 +201,12 @@ private static Calendar parseDate(String str) throws ParseException {
}
}
}

Calendar cal = CalendarFactory.getInstance().create();
cal.setTime(result);
return cal;
}

/**
* Outputs a help page.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* A very simple Swing application for GUI based file conversion.
*
* @author Richard "Shred" Körber
* @version $Revision: 523 $
*/
public class PdbConverterGui extends JFrame {
private static final long serialVersionUID = -3167361308090208721L;
Expand All @@ -56,4 +55,5 @@ public void run() {
public static void main(String[] args) {
new PdbConverterGui();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
* An abstract implementation of {@link Exporter} that handles filtering.
*
* @author Richard "Shred" Körber
* @version $Revision: 399 $
*/
public abstract class AbstractExporter<T extends Record, U extends AppInfo> implements Exporter<T, U> {

private ExportFilter<T> filter;

@Override
Expand All @@ -40,13 +39,13 @@ public void setFilter(ExportFilter<T> filter) {

/**
* Checks if the current filter accepts the given record.
*
*
* @param record
* {@link Record} to test
* @return {@code true} if the record is accepted
*/
protected boolean isAccepted(T record) {
return (filter == null || filter.accepts(record));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@
* Writes a {@link AddressRecord} database as a single XML file.
*
* @author Richard "Shred" Körber
* @version $Revision: 490 $
*/
public class AddressXmlExporter extends AbstractExporter<AddressRecord, AddressAppInfo> {

/**
* Writes the {@link AddressRecord} database XML to the given {@link OutputStream}.
*
*
* @param database
* {@link AddressRecord} {@link PdbDatabase} to write
* @param out
Expand All @@ -50,11 +49,11 @@ public void export(PdbDatabase<AddressRecord, AddressAppInfo> database, OutputSt
throws IOException {
XmlHelper xh = new XmlHelper();
xh.openXmlWriter(out, "addressdb");

xh.writeDatabase(database);
xh.writeValue("country", database.getAppInfo().getCountry());
xh.writeCategories(database);

writeLabelNames(database.getAppInfo(), xh);

xh.startElement("addresses");
Expand All @@ -72,33 +71,33 @@ public void export(PdbDatabase<AddressRecord, AddressAppInfo> database, OutputSt
}
}
xh.endElement();

xh.closeXmlWriter();
}

/**
* Writes an {@link AddressRecord}.
*
*
* @param address
* {@link AddressRecord} to be written
* @param xh
* {@link XmlHelper} for the output
*/
private void writeAddress(AddressRecord address, XmlHelper xh) throws IOException {
int pref = address.getDisplayPhone();

for (Field field : Field.values()) {
String value = address.getField(field);
Label label = address.getLabel(field);

boolean preferred = false;
if ( label == Label.PHONE1 || label == Label.PHONE2 || label == Label.PHONE3
|| label == Label.PHONE4 || label == Label.PHONE5 || label == Label.PHONE6
|| label == Label.PHONE7 || label == Label.PHONE8) {
preferred = (pref == 0);
pref--;
}

if (value != null) {
if (preferred) {
xh.startElement(
Expand All @@ -123,7 +122,7 @@ private void writeAddress(AddressRecord address, XmlHelper xh) throws IOExceptio

/**
* Writes the label names.
*
*
* @param appinfo
* {@link AddressAppInfo} with the label definitions
* @param xh
Expand All @@ -138,5 +137,5 @@ private void writeLabelNames(AddressAppInfo appinfo, XmlHelper xh) throws IOExce
}
xh.endElement();
}

}
7 changes: 3 additions & 4 deletions src/main/java/org/shredzone/pdbconverter/export/Exporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@
* Generic interface for a database exporter.
*
* @author Richard "Shred" Körber
* @version $Revision: 399 $
*/
public interface Exporter<T extends Record, U extends AppInfo> {

/**
* Sets a filter to only export certain records.
*
*
* @param filter ExportFilter to be used. {@code null} means to use no filter.
*/
void setFilter(ExportFilter<T> filter);

/**
* Exports the database to the given stream.
*
*
* @param database
* {@link PdbDatabase} to be exported
* @param out
Expand Down
Loading

0 comments on commit 67ce9f4

Please sign in to comment.