private QDomDocument modifyTags(QDomDocument doc) {
logger.log(logger.HIGH, "Entering NeverNote.modifyTags");
if (tempFiles == null)
tempFiles = new ArrayList<QTemporaryFile>();
tempFiles.clear();
QDomElement docElem = doc.documentElement();
// Modify en-media tags
QDomNodeList anchors = docElem.elementsByTagName("en-media");
int enMediaCount = anchors.length();
for (int i=enMediaCount-1; i>=0; --i) {
QDomElement enmedia = anchors.at(i).toElement();
if (enmedia.hasAttribute("type")) {
QDomAttr attr = enmedia.attributeNode("type");
QDomAttr hash = enmedia.attributeNode("hash");
String[] type = attr.nodeValue().split("/");
String appl = type[1];
if (type[0] != null) {
if (type[0].equals("image")) {
modifyImageTags(doc, docElem, enmedia, hash);
}
if (!type[0].equals("image")) {
modifyApplicationTags(doc, docElem, enmedia, hash, appl);
}
}
}
}
// Modify todo tags
anchors = docElem.elementsByTagName("en-todo");
int enTodoCount = anchors.length();
for (int i=enTodoCount-1; i>=0; i--) {
QDomElement enmedia = anchors.at(i).toElement();
modifyTodoTags(enmedia);
}
// Modify en-crypt tags
anchors = docElem.elementsByTagName("en-crypt");
int enCryptLen = anchors.length();
for (int i=enCryptLen-1; i>=0; i--) {
QDomElement enmedia = anchors.at(i).toElement();
enmedia.setAttribute("contentEditable","false");
enmedia.setAttribute("src", Global.getFileManager().getImageDirPath("encrypt.png"));
enmedia.setAttribute("en-tag","en-crypt");
enmedia.setAttribute("alt", enmedia.text());
Global.cryptCounter++;
enmedia.setAttribute("id", "crypt"+Global.cryptCounter.toString());
String encryptedText = enmedia.text();
// If the encryption string contains crlf at the end, remove them because they mess up the javascript.
if (encryptedText.endsWith("\n"))
encryptedText = encryptedText.substring(0,encryptedText.length()-1);
if (encryptedText.endsWith("\r"))
encryptedText = encryptedText.substring(0,encryptedText.length()-1);
// Add the commands
String hint = enmedia.attribute("hint");
hint = hint.replace("'","'");
enmedia.setAttribute("onClick", "window.jambi.decryptText('crypt"+Global.cryptCounter.toString()+"', '"+encryptedText+"', '"+hint+"');");
enmedia.setAttribute("onMouseOver", "style.cursor='hand'");
enmedia.setTagName("img");
enmedia.removeChild(enmedia.firstChild()); // Remove the actual encrypted text
}
// Modify link tags
anchors = docElem.elementsByTagName("a");
enCryptLen = anchors.length();
for (int i=0; i<anchors.length(); i++) {
QDomElement element = anchors.at(i).toElement();
if (!element.attribute("href").toLowerCase().startsWith("latex://"))
element.setAttribute("title", element.attribute("href"));
else {
element.setAttribute("title", element.attribute("title").toLowerCase().replace("http://latex.codecogs.com/gif.latex?",""));
}
}
logger.log(logger.HIGH, "Leaving NeverNote.modifyTags");
return doc;