Posts a new entry to the feed associated with the specified public signing key to the home server, creating a new feed if needed. @param signingKeys Required: the signing keys associated with public feed id of this feed. @param encryptionKey Required: the public enc
(KeyPair signingKeys, KeyPair encryptionKeys,
EntryOptions options, FeedOptions feedOptions)
| 377 | * @throws contentKey |
| 378 | */ |
| 379 | public Feed post(KeyPair signingKeys, KeyPair encryptionKeys, |
| 380 | EntryOptions options, FeedOptions feedOptions) throws IOException, |
| 381 | SecurityException, GeneralSecurityException, Exception { |
| 382 | // inlining all the steps to help implementors and porters (and |
| 383 | // debuggers) |
| 384 | |
| 385 | // configure for signing |
| 386 | Element signedNode, signatureElement, keyInfo; |
| 387 | AbderaSecurity security = new AbderaSecurity(Abdera.getInstance()); |
| 388 | Signature signer = security.getSignature(); |
| 389 | |
| 390 | String feedId = Common.toFeedId(signingKeys.getPublic()); |
| 391 | Feed feed = pull(feedId); |
| 392 | if (feed == null) { |
| 393 | feed = Abdera.getInstance().newFeed(); |
| 394 | feed.declareNS(Common.NS_URI, Common.NS_ABBR); |
| 395 | } |
| 396 | |
| 397 | // remove each entry and retain the most recent one (if any) |
| 398 | List<Entry> entries = feed.getEntries(); |
| 399 | Entry mostRecentEntry = null; |
| 400 | for (Entry entry : entries) { |
| 401 | if (mostRecentEntry == null || mostRecentEntry.getUpdated() == null |
| 402 | || mostRecentEntry.getUpdated().before(entry.getUpdated())) { |
| 403 | mostRecentEntry = entry; |
| 404 | } |
| 405 | entry.discard(); |
| 406 | } |
| 407 | |
| 408 | // update and sign feed (without any entries) |
| 409 | feed.setUpdated(new Date()); |
| 410 | |
| 411 | // ensure the correct keys are in place |
| 412 | signatureElement = feed.getFirstChild(new QName(Common.NS_URI, |
| 413 | Common.SIGN)); |
| 414 | if (signatureElement != null) { |
| 415 | signatureElement.discard(); |
| 416 | } |
| 417 | feed.addExtension(new QName(Common.NS_URI, Common.SIGN)).setText( |
| 418 | Common.toX509FromPublicKey(signingKeys.getPublic())); |
| 419 | signatureElement = feed.getFirstChild(new QName(Common.NS_URI, |
| 420 | Common.ENCRYPT)); |
| 421 | if (signatureElement != null) { |
| 422 | signatureElement.discard(); |
| 423 | } |
| 424 | feed.addExtension(new QName(Common.NS_URI, Common.ENCRYPT)).setText( |
| 425 | Common.toX509FromPublicKey(encryptionKeys.getPublic())); |
| 426 | feed.setId(Common.toFeedUrn(feedId)); |
| 427 | feed.setMustPreserveWhitespace(false); |
| 428 | |
| 429 | // update feed properties |
| 430 | if (feedOptions.title != null) { |
| 431 | feed.setTitle(feedOptions.title); |
| 432 | } |
| 433 | if (feedOptions.subtitle != null) { |
| 434 | feed.setSubtitle(feedOptions.subtitle); |
| 435 | } |
| 436 | if (feedOptions.icon != null) { |