[daisy] Daisy detachment
tim_cranfield at goldenboat.net
tim_cranfield at goldenboat.net
Tue Jul 11 02:03:24 CDT 2006
In the detachment project we need to be able to persist a
Document offline. It was suggested that we use an XML file
written with document.getXml(), and a separate file for
anything else useful like branch and language names.
http://lists.cocoondev.org/pipermail/daisy/2006-July/004380.html
Looking at the methods for DocumentDocument, I'm wondering if
and how its possible to set fields, links and parts.
Another issue I'm having is with unzipping detachment files. I
think the problem is with my zip method :
public static File zipDetachment(String dir2zip,
ZipOutputStream zos){
//create a new File object based on the directory we have to
zip
File zipDir = new File(dir2zip);
zipDir.mkdir();
try {
//get a listing of the directory content
String[] dirList = zipDir.list();
byte[] readBuffer = new byte[2156];
int bytesIn = 0;
//loop through dirList, and zip the files
for(int i=0; i<dirList.length; i++) {
File f = new File(zipDir, dirList[i]);
if(f.isDirectory()) {
//if the File object is a directory, call
this
//function again to add its content
recursively
String filePath = f.getPath();
zipDetachment(filePath, zos);
//loop again
continue;
}
//if we reached here, the File object f was not
a directory
//create a FileInputStream on top of f
FileInputStream fis = new FileInputStream(f);
//create a new zip entry
ZipEntry anEntry = new ZipEntry(f.getPath());
//place the zip entry in the ZipOutputStream
object
zos.putNextEntry(anEntry);
//now write the content of the file to the
ZipOutputStream
while((bytesIn = fis.read(readBuffer)) != -1){
zos.write(readBuffer, 0, bytesIn);
fis.close();
}
zos.close();
}
} catch(Exception e) {
//handle exception
}
return zipDir;
}
When I list the contents of the zipped file:
entries = zipFile.entries();
while(entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry)entries.nextElement();
System.out.println(entry.getName());
}
The directories are not listed and the paths are printed
instead of the name. This does not happen when I use the above
code on other zip files. It may be an issue with the file
separator character, I have tried various things without
success.
More information about the daisy
mailing list