SVNRepository workspaceRoot = getWorkspaceDirectory(workspaceName);
if (workspaceRoot == null) {
request.setError(new InvalidWorkspaceException(SVNRepositoryConnectorI18n.workspaceDoesNotExist.text(workspaceName)));
return false;
}
Path requestedPath = getPathFor(myLocation, request);
checkThePath(requestedPath, request); // same-name-sibling indexes are not supported
if (requestedPath.isRoot()) {
// workspace root must be a directory
if (children != null) {
final Collection<SVNDirEntry> entries = SVNRepositoryUtil.getDir(workspaceRoot, "");
for (SVNDirEntry entry : entries) {
// All of the children of a directory will be another directory or a file, but never a "jcr:content" node ...
String localName = entry.getName();
Name childName = nameFactory().create(defaultNamespaceUri, localName);
Path childPath = pathFactory().create(requestedPath, childName);
children.add(Location.create(childPath));
}
}
// There are no properties on the root ...
} else {
try {
// Generate the properties for this File object ...
PropertyFactory factory = getExecutionContext().getPropertyFactory();
DateTimeFactory dateFactory = getExecutionContext().getValueFactories().getDateFactory();
// Figure out the kind of node this represents ...
SVNNodeKind kind = getNodeKind(workspaceRoot, requestedPath, accessData.getRepositoryRootUrl(), workspaceName);
if (kind == SVNNodeKind.DIR) {
String directoryPath = getPathAsString(requestedPath);
if (!accessData.getRepositoryRootUrl().equals(workspaceName)) {
directoryPath = directoryPath.substring(1);
}
if (children != null) {
// Decide how to represent the children ...
Collection<SVNDirEntry> dirEntries = SVNRepositoryUtil.getDir(workspaceRoot, directoryPath);
for (SVNDirEntry entry : dirEntries) {
// All of the children of a directory will be another directory or a file,
// but never a "jcr:content" node ...
String localName = entry.getName();
Name childName = nameFactory().create(defaultNamespaceUri, localName);
Path childPath = pathFactory().create(requestedPath, childName);
children.add(Location.create(childPath));
}
}
if (properties != null) {
// Load the properties for this directory ......
addProperty(properties, factory, JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FOLDER);
SVNDirEntry entry = getEntryInfo(workspaceRoot, directoryPath);
if (entry != null) {
addProperty(properties, factory, JcrLexicon.LAST_MODIFIED, dateFactory.create(entry.getDate()));
}
}
} else {
// It's not a directory, so must be a file; the only child of an nt:file is the "jcr:content" node
// ...
if (requestedPath.endsWith(JcrLexicon.CONTENT)) {
// There are never any children of these nodes, just properties ...
if (properties != null) {
String contentPath = getPathAsString(requestedPath.getParent());
if (!accessData.getRepositoryRootUrl().equals(workspaceName)) {
contentPath = contentPath.substring(1);
}
SVNDirEntry entry = getEntryInfo(workspaceRoot, contentPath);
if (entry != null) {
// The request is to get properties of the "jcr:content" child node ...
// Do NOT use "nt:resource", since it extends "mix:referenceable". The JCR spec
// does not require that "jcr:content" is of type "nt:resource", but rather just
// suggests it. Therefore, we can use "dna:resource", which is identical to
// "nt:resource" except it does not extend "mix:referenceable"
addProperty(properties, factory, JcrLexicon.PRIMARY_TYPE, DnaLexicon.RESOURCE);
addProperty(properties, factory, JcrLexicon.LAST_MODIFIED, dateFactory.create(entry.getDate()));
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
SVNProperties fileProperties = new SVNProperties();
getData(contentPath, fileProperties, os);
String mimeType = fileProperties.getStringValue(SVNProperty.MIME_TYPE);
if (mimeType == null) mimeType = DEFAULT_MIME_TYPE;
addProperty(properties, factory, JcrLexicon.MIMETYPE, mimeType);
if (os.toByteArray().length > 0) {
// Now put the file's content into the "jcr:data" property ...
BinaryFactory binaryFactory = getExecutionContext().getValueFactories().getBinaryFactory();
addProperty(properties, factory, JcrLexicon.DATA, binaryFactory.create(os.toByteArray()));
}
}
} else {
// Determine the corresponding file path for this object ...
String filePath = getPathAsString(requestedPath);
if (!accessData.getRepositoryRootUrl().equals(workspaceName)) {
filePath = filePath.substring(1);
}
if (children != null) {
// Not a "jcr:content" child node but rather an nt:file node, so add the child ...
Path contentPath = pathFactory().create(requestedPath, JcrLexicon.CONTENT);
children.add(Location.create(contentPath));
}
if (properties != null) {
// Now add the properties to "nt:file" ...
addProperty(properties, factory, JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FILE);