public class ResourceHelper extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ResourceHelper.ImageFilenameFilter |
static class |
ResourceHelper.VideoFilenameFilter |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE |
protected static Logger |
logger
create a static logger.
|
static String |
PRIVATE_DIR
file in private dir could not be downloaded
|
static Object |
SYNCHRO_RESOURCE |
Constructor and Description |
---|
ResourceHelper() |
Modifier and Type | Method and Description |
---|---|
static void |
appendStringToFile(File file,
String line) |
static boolean |
canModifFolder(ContentContext ctx,
String folder) |
static String |
changeExtention(String filename,
String newext) |
static boolean |
checksumEquals(String checksum1,
String checksum2) |
static boolean |
cleanAllFileName(File file)
normalize all file name from a dir
|
static List<String> |
cleanFolderList(Collection<String> folders)
clear a folder list, remove '/' if found as first char and replace '\' by
'/'
|
static int |
cleanImportResource(ContentContext ctx,
File childImport) |
static int |
cleanImportResources(ContentContext ctx)
delete import without reference to a existing page.
|
static void |
closeResource(Closeable... resources) |
static void |
closeResource(HttpURLConnection... connections) |
static String |
computeChecksum(File file)
Return the standard checksum of the specified file.
|
static void |
copyDir(File dir1,
File dir2,
boolean overwrite,
FileFilter filter) |
static boolean |
copyFile(File source,
File destination,
boolean overwrite)
transactional copy a file other file
|
static void |
copyResourceData(ContentContext ctx,
File file,
File newFile)
duplicate static info of a resource to a new file
|
static void |
copyStream(InputStream input,
OutputStream output,
long start,
long length)
Copy the given byte range of the given input to the given output.
|
static int |
countLines(File file) |
static String |
createModulePath(ContentContext ctx,
String path) |
static boolean |
deleteFileAndParentDir(File file) |
static void |
deleteFolder(File folder) |
static boolean |
deleteResource(ContentContext ctx,
File file) |
static void |
deleteResourceData(ContentContext ctx,
File file) |
static void |
downloadResource(ContentContext ctx,
String localDir,
String baseURL,
NodeXML nodeXML) |
static String |
downloadResourceAsString(URL workURL) |
static String |
excutePost(String targetURL,
String urlParameters) |
static String |
excutePost(String targetURL,
String urlParameters,
String contentType,
String lang,
String user,
String pwd) |
static String |
extractNotStaticDir(StaticConfig staticConfig,
GlobalContext globalContext,
String fullPath)
extract a relative path from a full path.
|
static String |
extractResourceDir(StaticConfig staticConfig,
GlobalContext globalContext,
String fullPath)
extract a relative path from a full path.
|
static String |
extractTemplateName(GlobalContext globalContext,
File file)
return the name of the template
|
static String |
fileStructureToHtml(File file) |
static void |
filteredFileCopy(File file1,
File file2,
Map<String,String> filter) |
static void |
filteredFileCopyEscapeScriplet(File file1,
File file2,
Map<String,String> filter,
boolean compress) |
static List<File> |
getAllDirList(File dir)
get all directories under a directory (recursivly).
|
static Collection<File> |
getAllFiles(File dir,
FileFilter filter) |
static Collection<File> |
getAllFiles(File dir,
FileFilter filter,
Comparator<File> comp) |
static Collection<File> |
getAllFilesList(File dir)
get all files under a directory (recursivly).
|
static Collection<File> |
getAllResources(ContentContext ctx) |
static InputStream |
getChecksumInputStream(InputStream in)
Add a checksum computing layer to the given
InputStream . |
static String |
getChecksumResult(InputStream chkIn)
Exctract the result from a
InputStream returned by
getChecksumInputStream(InputStream) . |
static List<IContentVisualComponent> |
getComponentsUseResource(ContentContext ctx,
String uri) |
static InputStream |
getConfigFile(javax.servlet.ServletContext servletContext,
String fileName) |
static String[] |
getDirList(String directory)
return a recursive directory array path
|
static String |
getFile(String fileName) |
static String |
getFileContent(File file) |
static String |
getFileExtensionToMineType(String ext) |
static File[] |
getFileList(String directory,
javax.servlet.http.HttpServletRequest request) |
static long |
getFileSize(String filePath) |
static File |
getFreeFileName(File file)
return a free file name. if file exist add a number as suffix.
|
static IIOMetadata |
getImageMetadata(File image) |
static String |
getLinuxPath(String path)
convert a path to a correct path for current OS. sample: /static/images
on windows -> \static\images and on unix no change.
|
static String |
getOSPath(String path)
convert a path to a correct path for current OS. sample: /static/images
on windows -> \static\images and on unix no change.
|
static String |
getPath(String fileName) |
static String |
getRealPath(javax.servlet.ServletContext application,
String path) |
static String |
getRelativeStaticURL(ContentContext ctx,
File file) |
static Collection<File> |
getResourceWithoutMT(ContentContext ctx) |
static InputStream |
getStaticComponentResource(javax.servlet.ServletContext application,
String componentType,
String resource) |
static String |
getUserDirName(String userName) |
static String |
getWindowsFileName(String fileName)
with iexplorer the name of the file is all the path this method extract
the file name from a windows path
|
static boolean |
isAcceptedDocument(ContentContext ctx,
String fileName) |
static boolean |
isAcceptedImage(ContentContext ctx,
String fileName) |
static boolean |
isAcceptedVideo(ContentContext ctx,
String fileName) |
static boolean |
isChildOf(File file,
File folder)
check if a file (or a folder) is under a folder. sample :
/tmp/test/me.jpg with /tmp retrun true
|
static boolean |
isComponentsUseResource(ContentContext ctx,
String uri) |
static boolean |
isDocument(ContentContext ctx,
String filename)
check if this file is a document (list of extenion define in
static-config.properties
|
static boolean |
isImportPageExist(ContentContext ctx,
File childImport) |
static boolean |
isPreviewFile(String file) |
static boolean |
isResourceURL(ContentContext ctx,
String url) |
static boolean |
isSound(ContentContext ctx,
String filename)
check if this file is a document (list of extenion define in
static-config.properties
|
static boolean |
isTemplateFile(GlobalContext globalContext,
File file)
return true if file is insise template folder
|
static boolean |
isTransformURL(ContentContext ctx,
String url) |
static Serializable |
loadBeanFromXML(File file) |
static Serializable |
loadBeanFromXML(InputStream in) |
static Serializable |
loadBeanFromXML(String xml) |
static Serializable |
loadBeanFromXML(String xml,
ClassLoader cl) |
static List<String> |
loadCollectionFromFile(File file) |
static Properties |
loadProperties(File file) |
static String |
loadStringFromFile(File file) |
static String |
loadStringFromStream(InputStream in,
Charset encoding) |
static void |
main(String[] args) |
static boolean |
moveToGlobalTrash(StaticConfig staticConfig,
String fileOrFolder)
Move a file or a folder to the global trash, depending on staticConfig.
|
static String |
readLine(RandomAccessFile file,
Charset cs) |
static String |
removeDataFolderDir(GlobalContext globalContext,
String path)
remove the data folder directory this method is used for obtain a
relative file path from a ablute file path.
|
static String |
removePath(String path,
String pathCuted)
remove the path from a string this method is used for obtain a relative
file path from a absolute file path.
|
static List<String> |
removePrefixFromPathList(Collection<? extends Object> pathList,
String prefix) |
static void |
renameResource(ContentContext ctx,
File file,
File newFile)
change all the reference to a resource when a resource path or name if
changed
|
static void |
safeClose(Closeable... closeables)
Close streams, writers, readers, etc without any exception even if they
are
null . |
static String |
storeBean(Serializable bean,
File file) |
static String |
storeBean(Serializable bean,
OutputStream out) |
static String |
storeBeanFromXML(Serializable bean) |
static byte[] |
storeBeanToBin(Serializable bean) |
static void |
storeCollectionToFile(File file,
List<String> lines) |
static void |
writeBytesToFile(File file,
byte[] content) |
static File |
writeFileItemToFolder(org.apache.commons.fileupload.FileItem fileItem,
File folder,
boolean overwrite,
boolean rename) |
static int |
writeFileToFile(File fileIn,
File file) |
static int |
writeFileToStream(File fileIn,
OutputStream out) |
static boolean |
writeImageMetadata(IIOMetadata imageMetadata,
File target) |
static void |
writePropertiesToFile(ConfigurationProperties properties,
File file) |
static void |
writePropertiesToFile(Properties properties,
File file,
String title) |
static int |
writeStreamToFile(InputStream in,
File file) |
static int |
writeStreamToFile(InputStream in,
File file,
long maxSize) |
static int |
writeStreamToStream(InputStream in,
OutputStream out) |
static int |
writeStreamToStream(InputStream in,
OutputStream out,
long maxSize)
write a InputStream in a OuputStream, without close.
|
static String |
writeStreamToString(InputStream in,
String encoding) |
static void |
writeStringToFile(File file,
String content) |
static void |
writeStringToFile(File file,
String content,
String encoding) |
static void |
writeStringToStream(String content,
OutputStream out) |
static void |
writeStringToStream(String content,
OutputStream out,
String encoding) |
static void |
writeUrlToFile(URL url,
File imageFile) |
public static final int DEFAULT_BUFFER_SIZE
protected static Logger logger
public static Object SYNCHRO_RESOURCE
public static final String PRIVATE_DIR
public static void closeResource(Closeable... resources)
public static void closeResource(HttpURLConnection... connections)
public static String computeChecksum(File file) throws IOException
getChecksumInputStream(InputStream)
,
getChecksumResult(InputStream)
, formatChecksum(long)
file
- IOException
public static boolean deleteFileAndParentDir(File file)
public static void downloadResource(ContentContext ctx, String localDir, String baseURL, NodeXML nodeXML) throws Exception
Exception
public static String downloadResourceAsString(URL workURL) throws IOException
IOException
public static String extractNotStaticDir(StaticConfig staticConfig, GlobalContext globalContext, String fullPath)
application
- the servlet context.fullPath
- a full pathpublic static String extractResourceDir(StaticConfig staticConfig, GlobalContext globalContext, String fullPath)
application
- the servlet context.fullPath
- a full pathpublic static void filteredFileCopy(File file1, File file2, Map<String,String> filter) throws IOException
IOException
public static void copyDir(File dir1, File dir2, boolean overwrite, FileFilter filter) throws IOException
IOException
public static boolean copyFile(File source, File destination, boolean overwrite) throws IOException
source
- the source file, must existdestination
- the target file, could not existoverwrite
- if true and file desctination exist, this method done nothingIOException
- error width IO, file destination is'nt modified if there are
errorpublic static void filteredFileCopyEscapeScriplet(File file1, File file2, Map<String,String> filter, boolean compress) throws IOException
IOException
public static List<File> getAllDirList(File dir)
dir
- public static Collection<File> getAllFiles(File dir, FileFilter filter)
public static Collection<File> getAllFiles(File dir, FileFilter filter, Comparator<File> comp)
public static Collection<File> getAllFilesList(File dir)
dir
- public static Collection<File> getAllResources(ContentContext ctx)
public static InputStream getChecksumInputStream(InputStream in)
InputStream
. InputStream
to
getChecksumResult(InputStream)
to retrieve the checksum result.
getChecksumResult(InputStream)
, computeChecksum(File)
,
formatChecksum(long)
in
- InputStream
computing the checksum during the read,
call getChecksumResult(InputStream)
to retrieve the
checksum result.public static String getChecksumResult(InputStream chkIn)
InputStream
returned by
getChecksumInputStream(InputStream)
. getChecksumInputStream(InputStream)
,
computeChecksum(File)
, formatChecksum(long)
chkIn
- InputStream
previously wrapped by
getChecksumInputStream(InputStream)
public static final InputStream getConfigFile(javax.servlet.ServletContext servletContext, String fileName) throws ResourceNotFoundException
ResourceNotFoundException
public static String[] getDirList(String directory)
directory
- the base directoryrequest
- the current requestpublic static String getFileContent(File file) throws FileNotFoundException, IOException
FileNotFoundException
IOException
public static File[] getFileList(String directory, javax.servlet.http.HttpServletRequest request)
public static final long getFileSize(String filePath)
public static final String getLinuxPath(String path)
path
- a path to a filepublic static final String getOSPath(String path)
path
- a path to a filepublic static Collection<File> getResourceWithoutMT(ContentContext ctx) throws Exception
Exception
public static final InputStream getStaticComponentResource(javax.servlet.ServletContext application, String componentType, String resource) throws FileNotFoundException
FileNotFoundException
public static String getWindowsFileName(String fileName)
public static boolean isChildOf(File file, File folder) throws IOException
file
- a file, this file must be a real file or method return false.folder
- a folder (if file -> return false), this file must be a real
file or method return false.IOException
public static boolean isPreviewFile(String file)
public static boolean isDocument(ContentContext ctx, String filename)
ctx
- filename
- public static boolean isSound(ContentContext ctx, String filename)
ctx
- filename
- public static boolean isResourceURL(ContentContext ctx, String url)
public static boolean isTransformURL(ContentContext ctx, String url) throws Exception
Exception
public static Properties loadProperties(File file) throws IOException
IOException
public static final String loadStringFromStream(InputStream in, Charset encoding) throws IOException
IOException
public static final String loadStringFromFile(File file) throws IOException
IOException
public static final List<String> loadCollectionFromFile(File file) throws IOException
IOException
public static final void storeCollectionToFile(File file, List<String> lines) throws IOException
IOException
public static final void appendStringToFile(File file, String line) throws IOException
IOException
public static boolean moveToGlobalTrash(StaticConfig staticConfig, String fileOrFolder)
staticConfig
- fileOrFolder
- true
if origin doesn't exist; or the result of
File.renameTo(File)
.public static String removeDataFolderDir(GlobalContext globalContext, String path)
path
- public static String removePath(String path, String pathCuted)
path
- public static void renameResource(ContentContext ctx, File file, File newFile) throws Exception
ctx
- oldName
- newName
- Exception
public static void copyResourceData(ContentContext ctx, File file, File newFile) throws Exception
ctx
- oldName
- newName
- Exception
public static boolean deleteResource(ContentContext ctx, File file) throws Exception
Exception
public static void deleteResourceData(ContentContext ctx, File file) throws Exception
Exception
public static void safeClose(Closeable... closeables)
null
.closeables
- the objects to closepublic static final void writePropertiesToFile(Properties properties, File file, String title) throws IOException
IOException
public static final void writePropertiesToFile(ConfigurationProperties properties, File file) throws IOException
IOException
public static final int writeStreamToFile(InputStream in, File file) throws IOException
IOException
public static final int writeStreamToFile(InputStream in, File file, long maxSize) throws IOException
IOException
public static final String writeStreamToString(InputStream in, String encoding) throws IOException
IOException
public static final int writeFileToFile(File fileIn, File file) throws IOException
IOException
public static final int writeFileToStream(File fileIn, OutputStream out) throws IOException
IOException
public static final File writeFileItemToFolder(org.apache.commons.fileupload.FileItem fileItem, File folder, boolean overwrite, boolean rename) throws IOException
IOException
public static final int writeStreamToStream(InputStream in, OutputStream out) throws IOException
IOException
public static final int writeStreamToStream(InputStream in, OutputStream out, long maxSize) throws IOException
IOException
public static void copyStream(InputStream input, OutputStream output, long start, long length) throws IOException
input
- The input to copy the given range to the given output for.output
- The output to copy the given range from the given input for.start
- Start of the byte range.length
- Length of the byte range.IOException
- If something fails at I/O level.public static final void writeStringToFile(File file, String content) throws IOException
IOException
public static final void writeBytesToFile(File file, byte[] content) throws IOException
IOException
public static final void writeStringToFile(File file, String content, String encoding) throws IOException
IOException
public static final void writeStringToStream(String content, OutputStream out, String encoding) throws IOException
IOException
public static final void writeStringToStream(String content, OutputStream out) throws IOException
IOException
public static File getFreeFileName(File file)
file
- public static boolean isTemplateFile(GlobalContext globalContext, File file)
globalContext
- file
- public static String extractTemplateName(GlobalContext globalContext, File file)
globalContext
- file
- public static String readLine(RandomAccessFile file, Charset cs) throws IOException
IOException
public static String createModulePath(ContentContext ctx, String path) throws ModuleException, Exception
ModuleException
Exception
public static Serializable loadBeanFromXML(String xml)
public static Serializable loadBeanFromXML(File file) throws FileNotFoundException
FileNotFoundException
public static Serializable loadBeanFromXML(InputStream in)
public static Serializable loadBeanFromXML(String xml, ClassLoader cl)
public static String storeBeanFromXML(Serializable bean)
public static String storeBean(Serializable bean, OutputStream out)
public static String storeBean(Serializable bean, File file) throws FileNotFoundException
FileNotFoundException
public static byte[] storeBeanToBin(Serializable bean) throws IOException
IOException
public static IIOMetadata getImageMetadata(File image) throws IOException
IOException
public static boolean writeImageMetadata(IIOMetadata imageMetadata, File target) throws IOException
IOException
public static String excutePost(String targetURL, String urlParameters, String contentType, String lang, String user, String pwd)
public static List<String> cleanFolderList(Collection<String> folders)
folders
- public static List<String> removePrefixFromPathList(Collection<? extends Object> pathList, String prefix)
public static void writeUrlToFile(URL url, File imageFile) throws IOException
IOException
public static boolean canModifFolder(ContentContext ctx, String folder)
public static int cleanImportResources(ContentContext ctx) throws Exception
ctx
- Exception
public static boolean isImportPageExist(ContentContext ctx, File childImport) throws Exception
Exception
public static int cleanImportResource(ContentContext ctx, File childImport) throws Exception
Exception
public static List<IContentVisualComponent> getComponentsUseResource(ContentContext ctx, String uri) throws Exception
Exception
public static boolean isComponentsUseResource(ContentContext ctx, String uri) throws Exception
Exception
public static boolean isAcceptedImage(ContentContext ctx, String fileName)
public static boolean isAcceptedVideo(ContentContext ctx, String fileName)
public static boolean isAcceptedDocument(ContentContext ctx, String fileName)
public static boolean cleanAllFileName(File file) throws IOException
file
- IOException
public static String getRelativeStaticURL(ContentContext ctx, File file)
public static int countLines(File file) throws IOException
IOException
public static void deleteFolder(File folder)
public static void main(String[] args) throws IOException
IOException
Copyright © 2012-2018. All Rights Reserved.