Skip to content

Commit f16d02b

Browse files
committed
Finish sax parser for doc index and use mapdb to map data
1 parent 825b50e commit f16d02b

13 files changed

Lines changed: 325 additions & 85 deletions

dbptk-modules/dbptk-module-siard/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
<artifactId>xercesImpl</artifactId>
6363
</dependency>
6464

65+
<dependency>
66+
<groupId>com.h2database</groupId>
67+
<artifactId>h2</artifactId>
68+
<version>2.4.240</version>
69+
</dependency>
70+
6571
<!-- misc dependencies -->
6672
<dependency>
6773
<groupId>org.apache.commons</groupId>

dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDK1007ExtMetadataImportStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void loadMetadata(ReadStrategy readStrategy, SIARDArchiveContainer contai
143143
tableIndexUnmarshaller = tableIndexContext.createUnmarshaller();
144144
tableIndexUnmarshaller.setSchema(tableIndexXsdSchema);
145145
tableIndexInputStreamXml = readStrategyMD5Sum.createInputStream(container,
146-
pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTabelIndexExpectedMD5Sum());
146+
pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTableIndexExpectedMD5Sum());
147147
xmlRoot = (SiardDiark) tableIndexUnmarshaller.unmarshal(tableIndexInputStreamXml);
148148

149149
archiveIndexUnmarshaller = archiveIndexContext.createUnmarshaller();

dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDK1007MetadataImportStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void loadMetadata(ReadStrategy readStrategy, SIARDArchiveContainer contai
142142
tableIndexUnmarshaller = tableIndexContext.createUnmarshaller();
143143
tableIndexUnmarshaller.setSchema(tableIndexXsdSchema);
144144
tableIndexInputStreamXml = readStrategyMD5Sum.createInputStream(container,
145-
pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTabelIndexExpectedMD5Sum());
145+
pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTableIndexExpectedMD5Sum());
146146
xmlRoot = (SiardDiark) tableIndexUnmarshaller.unmarshal(tableIndexInputStreamXml);
147147

148148
archiveIndexUnmarshaller = archiveIndexContext.createUnmarshaller();

dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDK128ExtMetadataImportStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void loadMetadata(ReadStrategy readStrategy, SIARDArchiveContainer contai
142142
tableIndexUnmarshaller = tableIndexContext.createUnmarshaller();
143143
tableIndexUnmarshaller.setSchema(tableIndexXsdSchema);
144144
tableIndexInputStreamXml = readStrategyMD5Sum.createInputStream(container,
145-
pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTabelIndexExpectedMD5Sum());
145+
pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTableIndexExpectedMD5Sum());
146146
xmlRoot = (SiardDiark) tableIndexUnmarshaller.unmarshal(tableIndexInputStreamXml);
147147

148148
archiveIndexUnmarshaller = archiveIndexContext.createUnmarshaller();

dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/metadata/SIARDDK128MetadataImportStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void loadMetadata(ReadStrategy readStrategy, SIARDArchiveContainer contai
142142
tableIndexUnmarshaller = tableIndexContext.createUnmarshaller();
143143
tableIndexUnmarshaller.setSchema(tableIndexXsdSchema);
144144
tableIndexInputStreamXml = readStrategyMD5Sum.createInputStream(container,
145-
pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTabelIndexExpectedMD5Sum());
145+
pathStrategy.getXmlFilePath(SIARDDKConstants.TABLE_INDEX), pathStrategy.getTableIndexExpectedMD5Sum());
146146
xmlRoot = (SiardDiark) tableIndexUnmarshaller.unmarshal(tableIndexInputStreamXml);
147147

148148
archiveIndexUnmarshaller = archiveIndexContext.createUnmarshaller();

dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDK1007ExtPathImportStrategy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public SIARDDK1007ExtPathImportStrategy(SIARDArchiveContainer mainFolder, ReadSt
3131
FileIndexType.class);
3232
}
3333

34+
@Override
35+
SIARDDKFileIndexHandler<F> createFileIndexHandler() {
36+
return null;
37+
}
38+
3439
@Override
3540
byte[] getMd5(F fileInfo) {
3641
return fileInfo.getMd5();

dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDK1007PathImportStrategy.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,32 @@
88
package com.databasepreservation.modules.siard.in.path;
99

1010
import java.util.List;
11-
import com.databasepreservation.modules.siard.bindings.siard_dk_1007.FileIndexType;
12-
import com.databasepreservation.modules.siard.bindings.siard_dk_1007.FileIndexType.F;
13-
import com.databasepreservation.modules.siard.common.SIARDArchiveContainer;
14-
import com.databasepreservation.modules.siard.in.read.ReadStrategy;
11+
1512
import org.slf4j.Logger;
1613
import org.slf4j.LoggerFactory;
1714

15+
import com.databasepreservation.modules.siard.bindings.siard_dk_1007.FileIndexType;
16+
import com.databasepreservation.modules.siard.bindings.siard_dk_1007.FileIndexType.F;
17+
import com.databasepreservation.modules.siard.common.SIARDArchiveContainer;
1818
import com.databasepreservation.modules.siard.common.path.MetadataPathStrategy;
19+
import com.databasepreservation.modules.siard.in.read.ReadStrategy;
1920

2021
/**
2122
* @author António Lindo <alindo@keep.pt>
2223
*/
2324
public class SIARDDK1007PathImportStrategy extends SIARDDKPathImportStrategy<FileIndexType.F, FileIndexType> {
2425
protected final Logger logger = LoggerFactory.getLogger(ContentPathImportStrategy.class);
2526

26-
public SIARDDK1007PathImportStrategy(SIARDArchiveContainer mainFolder, ReadStrategy readStrategy, MetadataPathStrategy metadataPathStrategy, String importAsSchema, FileIndexXsdInputStreamStrategy fileIndexXsdInputStreamStrategy) {
27-
super(mainFolder, readStrategy, metadataPathStrategy, importAsSchema, fileIndexXsdInputStreamStrategy, FileIndexType.class);
27+
public SIARDDK1007PathImportStrategy(SIARDArchiveContainer mainFolder, ReadStrategy readStrategy,
28+
MetadataPathStrategy metadataPathStrategy, String importAsSchema,
29+
FileIndexXsdInputStreamStrategy fileIndexXsdInputStreamStrategy) {
30+
super(mainFolder, readStrategy, metadataPathStrategy, importAsSchema, fileIndexXsdInputStreamStrategy,
31+
FileIndexType.class);
32+
}
33+
34+
@Override
35+
SIARDDKFileIndexHandler<F> createFileIndexHandler() {
36+
return null;
2837
}
2938

3039
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.databasepreservation.modules.siard.in.path;
2+
3+
import java.nio.file.Path;
4+
import java.util.Map;
5+
6+
import org.apache.commons.codec.DecoderException;
7+
import org.apache.commons.codec.binary.Hex;
8+
import org.xml.sax.Attributes;
9+
import org.xml.sax.SAXException;
10+
11+
import com.databasepreservation.modules.siard.bindings.siard_dk_128_ext.FileIndexType;
12+
13+
/**
14+
* @author Alexandre Flores <aflores@keep.pt>
15+
*/
16+
public class SIARDDK128ExtFileIndexHandler extends SIARDDKFileIndexHandler<FileIndexType.F> {
17+
18+
public SIARDDK128ExtFileIndexHandler(Map<String, Path> archiveFolderLookupByFolderName,
19+
Map<String, FileIndexType.F> xsdFilePathLookupByFolderName,
20+
Map<String, FileIndexType.F> xmlFilePathLookupByFolderName) {
21+
super(archiveFolderLookupByFolderName, xsdFilePathLookupByFolderName, xmlFilePathLookupByFolderName);
22+
}
23+
24+
@Override
25+
protected void startElementFile(String uri, String localName, String qName, Attributes attributes) {
26+
this.currentFile = new FileIndexType.F();
27+
}
28+
29+
@Override
30+
protected void endElementFileName() throws SAXException {
31+
this.currentFile.setFiN(this.currentElementCharacters.toString());
32+
}
33+
34+
@Override
35+
protected void endElementFolderName() throws SAXException {
36+
this.currentFile.setFoN(this.currentElementCharacters.toString());
37+
}
38+
39+
@Override
40+
protected void endElementMD5() throws SAXException {
41+
try {
42+
this.currentFile.setMd5(Hex.decodeHex(this.currentElementCharacters.toString()));
43+
} catch (DecoderException e) {
44+
throw new SAXException("Unable to decode MD5 hex string", e);
45+
}
46+
}
47+
48+
@Override
49+
String getFileLocalName() {
50+
return "f";
51+
}
52+
53+
@Override
54+
String getFileNameLocalName() {
55+
return "fiN";
56+
}
57+
58+
@Override
59+
String getFolderNameLocalName() {
60+
return "foN";
61+
}
62+
63+
@Override
64+
String getMD5LocalName() {
65+
return "md5";
66+
}
67+
68+
@Override
69+
String getCurrentFileName() {
70+
return this.currentFile.getFiN();
71+
}
72+
73+
@Override
74+
String getCurrentFolderName() {
75+
return this.currentFile.getFoN();
76+
}
77+
78+
@Override
79+
byte[] getCurrentMD5() {
80+
return this.currentFile.getMd5();
81+
}
82+
}

dbptk-modules/dbptk-module-siard/src/main/java/com/databasepreservation/modules/siard/in/path/SIARDDK128ExtPathImportStrategy.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public SIARDDK128ExtPathImportStrategy(SIARDArchiveContainer mainFolder, ReadStr
2727
FileIndexType.class);
2828
}
2929

30+
@Override
31+
SIARDDKFileIndexHandler<F> createFileIndexHandler() {
32+
return new SIARDDK128ExtFileIndexHandler(archiveFolderLookupByFolderName, xsdFilePathLookupByFolderName,
33+
xmlFilePathLookupByFolderName);
34+
}
35+
3036
@Override
3137
byte[] getMd5(F fileInfo) {
3238
return fileInfo.getMd5();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.databasepreservation.modules.siard.in.path;
2+
3+
import java.nio.file.Path;
4+
import java.util.Map;
5+
6+
import org.apache.commons.codec.DecoderException;
7+
import org.apache.commons.codec.binary.Hex;
8+
import org.xml.sax.Attributes;
9+
import org.xml.sax.SAXException;
10+
11+
import com.databasepreservation.modules.siard.bindings.siard_dk_128.FileIndexType;
12+
13+
/**
14+
* @author Alexandre Flores <aflores@keep.pt>
15+
*/
16+
public class SIARDDK128FileIndexHandler extends SIARDDKFileIndexHandler<FileIndexType.F> {
17+
18+
public SIARDDK128FileIndexHandler(Map<String, Path> archiveFolderLookupByFolderName,
19+
Map<String, FileIndexType.F> xsdFilePathLookupByFolderName,
20+
Map<String, FileIndexType.F> xmlFilePathLookupByFolderName) {
21+
super(archiveFolderLookupByFolderName, xsdFilePathLookupByFolderName, xmlFilePathLookupByFolderName);
22+
}
23+
24+
@Override
25+
protected void startElementFile(String uri, String localName, String qName, Attributes attributes) {
26+
this.currentFile = new FileIndexType.F();
27+
}
28+
29+
@Override
30+
protected void endElementFileName() throws SAXException {
31+
this.currentFile.setFiN(this.currentElementCharacters.toString());
32+
}
33+
34+
@Override
35+
protected void endElementFolderName() throws SAXException {
36+
this.currentFile.setFoN(this.currentElementCharacters.toString());
37+
}
38+
39+
@Override
40+
protected void endElementMD5() throws SAXException {
41+
try {
42+
this.currentFile.setMd5(Hex.decodeHex(this.currentElementCharacters.toString()));
43+
} catch (DecoderException e) {
44+
throw new SAXException("Unable to decode MD5 hex string", e);
45+
}
46+
}
47+
48+
@Override
49+
String getFileLocalName() {
50+
return "f";
51+
}
52+
53+
@Override
54+
String getFileNameLocalName() {
55+
return "fiN";
56+
}
57+
58+
@Override
59+
String getFolderNameLocalName() {
60+
return "foN";
61+
}
62+
63+
@Override
64+
String getMD5LocalName() {
65+
return "md5";
66+
}
67+
68+
@Override
69+
String getCurrentFileName() {
70+
return this.currentFile.getFiN();
71+
}
72+
73+
@Override
74+
String getCurrentFolderName() {
75+
return this.currentFile.getFoN();
76+
}
77+
78+
@Override
79+
byte[] getCurrentMD5() {
80+
return this.currentFile.getMd5();
81+
}
82+
}

0 commit comments

Comments
 (0)