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 String navigateToCurrentUserPersonalWorkspace() { if (!initialized) { initialize(); } String returnView = DOCUMENT_VIEW; // force return to Documents tab webActions.setCurrentTabId(WebActions.MAIN_TABS_CATEGORY, DOCUMENT_MANAGEMENT_ACTION); // Rux INA-221: separated links for going to workspaces DocumentModel currentUserPersonalWorkspace = getCurrentUserPersonalWorkspace(); DocumentModel currentDocument = navigationContext.getCurrentDocument(); if (!isShowingPersonalWorkspace() && currentDocument != null && currentDocument.getPath().segment(0) != null) { lastAccessedDocument = mainTabsActions.getDocumentFor(DOCUMENT_MANAGEMENT_ACTION, navigationContext.getCurrentDocument()); } navigationContext.setCurrentDocument(currentUserPersonalWorkspace); showingPersonalWorkspace = true; Events.instance().raiseEvent(EventNames.GO_PERSONAL_WORKSPACE); return returnView; }
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; }
domainPath = "/" + docModel.getPath().segment(0); } else { domainPath = path;
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 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 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; }
@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 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; }
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; } }
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(); }); }
log.debug("Création de l'arborescence :" +uwsPath.toString()); String domainName = uwsPath.segment(0); log.debug(" -- Domaine des userWorkspaces : "+domainName); PathRef domainRef = new PathRef(domainName);
@Override public Annotation createAnnotation(CoreSession session, Annotation annotation) { ConfigurationService configurationService = Framework.getService(ConfigurationService.class); boolean annotationPlaceless = configurationService.isBooleanPropertyTrue( ANNOTATIONS_PLACELESS_STORAGE_PROPERTY); return CoreInstance.doPrivileged(session, s -> { String path = null; if (!annotationPlaceless) { // Create or retrieve the folder to store the annotation. // 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(annotation.getDocumentId())); String parentPath = s.getRootDocument().getPathAsString(); if (annotatedDoc.getPath().segmentCount() > 1) { parentPath += annotatedDoc.getPath().segment(0); } PathRef ref = new PathRef(parentPath, ANNOTATION_FOLDER_NAME); DocumentModel annotationFolderDoc = s.createDocumentModel(parentPath, ANNOTATION_FOLDER_NAME, HIDDEN_FOLDER_TYPE); s.getOrCreateDocument(annotationFolderDoc); s.save(); path = ref.toString(); } DocumentModel annotationModel = s.createDocumentModel(path, ANNOTATION_NAME, ANNOTATION_DOC_TYPE); setAnnotationProperties(annotationModel, annotation); annotationModel = s.createDocument(annotationModel); return new AnnotationImpl(annotationModel); }); }