demo.login(username, password);
List<FileCabinetPageEntry> entries = demo.getFileCabinets().getEntries(FileCabinetPageEntry.class);
System.out.println("Found " + entries.size() + " filecabinets:");
for (int i = 0; i < entries.size(); ++i) {
FileCabinetPageEntry entry = entries.get(i);
System.out.println(" " + (i + 1) + ") " + entry.getTitle().getPlainText() +
" {" + entry.getPageName().getValue() + "}");
}
System.out.println("");
int choice;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
while (true) {
System.out.print("Upload files to which? ");
try {
choice = Integer.parseInt(reader.readLine());
if (choice > 0 && choice <= entries.size()) {
break;
}
} catch (NumberFormatException e) {
// retry prompt
}
System.err.println("\nError: Please enter a valid choice");
}
while (true) {
FileCabinetPageEntry entry = entries.get(choice - 1);
System.out.print("Enter file to upload: ");
String filename = reader.readLine();
System.out.print("Enter file description: ");
String description = reader.readLine();
File file = new File(filename);
String mediaType = demo.mediaTypes.getContentType(file);
AttachmentEntry attachment =
demo.uploadAttachment(file, entry.getSelfLink().getHref(), description);
System.out.println("\nFiled uploaded! See it: " +
attachment.getLink(Link.Rel.ALTERNATE, mediaType).getHref() + "\n");
}
}