use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-filesystem-connectors by nuxeo.
the class WebDavClientTest method testDeleteFile.
@Test
public void testDeleteFile() throws Exception {
String name = "test.txt";
HttpDelete request = new HttpDelete(ROOT_URI + name);
int status;
try (CloseableHttpResponse response = client.execute(request, context)) {
status = response.getStatusLine().getStatusCode();
}
assertEquals(HttpStatus.SC_NO_CONTENT, status);
// check using Nuxeo Core APIs
// process invalidations
session.save();
PathRef pathRef = new PathRef("/workspaces/workspace/" + name);
// in the trash with different name
assertFalse(session.exists(pathRef));
// recreate it, for other tests using the same repo
byte[] bytes = "Hello, world!".getBytes("UTF-8");
doTestPutFile(name, bytes, "text/plain", "Note");
}
use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-filesystem-connectors by nuxeo.
the class WebDavClientTest method testCreateFolder.
@Test
public void testCreateFolder() throws Exception {
String name = "newfolder";
HttpMkcol request = new HttpMkcol(ROOT_URI + name);
int status;
try (CloseableHttpResponse response = client.execute(request, context)) {
status = response.getStatusLine().getStatusCode();
}
assertEquals(HttpStatus.SC_CREATED, status);
// check using Nuxeo Core APIs
// process invalidations
session.save();
PathRef pathRef = new PathRef("/workspaces/workspace/" + name);
assertTrue(session.exists(pathRef));
DocumentModel doc = session.getDocument(pathRef);
assertEquals("Folder", doc.getType());
assertEquals(name, doc.getTitle());
}
use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-filesystem-connectors by nuxeo.
the class SimpleBackend method cleanTrashPath.
protected boolean cleanTrashPath(DocumentModel parent, String name) {
Path checkedPath = new Path(parent.getPathAsString()).append(name);
if (getSession().exists(new PathRef(checkedPath.toString()))) {
DocumentModel model = getSession().getDocument(new PathRef(checkedPath.toString()));
if (model != null && model.isTrashed()) {
name = name + "." + System.currentTimeMillis();
getSession().move(model.getRef(), parent.getRef(), name);
return true;
}
}
return false;
}
use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-filesystem-connectors by nuxeo.
the class SimpleBackend method resolveLocation.
@Override
public DocumentModel resolveLocation(String location) {
Path resolvedLocation = parseLocation(location);
DocumentModel doc = null;
doc = getPathCache().get(resolvedLocation.toString());
if (doc != null) {
return doc;
}
DocumentRef docRef = new PathRef(resolvedLocation.toString());
if (exists(docRef)) {
doc = getSession().getDocument(docRef);
} else {
String encodedPath = urlEncode(resolvedLocation.toString());
if (!resolvedLocation.toString().equals(encodedPath)) {
DocumentRef encodedPathRef = new PathRef(encodedPath);
if (exists(encodedPathRef)) {
doc = getSession().getDocument(encodedPathRef);
}
}
if (doc == null) {
String filename = resolvedLocation.lastSegment();
Path parentLocation = resolvedLocation.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);
}
// look for a child
DocumentModel parentDocument = resolveParent(parentLocation.toString());
if (parentDocument == null) {
// parent doesn't exist, no use looking for a child
return null;
}
List<DocumentModel> children = getChildren(parentDocument.getRef());
for (DocumentModel child : children) {
BlobHolder bh = child.getAdapter(BlobHolder.class);
if (bh != null) {
Blob blob = bh.getBlob();
if (blob != null) {
try {
String blobFilename = blob.getFilename();
if (filename.equals(blobFilename)) {
doc = child;
break;
} else if (urlEncode(filename).equals(blobFilename)) {
doc = child;
break;
} else if (URLEncoder.encode(filename, "UTF-8").equals(blobFilename)) {
doc = child;
break;
} else if (encode(blobFilename.getBytes(), "ISO-8859-1").equals(filename)) {
doc = child;
break;
}
} catch (UnsupportedEncodingException e) {
// cannot happen for UTF-8
throw new RuntimeException(e);
}
}
}
}
}
}
getPathCache().put(resolvedLocation.toString(), doc);
return doc;
}
use of org.nuxeo.ecm.core.api.PathRef in project nuxeo-filesystem-connectors by nuxeo.
the class SimpleBackend method getVirtualFolderNames.
@Override
public LinkedList<String> getVirtualFolderNames() {
if (orderedBackendNames == null) {
List<DocumentModel> children = getChildren(new PathRef(rootPath));
orderedBackendNames = new LinkedList<String>();
if (children != null) {
for (DocumentModel model : children) {
orderedBackendNames.add(model.getName());
}
}
}
return orderedBackendNames;
}
Aggregations