-
-
-
- //**********************************************************
- //**********************************************************
- //* XML Modifying methods
- //**********************************************************
- //**********************************************************
- // find the appropriate icon for an attachment
- private String findIcon(String appl) {
- logger.log(logger.HIGH, "Entering NeverNote.findIcon");
- appl = appl.toLowerCase();
- String relativePath = appl + ".png";
- File f = Global.getFileManager().getImageDirFile(relativePath);
- if (f.exists()) {
- return relativePath;
- }
- if (f.exists())
- return appl+".png";
- logger.log(logger.HIGH, "Leaving NeverNote.findIcon");
- return "attachment.png";
- }
- // Modify the en-media tag into an attachment
- private void modifyApplicationTags(QDomDocument doc, QDomElement docElem, QDomElement enmedia, QDomAttr hash, String appl) {
- logger.log(logger.HIGH, "Entering NeverNote.modifyApplicationTags");
- if (appl.equalsIgnoreCase("vnd.evernote.ink"))
- inkNote = true;
- String resGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(currentNote.getGuid(), hash.value());
- Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid, false);
- if (r == null || r.getData() == null)
- resourceErrorMessage();
- 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("")) {
- enmedia.setAttribute("href", "nnres://" +r.getGuid() +Global.attachmentNameDelimeter +fileDetails);
- contextFileName = fileManager.getResDirPath(r.getGuid() + Global.attachmentNameDelimeter + fileDetails);
- } 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") && Global.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);
- if (goodPreview) {
- QDomElement span = doc.createElement("span");
- QDomElement table = doc.createElement("table");
- span.setAttribute("pdfNavigationTable", "true");
- QDomElement tr = doc.createElement("tr");
- QDomElement td = doc.createElement("td");
- QDomElement left = doc.createElement("img");
- left.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
- left.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
- left.setAttribute("onMouseOver", "style.cursor='hand'");
- QDomElement right = doc.createElement("img");
- right.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
- left.setAttribute("onMouseDown", "window.jambi.previousPage('" +file.fileName() +"')");
- // NFC TODO: should these be file:// URLs?
- left.setAttribute("src", Global.getFileManager().getImageDirPath("small_left.png"));
- right.setAttribute("src", Global.getFileManager().getImageDirPath("small_right.png"));
- right.setAttribute("onMouseOver", "style.cursor='hand'");
-
- table.appendChild(tr);
- tr.appendChild(td);
- td.appendChild(left);
- td.appendChild(right);
- span.appendChild(table);
- enmedia.parentNode().insertBefore(span, enmedia);
- }
- filePath = fileName+".png";
- }
- String icon = findIcon(appl);
- if (icon.equals("attachment.png"))
- icon = findIcon(fileDetails.substring(fileDetails.indexOf(".")+1));
- // NFC TODO: should this be a 'file://' URL?
- newText.setAttribute("src", Global.getFileManager().getImageDirPath(icon));
- if (goodPreview) {
- // NFC TODO: should this be a 'file://' URL?
- newText.setAttribute("src", fileManager.getResDirPath(filePath));
- newText.setAttribute("style", "border-style:solid; border-color:green; padding:0.5mm 0.5mm 0.5mm 0.5mm;");
- }
- newText.setAttribute("title", fileDetails);
- enmedia.removeChild(enmedia.firstChild());
-
- enmedia.appendChild(newText);
- }
- }
- logger.log(logger.HIGH, "Leaving NeverNote.modifyApplicationTags");
- }
- // Modify the en-to tag into an input field
- private void modifyTodoTags(QDomElement todo) {
- logger.log(logger.HIGH, "Entering NeverNote.modifyTodoTags");
- todo.setAttribute("type", "checkbox");
- String checked = todo.attribute("checked");
- todo.removeAttribute("checked");
- if (checked.equalsIgnoreCase("true"))
- todo.setAttribute("checked", "");
- else
- todo.setAttribute("unchecked","");
- todo.setAttribute("value", checked);
- todo.setAttribute("onClick", "value=checked;window.jambi.contentChanged(); ");
- todo.setTagName("input");
- logger.log(logger.HIGH, "Leaving NeverNote.modifyTodoTags");
- }
- // Modify any cached todo tags that may have changed
- private String modifyCachedTodoTags(String note) {
- logger.log(logger.HIGH, "Entering NeverNote.modifyCachedTodoTags");
- StringBuffer html = new StringBuffer(note);
- for (int i=html.indexOf("<input", 0); i>-1; i=html.indexOf("<input", i)) {
- int endPos =html.indexOf(">",i+1);
- String input = html.substring(i,endPos);
- if (input.indexOf("value=\"true\"") > 0)
- input = input.replace(" unchecked=\"\"", " checked=\"\"");
- else
- input = input.replace(" checked=\"\"", " unchecked=\"\"");
- html.replace(i, endPos, input);
- i++;