Package com.google.api.services.drive.model

Examples of com.google.api.services.drive.model.File


     
      UIJCRExplorer uiExplorer = event.getSource().getAncestorOfType(UIJCRExplorer.class);
      Node currentNode = uiExplorer.getCurrentNode();
     
      try {
        File googleDriveFile = null;
        String googleDriveFileID = null;
        if(!currentNode.isNodeType(GoogleDocsConstants.GOOGLE_DRIVE_NODE_TYPE) || !currentNode.hasProperty(GoogleDocsConstants.GOOGLE_DRIVE_NODE_PROPERTY)) {
          // insert doc in google drive
          googleDriveFile = googleDriveService.addFileInGoogleDrive(currentNode);
          googleDriveFileID = googleDriveFile.getId();
         
          // share the document with the main Google account
          googleDriveService.shareFileWithMasterAccount(googleDriveFileID);
         
          // add google drive mixin
          currentNode.addMixin(GoogleDocsConstants.GOOGLE_DRIVE_NODE_TYPE);
          currentNode.setProperty(GoogleDocsConstants.GOOGLE_DRIVE_NODE_PROPERTY, googleDriveFileID);
          currentNode.save();
        } else {
          // get the Google Drive file id
          googleDriveFileID = currentNode.getProperty(GoogleDocsConstants.GOOGLE_DRIVE_NODE_PROPERTY).getString();
         
          // get the Google Drive file
          googleDriveFile = googleDriveService.getFile(googleDriveFileID);         
        }
               
        // share the document with the contributor
        String userId = ConversationState.getCurrent().getIdentity().getUserId();
        User user = organizationService.getUserHandler().findUserByName(userId);
        if(user == null) {
          throw new GoogleDocsException("UIActionBar.msg.googledocs.user-not-found", "User " + userId + " not found");
        }
        String userEmail = user.getEmail();
        if(userEmail == null || userEmail.isEmpty()) {
          throw new GoogleDocsException("UIActionBar.msg.googledocs.no-user-email", "Email of user " + userId + " is empty");
        }
        googleDriveService.shareFileWith(googleDriveFileID, userEmail);
       
        event.getRequestContext().getJavascriptManager().addCustomizedOnLoadScript("ajaxRedirect('" + googleDriveFile.getAlternateLink() + "');");       
         
      } catch (GoogleDocsException gde) {
        log.error("Error while adding the document " + currentNode.getPath() + " in Google Drive - Cause : " + gde.getMessage(), gde);
        org.exoplatform.wcm.webui.Utils.createPopupMessage(uiExplorer,
                        gde.getMessageKey(),
View Full Code Here


    String mimeType = fileNode.getNode("jcr:content").getProperty("jcr:mimeType").getString();
    InputStream documentIS = fileNode.getNode("jcr:content").getProperty("jcr:data").getStream();

    // Insert a file
    File body = new File();
    body.setTitle(fileNode.getName());
    body.setMimeType(mimeType);

    // TODO files are created on file system, handle it right...
    java.io.File fileContent = new java.io.File(fileNode.getName());
    OutputStream out = new FileOutputStream(fileContent);
    byte buf[] = new byte[1024];
    int len;
    while ((len = documentIS.read(buf)) > 0) {
      out.write(buf, 0, len);
    }
    out.close();
    documentIS.close();

    FileContent mediaContent = new FileContent(mimeType, fileContent);

    Insert insert = driveService.files().insert(body, mediaContent);
    insert.getMediaHttpUploader().setDirectUploadEnabled(true);
    File file = insert.setConvert(true).execute();

    return file;
  }
View Full Code Here

   * @throws IOException
   */
  public InputStream getFileContent(String fileId, String mimeType) throws IOException, GeneralSecurityException {
    Drive driveService = getDriveService();

    File file = getFile(fileId);
   
    String url = (String) file.getExportLinks().get(mimeType);
    if (url != null && url.length() > 0) {
      HttpResponse resp = driveService.getRequestFactory().buildGetRequest(new GenericUrl(url)).execute();
      return resp.getContent();
    } else {
      throw new IOException("No export URL available for the file " + fileId + " with the mimetype " + mimeType);
View Full Code Here

TOP

Related Classes of com.google.api.services.drive.model.File

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.