/** * Default mutable constructor. */ public AttachmentEntry() { super(); getCategories().add(CATEGORY); }
/** * Returns the parent sites link. * * @return Parent sites link or {@code null} for none. */ public Link getParentLink() { return getLink(SitesLink.Rel.PARENT, Link.Type.ATOM); }
/** * Declare the extensions of the feeds for the Google Sites Data API. */ private void declareExtensions() { extProfile.setAutoExtending(true); new ActivityFeed().declareExtensions(extProfile); new AnnouncementEntry().declareExtensions(extProfile); new AnnouncementsPageEntry().declareExtensions(extProfile); new AttachmentEntry().declareExtensions(extProfile); new CommentEntry().declareExtensions(extProfile); new ContentFeed().declareExtensions(extProfile); new CreationActivityEntry().declareExtensions(extProfile); new DeletionActivityEntry().declareExtensions(extProfile); new EditActivityEntry().declareExtensions(extProfile); new FileCabinetPageEntry().declareExtensions(extProfile); new ListItemEntry().declareExtensions(extProfile); new ListPageEntry().declareExtensions(extProfile); new MoveActivityEntry().declareExtensions(extProfile); new RecoveryActivityEntry().declareExtensions(extProfile); new RevisionFeed().declareExtensions(extProfile); new WebAttachmentEntry().declareExtensions(extProfile); new WebPageEntry().declareExtensions(extProfile); BatchUtils.declareExtensions(extProfile); }
entry = new AnnouncementsPageEntry(); } else if (hasClass(element, "attachment")) { entry = new AttachmentEntry(); } else if (hasClass(element, "comment")) { entry = new CommentEntry();
private void downloadAttachment(AttachmentEntry attachment, File rootDirectory, EntryStore entryStore, SitesService sitesService) { BasePageEntry<?> parent = entryStore.getParent(attachment.getId()); if (parent != null) { File relativePath = getPath(parent, entryStore); if (relativePath != null) { File folder = new File(rootDirectory, relativePath.getPath()); folder.mkdirs(); File file = new File(folder, attachment.getTitle().getPlainText()); attachmentDownloader.download(attachment, file, sitesService); } } }
/** * Downloads the given attachment to the given file name. */ @Override public void download(AttachmentEntry attachment, File file, SitesService sitesService) { checkNotNull(attachment); checkNotNull(file); MediaContent mediaContent = new MediaContent(); mediaContent.setUri(((OutOfLineContent) attachment.getContent()).getUri()); try { MediaSource mediaSource = sitesService.getMedia(mediaContent); InputStream inStream = mediaSource.getInputStream(); OutputStream outStream = new FileOutputStream(file); byte[] buf = new byte[4*1024]; int bytesRead; while((bytesRead = inStream.read(buf)) != -1) { outStream.write(buf, 0, bytesRead); } inStream.close(); outStream.close(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Error downloading attachment: " + attachment.getTitle().getPlainText(), e); } catch (ServiceException e) { LOGGER.log(Level.WARNING, "Error downloading attachment: " + attachment.getTitle().getPlainText(), e); } } }
+ attachment.getTitle().getPlainText() + '.'); downloadAttachment(attachment, rootDirectory, entryStore, sitesService); progressListener.setProgress(((double) ++currentEntries) / totalEntries);
/** * Declare the extensions of the feeds for the Google Sites Data API. */ private void declareExtensions() { new AclFeed().declareExtensions(extProfile); new SiteFeed().declareExtensions(extProfile); /* Declarations for extensions that need to be handled as specific type * should be done before call to {@see ExtensionProfile#setAutoExtending}. * Order of declaration is important. */ extProfile.setAutoExtending(true); new ActivityFeed().declareExtensions(extProfile); new AnnouncementEntry().declareExtensions(extProfile); new AnnouncementsPageEntry().declareExtensions(extProfile); new AttachmentEntry().declareExtensions(extProfile); new CommentEntry().declareExtensions(extProfile); new ContentFeed().declareExtensions(extProfile); new CreationActivityEntry().declareExtensions(extProfile); new DeletionActivityEntry().declareExtensions(extProfile); new EditActivityEntry().declareExtensions(extProfile); new FileCabinetPageEntry().declareExtensions(extProfile); new ListItemEntry().declareExtensions(extProfile); new ListPageEntry().declareExtensions(extProfile); new MoveActivityEntry().declareExtensions(extProfile); new RecoveryActivityEntry().declareExtensions(extProfile); new RevisionFeed().declareExtensions(extProfile); new WebAttachmentEntry().declareExtensions(extProfile); new WebPageEntry().declareExtensions(extProfile); BatchUtils.declareExtensions(extProfile); }
/** * Default mutable constructor. */ public AttachmentEntry() { super(); getCategories().add(CATEGORY); }
/** * Returns the parent sites link. * * @return Parent sites link or {@code null} for none. */ public Link getParentLink() { return getLink(SitesLink.Rel.PARENT, Link.Type.ATOM); }