/** * If path parts contain namespace definitions they need to be escaped for the ZIP file. * Example: oak:index -> jcr_root/_oak_index * @param path Path * @return Safe path */ @VisibleForTesting static String buildJcrPathForZip(final String path) { String normalizedPath = StringUtils.defaultString(path); if (!normalizedPath.startsWith("/")) { normalizedPath = "/" + normalizedPath; } return ROOT_DIR + PlatformNameFormat.getPlatformPath(normalizedPath); }
/** * Creates a new abstract artifact with the given repository name, * platform extension and and type. the parent artifact is only used for * generating the paths and is not linked to this artifact. * * @param parent the parent artifact or {@code null}. * @param repoRelPath the repository name * @param extension the platform extension * @param type type of the artifact */ protected AbstractArtifact(Artifact parent, String repoRelPath, String extension, ArtifactType type) { this.type = type; this.extension = extension; if (parent == null) { this.repoRelPath = repoRelPath; this.platRelPath = PlatformNameFormat.getPlatformPath(repoRelPath + extension); } else { this.repoRelPath = PathUtil.append(parent.getRelativePath(), repoRelPath); this.platRelPath = PathUtil.append(parent.getPlatformPath(), PlatformNameFormat.getPlatformPath(repoRelPath + extension)); } if (this.platRelPath.equals(this.repoRelPath)) { this.platRelPath = null; } }
private File getFile(String path) { if (StringUtils.endsWith(path, DOT_CONTENT_XML_SUFFIX)) { return null; } File file = new File(providerFile, "." + PlatformNameFormat.getPlatformPath(path)); if (fileStatCache.exists(file)) { if (StringUtils.endsWith(path, XML_SUFFIX) && !hasDotDirFile(file)) { return null; } return file; } return null; }
private ContentFile getContentFile(String path, String subPath) { File file = new File(providerFile, "." + PlatformNameFormat.getPlatformPath(path) + DOT_CONTENT_XML_SUFFIX); if (fileStatCache.exists(file)) { ContentFile contentFile = new ContentFile(file, path, subPath, contentFileCache, ContentType.JCR_XML); if (contentFile.hasContent()) { return contentFile; } } file = new File(providerFile, "." + PlatformNameFormat.getPlatformPath(path) + XML_SUFFIX); if (fileStatCache.exists(file) && !hasDotDirFile(file)) { ContentFile contentFile = new ContentFile(file, path, subPath, contentFileCache, ContentType.JCR_XML); if (contentFile.hasContent()) { return contentFile; } } // try to find in parent path which contains content fragment String parentPath = ResourceUtil.getParent(path); if (parentPath == null) { return null; } String nextSubPath = path.substring(parentPath.length() + 1) + (subPath != null ? "/" + subPath : ""); return getContentFile(parentPath, nextSubPath); }
/** * Creates a new instance of this class. * @param provider The resource provider. * @param interval The interval between executions of the task, in milliseconds. * @param fsMode FS mode * @param contentFileExtensions Content file extensions * @param contentFileCache Content file cache * @param fileStatCache Cache reducing file-stat lookups (file exists or not, directory vs file). */ public FileMonitor(final FsResourceProvider provider, final long interval, FsMode fsMode, final ContentFileExtensions contentFileExtensions, final ContentFileCache contentFileCache, final FileStatCache fileStatCache) { this.provider = provider; this.fsMode = fsMode; this.contentFileExtensions = contentFileExtensions; this.contentFileCache = contentFileCache; this.fileStatCache = fileStatCache; File rootFile = this.provider.getRootFile(); if (fsMode == FsMode.FILEVAULT_XML) { rootFile = new File(this.provider.getRootFile(), "." + PlatformNameFormat.getPlatformPath(this.provider.getProviderRoot())); } this.root = new Monitorable(this.provider.getProviderRoot(), rootFile, null); createStatus(this.root, contentFileExtensions, contentFileCache); log.debug("Starting file monitor for {} with an interval of {}ms", this.root.file, interval); timer.schedule(this, 0, interval); }