}
/** Parse a .mdb file and return a list of referenced .lsm files. */
private String[] parseMDB(String mdbFile) throws FormatException, IOException
{
Location mdb = new Location(mdbFile).getAbsoluteFile();
Location parent = mdb.getParentFile();
MDBService mdbService = null;
try {
ServiceFactory factory = new ServiceFactory();
mdbService = factory.getInstance(MDBService.class);
}
catch (DependencyException de) {
throw new FormatException("MDB Tools Java library not found", de);
}
try {
mdbService.initialize(mdbFile);
}
catch (Exception e) {
return null;
}
Vector<Vector<String[]>> tables = mdbService.parseDatabase();
mdbService.close();
Vector<String> referencedLSMs = new Vector<String>();
int referenceCount = 0;
for (Vector<String[]> table : tables) {
String[] columnNames = table.get(0);
String tableName = columnNames[0];
for (int row=1; row<table.size(); row++) {
String[] tableRow = table.get(row);
for (int col=0; col<tableRow.length; col++) {
String key = tableName + " " + columnNames[col + 1];
if (currentId != null) {
addGlobalMetaList(key, tableRow[col]);
}
if (tableName.equals("Recordings") && columnNames[col + 1] != null &&
columnNames[col + 1].equals("SampleData"))
{
String filename = tableRow[col].trim();
filename = filename.replace('\\', File.separatorChar);
filename = filename.replace('/', File.separatorChar);
filename =
filename.substring(filename.lastIndexOf(File.separator) + 1);
if (filename.length() > 0) {
Location file = new Location(parent, filename);
if (file.exists()) {
referencedLSMs.add(file.getAbsolutePath());
}
}
referenceCount++;
}
}
}
}
if (referencedLSMs.size() == referenceCount) {
return referencedLSMs.toArray(new String[0]);
}
String[] fileList = parent.list(true);
Arrays.sort(fileList);
for (int i=0; i<fileList.length; i++) {
String absolutePath = new Location(parent, fileList[i]).getAbsolutePath();
if (checkSuffix(fileList[i], "mdb") &&
(!absolutePath.equals(mdbFile) && !fileList[i].equals(mdbFile)))
{
if (referencedLSMs.size() > 0) {
return referencedLSMs.toArray(new String[0]);
}
break;
}
}
referencedLSMs.clear();
int mdbCount = 0;
for (int i=0; i<fileList.length; i++) {
String absolutePath = new Location(parent, fileList[i]).getAbsolutePath();
if (checkSuffix(fileList[i], "lsm")) {
referencedLSMs.add(absolutePath);
}
else if (checkSuffix(fileList[i], "mdb")) {
mdbCount++;
}
}
if (mdbCount > 1 || ((referencedLSMs.size() > referenceCount) &&
mdbCount > 1))
{
for (int i=0; i<fileList.length; i++) {
String absolutePath =
new Location(parent, fileList[i]).getAbsolutePath();
if (checkSuffix(fileList[i], "mdb") && !absolutePath.endsWith(mdbFile))
{
String[] files = parseMDB(absolutePath);
for (String f : files) {
referencedLSMs.remove(f);