Package com.evernote.edam.type

Examples of com.evernote.edam.type.Resource


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


      index = guid.indexOf(Global.attachmentNameDelimeter);
      if (index > -1) {
        guid = guid.substring(0,index);
      }
      List<Resource> resList = currentNote.getResources();
      Resource res = null;
      for (int i=0; i<resList.size(); i++) {
        if (resList.get(i).getGuid().equals(guid)) {
          res = resList.get(i);
          i=resList.size();
        }
      }
      if (res == null) {
        String resGuid = Global.resourceMap.get(guid);
        if (resGuid != null)
          res = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid, true);
      }
      if (res != null) {
        String fileName;
        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()+"."+type;
        QFile file = new QFile(Global.getFileManager().getResDirPath(fileName));
            QFile.OpenMode mode = new QFile.OpenMode();
            mode.set(QFile.OpenModeFlag.WriteOnly);
            boolean openResult = file.open(mode);
        logger.log(logger.EXTREME, "File opened:" +openResult);
            QDataStream out = new QDataStream(file);
            Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(res.getGuid(), true);
        QByteArray binData = new QByteArray(resBinary.getData().getBody());
        resBinary = null;
        logger.log(logger.EXTREME, "Writing resource");
            out.writeBytes(binData.toByteArray());
            file.close();
             
View Full Code Here

    QUrl replyUrl = reply.url();   
    QByteArray image = reply.readAll();
    reply.close();
    logger.log(logger.EXTREME, "New image size: " +image.size());

    Resource newRes = null;
    QFile tfile;
    String path;
    if (latexGuid == null) {
      logger.log(logger.EXTREME, "Creating temporary gif");     
      path = Global.getFileManager().getResDirPath("latex-temp.gif");
      tfile = new QFile(path);
      tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));
      logger.log(logger.EXTREME, "File Open: " +tfile.errorString());
      tfile.write(image);
      logger.log(logger.EXTREME, "Bytes writtes: "+tfile.size());
      tfile.close();
      logger.log(logger.EXTREME, "Creating resource");
      int sequence = 0;
      if (currentNote.getResources() != null || currentNote.getResources().size() > 0)
        sequence = currentNote.getResources().size();
      newRes = createResource(path,sequence ,"image/gif", false);
      QImage pix = new QImage();
      pix.loadFromData(image);
      newRes.setHeight(new Integer(pix.height()).shortValue());
      newRes.setWidth(new Integer(pix.width()).shortValue());
      logger.log(logger.EXTREME, "Renaming temporary file to " +newRes.getGuid()+".gif");
      path = Global.getFileManager().getResDirPath(newRes.getGuid()+".gif");
      tfile.rename(path);
    } else {
      newRes = conn.getNoteTable().noteResourceTable.getNoteResource(latexGuid, false);
      path = Global.getFileManager().getResDirPath(newRes.getGuid()+".gif");
      tfile = new QFile(path);
      tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));
      tfile.write(image);
      tfile.close();
      newRes.getData().setBody(image.toByteArray());
      // Calculate the new hash value
        MessageDigest md;

        logger.log(logger.EXTREME, "Generating MD5");
        try {
        md = MessageDigest.getInstance("MD5");
          md.update(image.toByteArray());
          byte[] hash = md.digest();
          newRes.getData().setBodyHash(hash);
      } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
      }
      QImage pix = new QImage();
      pix.loadFromData(image);
      newRes.setHeight(new Integer(pix.height()).shortValue());
      newRes.setWidth(new Integer(pix.width()).shortValue());
      conn.getNoteTable().noteResourceTable.updateNoteResource(newRes, true);
    }

    logger.log(logger.EXTREME, "Setting source: " +replyUrl.toString());
    newRes.getAttributes().setSourceURL(replyUrl.toString());
    conn.getNoteTable().noteResourceTable.updateNoteSourceUrl(newRes.getGuid(), replyUrl.toString(), true);
   
    for(int i=0; i<currentNote.getResourcesSize(); i++) {
      if (currentNote.getResources().get(i).getGuid().equals(newRes.getGuid())) {
        currentNote.getResources().remove(i);
        i=currentNote.getResourcesSize();
      }
    }
    currentNote.getResources().add(newRes);
   

    // do the actual insert into the note.  We only do this on new formulas. 
    if (latexGuid == null) {
      StringBuffer buffer = new StringBuffer(100);
      String formula = replyUrl.toString().toLowerCase().replace("http://latex.codecogs.com/gif.latex?", "");
      buffer.append("<a href=\"latex://"+path.replace("\\", "/")+"\" title=\""+formula+"\""
          +"><img src=\"");
      buffer.append(path.replace("\\", "/"));
      buffer.append("\" en-tag=\"en-latex\" type=\"image/gif\""
        +" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\""
        +" guid=\"" +newRes.getGuid() +"\""
        + " /></a>");
   
      String script_start = new String("document.execCommand('insertHTML', false, '");
      String script_end = new String("');");
      browser.page().mainFrame().evaluateJavaScript(
View Full Code Here

        logger.log(logger.EXTREME, "Saving note");
        conn.getNoteTable().updateNoteSequence(enNote.getGuid(), enNote.getUpdateSequenceNum());
        List<Resource> rl = enNote.getResources();
        logger.log(logger.EXTREME, "Getting note resources");
        for (int j=0; j<enNote.getResourcesSize() && keepRunning; j++) {
          Resource newRes = rl.get(j);
          Data d = newRes.getData();
          if (d!=null) { 
            logger.log(logger.EXTREME, "Calculating resource hash");
            String hash = byteArrayToHexString(d.getBodyHash());
            logger.log(logger.EXTREME, "updating resources by hash");
            String oldGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(enNote.getGuid(), hash);
            conn.getNoteTable().updateNoteResourceGuidbyHash(enNote.getGuid(), newRes.getGuid(), hash);
            resourceSignal.resourceGuidChanged.emit(enNote.getGuid(), oldGuid, newRes.getGuid());
          }
        }
        logger.log(logger.EXTREME, "Resetting note dirty flag");
        conn.getNoteTable().resetDirtyFlag(enNote.getGuid());
        updateSequenceNumber = enNote.getUpdateSequenceNum();
View Full Code Here

      tfile.close();
      return;
    }
    tfile.close();
   
    Resource newRes = createResource(QUrl.fromLocalFile(path).toString(), 0, "image/jpeg", false);
    if (newRes == null)
      return;
    currentNote.getResources().add(newRes);

    // do the actual insert into the note
    StringBuffer buffer = new StringBuffer(100);
    buffer.append("<img src=\"");
    buffer.append(tfile.fileName());
    buffer.append("\" en-tag=en-media type=\"image/jpeg\""
        +" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\""
        +" guid=\"" +newRes.getGuid() +"\""
        +" onContextMenu=\"window.jambi.imageContextMenu(&amp." +tfile.fileName() +"&amp.);\""
        + " />");
   
    browser.page().mainFrame().evaluateJavaScript(
        script_start + buffer + script_end);
View Full Code Here

    // Copy the image over into the resource directory and create a new resource
    // record for each url pasted
    for (int i = 0; i < urlList.size(); i++) {
      url = urlList.get(i).toString();

      Resource newRes = createResource(url, i, mimeType, false);
      if (newRes == null)
        return;
      currentNote.getResources().add(newRes);
      buffer = new StringBuffer(100);
     
      // Open the file & write the data
      String fileName = Global.getFileManager().getResDirPath(newRes.getGuid());
      QFile tfile = new QFile(fileName);
      tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));
      tfile.write(newRes.getData().getBody());
      tfile.close();
      buffer.append(script_start_image);
      buffer.append("<img src=\"" + FileUtils.toForwardSlashedPath(fileName));
//      if (mimeType.equalsIgnoreCase("image/jpg"))
//        mimeType = "image/jpeg";
      buffer.append("\" en-tag=\"en-media\" type=\"" + mimeType +"\""
          +" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\""
          +" guid=\"" +newRes.getGuid() +"\""
          +" onContextMenu=\"window.jambi.imageContextMenu(&apos;" +tfile.fileName() +"&apos;);\""
          + " />");
      buffer.append(script_end);
      browser.page().mainFrame().evaluateJavaScript(buffer.toString());
    }
View Full Code Here

    Note n = conn.getNoteTable().getNote(resource.getNoteGuid(), false, false, false, false, false);
    if (n!=null) {
      logger.log(logger.HIGH, "Resource for note " +n.getGuid() +" : " +n.getTitle());
    }
    boolean saveNeeded = false;
    /* #1 */    Resource r = getEvernoteResource(noteStore, resource.getGuid(), true,true,true, authToken);
            Resource l = conn.getNoteTable().noteResourceTable.getNoteResource(r.getGuid(), false);
            if (l == null) {
              logger.log(logger.HIGH, "Local resource not found");
              saveNeeded = true;
            } else {
    /* #2 */      boolean isNoteDirty = conn.getNoteTable().isNoteDirty(r.getNoteGuid());
              if (!isNoteDirty) {
                logger.log(logger.HIGH, "Local resource found, but is not dirty");
                saveNeeded = true;
              } else {
    /* #3 */        String remoteHash = "";
                if (r != null && r.getData() != null && r.getData().getBodyHash() != null)
                  remoteHash = byteArrayToHexString(r.getData().getBodyHash());
                String localHash = "";
                if (l != null && l.getData() != null && l.getData().getBodyHash() != null)
                  remoteHash = byteArrayToHexString(l.getData().getBodyHash());
           
                if (localHash.equalsIgnoreCase(remoteHash))
                  saveNeeded = true;
              }
            }
View Full Code Here

      if (icon.equals("attachment.png"))
        icon = findIcon(url.substring(url.lastIndexOf(".")+1));
      String imageURL = FileUtils.toFileURLString(Global.getFileManager().getImageDirFile(icon));

      logger.log(logger.EXTREME, "Creating resource ");
      Resource newRes = createResource(url, i, mimeType, true);
      if (newRes == null)
        return;
      logger.log(logger.EXTREME, "New resource size: " +newRes.getData().getSize());
      currentNote.getResources().add(newRes);
     
      String fileName = newRes.getGuid() + Global.attachmentNameDelimeter+newRes.getAttributes().getFileName();
      // If we have a PDF, we need to setup the preview.
      if (icon.equalsIgnoreCase("pdf.png") && Global.pdfPreview()) {
        logger.log(logger.EXTREME, "Setting up PDF preview");
        if (newRes.getAttributes() != null &&
            newRes.getAttributes().getFileName() != null &&
            !newRes.getAttributes().getFileName().trim().equals(""))
          fileName = newRes.getGuid()+Global.attachmentNameDelimeter+
            newRes.getAttributes().getFileName();
        else
          fileName = newRes.getGuid()+".pdf";
        QFile file = new QFile(Global.getFileManager().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(newRes.getGuid(), true);
        QByteArray binData = new QByteArray(newRes.getData().getBody());
//        resBinary = null;
            out.writeBytes(binData.toByteArray());
            file.close();

        PDFPreview pdfPreview = new PDFPreview();
        if (pdfPreview.setupPreview(Global.getFileManager().getResDirPath(fileName), "pdf",0)) {
              imageURL = file.fileName() + ".png";
        }
      }
     
      logger.log(logger.EXTREME, "Generating link tags");
      buffer.delete(0, buffer.length());
      buffer.append("<a en-tag=\"en-media\" guid=\"" +newRes.getGuid()+"\" ");
      buffer.append(" onContextMenu=\"window.jambi.imageContextMenu(&apos;")
          .append(Global.getFileManager().getResDirPath(fileName))
          .append("&apos;);\" ");     
      buffer.append("type=\"" + mimeType + "\" href=\"nnres://" + fileName +"\" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\" >");
      buffer.append("<img src=\"" + imageURL + "\" title=\"" +newRes.getAttributes().getFileName());
      buffer.append("\"></img>");
      buffer.append("</a>");
      browser.page().mainFrame().evaluateJavaScript(
          script_start + buffer.toString() + script_end);
    }
View Full Code Here

      e.printStackTrace();
    }
    return n;
  }
  private Resource getEvernoteResource(Client noteStore, String guid, boolean withData, boolean withRecognition, boolean withAttributes, String token) {
    Resource n = null;
    try {
      logger.log(logger.EXTREME, "Retrieving resource " +guid);
      n = noteStore.getResource(token, guid, withData, withRecognition, withAttributes, withAttributes);
      logger.log(logger.EXTREME, "Resource " +guid +" has been retrieved.");
    } catch (EDAMUserException e) {
View Full Code Here

   
    private void downloadInkNoteImage(String guid, String authToken) {
    String urlBase = noteStoreUrl.replace("/edam/note/", "/shard/") + "/res/"+guid+".ink?slice=";
//    urlBase = "https://www.evernote.com/shard/s1/res/52b567a9-54ae-4a08-afc5-d5bae275b2a8.ink?slice=";
    Integer slice = 1;
    Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(guid, false);
    conn.getInkImagesTable().expungeImage(r.getGuid());
    int sliceCount = 1+((r.getHeight()-1)/480);
    HttpClient http = new DefaultHttpClient();
      for (int i=0; i<sliceCount; i++) {
        String url = urlBase + slice.toString();
        HttpPost post = new HttpPost(url);
        post.getParams().setParameter("auth", authToken);
        List <NameValuePair> nvps = new ArrayList <NameValuePair>();
            nvps.add(new BasicNameValuePair("auth", authToken));

            try {
        post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
      } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
      }
        try {
          HttpResponse response = http.execute(post);
          HttpEntity resEntity = response.getEntity();
          InputStream is = resEntity.getContent();
          QByteArray data = writeToFile(is);
          conn.getInkImagesTable().saveImage(guid, slice, data);
      } catch (ClientProtocolException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }

      slice++;
      }
      http.getConnectionManager().shutdown();
    noteSignal.noteChanged.emit(r.getNoteGuid(), null);   // Signal to ivalidate note cache
    }
View Full Code Here

TOP

Related Classes of com.evernote.edam.type.Resource

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.