Java Code Examples for org.alfresco.service.cmr.model.FileInfo#isFolder()
The following examples show how to use
org.alfresco.service.cmr.model.FileInfo#isFolder() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileFolderServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override public ContentWriter getWriter(NodeRef nodeRef) { FileInfo fileInfo = toFileInfo(nodeRef, false); if (fileInfo.isFolder()) { throw new InvalidTypeException("Unable to get a content writer for a folder: " + fileInfo); } final ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); // Ensure that a mimetype is set based on the filename (ALF-6560) // This has been removed from the create code in 3.4 to prevent insert-update behaviour // of the ContentData. if (writer.getMimetype() == null) { final String name = fileInfo.getName(); writer.guessMimetype(name); } // Done return writer; }
Example 2
Source File: MoveMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
private void copyContentOnly(FileInfo sourceFileInfo, FileInfo destFileInfo, FileFolderService fileFolderService) throws WebDAVServerException { ContentService contentService = getContentService(); ContentReader reader = contentService.getReader(sourceFileInfo.getNodeRef(), ContentModel.PROP_CONTENT); if (reader == null) { // There is no content for the node if it is a folder if (!sourceFileInfo.isFolder()) { // Non-folders should have content available. logger.error("Unable to get ContentReader for source node " + sourceFileInfo.getNodeRef()); throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND); } } else { ContentWriter contentWriter = contentService.getWriter(destFileInfo.getNodeRef(), ContentModel.PROP_CONTENT, true); contentWriter.putContent(reader); } }
Example 3
Source File: RepositoryExporterComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public RepositoryExportHandle[] export(NodeRef repositoryDestination, String packageName) { ParameterCheck.mandatory("repositoryDestination", repositoryDestination); FileInfo destInfo = fileFolderService.getFileInfo(repositoryDestination); if (destInfo == null || !destInfo.isFolder()) { throw new ExporterException("Repository destination " + repositoryDestination + " is not a folder."); } List<FileExportHandle> exportHandles = exportStores(exportStores, packageName, new TempFileExporter()); Map<String, String> mimetypeExtensions = mimetypeService.getExtensionsByMimetype(); List<RepositoryExportHandle> repoExportHandles = new ArrayList<RepositoryExportHandle>(exportHandles.size()); for (FileExportHandle exportHandle : exportHandles) { String name = exportHandle.packageName + "." + mimetypeExtensions.get(exportHandle.mimeType); String title = exportHandle.packageName; String description; if (exportHandle.storeRef != null) { description = I18NUtil.getMessage("export.store.package.description", new Object[] { exportHandle.storeRef.toString() }); } else { description = I18NUtil.getMessage("export.generic.package.description"); } NodeRef repoExportFile = addExportFile(repositoryDestination, name, title, description, exportHandle.mimeType, exportHandle.exportFile); RepositoryExportHandle handle = new RepositoryExportHandle(); handle.storeRef = exportHandle.storeRef; handle.packageName = exportHandle.packageName; handle.mimeType = exportHandle.mimeType; handle.exportFile = repoExportFile; repoExportHandles.add(handle); // delete temporary export file exportHandle.exportFile.delete(); } return repoExportHandles.toArray(new RepositoryExportHandle[repoExportHandles.size()]); }
Example 4
Source File: PropPatchMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void executeImpl() throws WebDAVServerException, Exception { FileInfo pathNodeInfo = null; try { // Check that the path exists pathNodeInfo = getNodeForPath(getRootNodeRef(), m_strPath); } catch (FileNotFoundException e) { // The path is not valid - send a 404 error back to the client throw new WebDAVServerException(HttpServletResponse.SC_NOT_FOUND); } checkNode(pathNodeInfo); // Create the path for the current location in the tree StringBuilder baseBuild = new StringBuilder(256); baseBuild.append(getPath()); if (baseBuild.length() == 0 || baseBuild.charAt(baseBuild.length() - 1) != WebDAVHelper.PathSeperatorChar) { baseBuild.append(WebDAVHelper.PathSeperatorChar); } basePath = baseBuild.toString(); // Build the href string for the current node boolean isFolder = pathNodeInfo.isFolder(); strHRef = getURLForPath(m_request, basePath, isFolder); // Do the real work: patch the properties patchProperties(pathNodeInfo, basePath); }
Example 5
Source File: PropFindMethod.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * Generates the required response XML for the current node * * @param xml XMLWriter * @param nodeInfo FileInfo * @param path String */ protected void generateResponseForNode(XMLWriter xml, FileInfo nodeInfo, String path) throws Exception { boolean isFolder = nodeInfo.isFolder(); // Output the response block for the current node xml.startElement( WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE, getDAVHelper().getNullAttributes()); // Build the href string for the current node String strHRef = getURLForPath(m_request, path, isFolder); xml.startElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF, getDAVHelper().getNullAttributes()); xml.write(strHRef); xml.endElement(WebDAV.DAV_NS, WebDAV.XML_HREF, WebDAV.XML_NS_HREF); switch (m_mode) { case GET_NAMED_PROPS: generateNamedPropertiesResponse(xml, nodeInfo, isFolder); break; case GET_ALL_PROPS: generateAllPropertiesResponse(xml, nodeInfo, isFolder); break; case FIND_PROPS: generateFindPropertiesResponse(xml, nodeInfo, isFolder); break; } // Close off the response element xml.endElement(WebDAV.DAV_NS, WebDAV.XML_RESPONSE, WebDAV.XML_NS_RESPONSE); }
Example 6
Source File: ActivityPosterImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void postFileFolderUpdated( String siteId, String tenantDomain, FileInfo nodeInfo) throws WebDAVServerException { if (! nodeInfo.isFolder()) { postFileFolderActivity(ActivityType.FILE_UPDATED, siteId, tenantDomain, null, null, nodeInfo); } }
Example 7
Source File: FileFolderServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Checks that the names and numbers of files and folders in the provided list is correct * * @param files the list of files * @param expectedFileCount the number of uniquely named files expected * @param expectedFolderCount the number of uniquely named folders expected * @param expectedNames the names of the files and folders expected */ private void checkFileList( List<FileInfo> files, int expectedFileCount, int expectedFolderCount, String[] expectedNames) { int fileCount = 0; int folderCount = 0; List<String> check = new ArrayList<String>(8); for (String filename : expectedNames) { check.add(filename); } for (FileInfo file : files) { if (file.isFolder()) { folderCount++; } else { fileCount++; } check.remove(file.getName()); } assertTrue("Name list was not exact - remaining: " + check, check.size() == 0); assertEquals("Incorrect number of files", expectedFileCount, fileCount); assertEquals("Incorrect number of folders", expectedFolderCount, folderCount); }
Example 8
Source File: ActivityPosterImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public ActivityInfo getActivityInfo(NodeRef nodeRef) { SiteInfo siteInfo = siteService.getSite(nodeRef); String siteId = (siteInfo != null ? siteInfo.getShortName() : null); if(siteId != null && !siteId.equals("")) { NodeRef parentNodeRef = nodeService.getPrimaryParent(nodeRef).getParentRef(); FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef); String name = fileInfo.getName(); boolean isFolder = fileInfo.isFolder(); NodeRef documentLibrary = siteService.getContainer(siteId, SiteService.DOCUMENT_LIBRARY); String parentPath = "/"; try { parentPath = getPathFromNode(documentLibrary, parentNodeRef); } catch (FileNotFoundException error) { if (logger.isDebugEnabled()) { logger.debug("No " + SiteService.DOCUMENT_LIBRARY + " container found."); } } return new ActivityInfo(nodeRef, parentPath, parentNodeRef, siteId, name, isFolder); } else { return null; } }
Example 9
Source File: NodesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
protected ActivityInfo getActivityInfo(NodeRef parentNodeRef, NodeRef nodeRef) { // runAs system, eg. user may not have permission see one or more parents (irrespective of whether in a site context of not) SiteInfo siteInfo = AuthenticationUtil.runAs(new RunAsWork<SiteInfo>() { @Override public SiteInfo doWork() throws Exception { return siteService.getSite(nodeRef); } }, AuthenticationUtil.getSystemUserName()); String siteId = (siteInfo != null ? siteInfo.getShortName() : null); if(siteId != null && !siteId.equals("")) { FileInfo fileInfo = fileFolderService.getFileInfo(nodeRef); if (fileInfo != null) { boolean isContent = isSubClass(fileInfo.getType(), ContentModel.TYPE_CONTENT); if (fileInfo.isFolder() || isContent) { return new ActivityInfo(null, parentNodeRef, siteId, fileInfo); } } } else { if (logger.isDebugEnabled()) { logger.debug("Non-site activity, so ignored " + nodeRef); } } return null; }
Example 10
Source File: RepoRemoteService.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public Pair<NodeRef, Boolean> lookup(NodeRef base, String path) { List<String> pathList = splitPath(path); try { FileInfo info = fFileFolderService.resolveNamePath(base, pathList); return new Pair<NodeRef, Boolean>(info.getNodeRef(), info.isFolder()); } catch (FileNotFoundException e) { return null; } }
Example 11
Source File: XSLTFunctions.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
public Map<String, Document> parseXMLDocuments(final String typeName, NodeRef rootNode, String repoPath) throws IOException, SAXException { final Map<String, Document> result = new TreeMap<String, Document>(); String[] pathElements = breakDownPath(repoPath); try { FileInfo file = fileService.resolveNamePath(rootNode, Arrays.asList(pathElements)); if (file.isFolder()) { QName typeQName = QName.createQName(typeName, namespaceService); Set<QName> types = new HashSet<QName>(dictionaryService.getSubTypes(typeQName, true)); types.add(typeQName); List<ChildAssociationRef> children = nodeService.getChildAssocs(file.getNodeRef(), types); for (ChildAssociationRef child : children) { String name = (String) nodeService.getProperty(child.getChildRef(), ContentModel.PROP_NAME); Document doc = XMLUtil.parse(child.getChildRef(), contentService); result.put(name, doc); } } } catch (Exception ex) { log.warn("Unexpected exception caught in call to parseXMLDocuments", ex); } return result; }
Example 12
Source File: MLTranslationInterceptor.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Converts the file info where an alternative translation should be used. * * @param fileInfo the basic file or folder info * @return Returns a replacement if required */ private FileInfo getTranslatedFileInfo(FileInfo fileInfo) { // Ignore null if (fileInfo == null) { return null; } // Ignore folders if (fileInfo.isFolder()) { return fileInfo; } NodeRef nodeRef = fileInfo.getNodeRef(); // Get the best translation for the node NodeRef translatedNodeRef = getTranslatedNodeRef(nodeRef); // Convert to FileInfo, if required FileInfo translatedFileInfo = null; if (nodeRef.equals(translatedNodeRef)) { // No need to do any more work translatedFileInfo = fileInfo; } else { // Get the FileInfo translatedFileInfo = fileFolderService.getFileInfo(translatedNodeRef); } return translatedFileInfo; }
Example 13
Source File: FileFolderServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public ContentReader getReader(NodeRef nodeRef) { FileInfo fileInfo = toFileInfo(nodeRef, false); if (fileInfo.isFolder()) { throw new InvalidTypeException("Unable to get a content reader for a folder: " + fileInfo); } return contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); }
Example 14
Source File: SiteServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Locate site "container" folder for component * * @param siteNodeRef * site * @param componentId * component id * @return "container" node ref, if it exists * @throws FileNotFoundException */ private NodeRef findContainer(NodeRef siteNodeRef, String componentId) throws FileNotFoundException { List<String> paths = new ArrayList<String>(1); paths.add(componentId); FileInfo fileInfo = fileFolderService.resolveNamePath(siteNodeRef, paths); if (!fileInfo.isFolder()) { throw new SiteServiceException(MSG_SITE_CONTAINER_NOT_FOLDER, new Object[]{fileInfo.getName()}); } return fileInfo.getNodeRef(); }
Example 15
Source File: JSONConversionComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * * @param nodeInfo FileInfo * @param rootJSONObject JSONObject * @param useShortQNames boolean */ @SuppressWarnings("unchecked") protected void setRootValues(final FileInfo nodeInfo, final JSONObject rootJSONObject, final boolean useShortQNames) { final NodeRef nodeRef = nodeInfo.getNodeRef(); rootJSONObject.put("nodeRef", nodeInfo.getNodeRef().toString()); rootJSONObject.put("type", nameToString(nodeInfo.getType(), useShortQNames)); rootJSONObject.put("isContainer", nodeInfo.isFolder()); //node.getIsContainer() || node.getIsLinkToContainer()); rootJSONObject.put("isLocked", isLocked(nodeInfo.getNodeRef())); rootJSONObject.put("isLink", nodeInfo.isLink()); if (nodeInfo.isLink()) { NodeRef targetNodeRef = nodeInfo.getLinkNodeRef(); if (targetNodeRef != null) { rootJSONObject.put("linkedNode", toJSONObject(targetNodeRef, useShortQNames)); } } // TODO should this be moved to the property output since we may have more than one content property // or a non-standard content property if (nodeInfo.isFolder() == false) { final ContentData cdata = nodeInfo.getContentData(); if (cdata != null) { String contentURL = MessageFormat.format( CONTENT_DOWNLOAD_API_URL, new Object[]{ nodeRef.getStoreRef().getProtocol(), nodeRef.getStoreRef().getIdentifier(), nodeRef.getId(), URLEncoder.encode(nodeInfo.getName())}); rootJSONObject.put("contentURL", contentURL); rootJSONObject.put("mimetype", cdata.getMimetype()); Map<String, String> mimetypeDescriptions; mimetypeDescriptions = mimetypeService.getDisplaysByMimetype(); if (mimetypeDescriptions.containsKey(cdata.getMimetype())) { rootJSONObject.put("mimetypeDisplayName", mimetypeDescriptions.get(cdata.getMimetype())); } rootJSONObject.put("encoding", cdata.getEncoding()); rootJSONObject.put("size", cdata.getSize()); } } }
Example 16
Source File: FileInfoPropsComparator.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private int compareImpl(FileInfo node1In, FileInfo node2In, List<Pair<QName, Boolean>> sortProps) { Object pv1 = null; Object pv2 = null; QName sortPropQName = (QName) sortProps.get(0).getFirst(); boolean sortAscending = sortProps.get(0).getSecond(); FileInfo node1 = node1In; FileInfo node2 = node2In; if (sortAscending == false) { node1 = node2In; node2 = node1In; } int result = 0; pv1 = node1.getProperties().get(sortPropQName); pv2 = node2.getProperties().get(sortPropQName); if (sortPropQName.getLocalName().equals(IS_FOLDER)) { pv1 = node1.isFolder(); pv2 = node2.isFolder(); } if (pv1 == null) { if (pv2 == null && sortProps.size() > 1) { return compareImpl(node1In, node2In, sortProps.subList(1, sortProps.size())); } else { return (pv2 == null ? 0 : -1); } } else if (pv2 == null) { return 1; } if (pv1 instanceof String) { result = collator.compare((String) pv1, (String) pv2); // TODO: use collation keys // (re: performance) } else if (pv1 instanceof Date) { result = (((Date) pv1).compareTo((Date) pv2)); } else if (pv1 instanceof Long) { result = (((Long) pv1).compareTo((Long) pv2)); } else if (pv1 instanceof Integer) { result = (((Integer) pv1).compareTo((Integer) pv2)); } else if (pv1 instanceof QName) { result = (((QName) pv1).compareTo((QName) pv2)); } else if (pv1 instanceof Boolean) { result = (((Boolean) pv1).compareTo((Boolean) pv2)); } else { throw new RuntimeException("Unsupported sort type: " + pv1.getClass().getName()); } if ((result == 0) && (sortProps.size() > 1)) { return compareImpl(node1In, node2In, sortProps.subList(1, sortProps.size())); } return result; }
Example 17
Source File: HiddenAspect.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void removeHidden(NodeRef nodeRef) { Client saveClient = FileFilterMode.getClient(); FileFilterMode.setClient(Client.admin); try { PagingRequest pagingRequest = new PagingRequest(0, Integer.MAX_VALUE, null); PagingResults<FileInfo> results = fileFolderService.list(nodeRef, true, true, null, null, pagingRequest); List<FileInfo> files = results.getPage(); for(FileInfo file : files) { String name = (String)nodeService.getProperty(file.getNodeRef(), ContentModel.PROP_NAME); // remove hidden aspect only if it doesn't match a hidden pattern if(isHidden(name) == null) { behaviourFilter.disableBehaviour(file.getNodeRef(), ContentModel.ASPECT_LOCKABLE); try { if (hasHiddenAspect(file.getNodeRef())) { removeHiddenAspect(file.getNodeRef()); } if (hasIndexControlAspect(file.getNodeRef())) { removeIndexControlAspect(file.getNodeRef()); } } finally { behaviourFilter.enableBehaviour(file.getNodeRef(), ContentModel.ASPECT_LOCKABLE); } if(file.isFolder()) { removeHidden(file.getNodeRef()); } } } } finally { FileFilterMode.setClient(saveClient); } }
Example 18
Source File: HiddenAspect.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private void applyHidden(FileInfo fileInfo, HiddenFileInfo filter) { NodeRef nodeRef = fileInfo.getNodeRef(); if(!hasHiddenAspect(nodeRef)) { // the file matches a pattern, apply the hidden and aspect control aspects addHiddenAspect(nodeRef, filter); } else { nodeService.setProperty(nodeRef, ContentModel.PROP_VISIBILITY_MASK, filter.getVisibilityMask()); nodeService.setProperty(nodeRef, ContentModel.PROP_CASCADE_HIDDEN, filter.cascadeHiddenAspect()); nodeService.setProperty(nodeRef, ContentModel.PROP_CASCADE_INDEX_CONTROL, filter.cascadeIndexControlAspect()); } if(!hasIndexControlAspect(nodeRef)) { addIndexControlAspect(nodeRef); } if(fileInfo.isFolder() && (filter.cascadeHiddenAspect() || filter.cascadeIndexControlAspect())) { PagingRequest pagingRequest = new PagingRequest(0, Integer.MAX_VALUE, null); PagingResults<FileInfo> results = fileFolderService.list(nodeRef, true, true, null, null, pagingRequest); List<FileInfo> files = results.getPage(); // apply the hidden aspect to all folders and folders and then recursively to all sub-folders, unless the sub-folder // already has the hidden aspect applied (it may have been applied for a different pattern). for(FileInfo file : files) { behaviourFilter.disableBehaviour(file.getNodeRef(), ContentModel.ASPECT_LOCKABLE); try { applyHidden(file, filter); } finally { behaviourFilter.enableBehaviour(file.getNodeRef(), ContentModel.ASPECT_LOCKABLE); } } } }
Example 19
Source File: ADMRemoteStore.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Deletes an existing document. * <p> * Delete methods are user authenticated, so the deletion of the document must be * allowed for the current user. * * @param path document path */ @Override protected void deleteDocument(final WebScriptResponse res, final String store, final String path) { final String encpath = encodePath(path); final FileInfo fileInfo = resolveFilePath(encpath); if (fileInfo == null || fileInfo.isFolder()) { res.setStatus(Status.STATUS_NOT_FOUND); return; } final String runAsUser = getPathRunAsUser(path); AuthenticationUtil.runAs(new RunAsWork<Void>() { @SuppressWarnings("synthetic-access") public Void doWork() throws Exception { try { final NodeRef fileRef = fileInfo.getNodeRef(); // MNT-16371: Revoke ownership privileges for surf-config folder contents, to tighten access for former SiteManagers. nodeService.addAspect(fileRef, ContentModel.ASPECT_TEMPORARY, null); // ALF-17729 NodeRef parentFolderRef = unprotNodeService.getPrimaryParent(fileRef).getParentRef(); behaviourFilter.disableBehaviour(parentFolderRef, ContentModel.ASPECT_AUDITABLE); try { nodeService.deleteNode(fileRef); } finally { behaviourFilter.enableBehaviour(parentFolderRef, ContentModel.ASPECT_AUDITABLE); } if (logger.isDebugEnabled()) logger.debug("deleteDocument: " + fileInfo.toString()); } catch (AccessDeniedException ae) { res.setStatus(Status.STATUS_UNAUTHORIZED); throw ae; } return null; } }, runAsUser); }
Example 20
Source File: FileFolderServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Full search with all options */ @Override @Extend(traitAPI=FileFolderServiceTrait.class,extensionAPI=FileFolderServiceExtension.class) public List<FileInfo> search( NodeRef contextNodeRef, String namePattern, boolean fileSearch, boolean folderSearch, boolean includeSubFolders) { // get the raw nodeRefs List<NodeRef> nodeRefs = searchInternal(contextNodeRef, namePattern, fileSearch, folderSearch, includeSubFolders); List<FileInfo> results = toFileInfo(nodeRefs); // eliminate unwanted files/folders Iterator<FileInfo> iterator = results.iterator(); while (iterator.hasNext()) { FileInfo file = iterator.next(); if (file.isFolder() && !folderSearch) { iterator.remove(); } else if (!file.isFolder() && !fileSearch) { iterator.remove(); } } // done if (logger.isTraceEnabled()) { logger.trace("Deep search: \n" + " context: " + contextNodeRef + "\n" + " pattern: " + namePattern + "\n" + " files: " + fileSearch + "\n" + " folders: " + folderSearch + "\n" + " deep: " + includeSubFolders + "\n" + " results: " + results); } return results; }