/** * Returns the reference of the target according to the a list of properties. * * @param resolver The resolver. * @return The target reference. * @throws ResourceException */ protected Reference getTargetRef(Resolver<String> resolver) throws ResourceException { final Template targetTemplate = new Template(getTargetUri()); Reference result = new Reference(targetTemplate.format(resolver)); if (result.isRelative()) { result.setBaseRef(getMailboxUri()); result = result.getTargetRef(); } return result; }
/** * Returns the reference of a mail according to its identifier. * * @param identifier The identifier of a mail. * @return The URI of the mail. * @throws ResourceException */ protected Reference getMailRef(String identifier) throws ResourceException { final Template mailTemplate = new Template(getMailUriTemplate()); Reference result = new Reference(mailTemplate.format(new MailResolver(identifier))); if (result.isRelative()) { result.setBaseRef(getMailboxUri()); result = result.getTargetRef(); } return result; }
/** * Returns the child resource defined by its URI relatively to the current resource. The child * resource is defined in the sense of hierarchical URIs. If the resource URI is not hierarchical, * then an exception is thrown. * * @param relativeRef The URI reference of the child resource relatively to the current resource * seen as the parent resource. * @return The child resource. * @throws ResourceException */ public ClientResource getChild(Reference relativeRef) throws ResourceException { ClientResource result = null; if ((relativeRef != null) && relativeRef.isRelative()) { result = new ClientResource(this); result.setReference(new Reference(getReference().getTargetRef(), relativeRef).getTargetRef()); } else { throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "The child URI is not relative."); } return result; }
/** * Returns the feed representation. * * @return The feed representation. * @throws Exception */ public Feed getFeed() throws Exception { final Reference feedRef = getHref(); if (feedRef.isRelative()) { feedRef.setBaseRef(getWorkspace().getService().getReference()); } final Request request = new Request(Method.GET, feedRef.getTargetRef()); final Response response = getWorkspace().getService().getClientDispatcher().handle(request); if (response.getStatus().equals(Status.SUCCESS_OK)) { return new Feed(response.getEntity()); } throw new Exception( "Couldn't get the feed representation. Status returned: " + response.getStatus()); }
/** * Deletes a mail after it has been processed. * * @param mailIdentifier The identifier of the mail * @throws ResourceException */ protected void deleteMail(String mailIdentifier) throws ResourceException { // A - Build the mail URI Reference mailRef = getMailRef(mailIdentifier); if (mailRef.isRelative()) { mailRef.setBaseRef(getMailboxUri()); mailRef = mailRef.getTargetRef(); } // B - Delete the mail final Request request = new Request(Method.DELETE, mailRef); if (getMailboxChallengeScheme() != null) { final ChallengeResponse challengeResponse = new ChallengeResponse( getMailboxChallengeScheme(), getMailboxLogin(), getMailboxPassword()); request.setChallengeResponse(challengeResponse); } final Response response = getContext().getClientDispatcher().handle(request); if (response.getStatus().isError()) { throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "Unable to delete the mail from the mailbox"); } }