1 package cx.fbn.nevernote.xml;
\r
4 import java.util.ArrayList;
\r
5 import java.util.List;
\r
7 import com.evernote.edam.type.Note;
\r
8 import com.evernote.edam.type.Resource;
\r
9 import com.trolltech.qt.core.QByteArray;
\r
10 import com.trolltech.qt.core.QDataStream;
\r
11 import com.trolltech.qt.core.QFile;
\r
12 import com.trolltech.qt.core.QIODevice;
\r
13 import com.trolltech.qt.core.QIODevice.OpenModeFlag;
\r
14 import com.trolltech.qt.core.QTemporaryFile;
\r
15 import com.trolltech.qt.core.QUrl;
\r
16 import com.trolltech.qt.core.Qt.BGMode;
\r
17 import com.trolltech.qt.gui.QColor;
\r
18 import com.trolltech.qt.gui.QPainter;
\r
19 import com.trolltech.qt.gui.QPixmap;
\r
20 import com.trolltech.qt.xml.QDomAttr;
\r
21 import com.trolltech.qt.xml.QDomDocument;
\r
22 import com.trolltech.qt.xml.QDomElement;
\r
23 import com.trolltech.qt.xml.QDomNodeList;
\r
25 import cx.fbn.nevernote.Global;
\r
26 import cx.fbn.nevernote.config.FileManager;
\r
27 import cx.fbn.nevernote.filters.EnSearch;
\r
28 import cx.fbn.nevernote.gui.PDFPreview;
\r
29 import cx.fbn.nevernote.sql.DatabaseConnection;
\r
30 import cx.fbn.nevernote.utilities.ApplicationLogger;
\r
32 public class NoteFormatter {
\r
34 private final ApplicationLogger logger;
\r
35 private final DatabaseConnection conn;
\r
36 public boolean resourceError = false;
\r
37 public boolean readOnly = false;
\r
38 public boolean inkNote = false;
\r
39 public boolean addHighlight = true;
\r
40 private Note currentNote;
\r
41 private String currentNoteGuid;
\r
42 private boolean pdfPreview;
\r
43 ArrayList<QTemporaryFile> tempFiles;
\r
44 private EnSearch enSearch;
\r
45 private boolean noteHistory;
\r
47 public NoteFormatter(ApplicationLogger logger, DatabaseConnection conn, List<QTemporaryFile> tempFiles2) {
\r
48 this.logger = logger;
\r
50 noteHistory = false;
\r
54 public void setNote(Note note, boolean pdfPreview) {
\r
56 this.pdfPreview = pdfPreview;
\r
58 currentNoteGuid = null;
\r
60 currentNoteGuid = note.getGuid();
\r
61 readOnly = conn.getNotebookTable().isReadOnly(note.getNotebookGuid());
\r
63 resourceError = false;
\r
66 public void setHighlight(EnSearch search) {
\r
67 if (search==null || search.hilightWords == null ||search.hilightWords.size() == 0) {
\r
69 addHighlight = false;
\r
72 addHighlight = true;
\r
76 // Set if we are coming here through note histary. It triggers longer file names to avoid conflicts
\r
77 public void setNoteHistory(boolean value) {
\r
78 noteHistory = value;
\r
81 // Rebuild the note HTML to something usable
\r
82 public String rebuildNoteHTML() {
\r
83 if (currentNote == null)
\r
85 logger.log(logger.HIGH, "Entering NeverNote.rebuildNoteHTML");
\r
86 logger.log(logger.EXTREME, "Note guid: " +currentNoteGuid);
\r
87 logger.log(logger.EXTREME, "Note Text:" +currentNote);
\r
88 QDomDocument doc = new QDomDocument();
\r
89 QDomDocument.Result result = doc.setContent(currentNote.getContent());
\r
90 if (!result.success) {
\r
91 logger.log(logger.MEDIUM, "Parse error when rebuilding HTML");
\r
92 logger.log(logger.MEDIUM, "Note guid: " +currentNoteGuid);
\r
93 logger.log(logger.EXTREME, "Start of unmodified note HTML");
\r
94 logger.log(logger.EXTREME, currentNote.getContent());
\r
95 logger.log(logger.EXTREME, "End of unmodified note HTML");
\r
96 return currentNote.getContent();
\r
99 if (tempFiles == null)
\r
100 tempFiles = new ArrayList<QTemporaryFile>();
\r
103 doc = modifyTags(doc);
\r
105 doc = addHilight(doc);
\r
106 QDomElement docElem = doc.documentElement();
\r
107 docElem.setTagName("Body");
\r
108 // docElem.setAttribute("bgcolor", "green");
\r
109 logger.log(logger.EXTREME, "Rebuilt HTML:");
\r
110 logger.log(logger.EXTREME, doc.toString());
\r
111 logger.log(logger.HIGH, "Leaving NeverNote.rebuildNoteHTML");
\r
112 // Fix the stupid problem where inserting an <img> tag after an <a> tag (which is done
\r
113 // to get the <en-media> application tag to work properly) causes spaces to be inserted
\r
114 // between the <a> & <img>. This messes things up later. This is an ugly hack.
\r
115 StringBuffer html = new StringBuffer(doc.toString());
\r
116 for (int i=html.indexOf("<a en-tag=\"en-media\" ", 0); i>-1; i=html.indexOf("<a en-tag=\"en-media\" ", i)) {
\r
117 i=html.indexOf(">\n",i+1);
\r
118 int z = html.indexOf("<img",i);
\r
119 for (int j=z-1; j>i; j--)
\r
120 html.deleteCharAt(j);
\r
121 i=html.indexOf("/>", z+1);
\r
122 z = html.indexOf("</a>",i);
\r
123 for (int j=z-1; j>i+1; j--)
\r
124 html.deleteCharAt(j);
\r
126 return html.toString();
\r
129 private void addImageHilight(String resGuid, QFile f) {
\r
130 if (enSearch == null || enSearch.hilightWords == null || enSearch.hilightWords.size() == 0)
\r
133 // Get the recognition XML that tells where to hilight on the image
\r
134 Resource recoResource = conn.getNoteTable().noteResourceTable.getNoteResourceRecognition(resGuid);
\r
135 if (recoResource.getRecognition().getBody() == null || recoResource.getRecognition().getBody().length == 0)
\r
137 QByteArray recoData = new QByteArray(recoResource.getRecognition().getBody());
\r
138 String xml = recoData.toString();
\r
140 // Get a painter for the image. This is the background (the initial image).
\r
141 QPixmap pix = new QPixmap(f.fileName());
\r
142 QPixmap hilightedPix = new QPixmap(pix.size());
\r
143 QPainter p = new QPainter(hilightedPix);
\r
144 p.drawPixmap(0,0, pix);
\r
146 // Create a transparent pixmap. The only non-transparent
\r
147 // piece is the hilight that will be overlayed to hilight text no the background
\r
148 QPixmap overlayPix = new QPixmap(pix.size());
\r
149 QPainter p2 = new QPainter(overlayPix);
\r
150 p2.setBackgroundMode(BGMode.TransparentMode);
\r
151 p2.setBrush(QColor.yellow);
\r
153 // Get the recognition data from the note
\r
154 QDomDocument doc = new QDomDocument();
\r
155 doc.setContent(xml);
\r
157 // Go through all "item" nodes
\r
158 QDomNodeList anchors = doc.elementsByTagName("item");
\r
159 for (int i=0; i<anchors.length(); i++) {
\r
160 QDomElement element = anchors.at(i).toElement();
\r
161 int x = new Integer(element.attribute("x")); // x coordinate
\r
162 int y = new Integer(element.attribute("y")); // y coordinate
\r
163 int w = new Integer(element.attribute("w")); // width
\r
164 int h = new Integer(element.attribute("h")); // height
\r
165 QDomNodeList children = element.childNodes(); // all children ("t" nodes).
\r
167 // Go through the children ("t" nodes)
\r
168 for (int j=0; j<children.length(); j++) {
\r
169 QDomElement child = children.at(j).toElement();
\r
170 if (child.nodeName().equalsIgnoreCase("t")) {
\r
171 String text = child.text(); // recognition text
\r
172 int weight = new Integer(child.attribute("w")); // recognition weight
\r
173 if (weight >= Global.getRecognitionWeight()) { // Are we above the maximum?
\r
175 // Check to see if this word matches something we were searching for.
\r
176 for (int k=0; k<enSearch.hilightWords.size(); k++) {
\r
177 String searchWord = enSearch.hilightWords.get(k).toLowerCase();
\r
178 if (searchWord.startsWith("*"))
\r
179 searchWord = searchWord.substring(1);
\r
180 if (searchWord.endsWith("*"))
\r
181 searchWord = searchWord.substring(0,searchWord.length()-1);
\r
182 if (text.toLowerCase().contains(searchWord))
\r
183 p2.drawRect(x,y,w,h);
\r
191 // Paint the hilight onto the background.
\r
192 p.setOpacity(0.40);
\r
193 p.drawPixmap(0,0, overlayPix);
\r
196 // Save over the initial pixmap.
\r
197 hilightedPix.save(f.fileName());
\r
200 // Modify the en-media tag into an image tag so it can be displayed.
\r
201 private void modifyImageTags(QDomElement docElem, QDomElement enmedia, QDomAttr hash) {
\r
202 logger.log(logger.HIGH, "Entering NeverNote.modifyImageTags");
\r
203 String type = enmedia.attribute("type");
\r
204 if (type.startsWith("image/"))
\r
205 type = "."+type.substring(6);
\r
209 String resGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(currentNoteGuid, hash.value());
\r
210 QFile tfile = new QFile(Global.getFileManager().getResDirPath(resGuid + type));
\r
211 // if (!tfile.exists()) {
\r
213 if (resGuid != null)
\r
214 r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid,true);
\r
215 if (r==null || r.getData() == null || r.getData().getBody().length == 0) {
\r
216 resourceError = true;
\r
219 if (r!= null && r.getData() != null && r.getData().getBody().length > 0) {
\r
220 tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));
\r
221 QByteArray binData = new QByteArray(r.getData().getBody());
\r
222 tfile.write(binData);
\r
225 // If we have recognition text, outline it
\r
226 addImageHilight(r.getGuid(), tfile);
\r
228 enmedia.setAttribute("src", QUrl.fromLocalFile(tfile.fileName()).toString());
\r
229 enmedia.setAttribute("en-tag", "en-media");
\r
230 enmedia.setNodeValue("");
\r
231 enmedia.setAttribute("guid", r.getGuid());
\r
232 enmedia.setTagName("img");
\r
235 // Technically, we should do a file:// to have a proper url, but for some reason QWebPage hates
\r
236 // them and won't generate a thumbnail image properly if we use them.
\r
237 // enmedia.setAttribute("src", QUrl.fromLocalFile(tfile.fileName()).toString());
\r
238 enmedia.setAttribute("src", tfile.fileName().toString());
\r
239 enmedia.setAttribute("en-tag", "en-media");
\r
240 enmedia.setAttribute("onContextMenu", "window.jambi.imageContextMenu('" +tfile.fileName() +"');");
\r
241 enmedia.setNodeValue("");
\r
242 enmedia.setAttribute("guid", resGuid);
\r
243 enmedia.setTagName("img");
\r
245 logger.log(logger.HIGH, "Leaving NeverNote.modifyImageTags");
\r
249 // Modify tags from Evernote specific things to XHTML tags.
\r
250 private QDomDocument modifyTags(QDomDocument doc) {
\r
251 logger.log(logger.HIGH, "Entering NeverNote.modifyTags");
\r
252 if (tempFiles == null)
\r
253 tempFiles = new ArrayList<QTemporaryFile>();
\r
255 QDomElement docElem = doc.documentElement();
\r
257 // Modify en-media tags
\r
258 QDomNodeList anchors = docElem.elementsByTagName("en-media");
\r
259 int enMediaCount = anchors.length();
\r
260 for (int i=enMediaCount-1; i>=0; i--) {
\r
261 QDomElement enmedia = anchors.at(i).toElement();
\r
262 if (enmedia.hasAttribute("type")) {
\r
263 QDomAttr attr = enmedia.attributeNode("type");
\r
264 QDomAttr hash = enmedia.attributeNode("hash");
\r
265 String[] type = attr.nodeValue().split("/");
\r
266 String appl = type[1];
\r
268 if (type[0] != null) {
\r
269 if (type[0].equals("image")) {
\r
270 modifyImageTags(docElem, enmedia, hash);
\r
272 if (!type[0].equals("image")) {
\r
273 modifyApplicationTags(doc, docElem, enmedia, hash, appl);
\r
279 // Modify todo tags
\r
280 anchors = docElem.elementsByTagName("en-todo");
\r
281 int enTodoCount = anchors.length();
\r
282 for (int i=enTodoCount-1; i>=0; i--) {
\r
283 QDomElement enmedia = anchors.at(i).toElement();
\r
284 modifyTodoTags(enmedia);
\r
287 // Modify en-crypt tags
\r
288 anchors = docElem.elementsByTagName("en-crypt");
\r
289 int enCryptLen = anchors.length();
\r
290 for (int i=enCryptLen-1; i>=0; i--) {
\r
291 QDomElement enmedia = anchors.at(i).toElement();
\r
292 enmedia.setAttribute("contentEditable","false");
\r
293 enmedia.setAttribute("src", Global.getFileManager().getImageDirPath("encrypt.png"));
\r
294 enmedia.setAttribute("en-tag","en-crypt");
\r
295 enmedia.setAttribute("alt", enmedia.text());
\r
296 Global.cryptCounter++;
\r
297 enmedia.setAttribute("id", "crypt"+Global.cryptCounter.toString());
\r
298 String encryptedText = enmedia.text();
\r
300 // If the encryption string contains crlf at the end, remove them because they mess up the javascript.
\r
301 if (encryptedText.endsWith("\n"))
\r
302 encryptedText = encryptedText.substring(0,encryptedText.length()-1);
\r
303 if (encryptedText.endsWith("\r"))
\r
304 encryptedText = encryptedText.substring(0,encryptedText.length()-1);
\r
306 // Add the commands
\r
307 String hint = enmedia.attribute("hint");
\r
308 hint = hint.replace("'","'");
\r
309 enmedia.setAttribute("onClick", "window.jambi.decryptText('crypt"+Global.cryptCounter.toString()+"', '"+encryptedText+"', '"+hint+"');");
\r
310 enmedia.setAttribute("onMouseOver", "style.cursor='hand'");
\r
311 enmedia.setTagName("img");
\r
312 enmedia.removeChild(enmedia.firstChild()); // Remove the actual encrypted text
\r
316 // Modify link tags
\r
317 anchors = docElem.elementsByTagName("a");
\r
318 enCryptLen = anchors.length();
\r
319 for (int i=0; i<anchors.length(); i++) {
\r
320 QDomElement element = anchors.at(i).toElement();
\r
321 element.setAttribute("title", element.attribute("href"));
\r
324 logger.log(logger.HIGH, "Leaving NeverNote.modifyTags");
\r
329 // Get an ink note image. If an image doesn't exist then we fall back
\r
330 // to the old ugly icon
\r
331 private boolean buildInkNote(QDomDocument doc, QDomElement docElem, QDomElement enmedia, QDomAttr hash, String appl) {
\r
332 String resGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(currentNote.getGuid(), hash.value());
\r
333 Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid, false);
\r
335 // If we can't find the resource, then fall back to the old method. We'll return & show
\r
337 if (r == null || r.getData() == null)
\r
340 // If there isn't some type of error, continue on.
\r
341 if (!resourceError) {
\r
343 // Get a list of images in the database. We'll use these to bulid the page.
\r
344 List<QByteArray> data = conn.getInkImagesTable().getImage(r.getGuid());
\r
346 // If no pictures are found, go back to & just show the icon
\r
347 if (data.size() == 0)
\r
350 // We have pictures, so append them to the page. This really isn't proper since
\r
351 // we leave the en-media tag in place, but since we can't edit the page it doesn't
\r
353 for (int i=0; i<data.size(); i++) {
\r
354 QFile f = new QFile(Global.getFileManager().getResDirPath(resGuid + new Integer(i).toString()+".png"));
\r
355 f.open(OpenModeFlag.WriteOnly);
\r
356 f.write(data.get(i));
\r
358 QDomElement newImage = doc.createElement("img");
\r
359 newImage.setAttribute("src", QUrl.fromLocalFile(f.fileName()).toString());
\r
360 enmedia.appendChild(newImage);
\r
368 // Modify the en-media tag into an attachment
\r
369 private void modifyApplicationTags(QDomDocument doc, QDomElement docElem, QDomElement enmedia, QDomAttr hash, String appl) {
\r
370 logger.log(logger.HIGH, "Entering NeverNote.modifyApplicationTags");
\r
371 if (appl.equalsIgnoreCase("vnd.evernote.ink")) {
\r
373 if (buildInkNote(doc, docElem, enmedia, hash, appl))
\r
376 String resGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(currentNote.getGuid(), hash.value());
\r
377 Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid, false);
\r
378 if (r == null || r.getData() == null)
\r
379 resourceError = true;
\r
381 if (r.getData()!=null) {
\r
382 // Did we get a generic applicaiton? Then look at the file name to
\r
383 // try and find a good application type for the icon
\r
384 if (appl.equalsIgnoreCase("octet-stream")) {
\r
385 if (r.getAttributes() != null && r.getAttributes().getFileName() != null) {
\r
386 String fn = r.getAttributes().getFileName();
\r
387 int pos = fn.lastIndexOf(".");
\r
389 appl = fn.substring(pos+1);
\r
394 String fileDetails = null;
\r
395 if (r.getAttributes() != null && r.getAttributes().getFileName() != null && !r.getAttributes().getFileName().equals(""))
\r
396 fileDetails = r.getAttributes().getFileName();
\r
397 String contextFileName;
\r
398 FileManager fileManager = Global.getFileManager();
\r
399 if (fileDetails != null && !fileDetails.equals("")) {
\r
400 if (!noteHistory) {
\r
401 enmedia.setAttribute("href", "nnres://" +r.getGuid()
\r
402 +Global.attachmentNameDelimeter +fileDetails);
\r
403 contextFileName = fileManager.getResDirPath(r.getGuid()
\r
404 +Global.attachmentNameDelimeter + fileDetails);
\r
406 enmedia.setAttribute("href", "nnres://" +r.getGuid() + currentNote.getUpdateSequenceNum()
\r
407 +Global.attachmentNameDelimeter +fileDetails);
\r
408 contextFileName = fileManager.getResDirPath(r.getGuid() + currentNote.getUpdateSequenceNum()
\r
409 +Global.attachmentNameDelimeter + fileDetails);
\r
412 if (!noteHistory) {
\r
413 enmedia.setAttribute("href", "nnres://" +r.getGuid() +currentNote.getUpdateSequenceNum()
\r
414 +Global.attachmentNameDelimeter +appl);
\r
415 contextFileName = fileManager.getResDirPath(r.getGuid() +currentNote.getUpdateSequenceNum()
\r
416 +Global.attachmentNameDelimeter + appl);
\r
418 enmedia.setAttribute("href", "nnres://" +r.getGuid()
\r
419 +Global.attachmentNameDelimeter +appl);
\r
420 contextFileName = fileManager.getResDirPath(r.getGuid()
\r
421 +Global.attachmentNameDelimeter + appl);
\r
424 contextFileName = contextFileName.replace("\\", "/");
\r
425 enmedia.setAttribute("onContextMenu", "window.jambi.resourceContextMenu('" +contextFileName +"');");
\r
426 if (fileDetails == null || fileDetails.equals(""))
\r
428 enmedia.setAttribute("en-tag", "en-media");
\r
429 enmedia.setAttribute("guid", r.getGuid());
\r
430 enmedia.setTagName("a");
\r
431 QDomElement newText = doc.createElement("img");
\r
432 boolean goodPreview = false;
\r
433 String filePath = "";
\r
434 if (appl.equalsIgnoreCase("pdf") && pdfPreview) {
\r
436 Resource res = conn.getNoteTable().noteResourceTable.getNoteResource(r.getGuid(), true);
\r
437 if (res.getAttributes() != null &&
\r
438 res.getAttributes().getFileName() != null &&
\r
439 !res.getAttributes().getFileName().trim().equals(""))
\r
440 fileName = res.getGuid()+Global.attachmentNameDelimeter+res.getAttributes().getFileName();
\r
442 fileName = res.getGuid()+".pdf";
\r
443 QFile file = new QFile(fileManager.getResDirPath(fileName));
\r
444 QFile.OpenMode mode = new QFile.OpenMode();
\r
445 mode.set(QFile.OpenModeFlag.WriteOnly);
\r
447 QDataStream out = new QDataStream(file);
\r
448 Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(res.getGuid(), true);
\r
449 QByteArray binData = new QByteArray(resBinary.getData().getBody());
\r
451 out.writeBytes(binData.toByteArray());
\r
453 PDFPreview pdfPreview = new PDFPreview();
\r
454 goodPreview = pdfPreview.setupPreview(file.fileName(), appl,0);
\r
456 QDomElement span = doc.createElement("span");
\r
457 QDomElement table = doc.createElement("table");
\r
458 span.setAttribute("pdfNavigationTable", "true");
\r
459 QDomElement tr = doc.createElement("tr");
\r
460 QDomElement td = doc.createElement("td");
\r
461 QDomElement left = doc.createElement("img");
\r
462 left.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
\r
463 left.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
\r
464 left.setAttribute("onMouseOver", "style.cursor='hand'");
\r
465 QDomElement right = doc.createElement("img");
\r
466 right.setAttribute("onMouseDown", "window.jambi.nextPage('" +file.fileName() +"')");
\r
467 left.setAttribute("onMouseDown", "window.jambi.previousPage('" +file.fileName() +"')");
\r
468 // NFC TODO: should these be file:// URLs?
\r
469 left.setAttribute("src", Global.getFileManager().getImageDirPath("small_left.png"));
\r
470 right.setAttribute("src", Global.getFileManager().getImageDirPath("small_right.png"));
\r
471 right.setAttribute("onMouseOver", "style.cursor='hand'");
\r
473 table.appendChild(tr);
\r
474 tr.appendChild(td);
\r
475 td.appendChild(left);
\r
476 td.appendChild(right);
\r
477 span.appendChild(table);
\r
478 enmedia.parentNode().insertBefore(span, enmedia);
\r
480 filePath = fileName+".png";
\r
482 String icon = findIcon(appl);
\r
483 if (icon.equals("attachment.png"))
\r
484 icon = findIcon(fileDetails.substring(fileDetails.indexOf(".")+1));
\r
485 // NFC TODO: should this be a 'file://' URL?
\r
486 newText.setAttribute("src", Global.getFileManager().getImageDirPath(icon));
\r
488 // NFC TODO: should this be a 'file://' URL?
\r
489 newText.setAttribute("src", fileManager.getResDirPath(filePath));
\r
490 newText.setAttribute("style", "border-style:solid; border-color:green; padding:0.5mm 0.5mm 0.5mm 0.5mm;");
\r
492 newText.setAttribute("title", fileDetails);
\r
493 enmedia.removeChild(enmedia.firstChild());
\r
495 enmedia.appendChild(newText);
\r
498 logger.log(logger.HIGH, "Leaving NeverNote.modifyApplicationTags");
\r
500 // Modify the en-to tag into an input field
\r
501 private void modifyTodoTags(QDomElement todo) {
\r
502 logger.log(logger.HIGH, "Entering NeverNote.modifyTodoTags");
\r
503 todo.setAttribute("type", "checkbox");
\r
504 String checked = todo.attribute("checked");
\r
505 todo.removeAttribute("checked");
\r
506 if (checked.equalsIgnoreCase("true"))
\r
507 todo.setAttribute("checked", "");
\r
509 todo.setAttribute("unchecked","");
\r
510 todo.setAttribute("value", checked);
\r
511 todo.setAttribute("onClick", "value=checked;window.jambi.contentChanged(); ");
\r
512 todo.setAttribute("onMouseOver", "style.cursor='hand'");
\r
513 todo.setTagName("input");
\r
514 logger.log(logger.HIGH, "Leaving NeverNote.modifyTodoTags");
\r
519 // Modify any cached todo tags that may have changed
\r
520 public String modifyCachedTodoTags(String note) {
\r
521 logger.log(logger.HIGH, "Entering NeverNote.modifyCachedTodoTags");
\r
522 StringBuffer html = new StringBuffer(note);
\r
523 for (int i=html.indexOf("<input", 0); i>-1; i=html.indexOf("<input", i)) {
\r
524 int endPos =html.indexOf(">",i+1);
\r
525 String input = html.substring(i,endPos);
\r
526 if (input.indexOf("value=\"true\"") > 0)
\r
527 input = input.replace(" unchecked=\"\"", " checked=\"\"");
\r
529 input = input.replace(" checked=\"\"", " unchecked=\"\"");
\r
530 html.replace(i, endPos, input);
\r
533 logger.log(logger.HIGH, "Leaving NeverNote.modifyCachedTodoTags");
\r
534 return html.toString();
\r
540 // Scan and do hilighting of words
\r
541 public QDomDocument addHilight(QDomDocument doc) {
\r
542 // EnSearch e = listManager.getEnSearch();
\r
543 if (enSearch.hilightWords == null || enSearch.hilightWords.size() == 0)
\r
545 XMLInsertHilight hilight = new XMLInsertHilight(doc, enSearch.hilightWords);
\r
546 return hilight.getDoc();
\r
550 // find the appropriate icon for an attachment
\r
551 private String findIcon(String appl) {
\r
552 logger.log(logger.HIGH, "Entering NeverNote.findIcon");
\r
553 appl = appl.toLowerCase();
\r
554 String relativePath = appl + ".png";
\r
555 File f = Global.getFileManager().getImageDirFile(relativePath);
\r
557 return relativePath;
\r
560 return appl+".png";
\r
561 logger.log(logger.HIGH, "Leaving NeverNote.findIcon");
\r
562 return "attachment.png";
\r