Package com.google.gdata.client.docs

Examples of com.google.gdata.client.docs.DocsService


public class GoogleOdtLoaderBehaviour {

    @Test
    public void shouldGetResourceFromDocsService() throws IOException, ServiceException {
        DocsService service = mock(DocsService.class);
        DocumentListFeed feed = mock(DocumentListFeed.class);
        DocumentListEntry entry = mock(DocumentListEntry.class);
        MediaSource mediaSource = mock(MediaSource.class);
        InputStream inputStream = mock(InputStream.class);
        final MediaContent content = mock(MediaContent.class);
        final DocumentQuery query = mock(DocumentQuery.class);
        when(service.getFeed(query, DocumentListFeed.class)).thenReturn(feed);
        when(service.getMedia(content)).thenReturn(mediaSource);
        when(feed.getEntries()).thenReturn(asList(entry));
        when(entry.getContent()).thenReturn(content);
        when(content.getUri()).thenReturn("http://docs.google.com");
        when(mediaSource.getInputStream()).thenReturn(inputStream);
View Full Code Here


  public GoogleDocumentList(String applicationName, String host) throws DocumentListException {
    if (host == null) {
      throw new DocumentListException("null passed in required parameters");
    }

    service = new DocsService(applicationName);

    // Creating a spreadsheets service is necessary for downloading spreadsheets
    spreadsheetsService = new GoogleService(SPREADSHEETS_SERVICE_NAME, applicationName);

    this.host = host;
View Full Code Here

   * @param contents the document's contents
   * @throws DocumentServiceException
   */
  @Override
  public DocumentServiceEntry createDocument(String title, String contents) throws DocumentServiceException {
    DocsService svc = getDocsService();
    DocumentEntry newDocument = new DocumentEntry();
    newDocument.setTitle(new PlainTextConstruct(title));
    DocumentEntry entry;
    try {
      MediaByteArraySource source = new MediaByteArraySource(contents.getBytes("UTF8"), "text/plain");
      newDocument.setMediaSource(source);
      entry = svc.insert(new URL(DOCS_SCOPE + "default/private/full"), newDocument);
    } catch (Exception e) {
      e.printStackTrace();
      throw new DocumentServiceException(e.getMessage());
    }
    return getDocumentReference(entry);
View Full Code Here

   * @param etag the document's version tag
   * @throws DocumentServiceException
   */
  @Override
  public boolean deleteDocument(String documentId, String etag) throws DocumentServiceException {
    DocsService svc = getDocsService();
    String documentUri = DOCS_SCOPE + "default/private/full/document%3A" + documentId;
    svc.getRequestFactory().setHeader("If-Match", etag);
    try {
      svc.delete(new URL(documentUri));
    } catch (Exception e) {
      e.printStackTrace();
      throw new DocumentServiceException(e.getMessage());
    }
    return true;
View Full Code Here

  AuthenticationToken token = this.store.getUserToken();
  if (token == null) {
    throw new DocumentServiceException("Service requires authentication.");
  }
  PrivateKey key = AuthenticationKey.getAuthSubKey();
    DocsService svc = new DocsService(GDATA_CLIENT_APPLICATION_NAME);
    svc.setConnectTimeout(0);
    svc.setReadTimeout(0);
    svc.setAuthSubToken(token.getToken(), key);
    svc.setProtocolVersion(DocsService.Versions.V3);
    return svc;
  }
View Full Code Here

   * @param contentUrl the resource content url
   * @throws DocumentServiceException
   */
  @Override
  public String getDocumentContents(String contentUrl) throws DocumentServiceException {
    DocsService svc = getDocsService();
    try {
      MediaContent mc = new MediaContent();
      mc.setUri(contentUrl);
      MediaSource ms = svc.getMedia(mc);
      InputStreamReader reader = null;
      try {
        reader = new InputStreamReader(ms.getInputStream(), "UTF8");
        BufferedReader br = new BufferedReader(reader);
        StringBuilder contents = new StringBuilder();
View Full Code Here

   * @param documentId the id of the document to retrieve
   * @return the GData document entry
   * @throws DocumentServiceException
   */
  private DocumentListEntry getDocumentEntry(String documentId) throws DocumentServiceException {
    DocsService svc = getDocsService();
    String documentUri = DOCS_SCOPE + "default/private/full/document%3A" + documentId;
    try {
      return svc.getEntry(new URL(documentUri), DocumentListEntry.class);
    } catch (Exception e) {
      e.printStackTrace();
      throw new DocumentServiceException(e.getMessage());
    }
  }
View Full Code Here

   * @throws DocumentServiceException
   */
  @Override
  public DocumentServiceEntry[] getDocuments(boolean starredOnly) throws DocumentServiceException {
    ArrayList<DocumentServiceEntry> docs = new ArrayList<DocumentServiceEntry>();
    DocsService svc = getDocsService();
    DocumentListFeed feed;
    try {
      String url = DOCS_SCOPE + "default/private/full/";
      if (starredOnly) {
        url += "-/starred";
      } else {
      url += "?showfolders=true";
      }
      feed = svc.getFeed(new URL(url), DocumentListFeed.class);
      for (DocumentListEntry entry : feed.getEntries()) {
        docs.add(getDocumentReference(entry));
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

   * @param contents the document contents
   * @throws DocumentServiceException
   */
  @Override
  public DocumentServiceEntry setDocumentContents(String documentId, String etag, String contents) throws DocumentServiceException {
    DocsService svc = getDocsService();
    svc.getRequestFactory().setHeader("If-Match", etag);
    try {
    MediaByteArraySource source = new MediaByteArraySource(contents.getBytes("UTF8"), "text/plain");
    String editMediaUri = DOCS_SCOPE + "default/media/document%3A" + documentId;
    DocumentListEntry entry = svc.updateMedia(new URL(editMediaUri), DocumentListEntry.class, source);
    entry = getDocumentEntry(documentId, etag);
    return getDocumentReference(entry);
    } catch (Exception e) {
      e.printStackTrace();
      throw new DocumentServiceException(e.getMessage());
View Full Code Here

    throws AuthenticationException
  {
    try
    {
      spreadsheetService = new SpreadsheetService(APPLICATION_NAME);
      docsService = new DocsService(APPLICATION_NAME);
     
      DocsCredentials credentials = DocsPlugin.getUserCredentials();
     
      if (credentials == null)
        throw new AuthenticationException("No username / password provided.");
View Full Code Here

TOP

Related Classes of com.google.gdata.client.docs.DocsService

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.