|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.clients.web.Base
public final class Base
This class is used to collect some useful methods for the web client into a single place. All methods in this class are static methods.
Field Summary | |
---|---|
private static Integer |
defaultMaxRecent
|
private static Float |
defaultScale
|
Constructor Summary | |
---|---|
Base()
|
Method Summary | ||
---|---|---|
static ItemContext |
createDefaultContext(String sortProperty,
String defaultColumns)
Create a default ItemContext with settings for default
visible columns and sort property. |
|
static ItemContext |
getAndSetCurrentContext(SessionControl sc,
Item itemType,
PageContext pageContext,
ItemContext defaultContext)
Same as: getAndSetCurrentContext(sc, itemType, "", pageContext, defaultContext, false) . |
|
static ItemContext |
getAndSetCurrentContext(SessionControl sc,
Item itemType,
PageContext pageContext,
ItemContext defaultContext,
boolean resetTemporary)
Same as: getAndSetCurrentContext(sc, itemType, "", pageContext, defaultContext, resetTemporary) . |
|
static ItemContext |
getAndSetCurrentContext(SessionControl sc,
Item itemType,
String subContext,
PageContext pageContext,
ItemContext defaultContext)
Same as: getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext, false) . |
|
static ItemContext |
getAndSetCurrentContext(SessionControl sc,
Item itemType,
String subContext,
PageContext pageContext,
ItemContext defaultContext,
boolean resetTemporary)
|
|
static ItemContext |
getAndSetCurrentContext(SessionControl sc,
Item itemType,
String subContext,
ServletRequest request,
ItemContext defaultContext,
boolean resetTemporary)
Get the current context and update it from request information if available. |
|
static ItemQuery<AnnotationType> |
getAnnotationTypesQuery(AnnotatableProxy proxy)
Get a query that returns all annotation types defined for a AnnotatableProxy item. |
|
static ItemQuery<AnnotationType> |
getAnnotationTypesQuery(Item itemType)
Get a query that returns all annotation types defined for a particular item type. |
|
static ItemQuery<AnnotationType> |
getAnnotationTypesQuery(Item itemType,
Boolean isProtocolParameter)
Get a query that returns all annotation types defined for a particular item type and, optionally, with a specific protocol parameter setting. |
|
static Enumeration<String,String> |
getBioMaterialListsEnum(DbControl dc,
Item memberType,
Collection<Include> include)
Get available biomaterial lists as an Enumeration that is suitable to use in a column definition for a table. |
|
static ColorGenerator |
getColorGenerator(SessionControl sc,
Coloring coloring)
|
|
static Color[] |
getConfiguredColors(SessionControl sc)
|
|
static
|
getConfiguredQuery(DbControl dc,
ItemContext cc,
boolean autoLeftJoin,
ItemQuery<T> query,
ModeInfo mode)
Configures a query. |
|
static
|
getConfiguredQuery(ItemContext cc,
boolean autoLeftJoin,
ItemQuery<T> query,
ModeInfo mode)
Deprecated. Use getConfiguredQuery(DbControl, ItemContext, boolean, ItemQuery, ModeInfo)
instead |
|
static Cookie |
getCookie(HttpServletRequest request,
String name)
Get the cookie with the specified name. |
|
static String |
getCookieValue(HttpServletRequest request,
String name)
Get the value of the cookie with the specified name. |
|
static ItemQuery<DataFileType> |
getDataFileTypes(Item itemType,
FileStoreEnabled item,
Platform platform,
PlatformVariant variant)
Get a query that returns all data file types for a specific platform/variant that can be used on a given item type. |
|
static String |
getEncodedName(Nameable item,
boolean denied)
|
|
static String |
getEncodedName(Nameable item,
boolean denied,
String link)
Deprecated. Use getLinkedName(String, Nameable, boolean, boolean) instead |
|
static SessionControl |
getExistingSessionControl(PageContext pageContext,
boolean checkLoggedIn)
Get an existing SessionControl object
given a PageContext and optionally check that a user is logged in. |
|
static SessionControl |
getExistingSessionControl(PageContext pageContext,
Permission permission,
Item itemType)
Get an existing SessionControl object given
a PageContext and check for generic (role-based)
permission to an item type. |
|
static SessionControl |
getExistingSessionControl(ServletRequest request,
boolean checkLoggedIn)
Get an existing SessionControl object
given a ServletRequest object and optionally check that a user is logged in. |
|
static SessionControl |
getExistingSessionControl(ServletRequest request,
Permission permission,
Item itemType)
Get an existing SessionControl object given
a ServletRequest and check for generic (role-based)
permission to an item type. |
|
static String |
getFileLinks(String ID,
File file,
String root)
Get view/download links for a file. |
|
static
|
getFirstMatching(DbControl dc,
ItemQuery<T> query,
String property,
PropertyFilter filter)
|
|
static String |
getLink(String ID,
String name,
Item itemType,
int itemId,
boolean enableEditLink)
|
|
static String |
getLink(String ID,
String name,
Item itemType,
int itemId,
boolean enableEditLink,
String tooltip)
|
|
static String |
getLinkedFile(String ID,
File file,
boolean denied,
boolean enableEditLink,
boolean enableViewDownload,
String root)
|
|
static String |
getLinkedName(String ID,
Nameable item,
boolean denied,
boolean enableEditLink)
|
|
static int |
getMaxRecent(SessionControl sc)
Get the setting for the maximum number of recently used items to save. |
|
static
|
getOldItem(SessionControl sc,
T newItem,
int oldVersion)
Get the old item that is stored in the SessionControl :s
session setting itemType.item . |
|
static String |
getPropertyFilterString(PropertyFilter filter,
Formatter<Date> dateFormatter)
Convert a property filter to a displayable string with operator + value. |
|
static ItemQuery<AnnotationType> |
getProtocolParametersQuery(Protocol protocol)
Get a query that returns all annotation types assigned as parameters to a specific protocol. |
|
static Enumeration<String,String> |
getReporterListsEnum(DbControl dc)
|
|
static float |
getScale(SessionControl sc)
Get the display scale setting. |
|
static SessionControl |
getSessionControl(PageContext pageContext,
boolean create)
Get a new or existing SessionControl object
given a PageContext . |
|
static SessionControl |
getSessionControl(ServletRequest request,
boolean create)
Get a new or existing SessionControl object
given a ServletRequest instance. |
|
static ItemContext |
loadContext(SessionControl sc,
int contextId,
ItemContext defaultContext)
|
|
private static boolean |
setInclude(Set<Include> includes,
String option,
Include i)
Set include option if option parameter isn't null. |
|
static void |
updateAnnotations(DbControl dc,
Annotatable oldItem,
Annotatable newItem,
HttpServletRequest request)
Update annotations on an item taking concurrent modifications into account. |
|
static void |
updateFiles(DbControl dc,
FileStoreEnabled item,
HttpServletRequest request,
boolean validate,
boolean extractMetadata,
ItemContext cc,
int maxRecent)
Update files that are associated with a FileStoreEnabled
item. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Float defaultScale
private static final Integer defaultMaxRecent
Constructor Detail |
---|
public Base()
Method Detail |
---|
public static final SessionControl getSessionControl(PageContext pageContext, boolean create) throws BaseException
SessionControl
object
given a PageContext
. This method will get
the ID
parameter from the page URL and
try to retrieve the corresponding object from the
BASE Application
. If no SessionControl
object exists, a new one will be created if the create
parameter is TRUE.
pageContext
- The JSP pageContext
variablecreate
- If a new SessionControl
should be created or not
SessionControl
object
BaseException
- If there is an errorpublic static final SessionControl getSessionControl(ServletRequest request, boolean create)
SessionControl
object
given a ServletRequest
instance. This method will get
the ID
parameter from the page URL and
try to retrieve the corresponding object from the
BASE Application
. If no SessionControl
object exists, a new one will be created if the create
parameter is TRUE.
request
- The Servlet request
variablecreate
- If a new SessionControl
should be created or not
SessionControl
object
BaseException
- If there is an errorpublic static final SessionControl getExistingSessionControl(PageContext pageContext, boolean checkLoggedIn) throws NotLoggedInException, BaseException
SessionControl
object
given a PageContext
and optionally check that a user is logged in.
This method will get the ID
parameter from the page URL and
try to retrieve the corresponding object from the
Application
and check that a user is logged in if
the checkLoggedIn
parameter is TRUE.
pageContext
- The JSP pageContext
variablecheckLoggedIn
- If the method should check if a user is logged in or not
SessionControl
object
NotLoggedInException
- If a SessionControl
object isn't found
or no user is logged in
BaseException
- If there is another errorpublic static final SessionControl getExistingSessionControl(ServletRequest request, boolean checkLoggedIn) throws NotLoggedInException, BaseException
SessionControl
object
given a ServletRequest
object and optionally check that a user is logged in.
This method will get the ID
parameter from the page URL and
try to retrieve the corresponding object from the
Application
and check that a user is logged in if
the checkLoggedIn
parameter is TRUE.
request
- The Servlet request
variablecheckLoggedIn
- If the method should check if a user is logged in or not
SessionControl
object
NotLoggedInException
- If a SessionControl
object isn't found
or no user is logged in
BaseException
- If there is another errorpublic static final SessionControl getExistingSessionControl(PageContext pageContext, Permission permission, Item itemType) throws PermissionDeniedException, NotLoggedInException, BaseException
SessionControl
object given
a PageContext
and check for generic (role-based)
permission to an item type.
This method will get the ID
parameter from the page URL and
try to retrieve the corresponding object from the Application
.
Then it checks that a user is logged in and that the logged in user has the
specified permission for item type. If Permission.DENIED
is specified,
this method checks that the logged in user haven't been denied acces to
those items.
pageContext
- The JSP pageContext
variablepermission
- The permission to check for, use one of the codes
defined by the Permission
classitemType
- The code for the item type to check for the permission,
use one of the values defined by the Item
class
SessionControl
object
PermissionDeniedException
- If the logged in user doesn't have the
requested permission
NotLoggedInException
- If no user is logged in or a SessionControl
object not is found
BaseException
- If there is another errorpublic static final SessionControl getExistingSessionControl(ServletRequest request, Permission permission, Item itemType) throws PermissionDeniedException, NotLoggedInException, BaseException
SessionControl
object given
a ServletRequest
and check for generic (role-based)
permission to an item type.
This method will get the ID
parameter from the page URL and
try to retrieve the corresponding object from the Application
.
Then it checks that a user is logged in and that the logged in user has the
specified permission for item type. If Permission.DENIED
is specified,
this method checks that the logged in user haven't been denied acces to
those items.
request
- The Servlet request
variablepermission
- The permission to check for, use one of the codes
defined by the Permission
classitemType
- The code for the item type to check for the permission,
use one of the values defined by the Item
class
SessionControl
object
PermissionDeniedException
- If the logged in user doesn't have the
requested permission
NotLoggedInException
- If no user is logged in or a SessionControl
object not is found
BaseException
- If there is another errorpublic static ItemContext getAndSetCurrentContext(SessionControl sc, Item itemType, PageContext pageContext, ItemContext defaultContext)
getAndSetCurrentContext(sc, itemType, "", pageContext, defaultContext, false)
.
getAndSetCurrentContext(SessionControl, Item, String, PageContext, ItemContext, boolean)
public static ItemContext getAndSetCurrentContext(SessionControl sc, Item itemType, PageContext pageContext, ItemContext defaultContext, boolean resetTemporary)
getAndSetCurrentContext(sc, itemType, "", pageContext, defaultContext, resetTemporary)
.
getAndSetCurrentContext(SessionControl, Item, String, PageContext, ItemContext, boolean)
public static ItemContext getAndSetCurrentContext(SessionControl sc, Item itemType, String subContext, PageContext pageContext, ItemContext defaultContext)
getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext, false)
.
getAndSetCurrentContext(SessionControl, Item, String, PageContext, ItemContext, boolean)
public static ItemContext getAndSetCurrentContext(SessionControl sc, Item itemType, String subContext, PageContext pageContext, ItemContext defaultContext, boolean resetTemporary)
getAndSetCurrentContext(SessionControl, Item, String, ServletRequest, ItemContext, boolean)
public static ItemContext getAndSetCurrentContext(SessionControl sc, Item itemType, String subContext, ServletRequest request, ItemContext defaultContext, boolean resetTemporary)
Include.IN_PROJECT
option is added
to ItemContext.getInclude()
defaultColumns
object is copied to the current context.
Setting | Request parameter |
---|---|
setSetting("columns") | columns |
setRowsPerPage | rowsperpage |
setPage | page |
setSortProperty | sortby |
setSortDirection | direction |
Include.REMOVED | removed |
Include.MINE | owned |
Include.SHARED | shared |
Include.IN_PROJECT | inproject |
Include.OTHERS | others |
If a the name of a request parameter starts with "filter:" it is interpreted as a
property filter. The name is formatted as follows: filter:TYPE:property
where TYPE is one of Enum.name()
strings and property is the name of the
property to filter on. This information is used to create a new PropertyFilter
object. The operator and value parameter is taken from the request parameters value.
Value starts with | Operator |
---|---|
= | Operator.EQ |
!= or <> | Operator.NEQ |
>= | Operator.GTEQ |
> | Operator.GT |
<= | Operator.LTEQ |
< | Operator.LT |
any other charcter | Operator.EQ or Operator.LIKE (if value contains % sign which is wildcard match) |
If the name of a request parameter is a number it is interpreted as the ID of
a selected itema and is added to the ItemContext.getSelected()
set.
sc
- The current session controlitemType
- The type of item to get the context forsubContext
- The name of the subcontextrequest
- A ServletRequest
object to get request
information from, or null if the current context shouldn't be updateddefaultContext
- A default context to copy information from if a current context
doesn't existresetTemporary
- If information of temporary nature should be reset or not, for
example the 'exclude' filter which is only used in popup windows
ItemContext
object.public static ItemContext loadContext(SessionControl sc, int contextId, ItemContext defaultContext)
public static String getPropertyFilterString(PropertyFilter filter, Formatter<Date> dateFormatter)
filter
- The property filter to convertdateFormatter
- Describing how the date is format locally.
The format will be yyyy-MM-dd if this is null.
private static boolean setInclude(Set<Include> includes, String option, Include i)
public static ItemContext createDefaultContext(String sortProperty, String defaultColumns)
ItemContext
with settings for default
visible columns and sort property. 'MINE' and 'SHARED' objects are set to be included.
sortProperty
- The property, as a String, to sort on. If it starts with
a '-', the sort is made in descending order (and the minus is removed)defaultColumns
- The visible columns as a comma separated String.
ItemContext
objectpublic static <T extends BasicItem> ItemQuery<T> getConfiguredQuery(ItemContext cc, boolean autoLeftJoin, ItemQuery<T> query, ModeInfo mode)
getConfiguredQuery(DbControl, ItemContext, boolean, ItemQuery, ModeInfo)
instead
public static <T extends BasicItem> ItemQuery<T> getConfiguredQuery(DbControl dc, ItemContext cc, boolean autoLeftJoin, ItemQuery<T> query, ModeInfo mode)
ItemContext.configureQuery(DbControl, EntityQuery, boolean)
and then adds the following filter:
ItemContext.getObject("exclude")
contains a list
of comma-separated ID:s those are added to the query as a filter
that excludes item with those ID:s from the query result
T
- The kind of BasicItem this method is used with.dc
- The DbControl that will be used to execute the querycc
- The current contextautoLeftJoin
- If associated items should be left joined or not when
they appear in a filterquery
- The query to configuremode
- Info about the mode the page has.
public static ItemQuery<AnnotationType> getAnnotationTypesQuery(Item itemType)
itemType
- The item type
ItemQuery
objectgetAnnotationTypesQuery(Item, Boolean)
public static ItemQuery<AnnotationType> getAnnotationTypesQuery(Item itemType, Boolean isProtocolParameter)
itemType
- The item typeisProtocolParameter
- Specify if only annotation types assigned as protocol
parameters should be returned, a null value ignores the protocol parameter flag
ItemQuery
objectpublic static ItemQuery<AnnotationType> getAnnotationTypesQuery(AnnotatableProxy proxy)
AnnotatableProxy
item.
proxy
- The annotatable proxy
ItemQuery
objectpublic static ItemQuery<AnnotationType> getProtocolParametersQuery(Protocol protocol)
protocol
- The protocol, or null
ItemQuery
object, or null if the protocol is nullpublic static ItemQuery<DataFileType> getDataFileTypes(Item itemType, FileStoreEnabled item, Platform platform, PlatformVariant variant)
itemType
- The item typeitem
- An optional itemplatform
- The platform to get file types for, or nullvariant
- The platform variant to get file types for, or null
ItemQuery
objectpublic static Enumeration<String,String> getReporterListsEnum(DbControl dc)
public static Enumeration<String,String> getBioMaterialListsEnum(DbControl dc, Item memberType, Collection<Include> include)
dc
- The DbControl to usememberType
- Only load lists with this member type, or null
to load any listsinclude
- Include options
public static float getScale(SessionControl sc)
sc
- SessionControl of the active session
public static int getMaxRecent(SessionControl sc)
sc
- SessionControl of the active session.
public static final Cookie getCookie(HttpServletRequest request, String name)
request
- The JSP request
variablename
- The name of the cookie
Cookie
object, or null if it is not foundpublic static final String getCookieValue(HttpServletRequest request, String name)
request
- The JSP request
variablename
- The name of the cookie
public static final <T extends BasicItem> T getOldItem(SessionControl sc, T newItem, int oldVersion) throws ItemModifiedException
SessionControl
:s
session setting itemType.item
. If the setting is null
compare the newItem
:s version with the oldVersion
,
and if the match the new item is returned as the old item. If the
versions doesn't match, an ItemModifiedException
is thrown.
T
- The kind of item that extends from BasicItem.sc
- The SessionControl
which keeps the old item
in the session settingsnewItem
- The new itemoldVersion
- The version of the old item
ItemModifiedException
- If the old item wasn't found in the session
setting and the old version is different from the new item's versionpublic static final void updateAnnotations(DbControl dc, Annotatable oldItem, Annotatable newItem, HttpServletRequest request) throws ItemModifiedException, BaseException
ItemModifiedException
is thrown. We do not have to compare with the values in the request, since
only modified annotations are submitted.
dc
- A DbControl
object used to read information from the
databaseoldItem
- The old annotatable item, or null if no old item existsnewItem
- The new item, or null if only an old item existsrequest
- The request object containing the modified annotations
ItemModifiedException
- If the new and old item don't match
BaseException
- If the update fails in some way.public static void updateFiles(DbControl dc, FileStoreEnabled item, HttpServletRequest request, boolean validate, boolean extractMetadata, ItemContext cc, int maxRecent)
FileStoreEnabled
item. The request
parameter is checked for parameters
with a name like datafile.id
where id
is
the numeric id of a DataFileType
. The parameter value is the
path of the file to associated with the data file type, or null
to remove an existing association.
dc
- A DbControl to access the databaseitem
- The item the files should be associated withrequest
- The request object containing the selected filesvalidate
- If FileSet.validate(DbControl, boolean)
should be called or notextractMetadata
- If meta data should be extracted or not
(requires that validate is true)cc
- Save the current context information. Null is allowed.maxRecent
- The maximum of recent items to remember.public static String getEncodedName(Nameable item, boolean denied)
getEncodedName(Nameable, boolean, String)
public static String getEncodedName(Nameable item, boolean denied, String link)
getLinkedName(String, Nameable, boolean, boolean)
instead
HTML.encodeTags(String)
method. If the item parameter is null, - none -
or
- denied -
is returned, depending on if the denied
parameter is true or false. The link parameter should contain the relative path
to the JSP page and include the session control ID:
../samples/index.jsp?ID=XXXX
. This method will
automatically add the id of the nameable item to the link:
../samples/index.jsp?ID=XXXX&cmd=ViewItem&item_id=YYYY
item
- The nameable item or nulldenied
- TRUE if the item is null because the current use
doesn't have read permissionlink
- The URL of the JSP page to link the name to, or null if
a link shouldn't be createdgetEncodedName(Nameable, boolean)
public static String getLinkedName(String ID, Nameable item, boolean denied, boolean enableEditLink)
public static String getLink(String ID, String name, Item itemType, int itemId, boolean enableEditLink)
public static String getLink(String ID, String name, Item itemType, int itemId, boolean enableEditLink, String tooltip)
public static String getLinkedFile(String ID, File file, boolean denied, boolean enableEditLink, boolean enableViewDownload, String root)
public static String getFileLinks(String ID, File file, String root)
ID
- The session IDfile
- The file itemroot
- Relative path to root directory of the web server
public static <T extends BasicItem> T getFirstMatching(DbControl dc, ItemQuery<T> query, String property, PropertyFilter filter)
public static Color[] getConfiguredColors(SessionControl sc)
public static ColorGenerator getColorGenerator(SessionControl sc, Coloring coloring)
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |