Package com.trolltech.qt.xml

Examples of com.trolltech.qt.xml.QDomElement


    tempFiles.clear();
   
    doc = modifyTags(doc);
    if (addHighlight)
      doc = addHilight(doc);
    QDomElement docElem = doc.documentElement();
    docElem.setTagName("Body");
//    docElem.setAttribute("bgcolor", "green");
    logger.log(logger.EXTREME, "Rebuilt HTML:");
    logger.log(logger.EXTREME, doc.toString())
    logger.log(logger.HIGH, "Leaving NeverNote.rebuildNoteHTML");
    // Fix the stupid problem where inserting an <img> tag after an <a> tag (which is done
View Full Code Here


      doc.setContent(xml);
     
      // Go through all "item" nodes
    QDomNodeList anchors = doc.elementsByTagName("item");
    for (int i=0; i<anchors.length(); i++) {
      QDomElement element = anchors.at(i).toElement();
      int x = new Integer(element.attribute("x"));   // x coordinate
      int y = new Integer(element.attribute("y"));   // y coordinate
      int w = new Integer(element.attribute("w"));   // width
      int h = new Integer(element.attribute("h"));   // height
      QDomNodeList children = element.childNodes()// all children ("t" nodes).
     
      // Go through the children ("t" nodes)
      for (int j=0; j<children.length(); j++) {
          QDomElement child = children.at(j).toElement();
          if (child.nodeName().equalsIgnoreCase("t")) {
            String text = child.text();   // recognition text
            int weight = new Integer(child.attribute("w"))// recognition weight
            if (weight >= Global.getRecognitionWeight()) {   // Are we above the maximum?
             
              // Check to see if this word matches something we were searching for.
              for (int k=0; k<enSearch.hilightWords.size(); k++) {
                String searchWord = enSearch.hilightWords.get(k).toLowerCase();
View Full Code Here

    enmedia.setTagName("img");
    if (r != null && r.getAttributes() != null &&
        (r.getAttributes().getSourceURL() == null || !r.getAttributes().getSourceURL().toLowerCase().startsWith("http://latex.codecogs.com/gif.latex?")))
      enmedia.setAttribute("onContextMenu", "window.jambi.imageContextMenu('" +tfile.fileName()  +"');");
    else {
      QDomElement newText = doc.createElement("a");
      enmedia.setAttribute("src", tfile.fileName().toString());
      enmedia.setAttribute("en-tag", "en-latex");
      newText.setAttribute("onMouseOver", "style.cursor='hand'");
      if (r!= null && r.getAttributes() != null && r.getAttributes().getSourceURL() != null)
        newText.setAttribute("title", r.getAttributes().getSourceURL());
      newText.setAttribute("href", "latex://"+tfile.fileName().toString());
      enmedia.parentNode().replaceChild(newText, enmedia);
      newText.appendChild(enmedia);

    }
    enmedia.setNodeValue("");
    enmedia.setAttribute("guid", resGuid);
View Full Code Here

  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("'","&apos;");
      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;
View Full Code Here

      for (int i=0; i<data.size(); i++) {
          QFile f = new QFile(Global.getFileManager().getResDirPath(resGuid + new Integer(i).toString()+".png"));
        f.open(OpenModeFlag.WriteOnly);
        f.write(data.get(i));
        f.close();
        QDomElement newImage = doc.createElement("img");
        newImage.setAttribute("src", QUrl.fromLocalFile(f.fileName()).toString());
        enmedia.appendChild(newImage);
      }
      return true;
    }
      return false;
View Full Code Here

        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);
          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);
View Full Code Here

    }
       
    List<String> returnArray = new ArrayList<String>();
    QDomNodeList anchors = doc.elementsByTagName("en-media");
    for (int i=0; i<anchors.length(); i++) {
      QDomElement enmedia = anchors.at(i).toElement();
      if (enmedia.hasAttribute("type")) {
        QDomAttr hash = enmedia.attributeNode("hash");
        returnArray.add(hash.value().toString());
      }
    }
    logger.log(logger.HIGH, "Leaving ListManager.scanNoteForResources");
    return returnArray;
View Full Code Here

    conn.commitTransaction();
    uncommittedCount = 0;
    conn.beginTransaction();
     
    doc.setContent(resourceBinary);
    QDomElement docElem = doc.documentElement();
     
    // look for text tags
    QDomNodeList anchors = docElem.elementsByTagName("t");
    for (int i=0; i<anchors.length() && keepRunning; i++) {
      if (interrupt) {
        if (interrupt) {
          processInterrupt();
        }
      }
      QDomElement enmedia = anchors.at(i).toElement();
      String weight = new String(enmedia.attribute("w"));
      String text = new String(enmedia.text()).toLowerCase();
      if (!text.equals("")) {
        conn.getWordsTable().addWordToNoteIndex(r.getNoteGuid(), text, "RESOURCE", new Integer(weight));
        uncommittedCount++;
        if (uncommittedCount > 100) {
          conn.commitTransaction();
View Full Code Here

      if (!valueStart.equals("")) {
        QDomText startText = doc.createTextNode(valueStart);
        fragment.appendChild(startText);
      }
     
      QDomElement hilight = doc.createElement("en-hilight");
      hilight.appendChild(doc.createTextNode(valueMiddle));
      fragment.appendChild(hilight);
    }
    if (matchFound) {
      if (previousPosition != value.length()) {
        QDomText endText = doc.createTextNode(valueEnd);
View Full Code Here

    QDomNodeList anchors;
    for (String key : Global.invalidAttributes.keySet()) {
      anchors = doc.elementsByTagName(key);
      int enMediaCount = anchors.length();
      for (int i=enMediaCount-1; i>=0; i--) {
        QDomElement element = anchors.at(i).toElement();
        ArrayList<String> names = Global.invalidAttributes.get(element.nodeName().toLowerCase());
        if (names != null) { 
          for (int j=0; j<names.size(); j++) {
            element.removeAttribute(names.get(j));
          }
        }
      }
    }

    List<String> elements = Global.invalidElements;
    for (int j=0; j<elements.size(); j++) {
      anchors = doc.elementsByTagName(elements.get(j));
      int enMediaCount = anchors.length();
      for (int i=enMediaCount-1; i>=0; i--) {
        QDomElement element = anchors.at(i).toElement();
        element.setTagName("span");
      }
    }
    // Replace the XML carrage returns that the toString() creates.
    content = doc.toString().replace( "&#xd;", "" );
View Full Code Here

TOP

Related Classes of com.trolltech.qt.xml.QDomElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.