use of org.alfresco.service.cmr.repository.Path in project acs-community-packaging by Alfresco.
the class SearchContext method getPathFromSpaceRef.
/**
* Generate a search XPATH pointing to the specified node, optionally return an XPATH
* that includes the child nodes.
*
* @param ref Of the node to generate path too
* @param children Whether to include children of the node
*
* @return the path
*/
public static String getPathFromSpaceRef(NodeRef ref, boolean children) {
FacesContext context = FacesContext.getCurrentInstance();
Path path = Repository.getServiceRegistry(context).getNodeService().getPath(ref);
NamespaceService ns = Repository.getServiceRegistry(context).getNamespaceService();
StringBuilder buf = new StringBuilder(64);
for (int i = 0; i < path.size(); i++) {
String elementString = "";
Path.Element element = path.get(i);
if (element instanceof Path.ChildAssocElement) {
ChildAssociationRef elementRef = ((Path.ChildAssocElement) element).getRef();
if (elementRef.getParentRef() != null) {
Collection<String> prefixes = ns.getPrefixes(elementRef.getQName().getNamespaceURI());
if (prefixes.size() > 0) {
elementString = '/' + (String) prefixes.iterator().next() + ':' + ISO9075.encode(elementRef.getQName().getLocalName());
}
}
}
buf.append(elementString);
}
if (children == true) {
// append syntax to get all children of the path
buf.append("//*");
} else {
// append syntax to just represent the path, not the children
buf.append("/*");
}
return buf.toString();
}
use of org.alfresco.service.cmr.repository.Path in project records-management by Alfresco.
the class FilePlanComponentsApiUtils method lookupPathInfo.
protected PathInfo lookupPathInfo(NodeRef nodeRefIn) {
List<ElementInfo> pathElements = new ArrayList<>();
Boolean isComplete = Boolean.TRUE;
final Path nodePath = nodeService.getPath(nodeRefIn);
;
final int 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);
pathElements.add(0, new ElementInfo(childNodeRef.getId(), nameProp.toString()));
} else {
// Just return the pathInfo up to the location where the user has access
isComplete = Boolean.FALSE;
break;
}
}
}
}
String pathStr = null;
if (!pathElements.isEmpty()) {
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 NodeBrowserPost method getPrimaryParent.
/**
* Gets the current node primary parent reference
*
* @return primary parent ref
*/
public NodeRef getPrimaryParent(NodeRef nodeRef) {
Path primaryPath = getNodeService().getPath(nodeRef);
Path.Element element = primaryPath.last();
NodeRef parentRef = ((Path.ChildAssocElement) element).getRef().getParentRef();
return parentRef;
}
use of org.alfresco.service.cmr.repository.Path in project alfresco-remote-api by Alfresco.
the class GetMethod method executeImpl.
/**
* Exceute the WebDAV request
*
* @exception WebDAVServerException
*/
protected void executeImpl() throws WebDAVServerException, Exception {
FileFolderService fileFolderService = getFileFolderService();
NodeRef rootNodeRef = getRootNodeRef();
String path = getPath();
if (!m_returnContent) {
// There are multiple cases where no content is sent (due to a HEAD request).
// All of them require that the content length is set appropriately.
m_response.setContentLength(0);
}
FileInfo nodeInfo = null;
try {
nodeInfo = getDAVHelper().getNodeForPath(rootNodeRef, path);
} catch (FileNotFoundException e) {
throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND);
}
FileInfo realNodeInfo = nodeInfo;
// This is at least consistent with the way the CIFS server handles links. See org.alfresco.filesys.repo.ContentDiskDriver.openFile().
if (realNodeInfo.isLink()) {
Path pathToNode = getNodeService().getPath(nodeInfo.getLinkNodeRef());
if (pathToNode.size() > 2) {
pathToNode = pathToNode.subPath(2, pathToNode.size() - 1);
}
String rootURL = getDAVHelper().getURLForPath(m_request, pathToNode.toDisplayPath(getNodeService(), getPermissionService()), true);
if (rootURL.endsWith(WebDAVHelper.PathSeperator) == false) {
rootURL = rootURL + WebDAVHelper.PathSeperator;
}
String fname = (String) getNodeService().getProperty(nodeInfo.getLinkNodeRef(), ContentModel.PROP_NAME);
StringBuilder urlStr = new StringBuilder(200);
urlStr.append("[InternetShortcut]\r\n");
urlStr.append("URL=file://");
urlStr.append(m_request.getServerName());
// Only append the port if it is non-default for compatibility with XP
int port = m_request.getServerPort();
if (port != 80) {
urlStr.append(":").append(port);
}
urlStr.append(rootURL).append(WebDAVHelper.encodeURL(fname, m_userAgent));
urlStr.append("\r\n");
m_response.setHeader(WebDAV.HEADER_CONTENT_TYPE, "text/plain; charset=ISO-8859-1");
m_response.setHeader(WebDAV.HEADER_CONTENT_LENGTH, String.valueOf(urlStr.length()));
m_response.getWriter().write(urlStr.toString());
} else // Check if the node is a folder
if (realNodeInfo.isFolder()) {
// is content required
if (!m_returnContent) {
// ALF-7883 fix, HEAD for collection (see http://www.webdav.org/specs/rfc2518.html#rfc.section.8.4)
return;
}
// Generate a folder listing
m_response.setContentType("text/html;charset=UTF-8");
generateDirectoryListing(nodeInfo);
} else {
// Return the node details, and content if requested, check that the node passes the pre-conditions
checkPreConditions(realNodeInfo);
// Build the response header
m_response.setHeader(WebDAV.HEADER_ETAG, getDAVHelper().makeQuotedETag(nodeInfo));
Date modifiedDate = realNodeInfo.getModifiedDate();
if (modifiedDate != null) {
long modDate = DefaultTypeConverter.INSTANCE.longValue(modifiedDate);
m_response.setHeader(WebDAV.HEADER_LAST_MODIFIED, WebDAV.formatHeaderDate(modDate));
}
m_response.setHeader("Content-Disposition", getContentDispositionHeader(nodeInfo));
ContentReader reader = fileFolderService.getReader(realNodeInfo.getNodeRef());
// ensure that we generate something, even if the content is missing
reader = FileContentReader.getSafeContentReader((ContentReader) reader, I18NUtil.getMessage(FileContentReader.MSG_MISSING_CONTENT), realNodeInfo.getNodeRef(), reader);
readContent(realNodeInfo, reader);
}
}
use of org.alfresco.service.cmr.repository.Path in project acs-community-packaging by Alfresco.
the class DisplayPathConverter method getAsString.
/**
* @see javax.faces.convert.Converter#getAsString(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.Object)
*/
public String getAsString(FacesContext context, UIComponent component, Object value) throws ConverterException {
String result = "";
if (value != null) {
try {
NodeService nodeService = Repository.getServiceRegistry(context).getNodeService();
Path path = null;
if (value instanceof NodeRef) {
path = nodeService.getPath((NodeRef) value);
} else if (value instanceof Path) {
path = (Path) value;
}
if (path != null) {
result = Repository.getNamePath(nodeService, path, null, "/", null);
}
} catch (AccessDeniedException accessErr) {
// use default if this occurs
} catch (InvalidNodeRefException nodeErr) {
// use default if this occurs
}
}
return result;
}
Aggregations