import org.dom4j.io.XMLWriter;
public class CreateLibraryPresentation {
public static ConverterProcessResult generateXMLDocument(File targetDirectory, String originalDocument,
String pdfDocument, String swfDocument){
ConverterProcessResult returnMap = new ConverterProcessResult();
returnMap.setProcess("generateXMLDocument");
try {
Document document = DocumentHelper.createDocument();
Element root = document.addElement( "presentation" );
File file = new File(targetDirectory, originalDocument);
root.addElement( "originalDocument" )
.addAttribute("lastmod", (new Long(file.lastModified())).toString())
.addAttribute("size", (new Long(file.length())).toString())
.addText( originalDocument );
if (pdfDocument!=null){
File pdfDocumentFile = new File(targetDirectory, pdfDocument);
root.addElement( "pdfDocument" )
.addAttribute("lastmod", (new Long(pdfDocumentFile.lastModified())).toString())
.addAttribute("size", (new Long(pdfDocumentFile.length())).toString())
.addText( pdfDocument );
}
if (swfDocument!=null){
File swfDocumentFile = new File(targetDirectory, originalDocument);
root.addElement( "swfDocument" )
.addAttribute("lastmod", (new Long(swfDocumentFile.lastModified())).toString())
.addAttribute("size", (new Long(swfDocumentFile.length())).toString())
.addText( swfDocument );
}
Element thumbs = root.addElement( "thumbs" );
//Secoond get all Files of this Folder
FilenameFilter ff = new FilenameFilter() {
public boolean accept(File b, String name) {
File f = new File(b, name);
return f.isFile();
}
};
String[] allfiles = targetDirectory.list(ff);
if(allfiles!=null){
Arrays.sort(allfiles);
for(int i=0; i<allfiles.length; i++){
File thumbfile = new File(targetDirectory, allfiles[i]);
if (allfiles[i].startsWith(thumbImagePrefix)){
thumbs.addElement( "thumb" )
.addAttribute("lastmod", (new Long(thumbfile.lastModified())).toString())
.addAttribute("size", (new Long(thumbfile.length())).toString())
.addText( allfiles[i] );
}
}
}
// lets write to a file
XMLWriter writer = new XMLWriter(
new FileOutputStream(new File(targetDirectory, OmFileHelper.libraryFileName))
);
writer.write( document );
writer.close();
returnMap.setExitValue("0");
return returnMap;
} catch (Exception err) {
err.printStackTrace();
returnMap.setError(err.getMessage());
returnMap.setExitValue("-1");
return returnMap;
}
}