private boolean isHead(String path, List<String> paths, int idx) { int level = new Path(path).segmentCount(); for (int i = idx; i >= 0; i--) { String other = paths.get(i); if (path.contains(other)) { if (new Path(other).segmentCount() == level - 1) { return false; } } } return true; }
public int matchingFirstSegments(Path anotherPath) { assert anotherPath != null; int anotherPathLen = anotherPath.segmentCount(); int max = Math.min(segments.length, anotherPathLen); int count = 0; for (int i = 0; i < max; i++) { if (!segments[i].equals(anotherPath.segment(i))) { return count; } count++; } return count; }
public synchronized void addDoc(String type, Path path, boolean isVersion) { Long counter = docsPerTypes.get(type); if (path.segmentCount() > maxDepth) { maxDepth = path.segmentCount(); } if (counter == null) { counter = 1L; } else { counter += 1; } docsPerTypes.put(type, counter); if (isVersion) { versions += 1; } long t2 = System.currentTimeMillis(); long delta = t2 - t1; if (delta == 0) delta = 1; speed = 1000 * getTotalNbDocs() / (float) delta; }
public synchronized void addDoc(String type, Path path, boolean isVersion) { Long counter = docsPerTypes.get(type); if (path.segmentCount() > maxDepth) { maxDepth = path.segmentCount(); } if (counter == null) { counter = 1L; } else { counter += 1; } docsPerTypes.put(type, counter); if (isVersion) { versions += 1; } long t2 = System.currentTimeMillis(); long delta = t2 - t1; if (delta == 0) delta = 1; speed = 1000 * getTotalNbDocs() / (float) delta; }
public ExtensibleDocumentTreeReader(CoreSession session, DocumentModel root, boolean excludeRoot) { super(session); iterator = new DocumentTreeIterator(session, root, excludeRoot); pathSegmentsToRemove = root.getPath().segmentCount() - (excludeRoot ? 0 : 1); }
public DocumentTreeReader(CoreSession session, DocumentModel root, boolean excludeRoot) { super(session); iterator = new DocumentTreeIterator(session, root, excludeRoot); pathSegmentsToRemove = root.getPath().segmentCount() - (excludeRoot ? 0 : 1); }
public Path makeAbsolute() { if (isAbsolute()) { return this; } Path result = new Path(segments, separators | HAS_LEADING); // may need canonicalizing if it has leading ".." or "." segments if (result.segmentCount() > 0) { String first = result.segment(0); if (first.equals("..") || first.equals(".")) { //$NON-NLS-1$ //$NON-NLS-2$ result.canonicalize(); } } return result; }
public boolean isPrefixOf(Path anotherPath) { if (isEmpty() || (isRoot() && anotherPath.isAbsolute())) { return true; } int len = segments.length; if (len > anotherPath.segmentCount()) { return false; } for (int i = 0; i < len; i++) { if (!segments[i].equals(anotherPath.segment(i))) { return false; } } return true; }
public static boolean isValidPath(String path) { Path test = new Path(path); for (int i = 0, max = test.segmentCount(); i < max; i++) { if (!isValidSegment(test.segment(i))) { return false; } } return true; }
public TreeItem findAndReveal(Path path) { // we expand only parents and not the last segment TreeItem item = this; int len = path.segmentCount(); for (int i = 0; i < len; i++) { item.expand(); item = item.getChild(path.segment(i)); if (item == null) { return null; } } return item; }
public TreeItem find(Path path) { if (root == null) { return null; } Path rootPath = root.getPath(); int p = path.matchingFirstSegments(rootPath); if (p == rootPath.segmentCount()) { return root.find(path.removeFirstSegments(p)); } return null; }
public Path append(Path tail) { // optimize some easy cases if (tail == null || tail.segmentCount() == 0) { return this; } if (isEmpty()) { return tail.makeRelative(); } if (isRoot()) { return tail.makeAbsolute(); } // concatenate the two segment arrays int myLen = segments.length; int tailLen = tail.segmentCount(); String[] newSegments = new String[myLen + tailLen]; System.arraycopy(segments, 0, newSegments, 0, myLen); for (int i = 0; i < tailLen; i++) { newSegments[myLen + i] = tail.segment(i); } // use my leading separators and the tail's trailing separator Path result = new Path(newSegments, (separators & HAS_LEADING) | (tail.hasTrailingSeparator() ? HAS_TRAILING : 0)); String tailFirstSegment = newSegments[myLen]; if (tailFirstSegment.equals("..") || tailFirstSegment.equals(".")) { //$NON-NLS-1$ //$NON-NLS-2$ result.canonicalize(); } return result; }
@Override public void handleEvent(Event event) { EventContext ec = event.getContext(); if (!(ec instanceof DocumentEventContext)) { return; } String evtName = event.getName(); if (!DocumentEventTypes.DOCUMENT_REMOVED.equals(evtName) && !TrashService.DOCUMENT_TRASHED.equals(evtName) && !TrashService.DOCUMENT_UNTRASHED.equals(evtName)) { return; } DocumentEventContext context = (DocumentEventContext) ec; DocumentModel doc = context.getSourceDocument(); Path path = doc.getPath(); if (path == null) { // Placeless document return; } if (path.segmentCount() == 1) { // the document is under root like are the domains // we need to invalidate user workspace location Framework.getService(UserWorkspaceService.class).invalidate(); } }
/** * Adds the concerned users to the list of targeted users for these notifications. */ private void gatherConcernedUsersForDocument(CoreSession coreSession, DocumentModel doc, List<Notification> notifs, Map<Notification, List<String>> targetUsers) { if (doc.getPath().segmentCount() > 1) { log.debug("Searching document: " + doc.getName()); getInterstedUsers(doc, notifs, targetUsers); if (doc.getParentRef() != null && coreSession.exists(doc.getParentRef())) { DocumentModel parent = getDocumentParent(coreSession, doc); gatherConcernedUsersForDocument(coreSession, parent, notifs, targetUsers); } } }
@Override public Backend getBackend(String uri) { Path path = new Path(uri); if (path.segmentCount() == 0) { return this; } else { String key = path.segment(0); initIfNeed(); if (backendMap == null) { return null; } Backend backend = backendMap.get(key); if (backend == null) { return null; } String location = path.removeFirstSegments(1).toString(); return backend.getBackend(location); } }
public TreeItem find(Path path) { TreeItem item = this; for (int i = 0, len = path.segmentCount() - 1; i < len; i++) { if (!item.hasChildren()) { return null; } item = item.getChild(path.segment(i)); if (item == null) { return null; } } if (!item.hasChildren()) { return null; } return item.getChild(path.lastSegment()); }
@Override public String getCurrentDomainPath() { if (currentDomain != null) { return currentDomain.getPathAsString(); } Path path; if (currentDocument != null) { path = currentDocument.getPath(); } else { // Find any document, and lookup its domain. DocumentModelList docs = documentManager.query("SELECT * FROM Document", 1); if (docs.size() < 1) { log.debug("Could not find a single document readable by current user."); return null; } path = docs.get(0).getPath(); } if (path.segmentCount() > 0) { String[] segs = { path.segment(0) }; return Path.createFromSegments(segs).toString(); } else { return null; } }
for (int i=2;i<uwsPath.segmentCount();i++){ log.debug(" - Création du document " + uwsPath.uptoSegment(i).toString()); PathRef nodeRef = new PathRef(uwsPath.uptoSegment(i).toString());
@Override public Path parseLocation(String location) { Path finalLocation = new Path(rootPath); Path rootUrlPath = new Path(rootUrl); Path urlLocation = new Path(location); Path cutLocation = urlLocation.removeFirstSegments(rootUrlPath.segmentCount()); finalLocation = finalLocation.append(cutLocation); String fileName = finalLocation.lastSegment(); String parentPath = finalLocation.removeLastSegments(1).toString(); return new Path(parentPath).append(fileName); }
protected String getCommentContainerPath(CoreSession session, String commentedDocumentId) { return CoreInstance.doPrivileged(session, s -> { // Create or retrieve the folder to store the comment. // If the document is under a domain, the folder is a child of this domain. // Otherwise, it is a child of the root document. DocumentModel annotatedDoc = s.getDocument(new IdRef(commentedDocumentId)); String parentPath = "/"; if (annotatedDoc.getPath().segmentCount() > 1) { parentPath += annotatedDoc.getPath().segment(0); } PathRef ref = new PathRef(parentPath, COMMENTS_DIRECTORY); DocumentModel commentFolderDoc = s.createDocumentModel(parentPath, COMMENTS_DIRECTORY, HIDDEN_FOLDER_TYPE); s.getOrCreateDocument(commentFolderDoc); s.save(); return ref.toString(); }); }