@Override public DocumentRef getParentRef() { if (parentRef == null && path != null) { if (path.isAbsolute()) { Path parentPath = path.removeLastSegments(1); parentRef = new PathRef(parentPath.toString()); } // else keep parentRef null } return parentRef; }
@Override public DocumentRef getParentRef() { if (path == null) { return null; } if (!path.isAbsolute()) { return null; } return new PathRef(path.removeLastSegments(1).toString()); }
public static String getParentPath(String path) { path = new Path(path).removeLastSegments(1).toString(); // Ensures that path starts with a "/" and doesn't end with a "/". if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } if (!path.startsWith("/")) { path = "/" + path; } return path; }
public Path removeFileExtension() { String extension = getFileExtension(); if (extension == null || extension.equals("")) { //$NON-NLS-1$ return this; } String lastSegment = lastSegment(); int index = lastSegment.lastIndexOf(extension) - 1; return removeLastSegments(1).append(lastSegment.substring(0, index)); }
@Override public boolean isRename(String source, String destination) { Path sourcePath = new Path(source); Path destinationPath = new Path(destination); return sourcePath.removeLastSegments(1).toString().equals(destinationPath.removeLastSegments(1).toString()); }
@Override public DocumentRef getParentRef() { if (path != null) { return new PathRef(path.removeLastSegments(1).toString()); } return null; }
public Path append(String tail) { // optimize addition of a single segment if (tail.indexOf(SEPARATOR) == -1) { int tailLength = tail.length(); if (tailLength < 3) { // some special cases if (tailLength == 0 || ".".equals(tail)) { //$NON-NLS-1$ return this; } if ("..".equals(tail)) { return removeLastSegments(1); } } // just add the segment int myLen = segments.length; String[] newSegments = new String[myLen + 1]; System.arraycopy(segments, 0, newSegments, 0, myLen); newSegments[myLen] = tail; return new Path(newSegments, separators & ~HAS_TRAILING); } // go with easy implementation return append(new Path(tail)); }
@GET @Path("@search") public Object search() { final HttpServletRequest request = ctx.getRequest(); String query = request.getParameter("query"); if (query == null) { String fullText = request.getParameter("fullText"); if (fullText == null) { throw new IllegalParameterException("Expecting a query or a fullText parameter"); } String orderBy = request.getParameter("orderBy"); String orderClause = ""; if (orderBy != null) { orderClause = " ORDER BY " + orderBy; } String path; if (doc.isFolder()) { path = doc.getPathAsString(); } else { path = doc.getPath().removeLastSegments(1).toString(); } query = "SELECT * FROM Document WHERE (ecm:fulltext = \"" + fullText + "\") AND (ecm:isVersion = 0) AND (ecm:path STARTSWITH \"" + path + "\")" + orderClause; } DocumentModelList docs = ctx.getCoreSession().query(query); return getView("search").arg("query", query).arg("result", docs); }
protected String findFarthestContainerPath(String documentPath) { Path containerPath = new Path(documentPath); String result; do { result = containerPath.toString(); containerPath = containerPath.removeLastSegments(1); } while (!containerPath.isRoot() && documentManager.exists(new PathRef(containerPath.toString()))); return result; }
@Factory(value = "currentPersonalWorkspacePath", scope = EVENT) public String getCurrentPersonalWorkspace() { if (currentPersonalWorkspacePath == null && Boolean.TRUE.equals(isUserWorkspace)) { // Do not compute path if not necessary Path path = navigationContext.getCurrentDocument().getPath(); String lastSegment = ""; while (!path.isRoot() || !path.isEmpty()) { if (UserWorkspaceConstants.USERS_PERSONAL_WORKSPACES_ROOT.equals(path.lastSegment())) { if (lastSegment.isEmpty()) { currentPersonalWorkspacePath = ""; } else { currentPersonalWorkspacePath = path.append(lastSegment).toString(); } return currentPersonalWorkspacePath; } else { lastSegment = path.lastSegment(); } path = path.removeLastSegments(1); } } return currentPersonalWorkspacePath; }
@Override protected DocumentModel doCreateUserWorkspacesRoot(CoreSession unrestrictedSession, PathRef rootRef) { String parentPath = new Path(rootRef.toString()).removeLastSegments(1).toString(); DocumentModel doc = unrestrictedSession.createDocumentModel(parentPath, UserWorkspaceConstants.USERS_PERSONAL_WORKSPACES_ROOT, getUserWorkspaceRootType()); doc.setProperty("dublincore", "title", UserWorkspaceConstants.USERS_PERSONAL_WORKSPACES_ROOT); doc.setProperty("dublincore", "description", ""); return doc; }
protected DocumentModel getParentDocument(CoreSession session, DocumentModel doc) { DocumentModel parent; if (session.exists(doc.getRef())) { parent = session.getParentDocument(doc.getRef()); } else { Path parentPath = doc.getPath().removeLastSegments(1); parent = session.getDocument(new PathRef(parentPath.toString())); } return parent; }
@Override public DocumentModel createComment(DocumentModel docModel, DocumentModel parent, DocumentModel child) { try (CloseableCoreSession session = CoreInstance.openCoreSessionSystem(docModel.getRepositoryName())) { DocumentModel parentDocModel = session.getDocument(parent.getRef()); String containerPath = parent.getPath().removeLastSegments(1).toString(); DocumentModel newComment = internalCreateComment(session, parentDocModel, child, containerPath); session.save(); return newComment; } }
@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 DocumentModel resolveParent(String location) { DocumentModel doc = null; DocumentRef docRef = new PathRef(location.toString()); if (exists(docRef)) { doc = getSession().getDocument(docRef); } else { Path locationPath = new Path(location); String filename = locationPath.lastSegment(); Path parentLocation = locationPath.removeLastSegments(1); // first try with spaces (for create New Folder) String folderName = filename; DocumentRef folderRef = new PathRef(parentLocation.append(folderName).toString()); if (exists(folderRef)) { doc = getSession().getDocument(folderRef); } } return doc; }
@Override protected DocumentModel doCreateUserWorkspace(CoreSession unrestrictedSession, PathRef wsRef, String userName) { String parentPath = new Path(wsRef.toString()).removeLastSegments(1).toString(); String wsName = new Path(wsRef.toString()).lastSegment(); DocumentModel doc = unrestrictedSession.createDocumentModel(parentPath, wsName, getUserWorkspaceType()); doc.setProperty("dublincore", "title", buildUserWorkspaceTitle(userName)); doc.setProperty("dublincore", "description", ""); return doc; }
@Override public DocumentModel updateDocument(DocumentModel doc, String name, Blob content) { FileManager fileManager = Framework.getService(FileManager.class); String parentPath = new Path(doc.getPathAsString()).removeLastSegments(1).toString(); try { // this cannot be done before the update anymore // doc.putContextData(SOURCE_EDIT_KEYWORD, "webdav"); FileImporterContext context = FileImporterContext.builder(session, content, parentPath) .overwrite(true) .fileName(name) .build(); doc = fileManager.createOrUpdateDocument(context); } catch (IOException e) { throw new NuxeoException("Error while updating document", e); } return doc; }
@Override public void run() { DocumentRef pathRef = new PathRef(parentPath); if (session.exists(pathRef)) { taskRootDoc = session.getDocument(pathRef); } else { Path path = new Path(parentPath); taskRootDoc = session.createDocumentModel(path.removeLastSegments(1).toString(), path.lastSegment(), TaskConstants.TASK_ROOT_TYPE_NAME); taskRootDoc = session.createDocument(taskRootDoc); ACP acp = taskRootDoc.getACP(); ACL acl = acp.getOrCreateACL(ACL.LOCAL_ACL); acl.add(new ACE("Everyone", "Everything", false)); taskRootDoc.setACP(acp, true); taskRootDoc = session.saveDocument(taskRootDoc); } }
protected static DocumentModel createUserWorkspace( CoreSession unrestrictedSession, PathRef wsRef, String userName) throws ClientException { String parentPath = new Path(wsRef.toString()).removeLastSegments(1).toString(); String wsName = new Path(wsRef.toString()).lastSegment(); DocumentModel doc = unrestrictedSession.createDocumentModel(parentPath, wsName,"UserWorkspace"); doc.setProperty("dublincore", "title", userName); doc.setProperty("dublincore", "description", ""); doc = unrestrictedSession.createDocument(doc); ACP acp = new ACPImpl(); ACE grantEverything = new ACE(userName, SecurityConstants.EVERYTHING, true); ACL acl = new ACLImpl(); acl.setACEs(new ACE[] { grantEverything }); acp.addACL(acl); doc.setACP(acp, true); return doc; }
protected static DocumentModel createUserWorkspacesRoot( CoreSession unrestrictedSession, PathRef rootRef) throws ClientException { String parentPath = new Path(rootRef.toString()).removeLastSegments(1).toString(); String docName = new Path(rootRef.toString()).lastSegment(); DocumentModel doc = unrestrictedSession.createDocumentModel(parentPath, docName,"UserWorkspacesRoot"); doc.setProperty("dublincore", "title", docName); doc.setProperty("dublincore", "description", ""); doc = unrestrictedSession.createDocument(doc); ACP acp = new ACPImpl(); ACE denyEverything = new ACE(SecurityConstants.EVERYONE, SecurityConstants.EVERYTHING, false); ACL acl = new ACLImpl(); acl.setACEs(new ACE[] { denyEverything }); acp.addACL(acl); doc.setACP(acp, true); return doc; }