public class Tools extends Object
Modifier and Type | Field and Description |
---|---|
static SimpleDateFormat |
DATE_FORMATTER
The Constant DATE_FORMATTER.
|
Constructor and Description |
---|
Tools() |
Modifier and Type | Method and Description |
---|---|
static void |
addOmexMetaData(de.unirostock.sems.cbarchive.meta.MetaDataHolder entity,
de.unirostock.sems.cbarchive.meta.omex.VCard creator,
boolean create)
Adds current date as modification and adds the creator, if not done yet, to every Omex description
Also creates new Omex description, if create is set to true and only if necessary.
|
static void |
addOmexMetaData(de.unirostock.sems.cbarchive.meta.MetaDataHolder entity,
de.unirostock.sems.cbarchive.meta.omex.VCard creator,
String additionalDescription,
boolean create)
Adds current date as modification and an additional description, as well as the creator,
if not done yet, to every Omex description.
|
static boolean |
areVCardEqual(de.unirostock.sems.cbarchive.meta.omex.VCard vcard1,
de.unirostock.sems.cbarchive.meta.omex.VCard vcard2)
Compares 2 VCards and returns true if both are identical in means of String.equal() or if both are null
|
static boolean |
checkQuota(long currentValue,
long quota)
Returns false, if a quota is exceeded.
|
static String |
cleanUpFileName(String fileName)
removes all non alpha-numeric symbols from a file name.
|
static boolean |
containsVCard(Collection<de.unirostock.sems.cbarchive.meta.omex.VCard> collection,
de.unirostock.sems.cbarchive.meta.omex.VCard vcard)
Checks if the given VCard exists already in the Collection.
|
static long |
copyStream(InputStream input,
OutputStream output,
long maxLength)
Copies an InputStream into an OutputStream and closes all streams afterwards.
|
static UserManager |
doLogin(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Tries to obtain user instance (workspace), if fails it crates a new one
|
static UserManager |
doLogin(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
boolean createNew)
Tries to obtain user instance (workspace)
if createNew is true, it also tries to create a new user instance. |
static String |
extractFileName(javax.servlet.http.Part part)
Extract file name.
|
static URI |
generateArchiveRedirectUri(javax.servlet.http.HttpServletRequest requestContext,
String archiveId)
Generates a redirect URI to an archive.
|
static String |
generateHashId(String input)
Generate hash id.
|
static URI |
generateWorkspaceRedirectUri(javax.servlet.http.HttpServletRequest requestContext,
String workspaceId)
Generates Share URI to a workspace.
|
static UserManager |
getUser(CookieManager cookies)
Gets the user.
|
static boolean |
isFilenameBlacklisted(String filename)
checks whether a filename is blacklisted or not
|
static void |
storeUserCookies(CookieManager cookies,
UserManager user)
Store user cookies.
|
static String |
suggestFileNameFromHttpResponse(org.apache.http.HttpRequest request,
org.apache.http.HttpResponse response)
Suggests a filename for the queried file, base on the Content-Disposition Header field or the URL.
|
static String |
suggestFileNameFromHttpResponse(org.apache.http.HttpResponse response)
Suggests a filename for the queried file, base on the Content-Disposition Header field.
|
static String |
suggestFileNameFromHttpResponse(String remoteUrl,
org.apache.http.HttpResponse response)
Suggests a filename for the queried file, base on the Content-Disposition Header field or the URL.
|
static Path |
writeStreamToTempFile(String tempFileName,
InputStream input)
writes a input stream entirely into a newly created temp file.
|
public static final SimpleDateFormat DATE_FORMATTER
public static UserManager doLogin(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws CombineArchiveWebException, CombineArchiveWebCriticalException
request
- the requestresponse
- the responseCombineArchiveWebException
- signals default problemsCombineArchiveWebCriticalException
- signals critical problemspublic static UserManager doLogin(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean createNew) throws CombineArchiveWebException, CombineArchiveWebCriticalException
request
- the requestresponse
- the responsecreateNew
- try to create new user instance?CombineArchiveWebException
- signals default problemsCombineArchiveWebCriticalException
- signals critical problemspublic static UserManager getUser(CookieManager cookies) throws IOException
cookies
- the cookiesIOException
- the IO exceptionpublic static void storeUserCookies(CookieManager cookies, UserManager user)
cookies
- the cookiesuser
- the userpublic static final String extractFileName(javax.servlet.http.Part part)
part
- the partpublic static String generateHashId(String input)
input
- the inputpublic static boolean checkQuota(long currentValue, long quota)
currentValue
- the current sizequota
- the quota sizepublic static URI generateArchiveRedirectUri(javax.servlet.http.HttpServletRequest requestContext, String archiveId)
requestContext
- the request contextarchiveId
- the archive idpublic static URI generateWorkspaceRedirectUri(javax.servlet.http.HttpServletRequest requestContext, String workspaceId)
requestContext
- the request contextworkspaceId
- the workspace idpublic static boolean isFilenameBlacklisted(String filename)
filename
- the file namepublic static void addOmexMetaData(de.unirostock.sems.cbarchive.meta.MetaDataHolder entity, de.unirostock.sems.cbarchive.meta.omex.VCard creator, boolean create)
entity
- the entitycreator
- the creatorcreate
- should omex description be created?public static void addOmexMetaData(de.unirostock.sems.cbarchive.meta.MetaDataHolder entity, de.unirostock.sems.cbarchive.meta.omex.VCard creator, String additionalDescription, boolean create)
entity
- the entitycreator
- the creatoradditionalDescription
- the additional descriptioncreate
- should omex description be created?public static boolean containsVCard(Collection<de.unirostock.sems.cbarchive.meta.omex.VCard> collection, de.unirostock.sems.cbarchive.meta.omex.VCard vcard)
collection
- the vcard collectionvcard
- the vcard in questionpublic static boolean areVCardEqual(de.unirostock.sems.cbarchive.meta.omex.VCard vcard1, de.unirostock.sems.cbarchive.meta.omex.VCard vcard2)
vcard1
- the vcard1vcard2
- the vcard2public static long copyStream(InputStream input, OutputStream output, long maxLength) throws IOException
input
- the inputoutput
- the outputmaxLength
- the max lengthIOException
- the IO exceptionpublic static Path writeStreamToTempFile(String tempFileName, InputStream input) throws IOException
tempFileName
- the temp file nameinput
- the inputIOException
- the IO exceptionpublic static String suggestFileNameFromHttpResponse(org.apache.http.HttpRequest request, org.apache.http.HttpResponse response)
request
- the requestresponse
- the responsepublic static String suggestFileNameFromHttpResponse(String remoteUrl, org.apache.http.HttpResponse response)
remoteUrl
- the remote urlresponse
- the responsepublic static String suggestFileNameFromHttpResponse(org.apache.http.HttpResponse response)
response
- the responseCopyright © 2018 SEMS project @ University of Rostock. All rights reserved.