use of org.alfresco.service.cmr.repository.Path in project alfresco-remote-api by Alfresco.
the class NodesImpl method lookupPathInfo.
@Override
public PathInfo lookupPathInfo(NodeRef nodeRefIn, ChildAssociationRef archivedParentAssoc) {
List<ElementInfo> pathElements = new ArrayList<>();
Boolean isComplete = Boolean.TRUE;
final Path nodePath;
final int pathIndex;
if (archivedParentAssoc != null) {
if (permissionService.hasPermission(archivedParentAssoc.getParentRef(), PermissionService.READ).equals(AccessStatus.ALLOWED) && nodeService.exists(archivedParentAssoc.getParentRef())) {
nodePath = nodeService.getPath(archivedParentAssoc.getParentRef());
// 1 => we want to include the given node in the path as well.
pathIndex = 1;
} else {
// We can't return a valid path
return null;
}
} else {
nodePath = nodeService.getPath(nodeRefIn);
// 2 => as we don't want to include the given node in the path as well.
pathIndex = 2;
}
for (int i = nodePath.size() - pathIndex; i >= 0; i--) {
Element element = nodePath.get(i);
if (element instanceof Path.ChildAssocElement) {
ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
if (elementRef.getParentRef() != null) {
NodeRef childNodeRef = elementRef.getChildRef();
if (permissionService.hasPermission(childNodeRef, PermissionService.READ) == AccessStatus.ALLOWED) {
Serializable nameProp = nodeService.getProperty(childNodeRef, ContentModel.PROP_NAME);
String type = getNodeType(childNodeRef).toPrefixString(namespaceService);
Set<QName> aspects = nodeService.getAspects(childNodeRef);
List<String> aspectNames = mapFromNodeAspects(aspects, EXCLUDED_NS, EXCLUDED_ASPECTS);
pathElements.add(0, new ElementInfo(childNodeRef.getId(), nameProp.toString(), type, aspectNames));
} else {
// Just return the pathInfo up to the location where the user has access
isComplete = Boolean.FALSE;
break;
}
}
}
}
String pathStr = null;
if (pathElements.size() > 0) {
StringBuilder sb = new StringBuilder(120);
for (PathInfo.ElementInfo e : pathElements) {
sb.append("/").append(e.getName());
}
pathStr = sb.toString();
} else {
// There is no path element, so set it to null in order to be
// ignored by Jackson during serialisation
isComplete = null;
}
return new PathInfo(pathStr, isComplete, pathElements);
}
use of org.alfresco.service.cmr.repository.Path in project alfresco-remote-api by Alfresco.
the class GetMethod method generateDirectoryListing.
/**
* Generates a HTML representation of the contents of the path represented by the given node
*
* @param fileInfo the file to use
*/
private void generateDirectoryListing(FileInfo fileInfo) {
MimetypeService mimeTypeService = getMimetypeService();
NodeService nodeService = getNodeService();
Writer writer = null;
try {
writer = m_response.getWriter();
boolean wasLink = false;
if (fileInfo.isLink()) {
fileInfo = getFileFolderService().getFileInfo(fileInfo.getLinkNodeRef());
wasLink = true;
}
// Get the list of child nodes for the parent node
List<FileInfo> childNodeInfos = getDAVHelper().getChildren(fileInfo);
// Send back the start of the HTML
writer.write("<html><head><title>");
writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.repository_title")));
writer.write("</title>");
writer.write("<style>");
writer.write("body { font-family: Arial, Helvetica; font-size: 12pt; background-color: white; }\n");
writer.write("table { font-family: Arial, Helvetica; font-size: 12pt; background-color: white; }\n");
writer.write(".listingTable { border: solid black 1px; }\n");
writer.write(".textCommand { font-family: verdana; font-size: 10pt; }\n");
writer.write(".textLocation { font-family: verdana; font-size: 11pt; font-weight: bold; color: #2a568f; }\n");
writer.write(".textData { font-family: verdana; font-size: 10pt; }\n");
writer.write(".tableHeading { font-family: verdana; font-size: 10pt; font-weight: bold; color: white; background-color: #2a568f; }\n");
writer.write(".rowOdd { background-color: #eeeeee; }\n");
writer.write(".rowEven { background-color: #dddddd; }\n");
writer.write("</style></head>\n");
writer.flush();
// Send back the table heading
writer.write("<body>\n");
writer.write("<table cellspacing='2' cellpadding='3' border='0' width='100%'>\n");
writer.write("<tr><td colspan='4' class='textLocation'>");
writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.directory_listing")));
writer.write(' ');
writer.write(WebDAVHelper.encodeHTML(getPath()));
writer.write("</td></tr>\n");
writer.write("<tr><td height='10' colspan='4'></td></tr></table>");
writer.write("<table cellspacing='2' cellpadding='3' border='0' width='100%' class='listingTable'>\n");
writer.write("<tr><td class='tableHeading' width='*'>");
writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.column.name")));
writer.write("</td>");
writer.write("<td class='tableHeading' width='10%'>");
writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.column.size")));
writer.write("</td>");
writer.write("<td class='tableHeading' width='20%'>");
writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.column.type")));
writer.write("</td>");
writer.write("<td class='tableHeading' width='25%'>");
writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.column.modifieddate")));
writer.write("</td>");
writer.write("</tr>\n");
// Get the URL for the root path
String rootURL = getURLForPath(m_request, getPath(), true);
if (rootURL.endsWith(WebDAVHelper.PathSeperator) == false) {
rootURL = rootURL + WebDAVHelper.PathSeperator;
}
if (wasLink) {
Path pathToNode = nodeService.getPath(fileInfo.getNodeRef());
if (pathToNode.size() > 2) {
pathToNode = pathToNode.subPath(2, pathToNode.size() - 1);
}
rootURL = getURLForPath(m_request, pathToNode.toDisplayPath(nodeService, getPermissionService()), true);
if (rootURL.endsWith(WebDAVHelper.PathSeperator) == false) {
rootURL = rootURL + WebDAVHelper.PathSeperator;
}
rootURL = rootURL + WebDAVHelper.encodeURL(fileInfo.getName(), m_userAgent) + WebDAVHelper.PathSeperator;
}
// Start with a link to the parent folder so we can navigate back up, unless we are at the root level
if (!getDAVHelper().isRootPath(getPath(), getServletPath())) {
writer.write("<tr class='rowOdd'>");
writer.write("<td colspan='4' class='textData'><a href=\"");
// Strip the last folder from the path
String parentFolderUrl = parentFolder(rootURL);
writer.write(parentFolderUrl);
writer.write("\">");
writer.write("[");
writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.column.navigate_up")));
writer.write("]</a>");
writer.write("</tr>\n");
}
// Send back what we have generated so far
writer.flush();
int rowId = 0;
for (FileInfo childNodeInfo : childNodeInfos) {
// Output the details for the current node
writer.write("<tr class='");
if ((rowId++ & 1) == 1) {
writer.write("rowOdd");
} else {
writer.write("rowEven");
}
writer.write("'><td class='textData'><a href=\"");
writer.write(rootURL);
// name field
String fname = childNodeInfo.getName();
writer.write(WebDAVHelper.encodeURL(fname, m_userAgent));
writer.write("\">");
writer.write(WebDAVHelper.encodeHTML(fname));
writer.write("</a>");
// size field
writer.write("</td><td class='textData'>");
ContentData contentData = null;
if (!childNodeInfo.isFolder()) {
Serializable contentPropertyName = nodeService.getProperty(childNodeInfo.getNodeRef(), ContentModel.PROP_CONTENT_PROPERTY_NAME);
QName contentPropertyQName = DefaultTypeConverter.INSTANCE.convert(QName.class, contentPropertyName);
if (null == contentPropertyQName) {
contentPropertyQName = ContentModel.PROP_CONTENT;
}
Serializable contentProperty = nodeService.getProperty(childNodeInfo.getNodeRef(), contentPropertyQName);
if (contentProperty instanceof ContentData) {
contentData = (ContentData) contentProperty;
}
}
if (childNodeInfo.isFolder()) {
writer.write(" ");
} else {
if (null != contentData) {
writer.write(formatSize(Long.toString(contentData.getSize())));
} else {
writer.write(" ");
}
}
writer.write("</td><td class='textData'>");
// mimetype field
if (childNodeInfo.isFolder()) {
writer.write(" ");
} else {
String mimetype = " ";
if (null != contentData) {
mimetype = contentData.getMimetype();
String displayType = mimeTypeService.getDisplaysByMimetype().get(mimetype);
if (displayType != null) {
mimetype = displayType;
}
}
writer.write(mimetype);
}
writer.write("</td><td class='textData'>");
// modified date field
Date modifiedDate = childNodeInfo.getModifiedDate();
if (modifiedDate != null) {
writer.write(WebDAV.formatHeaderDate(DefaultTypeConverter.INSTANCE.longValue(modifiedDate)));
} else {
writer.write(" ");
}
writer.write("</td></tr>\n");
// flush every few rows
if ((rowId & 15) == 0) {
writer.flush();
}
}
writer.write("</table></body></html>");
} catch (Throwable e) {
logger.error(e);
if (writer != null) {
try {
writer.write("</table><table><tr><td style='color:red'>");
writer.write(WebDAVHelper.encodeHTML(I18NUtil.getMessage("webdav.err.dir")));
writer.write("</td></tr></table></body></html>");
writer.flush();
} catch (IOException ioe) {
}
}
}
}
use of org.alfresco.service.cmr.repository.Path in project alfresco-remote-api by Alfresco.
the class SOLRWebScriptTest method testNodeMetaData.
public void testNodeMetaData() throws Exception {
long fromCommitTime = System.currentTimeMillis();
buildTransactions5();
JSONArray transactions = getTransactions(fromCommitTime);
assertEquals("Number of transactions is incorrect", 1, transactions.length());
List<Long> transactionIds = getTransactionIds(transactions);
GetNodesParameters params = new GetNodesParameters();
params.setTransactionIds(transactionIds);
params.setStoreProtocol(storeRef.getProtocol());
params.setStoreIdentifier(storeRef.getIdentifier());
JSONArray nodes = getNodes(params, 0, 2);
List<Long> nodeIds = new ArrayList<Long>(nodes.length());
for (int i = 0; i < nodes.length(); i++) {
JSONObject node = nodes.getJSONObject(i);
nodeIds.add(node.getLong("id"));
}
JSONArray nodesMetaData = getNodesMetaData(nodeIds, 0, 2);
// test second entry (second node created in buildTransactions)
NodeRef expectedNodeRef = contents.get(0);
JSONObject node = nodesMetaData.getJSONObject(1);
NodeRef nodeRef = new NodeRef(node.getString("nodeRef"));
assertEquals("NodeRef is incorrect", expectedNodeRef, nodeRef);
JSONArray aspects = node.getJSONArray("aspects");
JSONObject properties = node.getJSONObject("properties");
Map<QName, String> propertyMap = getPropertyMap(properties);
assertTrue("Expected author aspect", containsAspect(aspects, ContentModel.ASPECT_AUTHOR));
assertTrue("Expected author property", containsProperty(propertyMap, ContentModel.PROP_AUTHOR, "steve"));
JSONArray paths = node.getJSONArray("paths");
List<Path> expectedPaths = nodeService.getPaths(expectedNodeRef, false);
for (int i = 0; i < paths.length(); i++) {
JSONObject o = paths.getJSONObject(i);
String path = o.getString("path");
String qname = o.has("qname") ? o.getString("qname") : null;
String expectedPath = expectedPaths.get(i).toString();
assertEquals("Path element " + i + " is incorrect", expectedPath, path);
assertNull("qname should be null", qname);
}
}
Aggregations