Package com.google.gdata.data.gtt

Examples of com.google.gdata.data.gtt.DocumentEntry


    SimpleCommandLineParser parser = new SimpleCommandLineParser(args);

    String id = parser.getValue("id");
    URL feedUrl = FeedUris.getDocumentFeedUrl(id);

    DocumentEntry requestEntry = service.getEntry(feedUrl, DocumentEntry.class);
    requestEntry.setLastModifiedBy(null);

    System.out.println("You want to update document with id:" + id + "...");

    if (parser.containsKey("title")) {
      String title = parser.getValue("title");
      System.out.println("...by changing title to " + title);
      requestEntry.setTitle(new PlainTextConstruct(title));
    }

    if (parser.containsKey("tmids")) {
      String tmIds = parser.getValue("tmids");
      System.out.println("...by adding translation memories with ids: "
          + tmIds);
      TmsElement tm = new TmsElement();
      for (String tmId : tmIds.split(",")) {
        String tmHref = FeedUris.getTranslationMemoryFeedUrl(tmId).toString();

        Link tmLink = new Link();
        tmLink.setHref(tmHref);

        tm.addLink(tmLink);
      }
      requestEntry.setTranslationMemory(tm);
    }

    if (parser.containsKey("glids")) {
      String glIds = parser.getValue("glids");
      System.out.println("...by adding glossaries with ids: "
          + glIds);
      GlossariesElement gl = new GlossariesElement();
      for (String glId : glIds.split(",")) {
        String glHref = FeedUris.getGlossaryFeedUrl(glId).toString();

        Link glLink = new Link();
        glLink.setHref(glHref);

        gl.addLink(glLink);
      }
      requestEntry.setGlossary(gl);
    }

    System.out.print("Updating document....");
    System.out.flush();
    DocumentEntry resultEntry = service.update(feedUrl, requestEntry);
    printResults(resultEntry);
  }
View Full Code Here


  private UploadDocumentCommand() {
  }

  public void execute(GttService service, String[] args)
      throws IOException, ServiceException {
    DocumentEntry requestEntry = createEntryFromArgs(args);

    System.out.print("Creating document....");
    System.out.flush();

    URL feedUrl = FeedUris.getDocumentsFeedUrl();
    DocumentEntry resultEntry = service.insert(feedUrl, requestEntry);

    printResults(resultEntry);
  }
View Full Code Here

  }

  private DocumentEntry createEntryFromArgs(String[] args) throws IOException {
    SimpleCommandLineParser parser = new SimpleCommandLineParser(args);

    DocumentEntry entry = new DocumentEntry();

    System.out.println("You want to create a new document...");

    String srcLang = parser.getValue("srclang");
    System.out.println("... with source language " + srcLang);
    entry.setSourceLanguage(new SourceLanguage(srcLang));

    String targetLang = parser.getValue("targetlang");
    System.out.println("... with target language " + targetLang);
    entry.setTargetLanguage(new TargetLanguage(targetLang));

    String title = parser.getValue("title");
    System.out.println("... with title " + title);
    entry.setTitle(new PlainTextConstruct(title));

    if (parser.containsKey("weburl")) {
      String url = parser.getValue("weburl");
      System.out.println("... with html contents from " + url);
      DocumentSource docSource = new DocumentSource(DocumentSource.Type.HTML,
          url);
      entry.setDocumentSource(docSource);
    } else if (parser.containsKey("wikipediaurl")) {
      String url = parser.getValue("wikipediaurl");
      System.out.println("... with mediawiki contents from " + url);
      DocumentSource docSource = new DocumentSource(DocumentSource.Type.WIKI,
          url);
      entry.setDocumentSource(docSource);
    } else if (parser.containsKey("knolurl")) {
      String url = parser.getValue("knolurl");
      System.out.println("... with knol contents from " + url);
      DocumentSource docSource = new DocumentSource(DocumentSource.Type.KNOL,
          url);
      entry.setDocumentSource(docSource);
    } else if (parser.containsKey("file")) {
      String filename = parser.getValue("file");
      System.out.println("... with contents from file at " + filename);
      File file = new File(filename);
      String mimeType = MediaType.fromFileName(filename).getMimeType();

      MediaFileSource fileSource = new MediaFileSource(file, mimeType);
      MediaContent content = new MediaContent();
      content.setMediaSource(fileSource);
      content.setMimeType(new ContentType(mimeType));

      entry.setContent(content);
    }

    if (parser.containsKey("tmids")) {
      String tmIds = parser.getValue("tmids");
      System.out.println("...by adding translation memories with ids: "
          + tmIds);
      TmsElement tm = new TmsElement();
      for (String id : tmIds.split(",")) {
        String tmHref = FeedUris.getTranslationMemoryFeedUrl(id).toString();

        Link tmLink = new Link();
        tmLink.setHref(tmHref);

        tm.addLink(tmLink);
      }
      entry.setTranslationMemory(tm);
    }

    if (parser.containsKey("glids")) {
      String glIds = parser.getValue("glids");
      System.out.println("...by adding glossaries with ids: "
          + glIds);
      GlossariesElement gl = new GlossariesElement();
      for (String id : glIds.split(",")) {
        String glHref = FeedUris.getGlossaryFeedUrl(id).toString();

        Link glLink = new Link();
        glLink.setHref(glHref);

        gl.addLink(glLink);
      }
      entry.setGlossary(gl);
    }

    return entry;
  }
View Full Code Here

TOP

Related Classes of com.google.gdata.data.gtt.DocumentEntry

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.