Java Code Examples for org.alfresco.service.cmr.model.FileInfo#getName()

The following examples show how to use org.alfresco.service.cmr.model.FileInfo#getName() . 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 vote down vote up
@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: ActivityPosterImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void postFileFolderActivity(
            String activityType,
            String siteId,
            String tenantDomain,
            String path,
            NodeRef parentNodeRef,
            FileInfo contentNodeInfo) throws WebDAVServerException
{
    String fileName = contentNodeInfo.getName();
    NodeRef nodeRef = contentNodeInfo.getNodeRef();
    
    try
    {
        poster.postFileFolderActivity(activityType, path, tenantDomain, siteId,
                               parentNodeRef, nodeRef, fileName,
                               appTool, Client.asType(ClientType.webdav),contentNodeInfo);
    }
    catch (AlfrescoRuntimeException are)
    {
        logger.error("Failed to post activity.", are);
        throw new WebDAVServerException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}
 
Example 3
Source File: GetMethod.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected String getContentDispositionHeader(FileInfo nodeInfo)
{
    String filename = nodeInfo.getName();
    StringBuilder sb = new StringBuilder();
    sb.append("attachment; filename=\"");
    for(int i = 0; i < filename.length(); i++)
    {
        char c = filename.charAt(i);
        if(isValidQuotedStringHeaderParamChar(c))
        {
            sb.append(c);
        }
        else
        {
            sb.append(" ");
        }
    }
    sb.append("\"; filename*=UTF-8''");
    sb.append(URLEncoder.encode(filename));
    return sb.toString();
}
 
Example 4
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 5
Source File: ActivityInfo.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ActivityInfo(String parentPath, NodeRef parentNodeRef, String siteId, FileInfo fileInfo)
{
    super();
    this.nodeRef = fileInfo.getNodeRef();
    this.parentPath = parentPath;
    this.parentNodeRef = parentNodeRef;
    this.siteId = siteId;
    this.fileName = fileInfo.getName();
    this.isFolder = fileInfo.isFolder();
    this.fileInfo = fileInfo;
}
 
Example 6
Source File: ActivityPosterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 7
Source File: LargeArchiveAndRestoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private NodeRef addFolder(NodeRef parentNodeRef, String foldername, int depth)
{
    System.out.println(makeTabs(depth) + "Creating folder " + foldername + " in parent " + parentNodeRef);
    FileInfo info = fileFolderService.create(parentNodeRef, foldername, ContentModel.TYPE_FOLDER);
    String name = info.getName();
    if (!name.equals(foldername))
    {
        String msg = "A foldername '" + foldername + "' was not persisted: " + info;
        logger.error(msg);
        rollbackMessages.add(msg);
    }
    return info.getNodeRef();
}
 
Example 8
Source File: LargeArchiveAndRestoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private NodeRef addFile(NodeRef parentNodeRef, String filename, int depth)
{
    System.out.println(makeTabs(depth) + "Creating file " + filename + " in parent " + parentNodeRef);
    FileInfo info = fileFolderService.create(parentNodeRef, filename, ContentModel.TYPE_CONTENT);
    String name = info.getName();
    if (!name.equals(filename))
    {
        String msg = "A filename '" + filename + "' was not persisted: " + info;
        logger.error(msg);
        rollbackMessages.add(msg);
    }
    return info.getNodeRef();
}
 
Example 9
Source File: AlfrescoImapFolder.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Constructs {@link AlfrescoImapFolder} object.
 * 
 * @param folderInfo - reference to the {@link FileInfo} object representing the folder.
 * @param userName - name of the user (e.g. "admin" for admin user).
 * @param folderName - name of the folder.
 * @param folderPath - path of the folder.
 * @param viewMode - defines view mode. Can be one of the following: {@link ImapViewMode#ARCHIVE} or {@link ImapViewMode#VIRTUAL}.
 * @param imapService - the IMAP service.
 * @param serviceRegistry ServiceRegistry
 * @param selectable - defines whether the folder is selectable or not.
 * @param extractAttachmentsEnabled boolean
 * @param mountPointId int
 */
public AlfrescoImapFolder(
        FileInfo folderInfo,
        String userName,
        String folderName,
        String folderPath,
        ImapViewMode viewMode,
        ImapService imapService,
        ServiceRegistry serviceRegistry,
        Boolean selectable,
        boolean extractAttachmentsEnabled,
        int mountPointId)
{
    super(serviceRegistry);
    this.folderInfo = folderInfo;
    this.userName = userName;
    this.folderName = folderName != null ? folderName : (folderInfo != null ? folderInfo.getName() : null);
    this.folderPath = folderPath;
    this.viewMode = viewMode != null ? viewMode : ImapViewMode.ARCHIVE;
    this.extractAttachmentsEnabled = extractAttachmentsEnabled;
    this.imapService = imapService;
    
    // MailFolder object can be null if it is used to obtain hierarchy delimiter by LIST command:
    // Example:
    // C: 2 list "" ""
    // S: * LIST () "." ""
    // S: 2 OK LIST completed.
    if (folderInfo != null)
    {
        if (selectable == null)
        {
            // isSelectable();
            Boolean storedSelectable = !serviceRegistry.getNodeService().hasAspect(folderInfo.getNodeRef(), ImapModel.ASPECT_IMAP_FOLDER_NONSELECTABLE);
            if (storedSelectable == null)
            {
                this.selectable = true;
            }
            else
            {
                this.selectable = storedSelectable;
            }
        }
        else
        {
            this.selectable = selectable;
        }
    }
    else
    {
        this.selectable = false;
    }
    
    this.mountPointId = mountPointId;
}
 
Example 10
Source File: StandardRenditionLocationResolverImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private String renderPathTemplate(String pathTemplate, NodeRef sourceNode, NodeRef tempRenditionLocation, NodeRef companyHome)
{
    NodeService nodeService = serviceRegistry.getNodeService();
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    
    final Map<String, Object> root = new HashMap<String, Object>();

    List<FileInfo> sourcePathInfo;
    String fullSourceName;
    String cwd;
    try
    {
        //Since the root of the store is typically not a folder, we use company home as the root of this tree
        sourcePathInfo = fileFolderService.getNamePath(companyHome, sourceNode);
        //Remove the last element (the actual source file name)
        FileInfo sourceFileInfo = sourcePathInfo.remove(sourcePathInfo.size() - 1);
        fullSourceName = sourceFileInfo.getName();
        
        StringBuilder cwdBuilder = new StringBuilder("/");
        for (FileInfo file : sourcePathInfo)
        {
            cwdBuilder.append(file.getName());
            cwdBuilder.append('/');
        }
        cwd = cwdBuilder.toString();
    }
    catch (FileNotFoundException e)
    {
        log.warn("Failed to resolve path to source node: " + sourceNode + ". Default to Company Home");
        fullSourceName = nodeService.getPrimaryParent(sourceNode).getQName().getLocalName();
        cwd = "/";
    }

    String trimmedSourceName = fullSourceName;
    String sourceExtension = "";
    int extensionIndex = fullSourceName.lastIndexOf('.');
    if (extensionIndex != -1)
    {
        trimmedSourceName = (extensionIndex == 0) ? "" : fullSourceName.substring(0, extensionIndex);
        sourceExtension = (extensionIndex == fullSourceName.length() - 1) ? "" : fullSourceName
                    .substring(extensionIndex + 1);
    }

    root.put("name", trimmedSourceName);
    root.put("extension", sourceExtension);
    root.put("date", new SimpleDate(new Date(), SimpleDate.DATETIME));
    root.put("cwd", cwd);
    TemplateNode companyHomeNode = new TemplateNode(companyHome, serviceRegistry, null); 
    root.put("companyHome", companyHomeNode); 
    root.put("companyhome", companyHomeNode);   //Added this to be consistent with the script API
    root.put("sourceNode", new TemplateNode(sourceNode, serviceRegistry, null));
    root.put("sourceContentType", nodeService.getType(sourceNode).getLocalName());
    root.put("renditionContentType", nodeService.getType(tempRenditionLocation).getLocalName());
    NodeRef person = serviceRegistry.getPersonService().getPerson(AuthenticationUtil.getFullyAuthenticatedUser());
    root.put("person", new TemplateNode(person, serviceRegistry, null));

    if (sourceNodeIsXml(sourceNode))
    {
        try
        {
            Document xml = XMLUtil.parse(sourceNode, serviceRegistry.getContentService());
            pathTemplate = buildNamespaceDeclaration(xml) + pathTemplate;
            root.put("xml", NodeModel.wrap(xml));
        } catch (Exception ex)
        {
            log.warn("Failed to parse XML content into path template model: Node = " + sourceNode);
        }
    }

    if (log.isDebugEnabled())
    {
        log.debug("Path template model: " + root);
    }

    String result = null;
    try
    {
        if (log.isDebugEnabled())
        {
            log.debug("Processing " + pathTemplate + " using source node " + cwd + fullSourceName);
        }
        result = serviceRegistry.getTemplateService().processTemplateString("freemarker", pathTemplate,
                    new SimpleHash(root));
    } catch (TemplateException te)
    {
        log.error("Error while trying to process rendition path template: " + pathTemplate);
        log.error(te.getMessage(), te);
    }
    if (log.isDebugEnabled())
    {
        log.debug("processed pattern " + pathTemplate + " as " + result);
    }
    return result;
}
 
Example 11
Source File: FileFolderServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void checkPages(NodeRef parentRef, int pageSize, int totalItems, boolean hideCheckedOut, int checkedOutChildIdx)
{
    Set<QName> ignoreQNameTypes = null;
    if (hideCheckedOut)
    {
        ignoreQNameTypes = new HashSet<QName>(1);
        ignoreQNameTypes.add(ContentModel.ASPECT_CHECKED_OUT);
    }
    else
    {
        if (checkedOutChildIdx > -1)
        {
            totalItems++;
        }
    }
    
    List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>(1);
    sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME, true));
    
    int pageCount = (totalItems / pageSize) + 1;
    
    for (int i = 1; i <= pageCount; i++)
    {
        int offset = (i-1)*pageSize;
        
        PagingRequest pagingRequest = new PagingRequest(offset, pageSize);
        pagingRequest.setRequestTotalCountMax(10000); // need this so that total count is set
        
        PagingResults<FileInfo> results = fileFolderService.list(parentRef, true, true, ignoreQNameTypes, sortProps, pagingRequest);
        
        Pair<Integer, Integer> totalResultCount = results.getTotalResultCount();
        assertNotNull(totalResultCount.getFirst());
        assertEquals(totalItems, totalResultCount.getFirst().intValue());
        assertNotNull(totalResultCount.getSecond());
        assertEquals(totalItems, totalResultCount.getSecond().intValue());
        
        assertEquals((i != pageCount ? pageSize : (totalItems - ((pageCount-1)*pageSize))), results.getPage().size());
        
        int j = offset;
        for (FileInfo fileInfo : results.getPage())
        {
            String suffix = String.format("%05d", j);
            if (checkedOutChildIdx > -1)
            {
                if (! hideCheckedOut)
                {
                    if (j == checkedOutChildIdx+1)
                    {
                        suffix = String.format("%05d", j-1) + " (Working Copy)";
                    }
                    else if (j > checkedOutChildIdx+1)
                    {
                        suffix = String.format("%05d", j-1);
                    }
                }
                else
                {
                    if (j == checkedOutChildIdx)
                    {
                        suffix = String.format("%05d", j) + " (Working Copy)";
                    }
                }
            }
            
            String actual = fileInfo.getName();
            String expected = "child-"+suffix;
            assertTrue("Expected: "+expected+", Actual: "+actual+" (j="+j+")", expected.equals(actual));
            j++;
        }
    }
}
 
Example 12
Source File: WebDAVHelper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get the file info for the given paths
 * 
 * @param rootNodeRef       the acting webdav root
 * @param path              the path to search for
 * @return                  Return the file info for the path
 * @throws FileNotFoundException
 *                          if the path doesn't refer to a valid node
 */
public FileInfo getNodeForPath(NodeRef rootNodeRef, String path) throws FileNotFoundException
{
    if (rootNodeRef == null)
    {
        throw new IllegalArgumentException("Root node may not be null");
    }
    else if (path == null)
    {
        throw new IllegalArgumentException("Path may not be null");
    }
    
    FileFolderService fileFolderService = getFileFolderService();
    // Check for the root path
    if ( path.length() == 0 || path.equals(PathSeperator))
    {
        return fileFolderService.getFileInfo(rootNodeRef);
    }
    
    // split the paths up
    List<String> splitPath = splitAllPaths(path);
    
    // find it
    FileInfo fileInfo = m_fileFolderService.resolveNamePath(rootNodeRef, splitPath);
    
    String fileName = splitPath.get(splitPath.size() - 1);
    if (!fileInfo.getName().equals(fileName))
    {
        throw new FileNotFoundException("Requested filename " + fileName +
                    " does not match case of " + fileInfo.getName());
    }
    
    // done
    if (logger.isDebugEnabled())
    {
        logger.debug("Fetched node for path: \n" +
                "   root: " + rootNodeRef + "\n" +
                "   path: " + path + "\n" +
                "   result: " + fileInfo);
    }
    return fileInfo;
}