本文整理汇总了Java中com.google.gdata.data.sites.AttachmentEntry类的典型用法代码示例。如果您正苦于以下问题:Java AttachmentEntry类的具体用法?Java AttachmentEntry怎么用?Java AttachmentEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AttachmentEntry类属于com.google.gdata.data.sites包,在下文中一共展示了AttachmentEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetType
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
@Test
public void testGetType() {
assertEquals(EntryType.getType(new AnnouncementEntry()),
EntryType.ANNOUNCEMENT);
assertEquals(EntryType.getType(new AnnouncementsPageEntry()),
EntryType.ANNOUNCEMENTS_PAGE);
assertEquals(EntryType.getType(new AttachmentEntry()),
EntryType.ATTACHMENT);
assertEquals(EntryType.getType(new CommentEntry()),
EntryType.COMMENT);
assertEquals(EntryType.getType(new FileCabinetPageEntry()),
EntryType.FILE_CABINET_PAGE);
assertEquals(EntryType.getType(new ListItemEntry()),
EntryType.LIST_ITEM);
assertEquals(EntryType.getType(new ListPageEntry()),
EntryType.LIST_PAGE);
assertEquals(EntryType.getType(new WebAttachmentEntry()),
EntryType.WEB_ATTACHMENT);
assertEquals(EntryType.getType(new WebPageEntry()),
EntryType.WEB_PAGE);
}
示例2: downloadAttachment
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
/**
* Downloads an attachment.
*
* @param entry The attachment (entry) to download.
* @param entryId The content entry id of the attachment (e.g. 1234567890)
* @throws ServiceException
* @throws IOException
*/
public void downloadAttachment(String entryId, String directory)
throws IOException, ServiceException {
AttachmentEntry attachment = service.getEntry(
new URL(getContentFeedUrl() + entryId), AttachmentEntry.class);
String url = ((OutOfLineContent) attachment.getContent()).getUri();
///*MediaSource mediaSource = service.getMedia((MediaContent) entry.getContent());*/
downloadFile(url, directory + attachment.getTitle().getPlainText());
}
示例3: uploadAttachment
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
/**
* Uploads an attachment to a parent page.
*
* @param file The file contents to upload
* @param parentLink Full self id of the parent entry to upload the attach to.
* @param title A title for the attachment.
* @param description A description for the attachment.
* @return The created attachment entry.
* @throws ServiceException
* @throws IOException
*/
public AttachmentEntry uploadAttachment(File file, String parentLink, String title,
String description) throws IOException, ServiceException {
String fileMimeType = mediaTypes.getContentType(file);
AttachmentEntry newAttachment = new AttachmentEntry();
newAttachment.setMediaSource(new MediaFileSource(file, fileMimeType));
newAttachment.setTitle(new PlainTextConstruct(title));
newAttachment.setSummary(new PlainTextConstruct(description));
newAttachment.addLink(SitesLink.Rel.PARENT, Link.Type.ATOM, parentLink);
return service.insert(new URL(getContentFeedUrl()), newAttachment);
}
示例4: updateAttachment
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
/**
* Updates an existing attachment's metadata and content.
*
* @param entry Attachment entry to update.
* @param newFile The replacement file content.
* @param newTitle A new title for the attachment.
* @param newDescription A new description for the attachment.
* @return The created attachment.
* @throws ServiceException
* @throws IOException
*/
public AttachmentEntry updateAttachment(AttachmentEntry entry, File newFile,
String newTitle, String newDescription) throws IOException, ServiceException {
entry.setMediaSource(new MediaFileSource(newFile, mediaTypes.getContentType(newFile)));
if (newTitle != null) {
entry.setTitle(new PlainTextConstruct(newTitle));
}
if (newDescription != null) {
entry.setSummary(new PlainTextConstruct(newDescription));
}
return entry.updateMedia(true);
}
示例5: declareExtensions
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
/**
* 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);
}
示例6: downloadAttachment
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
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);
}
}
}
示例7: testIsPage
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
@Test
public void testIsPage() {
assertTrue(EntryType.isPage(new AnnouncementEntry()));
assertTrue(EntryType.isPage(new AnnouncementsPageEntry()));
assertTrue(EntryType.isPage(new FileCabinetPageEntry()));
assertTrue(EntryType.isPage(new ListPageEntry()));
assertTrue(EntryType.isPage(new WebPageEntry()));
assertFalse(EntryType.isPage(new AttachmentEntry()));
assertFalse(EntryType.isPage(new CommentEntry()));
assertFalse(EntryType.isPage(new ListItemEntry()));
}
示例8: testFileCabinetExport
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
@Test
public void testFileCabinetExport() throws IOException {
final FileCabinetPageEntry entry = new FileCabinetPageEntry();
entry.setId("entry");
entry.setTitle(new PlainTextConstruct("entry"));
final AttachmentEntry attachment1 = new AttachmentEntry();
attachment1.setId("attachment1");
attachment1.setUpdated(DateTime.parseDateTime("2009-08-06T16:08:12.107Z"));
EntryUtils.setParentId(attachment1, entry.getId());
final AttachmentEntry attachment2 = new AttachmentEntry();
attachment2.setId("attachment2");
attachment2.setUpdated(DateTime.parseDateTime("2009-08-06T16:26:57.019Z"));
EntryUtils.setParentId(attachment2, entry.getId());
entryStore.addEntry(entry);
entryStore.addEntry(attachment1);
entryStore.addEntry(attachment2);
final List<BaseContentEntry<?>> attachments = Lists.newArrayList();
attachments.add(attachment2);
attachments.add(attachment1);
context.checking(new Expectations() {{
oneOf (titleRenderer).renderTitle(entry);
will(returnValue(new XmlElement("div")));
oneOf (contentRenderer).renderContent(entry, false);
will(returnValue(new XmlElement("div")));
oneOf (fileCabinetRenderer).renderFileCabinet(with(equal(attachments)));
will(returnValue(new XmlElement("div")));
}});
exporter.exportPage(entry, entryStore, out, false);
}
示例9: writeEndWiki
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
@Override
public void writeEndWiki() throws IOException {
progressListener.setStatus("Processing Attachments.");
progressListener.setProgress(.5); // Arbitrarily chosen.
allImages.removeAll(attachments.keySet());
for (String image : allImages) {
attachments.put(image, Lists.<BasePageEntry<?>>newLinkedList());
}
for (Map.Entry<String, List<BasePageEntry<?>>>
entry : attachments.entrySet()) {
String name = entry.getKey();
progressListener.setStatus("Attachment: " + name);
AttachmentEntry attachment = new AttachmentEntry();
File file = new File(imagesDirectory, name);
String type = URLConnection.guessContentTypeFromName(file.getName());
MediaSource mediaSource = new MediaFileSource(file, type);
attachment.setMediaSource(mediaSource);
attachment.setTitle(TextConstruct.plainText(name));
pageImporter.importAttachment(
attachment, entry.getValue(),
feedUrl, sitesService);
}
progressListener.setStatus("Processed End of Wiki.");
progressListener.setProgress(.9); // Arbitrarily chosen.
}
示例10: exportSite
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
@Override
public void exportSite(String host, @Nullable String domain, String webspace,
boolean exportRevisions, SitesService sitesService, File rootDirectory,
ProgressListener progressListener) {
checkNotNull(host, "host");
checkNotNull(webspace, "webspace");
checkNotNull(sitesService, "sitesService");
checkNotNull(rootDirectory, "rootDirectory");
checkNotNull(progressListener, "progressListener");
Set<BaseContentEntry<?>> pages = Sets.newHashSet();
Set<AttachmentEntry> attachments = Sets.newHashSet();
EntryStore entryStore = entryStoreFactory.newEntryStore();
URL feedUrl = UrlUtils.getFeedUrl(host, domain, webspace);
URL siteUrl = UrlUtils.getSiteUrl(host, domain, webspace);
progressListener.setStatus("Retrieving site data (this may take a few minutes).");
Iterable<BaseContentEntry<?>> entries =
feedProvider.getEntries(feedUrl, sitesService);
int num = 1;
for (BaseContentEntry<?> entry : entries) {
if (entry != null) {
if (num % 20 == 0) {
progressListener.setStatus("Retrieved " + num + " entries.");
}
entryStore.addEntry(entry);
if (isPage(entry)) {
pages.add((BasePageEntry<?>) entry);
} else if (getType(entry) == ATTACHMENT) {
// TODO(gk5885): remove extra cast for
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302214
attachments.add((AttachmentEntry) entry);
}
else
{
progressListener.setStatus("The class of page is not supported!"
+ "The class of page:" + entry.getClass());
}
num++;
} else {
LOGGER.log(Level.WARNING, "Error parsing entries!");
}
}
int totalEntries = pages.size() + attachments.size();
if (totalEntries > 0) {
int currentEntries = 0;
for (BaseContentEntry<?> page : pages) {
progressListener.setStatus("Exporting page: "
+ page.getTitle().getPlainText() + '.');
linkConverter.convertLinks(page, entryStore, siteUrl, false);
File relativePath = getPath(page, entryStore);
if (relativePath != null) {
File directory = new File(rootDirectory, relativePath.getPath());
directory.mkdirs();
exportPage(page, directory, entryStore, exportRevisions);
if (exportRevisions) {
revisionsExporter.exportRevisions(page, entryStore, directory,
sitesService, siteUrl);
}
}
progressListener.setProgress(((double) ++currentEntries) / totalEntries);
}
for (AttachmentEntry attachment : attachments) {
progressListener.setStatus("Downloading attachment: "
+ attachment.getTitle().getPlainText() + '.');
downloadAttachment(attachment, rootDirectory, entryStore, sitesService);
progressListener.setProgress(((double) ++currentEntries) / totalEntries);
}
progressListener.setStatus("Export complete.");
} else {
progressListener.setStatus("No data returned. "
+ "Can you get anything from " + feedUrl.toString()+".");
}
}
示例11: testNormalExport
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testNormalExport() throws IOException {
final BasePageEntry<?> grandparent = new WebPageEntry();
grandparent.setId("grandparent");
grandparent.setTitle(new PlainTextConstruct("grandparent"));
grandparent.setPageName(new PageName("grandparent"));
final BasePageEntry<?> parent = new WebPageEntry();
parent.setId("parent");
EntryUtils.setParentId(parent, grandparent.getId());
final BasePageEntry<?> entry = new WebPageEntry();
entry.setId("entry");
entry.setTitle(new PlainTextConstruct("entry"));
EntryUtils.setParentId(entry, parent.getId());
final BasePageEntry<?> subpage1 = new WebPageEntry();
subpage1.setId("subpage1");
subpage1.setTitle(new PlainTextConstruct("subpage1"));
EntryUtils.setParentId(subpage1, entry.getId());
final BasePageEntry<?> subpage2 = new WebPageEntry();
subpage2.setId("subpage2");
subpage2.setTitle(new PlainTextConstruct("subpage2"));
EntryUtils.setParentId(subpage2, entry.getId());
final AttachmentEntry attachment1 = new AttachmentEntry();
attachment1.setId("attachment1");
attachment1.setUpdated(DateTime.parseDateTime("2009-08-06T16:08:12.107Z"));
EntryUtils.setParentId(attachment1, entry.getId());
final AttachmentEntry attachment2 = new AttachmentEntry();
attachment2.setId("attachment2");
attachment2.setUpdated(DateTime.parseDateTime("2009-08-06T16:26:57.019Z"));
EntryUtils.setParentId(attachment2, entry.getId());
final CommentEntry comment1 = new CommentEntry();
comment1.setId("comment1");
comment1.setUpdated(DateTime.parseDateTime("2009-08-06T16:08:12.107Z"));
EntryUtils.setParentId(comment1, entry.getId());
final CommentEntry comment2 = new CommentEntry();
comment2.setId("comment2");
comment2.setUpdated(DateTime.parseDateTime("2009-08-06T16:26:57.019Z"));
EntryUtils.setParentId(comment2, entry.getId());
entryStore.addEntry(grandparent);
entryStore.addEntry(parent);
entryStore.addEntry(entry);
entryStore.addEntry(subpage1);
entryStore.addEntry(subpage2);
entryStore.addEntry(attachment1);
entryStore.addEntry(attachment2);
entryStore.addEntry(comment1);
entryStore.addEntry(comment2);
final List<BasePageEntry<?>> ancestors = Lists.newArrayList();
ancestors.add(grandparent);
ancestors.add(parent);
final List<BasePageEntry<?>> subpages = Lists.newArrayList();
subpages.add(subpage1);
subpages.add(subpage2);
final List<BaseContentEntry<?>> attachments = Lists.newArrayList();
attachments.add(attachment2);
attachments.add(attachment1);
final List<CommentEntry> comments = Lists.newArrayList();
comments.add(comment2);
comments.add(comment1);
context.checking(new Expectations() {{
oneOf (ancestorLinksRenderer).renderAncestorLinks(
with(equal(ancestors)));
will(returnValue(new XmlElement("div")));
oneOf (titleRenderer).renderTitle(entry);
will(returnValue(new XmlElement("div")));
oneOf (contentRenderer).renderContent(entry, false);
will(returnValue(new XmlElement("div")));
oneOf (subpageLinksRenderer).renderSubpageLinks(with(equal(subpages)));
will(returnValue(new XmlElement("div")));
oneOf (attachmentsRenderer).renderAttachments(with(equal(attachments)));
will(returnValue(new XmlElement("div")));
oneOf (commentsRenderer).renderComments(with(equal(comments)));
will(returnValue(new XmlElement("div")));
}});
exporter.exportPage(entry, entryStore, out, false);
}
示例12: testOnePageWithAttachment
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
@Test
public void testOnePageWithAttachment() throws IOException {
final BasePageEntry<?> page = new FileCabinetPageEntry();
page.setId("1");
page.setTitle(new PlainTextConstruct("Page 1"));
page.setPageName(new PageName("Page-1"));
XmlBlob blob = new XmlBlob();
blob.setBlob("content");
page.setContent(new XhtmlTextConstruct(blob));
final BaseContentEntry<?> attachment = new AttachmentEntry();
attachment.setId("2");
attachment.setTitle(new PlainTextConstruct("attach this.wow"));
attachment.addLink(SitesLink.Rel.PARENT, ILink.Type.ATOM, "1");
entries.add(page);
entries.add(attachment);
final Appendable out = context.mock(Appendable.class);
context.checking(new Expectations() {{
allowing (entryStoreFactory).newEntryStore();
will(returnValue(entryStore));
allowing (feedProvider).getEntries(feedUrl, sitesService);
will(returnValue(entries));
allowing (entryStore).getEntry("1"); will(returnValue(page));
allowing (entryStore).getParent("1"); will(returnValue(null));
allowing (entryStore).getEntry("2"); will(returnValue(attachment));
allowing (entryStore).getParent("2"); will(returnValue(page));
allowing (progressListener).setStatus(with(any(String.class)));
allowing (progressListener).setProgress(with(any(Double.class)));
oneOf (entryStore).addEntry(page);
oneOf (entryStore).addEntry(attachment);
oneOf (appendableFactory).getAppendable(
new File("path/Page-1/index.html"));
will(returnValue(out));
oneOf (linkConverter).convertLinks(page, entryStore,
new URL("https://host/a/domain/webspace"), false);
oneOf (pageExporter).exportPage(page, entryStore, out, false);
}});
export(false);
assertTrue(downloaded.get(attachment).equals(
new File("path/Page-1/attach this.wow")));
}
示例13: download
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
@Override
public void download(AttachmentEntry attachment, File file,
SitesService sitesService) {
downloaded.put(attachment, file);
}
示例14: exportSite
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
@Override
public void exportSite(String host, @Nullable String domain, String webspace,
boolean exportRevisions, SitesService sitesService, File rootDirectory,
ProgressListener progressListener) {
checkNotNull(host, "host");
checkNotNull(webspace, "webspace");
checkNotNull(sitesService, "sitesService");
checkNotNull(rootDirectory, "rootDirectory");
checkNotNull(progressListener, "progressListener");
Set<BasePageEntry<?>> pages = Sets.newHashSet();
Set<AttachmentEntry> attachments = Sets.newHashSet();
EntryStore entryStore = entryStoreFactory.newEntryStore();
URL feedUrl = UrlUtils.getFeedUrl(host, domain, webspace);
URL siteUrl = UrlUtils.getSiteUrl(host, domain, webspace);
progressListener.setStatus("Retrieving site data (this may take a few minutes).");
Iterable<BaseContentEntry<?>> entries =
feedProvider.getEntries(feedUrl, sitesService);
int num = 1;
for (BaseContentEntry<?> entry : entries) {
if (entry != null) {
if (num % 20 == 0) {
progressListener.setStatus("Retrieved " + num + " entries.");
}
entryStore.addEntry(entry);
if (isPage(entry)) {
pages.add((BasePageEntry<?>) entry);
} else if (getType(entry) == ATTACHMENT) {
// TODO(gk5885): remove extra cast for
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302214
attachments.add((AttachmentEntry) (BaseContentEntry) entry);
}
num++;
} else {
LOGGER.log(Level.WARNING, "Error parsing entries!");
}
}
int totalEntries = pages.size() + attachments.size();
if (totalEntries > 0) {
int currentEntries = 0;
for (BasePageEntry<?> page : pages) {
progressListener.setStatus("Exporting page: "
+ page.getTitle().getPlainText() + '.');
linkConverter.convertLinks(page, entryStore, siteUrl, false);
File relativePath = getPath(page, entryStore);
if (relativePath != null) {
File directory = new File(rootDirectory, relativePath.getPath());
directory.mkdirs();
exportPage(page, directory, entryStore, exportRevisions);
if (exportRevisions) {
revisionsExporter.exportRevisions(page, entryStore, directory,
sitesService, siteUrl);
}
}
progressListener.setProgress(((double) ++currentEntries) / totalEntries);
}
for (AttachmentEntry attachment : attachments) {
progressListener.setStatus("Downloading attachment: "
+ attachment.getTitle().getPlainText() + '.');
downloadAttachment(attachment, rootDirectory, entryStore, sitesService);
progressListener.setProgress(((double) ++currentEntries) / totalEntries);
}
progressListener.setStatus("Export complete.");
} else {
progressListener.setStatus("No data returned. You may have provided "
+ "invalid Site information or credentials.");
}
}
示例15: downloadAllAttachments
import com.google.gdata.data.sites.AttachmentEntry; //导入依赖的package包/类
/**
* Downloads all attachments from a Site and assumes they all have different names.
*
* @param entry The attachment (entry) to download.
* @param directory Path to a local directory to download the attach to.
* @throws ServiceException
* @throws IOException
*/
public void downloadAllAttachments(String directory) throws IOException, ServiceException {
URL contentFeedUrl = new URL(getContentFeedUrl() + "?kind=attachment");
ContentFeed contentFeed = service.getFeed(contentFeedUrl, ContentFeed.class);
for (AttachmentEntry entry : contentFeed.getEntries(AttachmentEntry.class)) {
downloadAttachment(entry, directory);
}
}