org.apache.abdera.protocol.server
Class ProviderHelper

java.lang.Object
  extended by org.apache.abdera.protocol.server.ProviderHelper

public class ProviderHelper
extends Object

Provides support methods for Provider


Method Summary
static ResponseContext badrequest(RequestContext request)
           
static ResponseContext badrequest(RequestContext request, String reason)
          Return a 400 bad request error
static boolean beforeOrEqual(Date d1, Date d2)
           
static org.apache.abdera.util.EntityTag calculateEntityTag(Base base)
           
static boolean checkElementNamespaces(Element element, List<String> ignore)
          Return false if the element contains any extension elements that are not supported
static String combine(String... vals)
           
static ResponseContext conflict(RequestContext request)
           
static ResponseContext conflict(RequestContext request, String reason)
          Return a 409 conflict error
static AbstractResponseContext createErrorResponse(Abdera abdera, int code, String message)
          Returns an Error document based on the StreamWriter
static AbstractResponseContext createErrorResponse(Abdera abdera, int code, String message, Throwable t)
          Returns an Error document based on the StreamWriter
static boolean defaultCheckMethod(RequestContext request, String[] methods)
           
static ResponseContext forbidden(RequestContext request)
           
static ResponseContext forbidden(RequestContext request, String reason)
          Return an unauthorized error
static NamedWriter getAcceptableNamedWriter(Abdera abdera, String accept_header)
          Returns an appropriate NamedWriter instance given an appropriately formatted HTTP Accept header.
static String[] getAcceptableTypes(RequestContext request)
           
static String[] getDefaultMethods(RequestContext request)
           
static String getEditUriFromEntry(Entry entry)
           
static NamedWriter getNamedWriter(Abdera abdera, String mediatype)
           
static int getOffset(RequestContext request, String pageparam, int pageSize)
           
static int getPageSize(RequestContext request, String pagesizeparam, int defaultpagesize)
           
static boolean isAtom(RequestContext request)
           
static boolean isPreferred(RequestContext request, String s1, String s2)
           
static boolean isPreferred(String[] accepts, String s1, String s2)
           
static boolean isValidEntry(Entry entry)
          Check to see if the entry is minimally valid according to RFC4287.
static ResponseContext locked(RequestContext request)
           
static ResponseContext locked(RequestContext request, String reason)
          Return a 423 locked error
static ResponseContext nocontent()
           
static ResponseContext nocontent(String reason)
          Return a 204 No Content response
static ResponseContext notallowed(RequestContext request)
           
static ResponseContext notallowed(RequestContext request, String... methods)
           
static ResponseContext notallowed(RequestContext request, String reason, String... methods)
          Return a 405 method not allowed error
static ResponseContext notfound(RequestContext request)
           
static ResponseContext notfound(RequestContext request, String reason)
          Return a 404 not found error
static ResponseContext notmodified(RequestContext request)
           
static ResponseContext notmodified(RequestContext request, String reason)
           
static ResponseContext notsupported(RequestContext request)
           
static ResponseContext notsupported(RequestContext request, String reason)
          Return a 415 media type not-supported error
static String[] orderByQ(String header)
           Utility method for parsing HTTP content negotiation headers and sorting their tokens according to their q parameter values.
static ResponseContext preconditionfailed(RequestContext request)
           
static ResponseContext preconditionfailed(RequestContext request, String reason)
           
static IRI resolveBase(RequestContext request)
           
static ResponseContext returnBase(Base base, int status, Date lastModified)
          Return a document
static String sanitizeSlug(String slug)
          Sanitize the value of a Slug header.
static ResponseContext servererror(RequestContext request, String reason, Throwable t)
          Return a server error
static ResponseContext servererror(RequestContext request, Throwable t)
          Return a server error
static ResponseContext unauthorized(RequestContext request)
           
static ResponseContext unauthorized(RequestContext request, String reason)
          Return an unauthorized error
static ResponseContext unavailable(RequestContext request)
           
static ResponseContext unavailable(RequestContext request, String reason)
          Return a service unavailable error
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getPageSize

public static int getPageSize(RequestContext request,
                              String pagesizeparam,
                              int defaultpagesize)

getOffset

public static int getOffset(RequestContext request,
                            String pageparam,
                            int pageSize)

createErrorResponse

public static AbstractResponseContext createErrorResponse(Abdera abdera,
                                                          int code,
                                                          String message)
Returns an Error document based on the StreamWriter


createErrorResponse

public static AbstractResponseContext createErrorResponse(Abdera abdera,
                                                          int code,
                                                          String message,
                                                          Throwable t)
Returns an Error document based on the StreamWriter


servererror

public static ResponseContext servererror(RequestContext request,
                                          String reason,
                                          Throwable t)
Return a server error


servererror

public static ResponseContext servererror(RequestContext request,
                                          Throwable t)
Return a server error


unauthorized

public static ResponseContext unauthorized(RequestContext request,
                                           String reason)
Return an unauthorized error


unauthorized

public static ResponseContext unauthorized(RequestContext request)

forbidden

public static ResponseContext forbidden(RequestContext request,
                                        String reason)
Return an unauthorized error


forbidden

public static ResponseContext forbidden(RequestContext request)

nocontent

public static ResponseContext nocontent(String reason)
Return a 204 No Content response


nocontent

public static ResponseContext nocontent()

notfound

public static ResponseContext notfound(RequestContext request,
                                       String reason)
Return a 404 not found error


notfound

public static ResponseContext notfound(RequestContext request)

notallowed

public static ResponseContext notallowed(RequestContext request,
                                         String reason,
                                         String... methods)
Return a 405 method not allowed error


notallowed

public static ResponseContext notallowed(RequestContext request,
                                         String... methods)

notallowed

public static ResponseContext notallowed(RequestContext request)

badrequest

public static ResponseContext badrequest(RequestContext request,
                                         String reason)
Return a 400 bad request error


badrequest

public static ResponseContext badrequest(RequestContext request)

conflict

public static ResponseContext conflict(RequestContext request,
                                       String reason)
Return a 409 conflict error


conflict

public static ResponseContext conflict(RequestContext request)

unavailable

public static ResponseContext unavailable(RequestContext request,
                                          String reason)
Return a service unavailable error


unavailable

public static ResponseContext unavailable(RequestContext request)

notmodified

public static ResponseContext notmodified(RequestContext request,
                                          String reason)

notmodified

public static ResponseContext notmodified(RequestContext request)

preconditionfailed

public static ResponseContext preconditionfailed(RequestContext request,
                                                 String reason)

preconditionfailed

public static ResponseContext preconditionfailed(RequestContext request)

notsupported

public static ResponseContext notsupported(RequestContext request,
                                           String reason)
Return a 415 media type not-supported error


notsupported

public static ResponseContext notsupported(RequestContext request)

locked

public static ResponseContext locked(RequestContext request,
                                     String reason)
Return a 423 locked error


locked

public static ResponseContext locked(RequestContext request)

returnBase

public static ResponseContext returnBase(Base base,
                                         int status,
                                         Date lastModified)
Return a document


sanitizeSlug

public static String sanitizeSlug(String slug)
Sanitize the value of a Slug header. Any non alphanumeric characters in the slug are replaced with an underscore


isValidEntry

public static boolean isValidEntry(Entry entry)
Check to see if the entry is minimally valid according to RFC4287. This is not a complete check. It just verifies that the appropriate elements are present and that their values can be accessed.


checkElementNamespaces

public static boolean checkElementNamespaces(Element element,
                                             List<String> ignore)
Return false if the element contains any extension elements that are not supported


beforeOrEqual

public static boolean beforeOrEqual(Date d1,
                                    Date d2)

resolveBase

public static IRI resolveBase(RequestContext request)

combine

public static String combine(String... vals)

getDefaultMethods

public static String[] getDefaultMethods(RequestContext request)

defaultCheckMethod

public static boolean defaultCheckMethod(RequestContext request,
                                         String[] methods)

isAtom

public static boolean isAtom(RequestContext request)

orderByQ

public static String[] orderByQ(String header)

Utility method for parsing HTTP content negotiation headers and sorting their tokens according to their q parameter values.

e.g. Accept: audio/*; q=0.2, audio/basic, audio/mpeg; q=0.1

would sort into:

   audio/basic
   audio/*
   audio/mpeg
 


getAcceptableNamedWriter

public static NamedWriter getAcceptableNamedWriter(Abdera abdera,
                                                   String accept_header)
Returns an appropriate NamedWriter instance given an appropriately formatted HTTP Accept header. The header will be parsed and sorted according to it's q parameter values. The first named writer capable of supporting the specified type, in order of q-value preference, will be returned. The results on this are not always predictable. For instance, if the Accept header says "application/*" it could end up with either the JSON writer or the PrettyXML writer, or any other writer that supports any writer that supports a specific form of "application/*". It's always best to be very specific in the Accept headers.


getNamedWriter

public static NamedWriter getNamedWriter(Abdera abdera,
                                         String mediatype)

calculateEntityTag

public static org.apache.abdera.util.EntityTag calculateEntityTag(Base base)

getEditUriFromEntry

public static String getEditUriFromEntry(Entry entry)

getAcceptableTypes

public static String[] getAcceptableTypes(RequestContext request)

isPreferred

public static boolean isPreferred(RequestContext request,
                                  String s1,
                                  String s2)

isPreferred

public static boolean isPreferred(String[] accepts,
                                  String s1,
                                  String s2)


Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.