/** * 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); }
/** * Transform path for resource event. * @param path Path * @return Transformed path */ private String transformPath(String path) { if (fsMode == FsMode.FILEVAULT_XML) { return PlatformNameFormat.getRepositoryPath(path); } else { return path; } }
/** * Returns the repository path for the given platform one. * @param path the platform path * @param respectDotDir if {@code true}, all ".dir" are removed. * @return the repository path */ public static String getRepositoryPath(String path, boolean respectDotDir) { String[] elems = Text.explode(path, '/', true); for (int i=0; i<elems.length; i++) { if (elems[i].length() > 0) { if (respectDotDir && elems[i].endsWith(".dir")) { elems[i] = getRepositoryName(elems[i].substring(0, elems[i].length() - 4)); } else { elems[i] = getRepositoryName(elems[i]); } } } return Text.implode(elems, "/"); }
/** * Returns the platform path for the given repository one. * @param repoPath the repository path * @return the platform path */ public static String getPlatformPath(String repoPath) { String[] elems = Text.explode(repoPath, '/', true); for (int i=0; i<elems.length; i++) { if (elems[i].length() > 0) { elems[i] = getPlatformName(elems[i]); } } return Text.implode(elems, "/"); }
String[] p = Text.explode(aggName, '/'); for (int i=0; i<p.length-1; i++) { parent = parent.getOrAddChild(PlatformNameFormat.getPlatformName(p[i]));
/** * 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; } }
public void mkdir(String path) throws IOException, RepositoryException { changes.add(new Change(Type.MKDIR, PlatformNameFormat.getRepositoryPath(path), path, null)); }
/** * Returns the repository path for the given platform one. * @param path the platform path * @return the repository path */ public static String getRepositoryPath(String path) { String[] elems = Text.explode(path, '/', true); for (int i=0; i<elems.length; i++) { if (elems[i].length() > 0) { elems[i] = getRepositoryName(elems[i]); } } return Text.implode(elems, "/"); }
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 void addIgnores(File dir, File file) throws VltException, IOException { VltDirectory d = new VltDirectory(ctx, dir); String root = d.getAggregatePath(); if (root == null) { root = dir.getAbsolutePath().substring(rootLength); root = PlatformNameFormat.getRepositoryPath(root); log.info("Unable to detect correct repository path for {}. guessed: {}", dir.getPath(), root); } for (Object o: FileUtils.readLines(file, "utf-8")) { addIgnored(root, o.toString()); } }
public VaultFileImpl getChild(String name) throws RepositoryException { VaultFileImpl child = children == null ? null : children.get(name); if (child == null) { // try to load child String repoName = PlatformNameFormat.getRepositoryName(name); loadPendingNode(repoName); child = children == null ? null : children.get(name); // if still not present, load all if (child == null) { loadChildren(); } child = children == null ? null : children.get(name); } return child; }
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); }
public VaultFileOutput add(String path, VaultInputSource input) throws IOException, RepositoryException { String repoPath = PlatformNameFormat.getRepositoryPath(path, true); String repoName = Text.getName(repoPath); String parentPath = Text.getRelativeParent(path, 1);
Arrays.sort(files, FileNameComparator.INSTANCE); for (File childFile : files) { String childPath = parentPath + "/" + PlatformNameFormat.getRepositoryName(childFile.getName()); File file = getFile(childPath); if (file != null && pathMatches(childPath) && !childPaths.contains(childPath)) {
/** * 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); }
String repoName = PlatformNameFormat.getRepositoryName(fileName); String repoPath = parentPath + "/" + repoName; if (file.isDirectory()) {
continue; String repoName = PlatformNameFormat.getRepositoryName(fileName); String repoPath = parentInfo.path + "/" + repoName; if (repoName.endsWith(".dir")) { continue; String repoName = PlatformNameFormat.getRepositoryName(fileName); String repoPath = parentInfo.path + "/" + repoName; if (file.getName().equals(Constants.DOT_CONTENT_XML)) {
parentName = parentName.substring(0, parentName.length() - 4); repoName = PlatformNameFormat.getRepositoryName(parentName) + "/" + repoName; parentPath = Text.getRelativeParent(parentPath, 1); parent = fs.getFile(parentPath); parentName = parentName.substring(0, parentName.length() - 4); repoName = PlatformNameFormat.getRepositoryName(parentName) + "/" + repoName; parentPath = Text.getRelativeParent(parentPath, 1); parent = fs.getFile(parentPath); return false; String repoName = PlatformNameFormat.getRepositoryName(name); int idx = repoName.lastIndexOf('.'); if (idx > 0) {