Package com.evernote.edam.type

Examples of com.evernote.edam.type.Resource


        logger.log(logger.EXTREME, "Generating MD5");
        md = MessageDigest.getInstance("MD5");
        md.update(fileData);
        byte[] hash = md.digest();
 
        Resource r = new Resource();
        Calendar time = new GregorianCalendar();
        long prevTime = time.getTimeInMillis();
        while (prevTime == time.getTimeInMillis()) {
          time = new GregorianCalendar();
        }
        r.setGuid(time.getTimeInMillis()+new Integer(sequence).toString());
        r.setNoteGuid(currentNote.getGuid());
        r.setMime(mime);
        r.setActive(true);
        r.setUpdateSequenceNum(0);
        r.setWidth((short) 0);
        r.setHeight((short) 0);
        r.setDuration((short) 0);
             
        Data d = new Data();
        d.setBody(fileData);
        d.setBodyIsSet(true);
        d.setBodyHash(hash);
        d.setBodyHashIsSet(true);
        r.setData(d);
        d.setSize(fileData.length);
       
        int fileNamePos = url.lastIndexOf(File.separator);
        if (fileNamePos == -1)
          fileNamePos = url.lastIndexOf("/");
         String fileName = url.substring(fileNamePos+1);
        ResourceAttributes a = new ResourceAttributes();
        a.setAltitude(0);
        a.setAltitudeIsSet(false);
        a.setLongitude(0);
        a.setLongitudeIsSet(false);
        a.setLatitude(0);
        a.setLatitudeIsSet(false);
        a.setCameraMake("");
        a.setCameraMakeIsSet(false);
        a.setCameraModel("");
        a.setCameraModelIsSet(false);
        a.setAttachment(attachment);
        a.setAttachmentIsSet(true);
        a.setClientWillIndex(false);
        a.setClientWillIndexIsSet(true);
        a.setRecoType("");
        a.setRecoTypeIsSet(false);
        a.setSourceURL(url);
        a.setSourceURLIsSet(true);
        a.setTimestamp(0);
        a.setTimestampIsSet(false);
        a.setFileName(fileName);
        a.setFileNameIsSet(true);
        r.setAttributes(a);
       
        conn.getNoteTable().noteResourceTable.saveNoteResource(r, true);
        logger.log(logger.EXTREME, "Resource created");
        return r;
      } catch (NoSuchAlgorithmException e1) {
View Full Code Here


    pos = guid.lastIndexOf('.');
    if (pos > 0)
      guid = guid.substring(0,pos);
    if (fd.exec() != 0 && fd.selectedFiles().size() > 0) {
      name = name.replace('\\', '/');
      Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);
      QFile saveFile = new QFile(fd.selectedFiles().get(0));
      QFile.OpenMode mode = new QFile.OpenMode();
      mode.set(QFile.OpenModeFlag.WriteOnly);
      saveFile.open(mode);
      QDataStream saveOut = new QDataStream(saveFile);
      QByteArray binData = new QByteArray(resBinary.getData().getBody());
      saveOut.writeBytes(binData.toByteArray());
      saveFile.close();

    }
  }
View Full Code Here

    if (pos > -1) {
      guid = name.substring(0, pos);
      fd.selectFile(name.substring(pos+Global.attachmentNameDelimeter.length()));   
    }
    if (fd.exec() != 0 && fd.selectedFiles().size() > 0) {
      Resource resBinary = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);
      String fileName = fd.selectedFiles().get(0);
      QFile saveFile = new QFile(fileName);
      QFile.OpenMode mode = new QFile.OpenMode();
      mode.set(QFile.OpenModeFlag.WriteOnly);
      saveFile.open(mode);
      QDataStream saveOut = new QDataStream(saveFile);
      QByteArray binData = new QByteArray(resBinary.getData().getBody());
      saveOut.writeBytes(binData.toByteArray());
      saveFile.close();
    }
  }
View Full Code Here

        while (l==prevTime) {
          currentTime = new GregorianCalendar();
          l= new Long(currentTime.getTimeInMillis());
        }
       
        Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);
        // if r==null, then the image doesn't exist (it was probably cut out of another note, so
        // we need to recereate it
        if (r==null) {
          r = createResource(src, 1, mime, false);
          if (r==null)
            return "";
        }
          String randint = new String(Long.toString(l));
          String extension = null;
          if (r.getMime()!= null) {
            extension = r.getMime().toLowerCase();
            if (extension.indexOf("/")>-1)
              extension = extension.substring(extension.indexOf("/")+1);
          }
          String newFile = randint;
          if (r.getAttributes().getFileName() != null && r.getAttributes().getFileName() != "")
            if (!locTag.startsWith("src"))
              newFile = newFile+Global.attachmentNameDelimeter+r.getAttributes().getFileName();
          r.setNoteGuid(currentNote.getGuid());
         
          r.setGuid(randint);
          conn.getNoteTable().noteResourceTable.saveNoteResource(r, true);
        QFile f = new QFile(Global.getFileManager().getResDirPath(newFile));
        QByteArray bin = new QByteArray(r.getData().getBody());
        f.open(QFile.OpenModeFlag.WriteOnly);
        f.write(bin);
        f.close();
        newSegment = newSegment.replace("guid=\""+guid, "guid=\""+randint);
        currentNote.getResources().add(r);
View Full Code Here

   
      // Start building the resource itself
      StringBuffer buffer = new StringBuffer();
      buffer.append("<html><head></head><body>\n");
     
      Resource newRes;
     
      // If we have an image
      if (isImage(fileInfo.completeSuffix())) {
          String mimeType = "image/" +fileInfo.completeSuffix();
          if (mimeType.equals("image/jpg"))
            mimeType = "image/jpeg";
          newRes = createResource(mimeType, false);
         
        buffer.append("<img src=\"" +fileName);
        buffer.append("\" en-tag=\"en-media\" type=\"" + mimeType +"\""
            +" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\""
            +" guid=\"" +newRes.getGuid() +"\">");
      } else {
        // We have an attachment, not an image.
       
       
          String mimeType = "application/" +fileInfo.completeSuffix();
          newRes = createResource(mimeType, false);
          newRes.getAttributes().setFileName(fileInfo.fileName());
       
          String icon = findIcon(fileInfo.completeSuffix());
    String imageURL = FileUtils.toFileURLString(Global.getFileManager().getImageDirFile(icon));
        buffer.append("<a en-tag=\"en-media\" guid=\"" +newRes.getGuid()+"\" ");
      buffer.append("type=\"" + mimeType + "\" href=\"nnres://" + fileName +"\" hash=\""+Global.byteArrayToHexString(newRes.getData().getBodyHash()) +"\" >");
      buffer.append("<img src=\"" + imageURL +"\" title=\"" +newRes.getAttributes().getFileName());
      buffer.append("\">");
      buffer.append("</a>");
      }
    buffer.append("</body></html>");
   
View Full Code Here

      try {
        md = MessageDigest.getInstance("MD5");
        md.update(fileData);
        byte[] hash = md.digest();
 
        Resource r = new Resource();
        Calendar time = new GregorianCalendar();
        Long l = time.getTimeInMillis();
        long prevTime = l;
        while (l==prevTime) {
          time = new GregorianCalendar();
          l=time.getTimeInMillis();
        }
        r.setGuid(new Long(l).toString());
        r.setNoteGuid(newNote.getGuid());
        r.setMime(mime);
        r.setActive(true);
        r.setUpdateSequenceNum(0);
        r.setWidth((short) 0);
        r.setHeight((short) 0);
        r.setDuration((short) 0);
             
        Data d = new Data();
        d.setBody(fileData);
        d.setBodyIsSet(true);
        d.setBodyHash(hash);
        d.setBodyHashIsSet(true);
        r.setData(d);
        d.setSize(fileData.length);
       
        ResourceAttributes a = new ResourceAttributes();
        a.setAltitude(0);
        a.setAltitudeIsSet(false);
        a.setLongitude(0);
        a.setLongitudeIsSet(false);
        a.setLatitude(0);
        a.setLatitudeIsSet(false);
        a.setCameraMake("");
        a.setCameraMakeIsSet(false);
        a.setCameraModel("");
        a.setCameraModelIsSet(false);
        a.setAttachment(attachment);
        a.setAttachmentIsSet(true);
        a.setClientWillIndex(false);
        a.setClientWillIndexIsSet(true);
        a.setRecoType("");
        a.setRecoTypeIsSet(false);
        a.setSourceURLIsSet(false);
        a.setTimestamp(0);
        a.setTimestampIsSet(false);
        a.setFileName(fileInfo.fileName());
        a.setFileNameIsSet(true);
        r.setAttributes(a);
       
        conn.getNoteTable().noteResourceTable.saveNoteResource(r, true);
        return r;
      } catch (NoSuchAlgorithmException e1) {
        e1.printStackTrace();
View Full Code Here

      logger.log(logger.EXTREME, "New note content");
      logger.log(logger.EXTREME, newContent);
      logger.log(logger.EXTREME, "End of content");
      for (int j=0; j<source.getResourcesSize(); j++) {
        logger.log(logger.EXTREME, "Reassigning resource: "+source.getResources().get(j).getGuid());
        Resource r = source.getResources().get(j);
        Resource newRes = conn.getNoteTable().noteResourceTable.getNoteResource(r.getGuid(), true);
       
        Calendar currentTime = new GregorianCalendar();
        Long l = new Long(currentTime.getTimeInMillis());
             
        long prevGuid = 0;
        l = prevGuid;
        while (l == prevGuid) {
          currentTime = new GregorianCalendar();
          l = new Long(currentTime.getTimeInMillis());
        }
        String newResGuid = new String(Long.toString(l));
        newRes.setNoteGuid(targetGuid);
        newRes.setGuid(newResGuid);
        newRes.setUpdateSequenceNum(0);
        newRes.setActive(true);
        conn.getNoteTable().noteResourceTable.saveNoteResource(newRes, true);
      }
    }
    logger.log(logger.EXTREME, "Updating note");
    conn.getNoteTable().updateNoteContent(targetGuid, newContent +"</en-note>");
View Full Code Here

          logger.log(logger.LOW, "Unable to save externally edited file.  Saving for later.");
          externalFiles.add(fileName);
          return;
        }
       
        Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);
        if (r==null)
          r = conn.getNoteTable().noteResourceTable.getNoteResource(Global.resourceMap.get(guid), true);
        if (r == null || r.getData() == null || r.getData().getBody() == null)
          return;
        String oldHash = Global.byteArrayToHexString(r.getData().getBodyHash());
        MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(binData.toByteArray());
    byte[] hash = md.digest();
        String newHash = Global.byteArrayToHexString(hash);
        if (r.getNoteGuid().equalsIgnoreCase(currentNoteGuid)) {
          updateResourceContentHash(browserWindow, r.getGuid(), oldHash, newHash);
        }
        if (externalWindows.containsKey(r.getNoteGuid())) {
          updateResourceContentHash(externalWindows.get(r.getNoteGuid()).getBrowserWindow(),
              r.getGuid(), oldHash, newHash);
        }
        conn.getNoteTable().updateResourceContentHash(r.getNoteGuid(), oldHash, newHash);
        Data data = r.getData();
        data.setBody(binData.toByteArray());
        data.setBodyHash(hash);
        logger.log(logger.LOW, "externalFileEdited: " +data.getSize() +" bytes");
        r.setData(data);
        conn.getNoteTable().noteResourceTable.updateNoteResource(r,true);
       
        if (r.getNoteGuid().equals(currentNoteGuid)) {
      QWebSettings.setMaximumPagesInCache(0);
      QWebSettings.setObjectCacheCapacities(0, 0, 0);
      refreshEvernoteNote(true);
      browserWindow.getBrowser().triggerPageAction(WebAction.Reload);
        }
       
        if (externalWindows.containsKey(r.getNoteGuid())) {
          QWebSettings.setMaximumPagesInCache(0);
      QWebSettings.setObjectCacheCapacities(0, 0, 0);
      externalWindows.get(r.getNoteGuid()).getBrowserWindow().getBrowser().triggerPageAction(WebAction.Reload);
     
        }
       
    logger.log(logger.HIGH, "Exiting externalFielEdited");
  }
View Full Code Here

    if (!query.next()) {
      logger.log(logger.MEDIUM, "Note Resource not found.");
      return null;
    }
   
    Resource r = new Resource();
    r.setGuid(query.valueString(0));
    r.setMime(query.valueString(1));
   
    NSqlQuery binary = new NSqlQuery(db.getResourceConnection());
    if (!binary.prepare("Select databinary from NoteResources " +
          "where guid=:guid")) {
      logger.log(logger.MEDIUM, "Prepare for NoteResources Binary failed");
      logger.log(logger.MEDIUM, binary.lastError());
    }
   
    if (!binary.exec()) {
      logger.log(logger.MEDIUM, "NoteResources Binary Select failed." +
          "Note Guid:" +noteGuid+
          "Data Body Hash:" +hash);   
      logger.log(logger.MEDIUM, binary.lastError());
    }
    if (!binary.next()) {
      logger.log(logger.MEDIUM, "Note Resource Binary not found.");
      return null;
    }
   
    Data d = new Data();
    r.setData(d);
    d.setBody(binary.valueString(0).getBytes());
    logger.log(logger.HIGH, "Leaving DBRunner.getNoteResourceDataBodyByHash");
    return r;
  }
View Full Code Here

    if (!query.exec()) {
      logger.log(logger.EXTREME, "NoteResources SQL select has failed.");
      logger.log(logger.MEDIUM, query.lastError());
      return null;
    }
    Resource r = null;
    if (query.next()) {
                 
      r = new Resource();
      r.setGuid(query.valueString(0));       // Resource Guid
      r.setNoteGuid(query.valueString(1));   // note Guid
      r.setMime(query.valueString(2));       // Mime Type
      r.setWidth(new Short(query.valueString(3)))// Width
      r.setHeight(new Short(query.valueString(4)))// Height
      r.setDuration(new Short(query.valueString(5)))// Duration
      r.setActive(new Boolean(query.valueString(6)))// active
      r.setUpdateSequenceNum(new Integer(query.valueString(7)))// update sequence number
     
      Data d = new Data();
      byte[] h = query.valueString(8).getBytes();    // data hash
      QByteArray hData = new QByteArray(h);
      QByteArray bData = new QByteArray(QByteArray.fromHex(hData));
      d.setBodyHash(bData.toByteArray());
      d.setSize(new Integer(query.valueString(9)));
      r.setData(d);
     
      Data rec = new Data();
      if (query.valueObject(10) != null)
        rec.setBodyHash(query.valueString(10).getBytes());   // Recognition Hash
      if (query.valueObject(11) != null)
        rec.setSize(new Integer(query.valueString(11)));
      else
        rec.setSize(0);
      r.setRecognition(rec);

      ResourceAttributes a = new ResourceAttributes();
      if (!query.valueString(12).equals(""))              // Latitude
        a.setLatitude(new Float(query.valueString(12)));
      if (!query.valueString(13).equals(""))              // Longitude
        a.setLongitude(new Float(query.valueString(13)));
      if (!query.valueString(14).equals(""))              // Altitude
        a.setAltitude(new Float(query.valueString(14)));
      a.setCameraMake(stringValue(query.valueString(15)));              // Camera Make
      a.setCameraModel(stringValue(query.valueString(16)));
      a.setClientWillIndex(booleanValue(query.valueString(17).toString(),false))// Camera Model
      a.setRecoType(stringValue(query.valueString(18)));                 // Recognition Type
      a.setFileName(stringValue(query.valueString(19)));                  // File Name
      a.setAttachment(booleanValue(query.valueString(20).toString(),false));
      a.setSourceURL(query.valueString(21));
      r.setAttributes(a);
   
      if (withBinary) {
         
        query.prepare("Select dataBinary from NoteResources where guid=:guid");
        query.bindValue(":guid", r.getGuid());
        query.exec();
        if (query.next()) {
          byte[] b = query.getBlob(0);
          r.getData().setBody(b);
        }
      }
    }
    return r;
  }
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.