Hi!
The following code can import metadata from Excel to create the archive folder
structure acceptable for DSpace batch import. Attached is the program code and
please share your comments. If anyone wants to try this code please let me
know. I would be happy to assist.
Thanks,
Jayan
/**
* @(#)MetaDataImport.java
*
*
* @author Jayan C Kurian, SCI, Nanyang Technological University, Singapore
* @version 1.00 2007/5/11
*/
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.io.*;
import java.nio.channels.*;
public class MetaDataImport
{
public static void main( String [] args )
{
Connection c = null;
Statement stmnt = null;
int initialDocumentNo=1;
System.out.print("Enter Your Main Archive Folder Name: ");
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
String readFolderName = null;
String archiveFolderName = null;
try
{
readFolderName = br.readLine();
archiveFolderName = readFolderName.toUpperCase();
File mainArchiveDirectory= new File("c:/"+ archiveFolderName);
mainArchiveDirectory.mkdir();
Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver" );
c = DriverManager.getConnection("jdbc:odbc:qalist","","");
stmnt = c.createStatement();
String query = "select * from [qas$]";
ResultSet rs = stmnt.executeQuery( query );
while( rs.next() )
{
File itemArchiveDirectory= new File(mainArchiveDirectory,archiveFolderName +
"_" + initialDocumentNo);
itemArchiveDirectory.mkdir();
File contentSource = new File(rs.getString( "url" ));
String path = contentSource.getAbsolutePath().trim();
int findItemType = path.indexOf(".");
File contentDestination=null;
File dublinCoreFile = new File(itemArchiveDirectory, "dublin_core.xml");
dublinCoreFile.createNewFile();
File contentsFile = new File(itemArchiveDirectory, "contents");
contentsFile.createNewFile();
BufferedWriter out = new BufferedWriter(new FileWriter(dublinCoreFile));
BufferedWriter outFC = new BufferedWriter(new FileWriter(contentsFile));
out.write("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n");
if (path.substring(findItemType+1 ,findItemType+4).equals("pdf"))
{ contentDestination = new File(itemArchiveDirectory,archiveFolderName + "_" +
initialDocumentNo + ".pdf");
out.write("<!-- title of pdf " + archiveFolderName + "_" + initialDocumentNo +
".pdf-->\n");
outFC.write(archiveFolderName + "_" + initialDocumentNo + ".pdf");
System.out.println("Metadata created for " + archiveFolderName + "_" +
initialDocumentNo + ".pdf");
}
if (path.substring(findItemType+1 ,findItemType+4).equals("doc"))
{contentDestination = new File(itemArchiveDirectory,archiveFolderName + "_" +
initialDocumentNo + ".doc");
out.write("<!-- title of doc " + archiveFolderName + "_" + initialDocumentNo +
".doc-->\n");
outFC.write(archiveFolderName + "_" + initialDocumentNo + ".doc");
System.out.println("Metadata created for " + archiveFolderName + "_" +
initialDocumentNo + ".doc");
}
if (path.substring(findItemType+1 ,findItemType+4).equals("jpg"))
{contentDestination = new File(itemArchiveDirectory,archiveFolderName + "_" +
initialDocumentNo + ".jpg");
out.write("<!-- title of jpg " + archiveFolderName + "_" + initialDocumentNo +
".jpg-->\n");
outFC.write(archiveFolderName + "_" + initialDocumentNo + ".jpg");
System.out.println("Metadata created for " + archiveFolderName + "_" +
initialDocumentNo + ".jpg");
}
if (path.substring(findItemType+1 ,findItemType+4).equals("txt"))
{contentDestination = new File(itemArchiveDirectory,archiveFolderName + "_" +
initialDocumentNo + ".txt");
out.write("<!-- title of txt " + archiveFolderName + "_" + initialDocumentNo +
".txt-->\n");
outFC.write(archiveFolderName + "_" + initialDocumentNo + ".txt");
System.out.println("Metadata created for " + archiveFolderName + "_" +
initialDocumentNo + ".txt");
}
copyFile(contentSource, contentDestination);
initialDocumentNo++;
out.write("<dublin_core>\n");
out.write(" <dcvalue element=\"creator\" qualifier=\"conference\"> ");
out.write( rs.getString( "creator" ) );
out.write("</dcvalue>\n");
out.write(" <dcvalue element=\"title\" qualifier=\"none\"> ");
out.write( rs.getString( "title" ) );
out.write("</dcvalue>\n");
out.write("<dcvalue element=\"contributor\" qualifier=\"author\">");
out.write( rs.getString( "contributor" ) );
out.write("</dcvalue>\n");
out.write("<dcvalue element=\"date\" qualifier=\"issued\"> ");
out.write( rs.getString( "date" ).substring(0,10));
out.write("</dcvalue>\n");
out.write("</dublin_core>");
out.close();
outFC.close();
}
}
catch( Exception e )
{
System.err.println( e );
}
finally
{
try
{
stmnt.close();
c.close();
}
catch( Exception e )
{
System.err.println( e );
}
}
}
public static void copyFile(File sourceFile, File destFile) throws IOException
{
FileChannel contentSource = null;
FileChannel contentDestination = null;
try {
contentSource = new FileInputStream(sourceFile).getChannel();
contentDestination = new FileOutputStream(destFile).getChannel();
contentDestination.transferFrom(contentSource, 0, contentSource.size());
}
finally {
if(contentSource != null) {
contentSource.close();
}
if(contentDestination != null) {
contentDestination.close();
}
}
}
}
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
DSpace-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-tech