}
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;
}