use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentDiskDriver method getFileInformation.
/**
* Get the file information for the specified file.
*
* @param session Server session
* @param tree Tree connection
* @param path File name/path that information is required for.
* @return File information if valid, else null
* @exception java.io.IOException The exception description.
*/
public FileInfo getFileInformation(SrvSession session, TreeConnection tree, String path) throws IOException {
if (logger.isDebugEnabled()) {
logger.debug("getFileInformation:" + path);
}
// Start a transaction
beginReadTransaction(session);
// Get the device root
ContentContext ctx = (ContentContext) tree.getContext();
NodeRef infoParentNodeRef = ctx.getRootNode();
if (path == null || path.length() == 0)
path = FileName.DOS_SEPERATOR_STR;
String infoPath = path;
try {
// Check if the path is to a pseudo file
FileInfo finfo = null;
// Get the node ref for the path, chances are there is a file state in the cache
NodeRef nodeRef = getNodeForPath(tree, infoPath);
if (nodeRef != null) {
// Get the file information for the node
finfo = cifsHelper.getFileInformation(nodeRef, isReadOnly, isLockedFilesAsOffline);
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
logger.debug("getInfo using cached noderef for path " + path);
}
if (finfo == null) {
String[] paths = FileName.splitPath(path);
if (paths[0] != null && paths[0].length() > 1) {
// Find the node ref for the folder being searched
nodeRef = getNodeForPath(tree, paths[0]);
if (nodeRef != null) {
infoParentNodeRef = nodeRef;
infoPath = paths[1];
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
logger.debug("getInfo using cached noderef for parent " + path);
}
}
// Access the repository to get the file information
finfo = cifsHelper.getFileInformation(infoParentNodeRef, infoPath, isReadOnly, isLockedFilesAsOffline);
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
logger.debug("Getting file information: path=" + path + " file info: " + finfo);
}
if (finfo != null) {
// Set the file id
long id = DefaultTypeConverter.INSTANCE.convert(Long.class, nodeService.getProperty(nodeRef, ContentModel.PROP_NODE_DBID));
finfo.setFileId((int) (id & 0xFFFFFFFFL));
// Copy cached file details, if available
FileState fstate = getStateForPath(tree, infoPath);
if (fstate != null) {
// finfo.setAccessDateTime(fstate.getAccessDateTime());
if (fstate.hasChangeDateTime())
finfo.setChangeDateTime(fstate.getChangeDateTime());
if (fstate.hasModifyDateTime())
finfo.setModifyDateTime(fstate.getModifyDateTime());
if (fstate.hasAllocationSize() && fstate.getAllocationSize() > finfo.getSize())
finfo.setAllocationSize(fstate.getAllocationSize());
} else {
// Create a file state for the file/folder
fstate = ctx.getStateCache().findFileState(path, true);
if (finfo.isDirectory())
fstate.setFileStatus(DirectoryExists);
else
fstate.setFileStatus(FileExists);
fstate.setFilesystemObject(nodeRef);
}
}
return finfo;
} catch (FileNotFoundException e) {
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
logger.debug("Get file info - file not found, " + path);
throw e;
} catch (org.alfresco.repo.security.permissions.AccessDeniedException ex) {
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
logger.debug("Get file info - access denied, " + path);
throw new AccessDeniedException("Get file information " + path);
} catch (RuntimeException ex) {
if (logger.isDebugEnabled() && ctx.hasDebug(AlfrescoContext.DBG_INFO))
logger.debug("Get file info error", ex);
throw new IOException("Get file information " + path);
}
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentNetworkFile method createFile.
/**
* Helper method to create a {@link NetworkFile network file} given a node reference.
*/
public static ContentNetworkFile createFile(NodeService nodeService, ContentService contentService, MimetypeService mimetypeService, CifsHelper cifsHelper, NodeRef nodeRef, String path, boolean readOnly, boolean attributesOnly, SrvSession sess) {
// Create the file
ContentNetworkFile netFile = null;
if (isMSOfficeSpecialFile(path, sess, nodeService, nodeRef)) {
// Create a file for special processing for Excel
netFile = new MSOfficeContentNetworkFile(nodeService, contentService, mimetypeService, nodeRef, path);
} else if (isOpenOfficeSpecialFile(path, sess, nodeService, nodeRef)) {
// Create a file for special processing
netFile = new OpenOfficeContentNetworkFile(nodeService, contentService, mimetypeService, nodeRef, path);
} else {
// Create a normal content file
netFile = new ContentNetworkFile(nodeService, contentService, mimetypeService, nodeRef, path);
}
if (attributesOnly) {
netFile.setGrantedAccess(NetworkFile.ATTRIBUTESONLY);
} else if (readOnly) {
netFile.setGrantedAccess(NetworkFile.READONLY);
} else {
netFile.setGrantedAccess(NetworkFile.READWRITE);
}
// Check the type
FileInfo fileInfo;
try {
fileInfo = cifsHelper.getFileInformation(nodeRef, "", false, false);
} catch (FileNotFoundException e) {
throw new AlfrescoRuntimeException("File not found when creating network file: " + nodeRef, e);
}
if (fileInfo.isDirectory()) {
netFile.setAttributes(FileAttribute.Directory);
} else {
// Set the current size
netFile.setFileSize(fileInfo.getSize());
}
if (fileInfo.hasCreationDateTime())
netFile.setCreationDate(fileInfo.getCreationDateTime());
if (fileInfo.hasModifyDateTime() && fileInfo.getModifyDateTime() > 0L)
netFile.setModifyDate(fileInfo.getModifyDateTime());
else
netFile.setModifyDate(fileInfo.getCreationDateTime());
if (fileInfo.hasAccessDateTime() && fileInfo.getAccessDateTime() > 0L)
netFile.setAccessDate(fileInfo.getAccessDateTime());
else
netFile.setAccessDate(fileInfo.getCreationDateTime());
// Set the file attributes
netFile.setAttributes(fileInfo.getFileAttributes());
if (netFile.isReadOnly() && netFile.getGrantedAccess() == NetworkFile.READWRITE)
netFile.setGrantedAccess(NetworkFile.READONLY);
if (logger.isDebugEnabled())
logger.debug("Create file node=" + nodeRef + ", path=" + path + ", netfile=" + netFile);
return netFile;
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class ContentSearchContext method nextFileName.
/**
* Return the file name of the next file in the active search. Returns null is the search is
* complete.
*
* @return String
*/
public String nextFileName() {
if (!hasMoreFiles())
return null;
// Increment the index and resume id
index++;
resumeId++;
// Get the next file info from the node search
NodeRef nextNodeRef = results.get(index);
try {
// Get the file information and copy across to the callers file info
FileInfo nextInfo = cifsHelper.getFileInformation(nextNodeRef, "", false, false);
// Keep track of the last file name returned
m_lastFileName = nextInfo.getFileName();
return nextInfo.getFileName();
} catch (FileNotFoundException e) {
}
return null;
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class BufferedContentDiskDriver method getFileInformationInternal.
private FileInfo getFileInformationInternal(SrvSession sess, TreeConnection tree, String path) throws IOException {
// String userName = AuthenticationUtil.getFullyAuthenticatedUser();
SharedDevice device = tree.getSharedDevice();
String deviceName = device.getName();
if (logger.isDebugEnabled()) {
logger.debug("getFileInformation session:" + sess.getUniqueId() + ", deviceName:" + deviceName + ", path:" + path);
}
if (path == null) {
throw new IllegalArgumentException("Path is null");
}
FileInfoKey key = new FileInfoKey(sess, path, tree);
FileInfo fromCache = fileInfoCache.get(key);
if (fromCache != null) {
if (logger.isDebugEnabled()) {
logger.debug("returning FileInfo from cache");
}
return fromCache;
}
FileInfo info = diskInterface.getFileInformation(sess, tree, path);
if (info != null) {
/**
* Don't cache directories since the modification date is important.
*/
if (!info.isDirectory()) {
fileInfoCache.put(key, info);
}
}
/*
* Dual Key the cache so it can be looked up by NodeRef or Path
*/
if (info instanceof ContentFileInfo) {
ContentFileInfo cinfo = (ContentFileInfo) info;
fileInfoCache.put(cinfo.getNodeRef(), info);
}
return info;
}
use of org.alfresco.jlan.server.filesys.FileInfo in project alfresco-repository by Alfresco.
the class BufferedContentDiskDriver method fileExists.
@Override
public int fileExists(SrvSession sess, TreeConnection tree, String path) {
String deviceName = tree.getSharedDevice().getName();
if (logger.isDebugEnabled()) {
logger.debug("fileExists session:" + sess.getUniqueId() + ", deviceName" + deviceName + ", path:" + path);
}
FileInfoKey key = new FileInfoKey(sess, path, tree);
FileInfo fromCache = fileInfoCache.get(key);
if (fromCache != null) {
if (logger.isDebugEnabled()) {
logger.debug("fileExists found FileInfo in cache");
}
if (fromCache.isDirectory()) {
return FileStatus.DirectoryExists;
} else {
return FileStatus.FileExists;
}
} else {
try {
FileInfo lookup = getFileInformationInternal(sess, tree, path);
if (logger.isDebugEnabled()) {
logger.debug("fileExists obtained file information");
}
if (lookup.isDirectory()) {
return FileStatus.DirectoryExists;
} else {
return FileStatus.FileExists;
}
} catch (IOException ie) {
return FileStatus.NotExist;
}
}
}
Aggregations