Package com.evernote.edam.type

Examples of com.evernote.edam.type.Resource


    writer.writeEndElement();
  }

 
  private void writeResources(List<Resource> resourceTable) {
    Resource resource;
    if (resourceTable.size() == 0)
      return;
    for (int i=0; i<resourceTable.size(); i++) {
      resource = resourceTable.get(i);
      writer.writeStartElement("NoteResource");
      createTextNode("Guid", resource.getGuid());
      createTextNode("NoteGuid", resource.getNoteGuid());
      createTextNode("UpdateSequenceNumber", new Integer(resource.getUpdateSequenceNum()).toString());
      createTextNode("Mime", resource.getMime());
      createTextNode("Duration", new Integer(resource.getDuration()).toString());
      createTextNode("Height", new Integer(resource.getHeight()).toString());
      createTextNode("Width", new Integer(resource.getWidth()).toString());
      logger.log(logger.EXTREME, "Checking for data node");
      if (resource.getData() != null)
        writeDataNode("Data", resource.getData());
      logger.log(logger.EXTREME, "Checking for alternate data node");
      if (resource.getAlternateData() != null)
        writeDataNode("AlternateData", resource.getAlternateData());
      logger.log(logger.EXTREME, "Checking for recognition");
      if (resource.getRecognition() != null)
        writeRecognitionNode("Recognition", resource.getRecognition());
      if (resource.isActive())
        createTextNode("Active", "true");
      else
        createTextNode("Active", "false");
        logger.log(logger.EXTREME, "Checking resource attributes");
      if (resource.getAttributes() != null) {
        writer.writeStartElement("NoteResourceAttribute");
        createTextNode("CameraMake", resource.getAttributes().getCameraMake());
        createTextNode("CameraModel", resource.getAttributes().getCameraModel());
        createTextNode("FileName", resource.getAttributes().getFileName());
        createTextNode("RecoType", resource.getAttributes().getRecoType());
        createTextNode("SourceURL", resource.getAttributes().getSourceURL());
        createTextNode("Altitude", new Double(resource.getAttributes().getAltitude()).toString());
        createTextNode("Longitude", new Double(resource.getAttributes().getLongitude()).toString());
        createTextNode("Latitude", new Double(resource.getAttributes().getLatitude()).toString());
        createTextNode("Timestamp", new Long(resource.getAttributes().getTimestamp()).toString());
        if (resource.getAttributes().isAttachment())
          createTextNode("Attachment", "true");
        else 
          createTextNode("Attachment", "false");
        if (resource.getAttributes().isClientWillIndex())
          createTextNode("ClientWillIndex", "true");
        else
          createTextNode("ClientWillIndex", "false");
        writer.writeEndElement();
      }
View Full Code Here


  private final DatabaseConnection conn;
  private final String noteGuid;
 
 
  public ImageFetcher(DatabaseConnection c, ApplicationLogger l, String g) {
    newResource = new Resource();
    logger = l;
    conn = c;
    noteGuid = g;
  }
View Full Code Here

        logger.log(logger.EXTREME, "Generating MD5");
        md = MessageDigest.getInstance("MD5");
        md.update(fileData);
        byte[] hash = md.digest();
 
        Resource r = new Resource();
        r.setGuid(QUuid.createUuid().toString().replace("}", "").replace("{", ""));
        r.setNoteGuid(noteGuid);
        r.setMime("image/" +address.substring(address.lastIndexOf(".")+1));
        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 = address.lastIndexOf(File.separator);
        if (fileNamePos == -1)
          fileNamePos = address.lastIndexOf("/");
         String fileName = address.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(false);
        a.setAttachmentIsSet(true);
        a.setClientWillIndex(false);
        a.setClientWillIndexIsSet(true);
        a.setRecoType("");
        a.setRecoTypeIsSet(false);
        a.setSourceURL(fileName);
        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");
       
        // Now write it out so someone else can look at it
View Full Code Here

  public void indexResource() {
   
    if (guid == null)
      return;
    foundWords.clear();
    Resource r = conn.getNoteTable().noteResourceTable.getNoteResourceRecognition(guid);
    if (!indexImageRecognition ||
        r == null || r.getRecognition() == null ||
        r.getRecognition().getBody() == null ||
        r.getRecognition().getBody().length == 0)
      resourceBinary = new QByteArray(" ");
    else
      resourceBinary = new QByteArray(r.getRecognition().getBody());
   
    conn.commitTransaction();
    conn.beginTransaction();
    conn.getWordsTable().expungeFromWordIndex(r.getNoteGuid(), "RESOURCE");
    // This is due to an old bug & can be removed at some point in the future 11/23/2010
    conn.getWordsTable().expungeFromWordIndex(guid, "RESOURCE");  
    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();
          uncommittedCount=0;
        }
View Full Code Here

    conn.commitTransaction();
    uncommittedCount = 0;
  }
 
  private void indexResourceContent(String guid) {
    Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(guid, true);
    if (r != null && r.getMime() != null) {
      if (r.getMime().equalsIgnoreCase("application/pdf")) {
        indexResourcePDF(r);
        return;
      }
      if (r.getMime().equalsIgnoreCase("application/docx") ||
        r.getMime().equalsIgnoreCase("application/xlsx") ||
        r.getMime().equalsIgnoreCase("application/pptx")) {
        indexResourceOOXML(r);
        return;
      }
      if (r.getMime().equalsIgnoreCase("application/vsd") ||
          r.getMime().equalsIgnoreCase("application/ppt") ||
          r.getMime().equalsIgnoreCase("application/xls") ||
          r.getMime().equalsIgnoreCase("application/msg") ||
          r.getMime().equalsIgnoreCase("application/doc")) {
        indexResourceOffice(r);
        return;
      }
      if (r.getMime().equalsIgnoreCase("application/rtf")) {
          indexResourceRTF(r);
          return;
      }
      if (r.getMime().equalsIgnoreCase("application/odf") ||
        r.getMime().equalsIgnoreCase("application/odt") ||
        r.getMime().equalsIgnoreCase("application/odp") ||
        r.getMime().equalsIgnoreCase("application/odg") ||
        r.getMime().equalsIgnoreCase("application/odb") ||
        r.getMime().equalsIgnoreCase("application/ods")) {
        indexResourceODF(r);
        return;
      }
    }
  }
View Full Code Here

   
    return;
   
 
  private Resource processResource() {
    Resource resource = new Resource();
    boolean atEnd = false;
    boolean isDirty = false;
    while(!atEnd) {
      if (reader.isStartElement()) {
        if (reader.name().equalsIgnoreCase("Guid"))
          resource.setGuid(textValue());
        if (!backup) {
          Random random1 = new Random();
          String newGuid = "IMP" +new Integer(random1.nextInt(1000)).toString();
          newGuid = newGuid+"-"+new Integer(random1.nextInt(1000)).toString();
          newGuid = newGuid+"-"+new Integer(random1.nextInt(1000)).toString();
          newGuid = newGuid+"-"+new Integer(random1.nextInt(1000)).toString();
          resource.setGuid(newGuid);
        }
        if (reader.name().equalsIgnoreCase("NoteGuid")) {
          String tx = textValue();
          resource.setNoteGuid(noteMap.get(textValue()))
          resource.setNoteGuid(noteMap.get(tx));
        }
        if (reader.name().equalsIgnoreCase("UpdateSequenceNumber"))
          resource.setUpdateSequenceNum(intValue());
        if (reader.name().equalsIgnoreCase("Active"))
          resource.setActive(booleanValue());
        if (reader.name().equalsIgnoreCase("Mime"))
          resource.setMime(textValue());
        if (reader.name().equalsIgnoreCase("Duration"))
          resource.setDuration(shortValue());
        if (reader.name().equalsIgnoreCase("Height"))
          resource.setHeight(shortValue());
        if (reader.name().equalsIgnoreCase("Width"))
          resource.setWidth(shortValue());
        if (reader.name().equalsIgnoreCase("dirty"))
          isDirty = booleanValue();
        if (reader.name().equalsIgnoreCase("Data"))
          resource.setData(processData("Data"));
        if (reader.name().equalsIgnoreCase("AlternateData"))
          resource.setAlternateData(processData("AlternateData"));
        if (reader.name().equalsIgnoreCase("RecognitionData"))
          resource.setRecognition(processData("RecognitionData"));
        if (reader.name().equalsIgnoreCase("NoteResourceAttribute"))
          resource.setAttributes(processResourceAttributes());
      }
      reader.readNext();
      if (reader.name().equalsIgnoreCase("noteresource") && reader.isEndElement())
        atEnd = true;
    }
View Full Code Here

        atEnd = true;
    }
    return;
 
  private Resource processResource() {
    Resource resource = new Resource();
    boolean atEnd = false;
    while(!atEnd) {
      if (reader.isStartElement() && reader.name().equalsIgnoreCase("resource")) {
        String newResGuid = QUuid.createUuid().toString().replace("{", "").replace("}", "");
        resource.setGuid(newResGuid);
        resource.setNoteGuid(this.newGuid);
      }
      if (reader.name().equalsIgnoreCase("mime"))
        resource.setMime(textValue());
      if (reader.name().equalsIgnoreCase("height"))
        resource.setHeight(shortValue());
      if (reader.name().equalsIgnoreCase("width"))
        resource.setWidth(shortValue());
      if (reader.name().equalsIgnoreCase("data"))
        resource.setData(processData("data"));
      if (reader.name().equalsIgnoreCase("resource-attributes"))
        resource.setAttributes(processResourceAttributes());
      if (reader.name().equalsIgnoreCase("recognition"))
        resource.setRecognition(processRecognition());
      reader.readNext();
      if (reader.name().equalsIgnoreCase("resource") && reader.isEndElement())
        atEnd = true;
    }
    if (resource.getAttributes() == null)
      resource.setAttributes(new ResourceAttributes());
    conn.getNoteTable().noteResourceTable.updateNoteResource(resource, true);
    return resource;
  }
View Full Code Here

  private void addImageHilight(String resGuid, QFile f) {
    if (enSearch == null || enSearch.hilightWords == null || enSearch.hilightWords.size() == 0)
      return;
   
    // Get the recognition XML that tells where to hilight on the image
    Resource recoResource = conn.getNoteTable().noteResourceTable.getNoteResourceRecognition(resGuid);
    if (recoResource.getRecognition().getBody() == null || recoResource.getRecognition().getBody().length == 0)
      return;
    QByteArray recoData = new QByteArray(recoResource.getRecognition().getBody());
    String xml = recoData.toString();
   
    // Get a painter for the image.  This is the background (the initial image).
      QPixmap pix = new QPixmap(f.fileName());
      QPixmap hilightedPix = new QPixmap(pix.size());
View Full Code Here

        type="";
     
      String resGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(currentNoteGuid, hash.value());
      QFile tfile = new QFile(Global.getFileManager().getResDirPath(resGuid + type));
//      if (!tfile.exists()) {
        Resource r = null;
        if (resGuid != null)
           r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid,true);
         if (r==null || r.getData() == null || r.getData().getBody().length == 0) {
           resourceError = true;
           readOnly = true;
         }
         if (r!= null && r.getData() != null && r.getData().getBody().length > 0) {
         tfile.open(new QIODevice.OpenMode(QIODevice.OpenModeFlag.WriteOnly));
         QByteArray binData = new QByteArray(r.getData().getBody());
        tfile.write(binData);
         tfile.close();
        
         // If we have recognition text, outline it
         addImageHilight(r.getGuid(), tfile);
        
        enmedia.setAttribute("src", QUrl.fromLocalFile(tfile.fileName()).toString());
          enmedia.setAttribute("en-tag", "en-media");
          enmedia.setNodeValue("");
          enmedia.setAttribute("guid", r.getGuid());
          enmedia.setTagName("img");
        }
//      }
      // Technically, we should do a file:// to have a proper url, but for some reason QWebPage hates
      // them and won't generate a thumbnail image properly if we use them.
//    enmedia.setAttribute("src", QUrl.fromLocalFile(tfile.fileName()).toString());
    enmedia.setAttribute("src", tfile.fileName().toString());
    enmedia.setAttribute("en-tag", "en-media");
    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);

    }
View Full Code Here

  // Get an ink note image.  If an image doesn't exist then we fall back
  // to the old ugly icon
    private boolean buildInkNote(QDomDocument doc, QDomElement docElem, QDomElement enmedia, QDomAttr hash, String appl) {
      String resGuid = conn.getNoteTable().noteResourceTable.getNoteResourceGuidByHashHex(currentNote.getGuid(), hash.value());
      Resource r = conn.getNoteTable().noteResourceTable.getNoteResource(resGuid, false);
      // If we can't find the resource, then fall back to the old method.  We'll return & show
      // an error later
      if (r == null || r.getData() == null)
        return false;
     
      // If there isn't some type of error, continue on.
    if (!resourceError) {
     
      // Get a list of images in the database.  We'll use these to bulid the page.
      List<QByteArray> data = conn.getInkImagesTable().getImage(r.getGuid());
     
      // If no pictures are found, go back to & just show the icon
      if (data.size() == 0)
        return false;
     
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.