be.re.repo
Class Tools

java.lang.Object
  extended by be.re.repo.Tools

public class Tools
extends Object

Public utilities which are targeted to module developers.

Author:
Werner Donné

Constructor Summary
Tools()
           
 
Method Summary
static boolean canRead(URLConnection connection)
          Checks the read access right.
static String generateContextUrl(Context context)
          Returns the context URL of the request.
static String generateFullPath(String localPath, Context context)
          Takes into account a possible context path.
static String generateLocalUrl(String localPath)
          Returns a URL with the "local" protocol constructed from localPath.
static String generateUrl(String localPath, Context context)
          Returns the absolute URL constructed from localPath.
static String generateVcrUrl(String vcr, Context context)
          Returns the absolute URL constructed from vcr.
static String getEnv(String name)
          Returns an environment setting from the configuration.
static Locale getLocale(Context context)
          Returns the locale in which the request was made.
static String[] getMetaPropertyValues(String property, Context context)
          Returns the property values that exist for property.
static ResourceBundle getResourceBundle(String name, Context context)
          Selects the resource bundle based on the locale derived from context.
static String getUsername(Context context)
          Returns the username corresponding to the request.
static String labelToName(String propertyLabel, Context context)
          Returns the property name for the given label.
static String nameToLabel(String propertyName, Context context)
          Returns the property label for the given name.
static void retainNewest(Set<Property> newProperties, Set<Property> oldProperties, Set<String> singleValued, Context context)
          If a single-valued property occurs more than once, the new value is retained.
static void setAtom(Set<Property> properties, String key, String value)
          Sets the property in properties with the "atom:" prefix if value is not null and not an empty string or a string with only whitespace.
static void setDublinCoreElement(Set<Property> properties, String element, String value)
          Sets the property in properties with the "dc:" prefix if value is not null and not an empty string or a string with only whitespace.
static void setDublinCoreTerm(Set<Property> properties, String term, String value)
          Sets the property in properties with the "dcterms:" prefix if value is not null and not an empty string or a string with only whitespace.
static void setKeywords(Set<Property> properties, String keywords)
          Sets the keywords in properties under the name "re:keyword" if keywords is not null and not an empty string or a string with only whitespace.
static void setRe(Set<Property> properties, String key, String value)
          Sets the property in properties with the "re:" prefix if value is not null and not an empty string or a string with only whitespace.
static void setUserDefined(Set<Property> properties, String name, String value, Context context)
          Sets the property in properties if value is not null and not an empty string or a string with only whitespace.
static void setWarning(String message, Context context)
          Sets a warning on the HTTP response.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tools

public Tools()
Method Detail

canRead

public static boolean canRead(URLConnection connection)
Checks the read access right. This is meant for connections using the "local" scheme.


generateContextUrl

public static String generateContextUrl(Context context)
Returns the context URL of the request.


generateFullPath

public static String generateFullPath(String localPath,
                                      Context context)
Takes into account a possible context path. The result is URI escaped.


generateLocalUrl

public static String generateLocalUrl(String localPath)
Returns a URL with the "local" protocol constructed from localPath.


generateUrl

public static String generateUrl(String localPath,
                                 Context context)
Returns the absolute URL constructed from localPath.


generateVcrUrl

public static String generateVcrUrl(String vcr,
                                    Context context)
Returns the absolute URL constructed from vcr. Takes into account the current view. If there is a view, the view path will be prepended to the vcr.


getEnv

public static String getEnv(String name)
Returns an environment setting from the configuration.


getLocale

public static Locale getLocale(Context context)
Returns the locale in which the request was made.


getMetaPropertyValues

public static String[] getMetaPropertyValues(String property,
                                             Context context)
                                      throws IOException
Returns the property values that exist for property.

Throws:
IOException

getResourceBundle

public static ResourceBundle getResourceBundle(String name,
                                               Context context)
Selects the resource bundle based on the locale derived from context. The name is the name of a resource bundle.


getUsername

public static String getUsername(Context context)
Returns the username corresponding to the request. If there is no user then the value will be unauthenticated.


labelToName

public static String labelToName(String propertyLabel,
                                 Context context)
Returns the property name for the given label. The name has one of the following prefixes: "atom:", "dc:", "dcterms:", "opds:" and "re:". This is a method for localized built-in properties.


nameToLabel

public static String nameToLabel(String propertyName,
                                 Context context)
Returns the property label for the given name. The name should have one of the following prefixes: "atom:", "dc:", "dcterms:", "opds:" and "re:". This is a method for localized built-in properties.


retainNewest

public static void retainNewest(Set<Property> newProperties,
                                Set<Property> oldProperties,
                                Set<String> singleValued,
                                Context context)
If a single-valued property occurs more than once, the new value is retained. If more than one new value is provided, a random one will be retained.

Parameters:
newProperties - the property set that will be modified.
oldProperties - the properties a document currently has.
singleValued - the set of property names that should be treated as single-valued.
context - the context of the repository.

setAtom

public static void setAtom(Set<Property> properties,
                           String key,
                           String value)
Sets the property in properties with the "atom:" prefix if value is not null and not an empty string or a string with only whitespace.


setDublinCoreElement

public static void setDublinCoreElement(Set<Property> properties,
                                        String element,
                                        String value)
Sets the property in properties with the "dc:" prefix if value is not null and not an empty string or a string with only whitespace.


setDublinCoreTerm

public static void setDublinCoreTerm(Set<Property> properties,
                                     String term,
                                     String value)
Sets the property in properties with the "dcterms:" prefix if value is not null and not an empty string or a string with only whitespace.


setKeywords

public static void setKeywords(Set<Property> properties,
                               String keywords)
Sets the keywords in properties under the name "re:keyword" if keywords is not null and not an empty string or a string with only whitespace. The keywords argument may be a comma-separated or space-separated list of words.


setRe

public static void setRe(Set<Property> properties,
                         String key,
                         String value)
Sets the property in properties with the "re:" prefix if value is not null and not an empty string or a string with only whitespace. The supported properties are "company", "keyword", "manager" and "status".


setUserDefined

public static void setUserDefined(Set<Property> properties,
                                  String name,
                                  String value,
                                  Context context)
Sets the property in properties if value is not null and not an empty string or a string with only whitespace. An attempt is made to treat name as a label of a built-in property (DublinCore, Atom or Re). The locale of the request is used for this. If the attempt fails name is used as such.


setWarning

public static void setWarning(String message,
                              Context context)
Sets a warning on the HTTP response.