/** * Creates a new disk cache.<p> * * @param basepath the base path for the cache in the RFS * @param foldername the folder name for this cache, to be used a subfolder for the base folder */ public CmsExtractionResultCache(String basepath, String foldername) { // normalize the given folder name m_rfsRepository = CmsFileUtil.normalizePath(basepath + foldername + File.separatorChar); }
/** * Creates a new disk cache.<p> * * @param basepath the base path for the cache in the RFS * @param foldername the folder name for this cache, to be used a sub-folder for the base folder */ public CmsVfsNameBasedDiskCache(String basepath, String foldername) { // normalize the given folder name m_rfsRepository = CmsFileUtil.normalizePath(basepath + foldername + File.separatorChar); }
/** * Creates a new disk cache.<p> * * @param basepath the base path for the cache in the RFS * @param foldername the folder name for this cache, to be used a subfolder for the base folder */ public CmsVfsDiskCache(String basepath, String foldername) { // normalize the given folder name m_rfsRepository = CmsFileUtil.normalizePath(basepath + foldername + File.separatorChar); }
/** * Creates a new disk cache.<p> * * @param basepath the base path for the cache in the RFS * @param foldername the folder name for this cache, to be used a subfolder for the base folder */ public CmsVfsDiskCache(String basepath, String foldername) { // normalize the given folder name m_rfsRepository = CmsFileUtil.normalizePath(basepath + foldername + File.separatorChar); }
/** * Creates a new disk cache.<p> * * @param basepath the base path for the cache in the RFS * @param foldername the folder name for this cache, to be used a sub-folder for the base folder */ public CmsVfsNameBasedDiskCache(String basepath, String foldername) { // normalize the given folder name m_rfsRepository = CmsFileUtil.normalizePath(basepath + foldername + File.separatorChar); }
/** * Creates a new disk cache.<p> * * @param basepath the base path for the cache in the RFS * @param foldername the folder name for this cache, to be used a subfolder for the base folder */ public CmsExtractionResultCache(String basepath, String foldername) { // normalize the given folder name m_rfsRepository = CmsFileUtil.normalizePath(basepath + foldername + File.separatorChar); }
/** * Normalizes a file path that might contain <code>'../'</code> or <code>'./'</code> or <code>'//'</code> * elements to a normal absolute path, the path separator char used is {@link File#separatorChar}.<p> * * @param path the path to normalize * * @return the normalized path * * @see #normalizePath(String, char) */ public static String normalizePath(String path) { return normalizePath(path, File.separatorChar); }
/** * Normalizes a file path that might contain <code>'../'</code> or <code>'./'</code> or <code>'//'</code> * elements to a normal absolute path, the path separator char used is {@link File#separatorChar}.<p> * * @param path the path to normalize * * @return the normalized path * * @see #normalizePath(String, char) */ public static String normalizePath(String path) { return normalizePath(path, File.separatorChar); }
/** * Returns the normalized file path created from the given URL.<p> * * The path part {@link URL#getPath()} is used, unescaped and * normalized using {@link #normalizePath(String, char)} using {@link File#separatorChar}.<p> * * @param url the URL to extract the path information from * * @return the normalized file path created from the given URL using {@link File#separatorChar} * * @see #normalizePath(URL, char) */ public static String normalizePath(URL url) { return normalizePath(url, File.separatorChar); }
/** * Returns the normalized file path created from the given URL.<p> * * The path part {@link URL#getPath()} is used, unescaped and * normalized using {@link #normalizePath(String, char)} using {@link File#separatorChar}.<p> * * @param url the URL to extract the path information from * * @return the normalized file path created from the given URL using {@link File#separatorChar} * * @see #normalizePath(URL, char) */ public static String normalizePath(URL url) { return normalizePath(url, File.separatorChar); }
/** * Returns an absolute path (to a directory or a file in the "real" file system) from a path relative to * the "WEB-INF" folder of the OpenCms web application.<p> * * If the provided path is already absolute, then it is returned unchanged.<p> * * @param path the path (relative) to generate an absolute path from * @return an absolute path (to a directory or a file) from a path relative to the "WEB-INF" folder */ public String getAbsoluteRfsPathRelativeToWebInf(String path) { if (path == null) { return null; } // check for absolute path is system depended, let's just use the standard check File f = new File(path); if (f.isAbsolute()) { // apparently this is an absolute path already return f.getAbsolutePath(); } return CmsFileUtil.normalizePath(getWebInfRfsPath() + path); }
/** * Returns an absolute path (to a directory or a file in the "real" file system) from a path relative to * the "WEB-INF" folder of the OpenCms web application.<p> * * If the provided path is already absolute, then it is returned unchanged.<p> * * @param path the path (relative) to generate an absolute path from * @return an absolute path (to a directory or a file) from a path relative to the "WEB-INF" folder */ public String getAbsoluteRfsPathRelativeToWebInf(String path) { if (path == null) { return null; } // check for absolute path is system depended, let's just use the standard check File f = new File(path); if (f.isAbsolute()) { // apparently this is an absolute path already return f.getAbsolutePath(); } return CmsFileUtil.normalizePath(getWebInfRfsPath() + path); }
/** * Returns the normalized file path created from the given URL.<p> * * The path part {@link URL#getPath()} is used, unescaped and * normalized using {@link #normalizePath(String, char)}.<p> * * @param url the URL to extract the path information from * @param separatorChar the file separator char to use, for example {@link File#separatorChar} * * @return the normalized file path created from the given URL */ public static String normalizePath(URL url, char separatorChar) { // get the path part from the URL String path = new File(url.getPath()).getAbsolutePath(); // trick to get the OS default encoding, taken from the official Java i18n FAQ String systemEncoding = (new OutputStreamWriter(new ByteArrayOutputStream())).getEncoding(); // decode url in order to remove spaces and escaped chars from path return CmsFileUtil.normalizePath(CmsEncoder.decode(path, systemEncoding), separatorChar); }
/** * Returns the normalized file path created from the given URL.<p> * * The path part {@link URL#getPath()} is used, unescaped and * normalized using {@link #normalizePath(String, char)}.<p> * * @param url the URL to extract the path information from * @param separatorChar the file separator char to use, for example {@link File#separatorChar} * * @return the normalized file path created from the given URL */ public static String normalizePath(URL url, char separatorChar) { // get the path part from the URL String path = new File(url.getPath()).getAbsolutePath(); // trick to get the OS default encoding, taken from the official Java i18n FAQ String systemEncoding = (new OutputStreamWriter(new ByteArrayOutputStream())).getEncoding(); // decode url in order to remove spaces and escaped chars from path return CmsFileUtil.normalizePath(CmsEncoder.decode(path, systemEncoding), separatorChar); }
/** * Returns a normalized rfs prefix.<p> * * Replacing macros and normalizing the path.<p> * * @param rfsPrefix the prefix to normalize * * @return the normalized rfs prefix */ protected String normalizeRfsPrefix(String rfsPrefix) { String result = insertContextStrings(rfsPrefix); if (!isValidURL(result)) { result = CmsFileUtil.normalizePath(result, '/'); } result = CmsFileUtil.normalizePath(result, '/'); if (CmsResource.isFolder(result)) { // ensure prefix does NOT end with a folder '/' result = result.substring(0, result.length() - 1); } return result; }
/** * Creates the parent folder for a exported resource in the RFS.<p> * * @param exportPath the path to export the file * @param rfsName the rfs name of the resource * * @throws CmsException if the folder could not be created */ protected void createExportFolder(String exportPath, String rfsName) throws CmsException { String exportFolderName = CmsFileUtil.normalizePath(exportPath + CmsResource.getFolderPath(rfsName)); File exportFolder = new File(exportFolderName); if (!exportFolder.exists()) { // in case of concurrent requests to create this folder, check the folder existence again if (!exportFolder.mkdirs() && !exportFolder.exists()) { throw new CmsStaticExportException(Messages.get().container(Messages.ERR_CREATE_FOLDER_1, rfsName)); } } }
/** * Returns the export file name starting from the OpenCms webapp folder.<p> * * @param file the file to delete * @param vfsName the VFS name of the file (required for logging) * * @return the export file name starting from the OpenCms webapp folder */ private String getRfsName(File file, String vfsName) { String filePath = file.getAbsolutePath(); String result = CmsFileUtil.normalizePath(OpenCms.getStaticExportManager().getRfsPrefix(vfsName) + filePath.substring(OpenCms.getStaticExportManager().getExportPath(vfsName).length())); return CmsStringUtil.substitute(result, new String(new char[] {File.separatorChar}), "/"); } }
/** * Returns the export file name starting from the OpenCms webapp folder.<p> * * @param file the file to delete * @param vfsName the VFS name of the file, the root path! * * @return the export file name starting from the OpenCms webapp folder */ private String getRfsName(File file, String vfsName) { CmsStaticExportManager manager = OpenCms.getStaticExportManager(); String filePath = file.getAbsolutePath(); String result = CmsFileUtil.normalizePath( manager.getRfsPrefix(vfsName) + filePath.substring(OpenCms.getStaticExportManager().getExportPath(vfsName).length())); return CmsStringUtil.substitute(result, new String(new char[] {File.separatorChar}), "/"); }
/** * Creates the parent folder for a exported resource in the RFS.<p> * * @param exportPath the path to export the file * @param rfsName the rfs name of the resource * * @throws CmsException if the folder could not be created */ protected void createExportFolder(String exportPath, String rfsName) throws CmsException { String exportFolderName = CmsFileUtil.normalizePath(exportPath + CmsResource.getFolderPath(rfsName)); File exportFolder = new File(exportFolderName); if (!exportFolder.exists()) { if (!exportFolder.mkdirs()) { throw new CmsStaticExportException(Messages.get().container(Messages.ERR_CREATE_FOLDER_1, rfsName)); } } }
/** * Purges a list of files from the rfs.<p> * * @param files the list of files to purge * @param vfsName the vfs name of the originally file to purge * @param scrubbedFiles the list which stores all the scrubbed files */ private void purgeFiles(List<File> files, String vfsName, Set<String> scrubbedFiles) { for (File file : files) { purgeFile(file.getAbsolutePath(), vfsName); String rfsName = CmsFileUtil.normalizePath( OpenCms.getStaticExportManager().getRfsPrefix(vfsName) + "/" + file.getAbsolutePath().substring( OpenCms.getStaticExportManager().getExportPath(vfsName).length())); rfsName = CmsStringUtil.substitute(rfsName, new String(new char[] {File.separatorChar}), "/"); scrubbedFiles.add(rfsName); } } }