inkNote = true;
if (buildInkNote(doc, docElem, enmedia, hash, appl))
return;
}
String resGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(currentNote.getGuid(), hash.value());
Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid, false);
if (r == null || r.getData() == null)
resourceError = true;
if (r!= null) {
if (r.getData()!=null) {
// Did we get a generic applicaiton? Then look at the file name to
// try and find a good application type for the icon
if (appl.equalsIgnoreCase("octet-stream")) {
if (r.getAttributes() != null && r.getAttributes().getFileName() != null) {
String fn = r.getAttributes().getFileName();
int pos = fn.lastIndexOf(".");
if (pos > -1) {
appl = fn.substring(pos+1);
}
}
}
String fileDetails = null;
if (r.getAttributes() != null && r.getAttributes().getFileName() != null && !r.getAttributes().getFileName().equals(""))
fileDetails = r.getAttributes().getFileName();
String contextFileName;
FileManager fileManager = Global.getFileManager();
if (fileDetails != null && !fileDetails.equals("")) {
if (!noteHistory) {
enmedia.setAttribute("href", "nnres://" +r.getGuid()
+Global.attachmentNameDelimeter +fileDetails);
contextFileName = fileManager.getResDirPath(r.getGuid()
+Global.attachmentNameDelimeter + fileDetails);
} else {
enmedia.setAttribute("href", "nnres://" +r.getGuid() + currentNote.getUpdateSequenceNum()
+Global.attachmentNameDelimeter +fileDetails);
contextFileName = fileManager.getResDirPath(r.getGuid() + currentNote.getUpdateSequenceNum()
+Global.attachmentNameDelimeter + fileDetails);
}
} else {
if (!noteHistory) {
enmedia.setAttribute("href", "nnres://" +r.getGuid() +currentNote.getUpdateSequenceNum()
+Global.attachmentNameDelimeter +appl);
contextFileName = fileManager.getResDirPath(r.getGuid() +currentNote.getUpdateSequenceNum()
+Global.attachmentNameDelimeter + appl);
} else {
enmedia.setAttribute("href", "nnres://" +r.getGuid()
+Global.attachmentNameDelimeter +appl);
contextFileName = fileManager.getResDirPath(r.getGuid()
+Global.attachmentNameDelimeter + appl);
}
}
contextFileName = contextFileName.replace("\\", "/");
enmedia.setAttribute("onContextMenu", "window.jambi.resourceContextMenu('" +contextFileName +"');");
if (fileDetails == null || fileDetails.equals(""))
fileDetails = "";
enmedia.setAttribute("en-tag", "en-media");
enmedia.setAttribute("guid", r.getGuid());
enmedia.setTagName("a");
QDomElement newText = doc.createElement("img");
boolean goodPreview = false;
String filePath = "";
if (appl.equalsIgnoreCase("pdf") && pdfPreview) {
String fileName;
Resource res = conn.getNoteTable().noteResourceTable.getNoteResource(r.getGuid(), true);
if (res.getAttributes() != null &&
res.getAttributes().getFileName() != null &&
!res.getAttributes().getFileName().trim().equals(""))
fileName = res.getGuid()+Global.attachmentNameDelimeter+res.getAttributes().getFileName();
else
fileName = res.getGuid()+".pdf";
QFile file = new QFile(fileManager.getResDirPath(fileName));
QFile.OpenMode mode = new QFile.OpenMode();
mode.set(QFile.OpenModeFlag.WriteOnly);
file.open(mode);
QDataStream out = new QDataStream(file);
Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(res.getGuid(), true);
QByteArray binData = new QByteArray(resBinary.getData().getBody());
resBinary = null;
out.writeBytes(binData.toByteArray());
file.close();
PDFPreview pdfPreview = new PDFPreview();
goodPreview = pdfPreview.setupPreview(file.fileName(), appl,0);