SimpleCommandLineParser parser = new SimpleCommandLineParser(args);
String id = parser.getValue("id");
URL feedUrl = FeedUris.getTranslationMemoryFeedUrl(id);
TranslationMemoryEntry requestEntry = service.getEntry(feedUrl,
TranslationMemoryEntry.class);
System.out.println("You want to update translation memory 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("file")) {
String filename = parser.getValue("file");
System.out.println("...by appending contents from file " + filename);
File file = new File(filename);
String mimeType = "text/xml";
MediaFileSource fileSource = new MediaFileSource(file, mimeType);
MediaContent content = new MediaContent();
content.setMediaSource(fileSource);
content.setMimeType(new ContentType(mimeType));
requestEntry.setContent(content);
}
System.out.print("Updating translation memory....");
System.out.flush();
TranslationMemoryEntry resultEntry = null;
if (requestEntry.getContent() == null) {
resultEntry = service.update(feedUrl, requestEntry);
} else {
resultEntry = service.updateMedia(feedUrl, requestEntry);
}