mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Refactoring of the pseudo file/desktop action code to allow use by AVM and repo filesystem drivers.
Added virtualization view to the AVM filesystem driver that shows all stores and versions using a single shared filesystem. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4443 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -40,6 +40,9 @@ import org.alfresco.config.ConfigElement;
|
||||
import org.alfresco.config.ConfigLookupContext;
|
||||
import org.alfresco.config.ConfigService;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.filesys.alfresco.DesktopAction;
|
||||
import org.alfresco.filesys.alfresco.DesktopActionException;
|
||||
import org.alfresco.filesys.alfresco.DesktopActionTable;
|
||||
import org.alfresco.filesys.avm.AVMContext;
|
||||
import org.alfresco.filesys.avm.AVMDiskDriver;
|
||||
import org.alfresco.filesys.avm.AVMShareMapper;
|
||||
@@ -72,9 +75,6 @@ import org.alfresco.filesys.server.filesys.DiskSharedDevice;
|
||||
import org.alfresco.filesys.smb.ServerType;
|
||||
import org.alfresco.filesys.smb.TcpipSMB;
|
||||
import org.alfresco.filesys.smb.server.repo.ContentContext;
|
||||
import org.alfresco.filesys.smb.server.repo.DesktopAction;
|
||||
import org.alfresco.filesys.smb.server.repo.DesktopActionException;
|
||||
import org.alfresco.filesys.smb.server.repo.DesktopActionTable;
|
||||
import org.alfresco.filesys.smb.server.repo.HomeShareMapper;
|
||||
import org.alfresco.filesys.util.IPAddress;
|
||||
import org.alfresco.filesys.util.StringList;
|
||||
@@ -1810,6 +1810,7 @@ public class ServerConfiguration extends AbstractLifecycleBean
|
||||
// Create the new share for the store
|
||||
|
||||
AVMContext avmContext = new AVMContext( storeName, storeName + ":/", AVMContext.VERSION_HEAD);
|
||||
avmContext.enableStateTable( true, avmDriver.getStateReaper());
|
||||
|
||||
// Create the shared filesystem
|
||||
|
||||
|
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.server.pseudo;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.alfresco.filesys.server.filesys.FileInfo;
|
||||
import org.alfresco.filesys.server.filesys.NetworkFile;
|
||||
|
||||
/**
|
||||
* Local Pseudo File Class
|
||||
*
|
||||
* <p>Pseudo file class that uses a file on the local filesystem.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public class LocalPseudoFile extends PseudoFile
|
||||
{
|
||||
// Path to the file on the local filesystem
|
||||
|
||||
private String m_path;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param name String
|
||||
* @param path String
|
||||
*/
|
||||
public LocalPseudoFile(String name, String path)
|
||||
{
|
||||
super(name);
|
||||
|
||||
m_path = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path to the file on the local filesystem
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public final String getFilePath()
|
||||
{
|
||||
return m_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file information for the pseudo file
|
||||
*
|
||||
* @return FileInfo
|
||||
*/
|
||||
public FileInfo getFileInfo()
|
||||
{
|
||||
// Check if the file information is valid
|
||||
|
||||
if ( getInfo() == null) {
|
||||
|
||||
// Get the file details
|
||||
|
||||
File localFile = new File( getFilePath());
|
||||
if ( localFile.exists())
|
||||
{
|
||||
// Create the file information
|
||||
|
||||
FileInfo fInfo = new FileInfo( getFileName(), localFile.length(), getAttributes());
|
||||
|
||||
// Set the file creation/modification times
|
||||
|
||||
fInfo.setModifyDateTime( localFile.lastModified());
|
||||
fInfo.setCreationDateTime( _creationDateTime);
|
||||
fInfo.setChangeDateTime( _creationDateTime);
|
||||
|
||||
// Set the allocation size, round up the actual length
|
||||
|
||||
fInfo.setAllocationSize(( localFile.length() + 512L) & 0xFFFFFFFFFFFFFE00L);
|
||||
|
||||
setFileInfo( fInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the file information
|
||||
|
||||
return getInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a network file for reading/writing the pseudo file
|
||||
*
|
||||
* @param netPath String
|
||||
* @return NetworkFile
|
||||
*/
|
||||
public NetworkFile getFile(String netPath)
|
||||
{
|
||||
// Create a pseudo file mapped to a file in the local filesystem
|
||||
|
||||
return new PseudoNetworkFile( getFileName(), getFilePath(), netPath);
|
||||
}
|
||||
}
|
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.server.pseudo;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.alfresco.filesys.server.filesys.FileInfo;
|
||||
import org.alfresco.filesys.server.filesys.NetworkFile;
|
||||
import org.alfresco.filesys.smb.SeekType;
|
||||
|
||||
/**
|
||||
* In Memory Network File Class
|
||||
*
|
||||
* <p>In memory network file implementation that uses a memory buffer for the file data.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public class MemoryNetworkFile extends NetworkFile
|
||||
{
|
||||
// Current file position
|
||||
|
||||
private long m_filePos;
|
||||
|
||||
// File data
|
||||
|
||||
private byte[] m_data;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param name String
|
||||
* @param localPath String
|
||||
* @param finfo FileInfo
|
||||
*/
|
||||
public MemoryNetworkFile(String name, byte[] data, FileInfo finfo)
|
||||
{
|
||||
super( name);
|
||||
|
||||
// Set the file data
|
||||
|
||||
m_data = data;
|
||||
if ( m_data == null)
|
||||
m_data = new byte[0];
|
||||
|
||||
// Set the file size
|
||||
|
||||
setFileSize( m_data.length);
|
||||
|
||||
// Set the creation and modification date/times
|
||||
|
||||
setModifyDate( finfo.getModifyDateTime());
|
||||
setCreationDate( finfo.getCreationDateTime());
|
||||
|
||||
// Set the file id and relative path
|
||||
|
||||
if ( finfo.getPath() != null)
|
||||
{
|
||||
setFileId( finfo.getPath().hashCode());
|
||||
setFullName( finfo.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the network file.
|
||||
*/
|
||||
public void closeFile() throws java.io.IOException
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current file position.
|
||||
*
|
||||
* @return long
|
||||
*/
|
||||
public long currentPosition()
|
||||
{
|
||||
return m_filePos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the file.
|
||||
*
|
||||
* @exception IOException
|
||||
*/
|
||||
public void flushFile() throws IOException
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the end of file has been reached.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isEndOfFile() throws java.io.IOException
|
||||
{
|
||||
// Check if we reached end of file
|
||||
|
||||
if ( m_filePos == m_data.length)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the file.
|
||||
*
|
||||
* @param createFlag boolean
|
||||
* @exception IOException
|
||||
*/
|
||||
public void openFile(boolean createFlag) throws java.io.IOException
|
||||
{
|
||||
// Indicate that the file is open
|
||||
|
||||
setClosed(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the file.
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param len int
|
||||
* @param pos int
|
||||
* @param fileOff long
|
||||
* @return Length of data read.
|
||||
* @exception IOException
|
||||
*/
|
||||
public int readFile(byte[] buf, int len, int pos, long fileOff) throws java.io.IOException
|
||||
{
|
||||
// Check if the read is within the file data range
|
||||
|
||||
long fileLen = (long) m_data.length;
|
||||
|
||||
if ( fileOff >= fileLen)
|
||||
return 0;
|
||||
|
||||
// Calculate the actual read length
|
||||
|
||||
if (( fileOff + len) > fileLen)
|
||||
len = (int) ( fileLen - fileOff);
|
||||
|
||||
// Copy the data to the user buffer
|
||||
|
||||
System.arraycopy( m_data, (int) fileOff, buf, pos, len);
|
||||
|
||||
// Update the current file position
|
||||
|
||||
m_filePos = fileOff + len;
|
||||
|
||||
// Return the actual length of data read
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seek to the specified file position.
|
||||
*
|
||||
* @param pos long
|
||||
* @param typ int
|
||||
* @return long
|
||||
* @exception IOException
|
||||
*/
|
||||
public long seekFile(long pos, int typ) throws IOException
|
||||
{
|
||||
// Seek to the required file position
|
||||
|
||||
switch (typ)
|
||||
{
|
||||
// From start of file
|
||||
|
||||
case SeekType.StartOfFile:
|
||||
if (currentPosition() != pos)
|
||||
m_filePos = pos;
|
||||
break;
|
||||
|
||||
// From current position
|
||||
|
||||
case SeekType.CurrentPos:
|
||||
m_filePos += pos;
|
||||
break;
|
||||
|
||||
// From end of file
|
||||
|
||||
case SeekType.EndOfFile:
|
||||
m_filePos += pos;
|
||||
if ( m_filePos < 0)
|
||||
m_filePos = 0L;
|
||||
break;
|
||||
}
|
||||
|
||||
// Return the new file position
|
||||
|
||||
return currentPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate the file
|
||||
*
|
||||
* @param siz long
|
||||
* @exception IOException
|
||||
*/
|
||||
public void truncateFile(long siz) throws IOException
|
||||
{
|
||||
// Allow the truncate, do not alter the pseduo file data
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a block of data to the file.
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param len int
|
||||
* @exception IOException
|
||||
*/
|
||||
public void writeFile(byte[] buf, int len, int pos) throws java.io.IOException
|
||||
{
|
||||
// Allow the write, just do not do anything
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a block of data to the file.
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param len int
|
||||
* @param pos int
|
||||
* @param offset long
|
||||
* @exception IOException
|
||||
*/
|
||||
public void writeFile(byte[] buf, int len, int pos, long offset) throws java.io.IOException
|
||||
{
|
||||
// Allow the write, just do not do anything
|
||||
}
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.server.pseudo;
|
||||
|
||||
import org.alfresco.filesys.server.filesys.FileInfo;
|
||||
import org.alfresco.filesys.server.filesys.NetworkFile;
|
||||
|
||||
/**
|
||||
* In Memory Pseudo File Class
|
||||
*
|
||||
* <p>Pseudo file class that uses an in memory buffer for the file data.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public class MemoryPseudoFile extends PseudoFile
|
||||
{
|
||||
// File data buffer
|
||||
|
||||
private byte[] m_data;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param name String
|
||||
* @param data byte[]
|
||||
*/
|
||||
public MemoryPseudoFile(String name, byte[] data)
|
||||
{
|
||||
super( name);
|
||||
|
||||
m_data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file information for the pseudo file
|
||||
*
|
||||
* @return FileInfo
|
||||
*/
|
||||
public FileInfo getFileInfo()
|
||||
{
|
||||
// Check if the file information is valid
|
||||
|
||||
if ( getInfo() == null) {
|
||||
|
||||
// Create the file information
|
||||
|
||||
FileInfo fInfo = new FileInfo( getFileName(), m_data != null ? m_data.length : 0, getAttributes());
|
||||
|
||||
// Set the file creation/modification times
|
||||
|
||||
fInfo.setCreationDateTime( _creationDateTime);
|
||||
fInfo.setModifyDateTime( _creationDateTime);
|
||||
fInfo.setChangeDateTime( _creationDateTime);
|
||||
|
||||
// Set the allocation size, round up the actual length
|
||||
|
||||
fInfo.setAllocationSize(( fInfo.getSize() + 512L) & 0xFFFFFFFFFFFFFE00L);
|
||||
|
||||
setFileInfo( fInfo);
|
||||
}
|
||||
|
||||
// Return the file information
|
||||
|
||||
return getInfo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a network file for reading/writing the pseudo file
|
||||
*
|
||||
* @param netPath String
|
||||
* @return NetworkFile
|
||||
*/
|
||||
public NetworkFile getFile(String netPath)
|
||||
{
|
||||
// Create a pseudo file mapped to the in memory file data
|
||||
|
||||
FileInfo finfo = getFileInfo();
|
||||
finfo.setPath( netPath);
|
||||
|
||||
return new MemoryNetworkFile( getFileName(), m_data, finfo);
|
||||
}
|
||||
}
|
184
source/java/org/alfresco/filesys/server/pseudo/PseudoFile.java
Normal file
184
source/java/org/alfresco/filesys/server/pseudo/PseudoFile.java
Normal file
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.server.pseudo;
|
||||
|
||||
import org.alfresco.filesys.server.filesys.FileAttribute;
|
||||
import org.alfresco.filesys.server.filesys.FileInfo;
|
||||
import org.alfresco.filesys.server.filesys.NetworkFile;
|
||||
|
||||
/**
|
||||
* Pseudo File Class
|
||||
*
|
||||
* <p>Creates a pseudo file entry for a folder that maps to a file outside of the usual file area but appears
|
||||
* in folder listings for the owner folder.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public abstract class PseudoFile
|
||||
{
|
||||
// Dummy creation date/time to use for pseudo files
|
||||
|
||||
protected static long _creationDateTime = System.currentTimeMillis();
|
||||
|
||||
// File name for pseudo file
|
||||
|
||||
private String m_fileName;
|
||||
|
||||
// File flags/attributes
|
||||
|
||||
private int m_fileFlags = FileAttribute.ReadOnly;
|
||||
|
||||
// File information, used for file information/folder searches
|
||||
|
||||
private FileInfo m_fileInfo;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param name String
|
||||
*/
|
||||
protected PseudoFile(String name)
|
||||
{
|
||||
m_fileName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param name String
|
||||
* @param flags int
|
||||
*/
|
||||
protected PseudoFile(String name, int flags)
|
||||
{
|
||||
m_fileName = name;
|
||||
m_fileFlags = flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the pseudo file name as it will appear in folder listings
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public final String getFileName()
|
||||
{
|
||||
return m_fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the standard file attributes
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public final int getAttributes()
|
||||
{
|
||||
return m_fileFlags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the pseudo file is a file
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean isFile()
|
||||
{
|
||||
return (m_fileFlags & FileAttribute.Directory) != 0 ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the pseudo file is a folder
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean isDirectory()
|
||||
{
|
||||
return (m_fileFlags & FileAttribute.Directory) != 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the pseudo file is read-only
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean isReadOnly()
|
||||
{
|
||||
return (m_fileFlags & FileAttribute.ReadOnly) != 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the pseudo file is hidden
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public final boolean isHidden()
|
||||
{
|
||||
return (m_fileFlags & FileAttribute.Hidden) != 0 ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file information for the pseudo file
|
||||
*
|
||||
* @return FileInfo
|
||||
*/
|
||||
public abstract FileInfo getFileInfo();
|
||||
|
||||
/**
|
||||
* Return a network file for reading/writing the pseudo file
|
||||
*
|
||||
* @param netPath String
|
||||
* @return NetworkFile
|
||||
*/
|
||||
public abstract NetworkFile getFile(String netPath);
|
||||
|
||||
/**
|
||||
* Set the file information
|
||||
*
|
||||
* @param fileInfo FileInfo
|
||||
*/
|
||||
protected final void setFileInfo( FileInfo finfo)
|
||||
{
|
||||
m_fileInfo = finfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file information
|
||||
*
|
||||
* @return FileInfo
|
||||
*/
|
||||
protected final FileInfo getInfo()
|
||||
{
|
||||
return m_fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the pseudo file as a string
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuilder str = new StringBuilder();
|
||||
|
||||
str.append("[");
|
||||
str.append(getFileName());
|
||||
str.append(",");
|
||||
str.append(getFileInfo());
|
||||
str.append("]");
|
||||
|
||||
return str.toString();
|
||||
}
|
||||
}
|
@@ -0,0 +1,287 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2006 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
package org.alfresco.filesys.server.pseudo;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.alfresco.filesys.alfresco.DesktopAction;
|
||||
import org.alfresco.filesys.alfresco.DesktopActionTable;
|
||||
import org.alfresco.filesys.server.SrvSession;
|
||||
import org.alfresco.filesys.server.filesys.FileName;
|
||||
import org.alfresco.filesys.server.filesys.TreeConnection;
|
||||
import org.alfresco.filesys.server.pseudo.MemoryPseudoFile;
|
||||
import org.alfresco.filesys.server.pseudo.PseudoFile;
|
||||
import org.alfresco.filesys.server.pseudo.PseudoFileInterface;
|
||||
import org.alfresco.filesys.server.state.FileState;
|
||||
import org.alfresco.filesys.smb.server.SMBSrvSession;
|
||||
import org.alfresco.filesys.smb.server.repo.ContentContext;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* Alfresco Filesystem Driver Pseudo File Implementation
|
||||
*
|
||||
* <p>Pseudo file implementation for the Alfresco filesystem drivers.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public class PseudoFileImpl implements PseudoFileInterface
|
||||
{
|
||||
// Logging
|
||||
|
||||
private static final Log logger = LogFactory.getLog(PseudoFileImpl.class);
|
||||
|
||||
/**
|
||||
* Check if the specified path refers to a pseudo file
|
||||
*
|
||||
* @param sess SrvSession
|
||||
* @param tree TreeConnection
|
||||
* @param path String
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isPseudoFile(SrvSession sess, TreeConnection tree, String path)
|
||||
{
|
||||
// Check if the path is for a pseudo file
|
||||
|
||||
ContentContext ctx = (ContentContext) tree.getContext();
|
||||
boolean isPseudo = false;
|
||||
|
||||
String[] paths = FileName.splitPath( path);
|
||||
FileState fstate = getStateForPath( ctx, paths[0]);
|
||||
|
||||
if ( fstate != null && fstate.hasPseudoFiles())
|
||||
{
|
||||
// Check if there is a matching pseudo file
|
||||
|
||||
PseudoFile pfile = fstate.getPseudoFileList().findFile( paths[1], false);
|
||||
if ( pfile != null)
|
||||
isPseudo = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if the file name matches a pseudo-file name in the desktop actions list
|
||||
|
||||
if ( ctx.hasDesktopActions())
|
||||
{
|
||||
DesktopActionTable actions = ctx.getDesktopActions();
|
||||
if ( actions.getActionViaPseudoName( paths[1]) != null)
|
||||
isPseudo = true;
|
||||
}
|
||||
|
||||
// Check if the URL file is enabled
|
||||
|
||||
if ( isPseudo == false && ctx.hasURLFile())
|
||||
{
|
||||
// Check if it is the URL file name
|
||||
|
||||
if ( ctx.getURLFileName().equals( paths[1]))
|
||||
isPseudo = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the pseudo file status
|
||||
|
||||
return isPseudo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the pseudo file for the specified path, or null if the path is not a pseudo file
|
||||
*
|
||||
* @param sess SrvSession
|
||||
* @param tree TreeConnection
|
||||
* @param path String
|
||||
* @return PseudoFile
|
||||
*/
|
||||
public PseudoFile getPseudoFile(SrvSession sess, TreeConnection tree, String path)
|
||||
{
|
||||
// Check if the path is for a pseudo file
|
||||
|
||||
ContentContext ctx = (ContentContext) tree.getContext();
|
||||
|
||||
String[] paths = FileName.splitPath( path);
|
||||
FileState fstate = getStateForPath( ctx, paths[0]);
|
||||
|
||||
if ( fstate != null && fstate.hasPseudoFiles())
|
||||
{
|
||||
// Check if there is a matching pseudo file
|
||||
|
||||
PseudoFile pfile = fstate.getPseudoFileList().findFile( paths[1], false);
|
||||
if ( pfile != null)
|
||||
return pfile;
|
||||
}
|
||||
|
||||
// Not a pseudo file
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add pseudo files to a folder so that they appear in a folder search
|
||||
*
|
||||
* @param sess SrvSession
|
||||
* @param tree TreeConnection
|
||||
* @param path String
|
||||
* @return int
|
||||
*/
|
||||
public int addPseudoFilesToFolder(SrvSession sess, TreeConnection tree, String path)
|
||||
{
|
||||
// Access the device context
|
||||
|
||||
int pseudoCnt = 0;
|
||||
ContentContext ctx = (ContentContext) tree.getContext();
|
||||
FileState fstate = getStateForPath( ctx, path);
|
||||
|
||||
// Check if pseudo files have already been added for this folder
|
||||
|
||||
if ( fstate.hasPseudoFiles())
|
||||
return 0;
|
||||
|
||||
// Check if this is a CIFS session
|
||||
|
||||
boolean isCIFS = sess instanceof SMBSrvSession;
|
||||
|
||||
// Add the desktop action pseudo files
|
||||
|
||||
if ( isCIFS && ctx.numberOfDesktopActions() > 0)
|
||||
{
|
||||
// If the file state is null create a file state for the path
|
||||
|
||||
if ( fstate == null)
|
||||
ctx.getStateTable().findFileState( path, true, true);
|
||||
|
||||
// Add the desktop action pseudo files
|
||||
|
||||
DesktopActionTable actions = ctx.getDesktopActions();
|
||||
Enumeration<String> actionNames = actions.enumerateActionNames();
|
||||
|
||||
while(actionNames.hasMoreElements())
|
||||
{
|
||||
// Get the current desktop action
|
||||
|
||||
String name = actionNames.nextElement();
|
||||
DesktopAction action = actions.getAction(name);
|
||||
|
||||
// Add the pseudo file for the desktop action
|
||||
|
||||
if ( action.hasPseudoFile())
|
||||
{
|
||||
fstate.addPseudoFile( action.getPseudoFile());
|
||||
pseudoCnt++;
|
||||
|
||||
// DEBUG
|
||||
|
||||
if ( logger.isInfoEnabled())
|
||||
logger.info("Added desktop action " + action.getName() + " for " + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the URL link pseudo file, if enabled
|
||||
|
||||
if ( isCIFS && ctx.hasURLFile())
|
||||
{
|
||||
// Make sure the state has the associated node details
|
||||
|
||||
if ( fstate.getNodeRef() != null)
|
||||
{
|
||||
// Build the URL file data
|
||||
|
||||
StringBuilder urlStr = new StringBuilder();
|
||||
|
||||
urlStr.append("[InternetShortcut]\r\n");
|
||||
urlStr.append("URL=");
|
||||
urlStr.append(ctx.getURLPrefix());
|
||||
urlStr.append("navigate/browse/workspace/SpacesStore/");
|
||||
urlStr.append( fstate.getNodeRef().getId());
|
||||
urlStr.append("\r\n");
|
||||
|
||||
// Create the in memory pseudo file for the URL link
|
||||
|
||||
byte[] urlData = urlStr.toString().getBytes();
|
||||
|
||||
MemoryPseudoFile urlFile = new MemoryPseudoFile( ctx.getURLFileName(), urlData);
|
||||
fstate.addPseudoFile( urlFile);
|
||||
|
||||
// Update the count of files added
|
||||
|
||||
pseudoCnt++;
|
||||
|
||||
// DEBUG
|
||||
|
||||
if ( logger.isInfoEnabled())
|
||||
logger.info("Added URL link pseudo file for " + path);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the count of pseudo files added
|
||||
|
||||
return pseudoCnt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a pseudo file
|
||||
*
|
||||
* @param sess SrvSession
|
||||
* @param tree TreeConnection
|
||||
* @param path String
|
||||
*/
|
||||
public void deletePseudoFile(SrvSession sess, TreeConnection tree, String path)
|
||||
{
|
||||
// Access the device context
|
||||
|
||||
ContentContext ctx = (ContentContext) tree.getContext();
|
||||
|
||||
// Get the file state for the parent folder
|
||||
|
||||
String[] paths = FileName.splitPath( path);
|
||||
FileState fstate = getStateForPath( ctx, paths[0]);
|
||||
|
||||
// Check if the folder has any pseudo files
|
||||
|
||||
if ( fstate == null || fstate.hasPseudoFiles() == false)
|
||||
return;
|
||||
|
||||
// Remove the pseudo file from the list
|
||||
|
||||
fstate.getPseudoFileList().removeFile( paths[1], false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file state for the specified path
|
||||
*
|
||||
* @param ctx ContentContext
|
||||
* @param path String
|
||||
* @return FileState
|
||||
*/
|
||||
private final FileState getStateForPath(ContentContext ctx, String path)
|
||||
{
|
||||
// Check if there is a cached state for the path
|
||||
|
||||
FileState fstate = null;
|
||||
|
||||
if ( ctx.hasStateTable())
|
||||
{
|
||||
// Get the file state for a file/folder
|
||||
|
||||
fstate = ctx.getStateTable().findFileState(path);
|
||||
}
|
||||
|
||||
// Return the file state
|
||||
|
||||
return fstate;
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.server.pseudo;
|
||||
|
||||
import org.alfresco.filesys.server.SrvSession;
|
||||
import org.alfresco.filesys.server.filesys.TreeConnection;
|
||||
|
||||
/**
|
||||
* Pseudo File Interface
|
||||
*
|
||||
* <p>Provides the ability to add files into the file listing of a folder.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public interface PseudoFileInterface
|
||||
{
|
||||
/**
|
||||
* Check if the specified path refers to a pseudo file
|
||||
*
|
||||
* @param sess SrvSession
|
||||
* @param tree TreeConnection
|
||||
* @param path String
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isPseudoFile(SrvSession sess, TreeConnection tree, String path);
|
||||
|
||||
/**
|
||||
* Return the pseudo file for the specified path, or null if the path is not a pseudo file
|
||||
*
|
||||
* @param sess SrvSession
|
||||
* @param tree TreeConnection
|
||||
* @param path String
|
||||
* @return PseudoFile
|
||||
*/
|
||||
public PseudoFile getPseudoFile(SrvSession sess, TreeConnection tree, String path);
|
||||
|
||||
/**
|
||||
* Add pseudo files to a folder so that they appear in a folder search
|
||||
*
|
||||
* @param sess SrvSession
|
||||
* @param tree TreeConnection
|
||||
* @param path String
|
||||
* @return int
|
||||
*/
|
||||
public int addPseudoFilesToFolder(SrvSession sess, TreeConnection tree, String path);
|
||||
|
||||
/**
|
||||
* Delete a pseudo file
|
||||
*
|
||||
* @param sess SrvSession
|
||||
* @param tree TreeConnection
|
||||
* @param path String
|
||||
*/
|
||||
public void deletePseudoFile(SrvSession sess, TreeConnection tree, String path);
|
||||
}
|
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.server.pseudo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Pseudo File List Class
|
||||
*
|
||||
* <p>Contains a list of pseudo file list entries for a folder.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public class PseudoFileList
|
||||
{
|
||||
// List of pseudo files
|
||||
|
||||
private List<PseudoFile> m_list;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public PseudoFileList()
|
||||
{
|
||||
m_list = new ArrayList<PseudoFile>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a pseudo file to the list
|
||||
*
|
||||
* @param pfile PseudoFile
|
||||
*/
|
||||
public final void addFile( PseudoFile pfile)
|
||||
{
|
||||
m_list.add( pfile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the count of files in the list
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public final int numberOfFiles()
|
||||
{
|
||||
return m_list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the file at the specified index in the list
|
||||
*
|
||||
* @param idx int
|
||||
* @return PseudoFile
|
||||
*/
|
||||
public final PseudoFile getFileAt(int idx)
|
||||
{
|
||||
if ( idx < m_list.size())
|
||||
return m_list.get(idx);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for the specified pseudo file name
|
||||
*
|
||||
* @param fname String
|
||||
* @param caseSensitive boolean
|
||||
* @return PseudoFile
|
||||
*/
|
||||
public final PseudoFile findFile( String fname, boolean caseSensitive)
|
||||
{
|
||||
// Check if there are any entries in the list
|
||||
|
||||
if ( m_list == null || m_list.size() == 0)
|
||||
return null;
|
||||
|
||||
// Search for the name match
|
||||
|
||||
for ( PseudoFile pfile : m_list)
|
||||
{
|
||||
if ( caseSensitive && pfile.getFileName().equals( fname))
|
||||
return pfile;
|
||||
else if ( pfile.getFileName().equalsIgnoreCase( fname))
|
||||
return pfile;
|
||||
}
|
||||
|
||||
// File not found
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified pseudo file from the list
|
||||
*
|
||||
* @param fname String
|
||||
* @param caseSensitive boolean
|
||||
* @return PseudoFile
|
||||
*/
|
||||
public final PseudoFile removeFile( String fname, boolean caseSensitive)
|
||||
{
|
||||
// Check if there are any entries in the list
|
||||
|
||||
if ( m_list == null || m_list.size() == 0)
|
||||
return null;
|
||||
|
||||
// Search for the name match
|
||||
|
||||
for ( int idx = 0; idx < m_list.size(); idx++)
|
||||
{
|
||||
// Get the current pseudo file
|
||||
|
||||
PseudoFile pfile = m_list.get( idx);
|
||||
boolean match = false;
|
||||
|
||||
if ( caseSensitive && pfile.getFileName().equals( fname))
|
||||
match = true;
|
||||
else if ( pfile.getFileName().equalsIgnoreCase( fname))
|
||||
match = true;
|
||||
|
||||
// If we found the matching pseudo file remove it from the list
|
||||
|
||||
if ( match)
|
||||
{
|
||||
m_list.remove( idx);
|
||||
return pfile;
|
||||
}
|
||||
}
|
||||
|
||||
// File not found
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* Copyright (C) 2006 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.server.pseudo;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.alfresco.filesys.server.filesys.AccessDeniedException;
|
||||
import org.alfresco.filesys.server.filesys.FileAttribute;
|
||||
import org.alfresco.filesys.server.filesys.NetworkFile;
|
||||
|
||||
/**
|
||||
* Pseudo Folder Network File Class
|
||||
*
|
||||
* <p>Represents an open pseudo folder.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public class PseudoFolderNetworkFile extends NetworkFile {
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param name String
|
||||
*/
|
||||
public PseudoFolderNetworkFile(String name)
|
||||
{
|
||||
super( name);
|
||||
|
||||
setAttributes( FileAttribute.Directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param name String
|
||||
* @param relPath String
|
||||
*/
|
||||
public PseudoFolderNetworkFile(String name, String relPath)
|
||||
{
|
||||
super( name);
|
||||
|
||||
setFullName( relPath);
|
||||
setAttributes( FileAttribute.Directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the network file.
|
||||
*/
|
||||
public void closeFile() throws java.io.IOException
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current file position.
|
||||
*
|
||||
* @return long
|
||||
*/
|
||||
public long currentPosition()
|
||||
{
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the file.
|
||||
*
|
||||
* @exception IOException
|
||||
*/
|
||||
public void flushFile() throws IOException
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the end of file has been reached.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isEndOfFile() throws java.io.IOException
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the file.
|
||||
*
|
||||
* @param createFlag boolean
|
||||
* @exception IOException
|
||||
*/
|
||||
public void openFile(boolean createFlag) throws java.io.IOException
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the file.
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param len int
|
||||
* @param pos int
|
||||
* @param fileOff long
|
||||
* @return Length of data read.
|
||||
* @exception IOException
|
||||
*/
|
||||
public int readFile(byte[] buf, int len, int pos, long fileOff) throws java.io.IOException
|
||||
{
|
||||
throw new AccessDeniedException( "Attempt to read/write folder file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Seek to the specified file position.
|
||||
*
|
||||
* @param pos long
|
||||
* @param typ int
|
||||
* @return long
|
||||
* @exception IOException
|
||||
*/
|
||||
public long seekFile(long pos, int typ) throws IOException
|
||||
{
|
||||
throw new AccessDeniedException( "Attempt to read/write folder file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate the file
|
||||
*
|
||||
* @param siz long
|
||||
* @exception IOException
|
||||
*/
|
||||
public void truncateFile(long siz) throws IOException
|
||||
{
|
||||
throw new AccessDeniedException( "Attempt to read/write folder file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a block of data to the file.
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param len int
|
||||
* @exception IOException
|
||||
*/
|
||||
public void writeFile(byte[] buf, int len, int pos) throws java.io.IOException
|
||||
{
|
||||
throw new AccessDeniedException( "Attempt to read/write folder file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a block of data to the file.
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param len int
|
||||
* @param pos int
|
||||
* @param offset long
|
||||
* @exception IOException
|
||||
*/
|
||||
public void writeFile(byte[] buf, int len, int pos, long offset) throws java.io.IOException
|
||||
{
|
||||
throw new AccessDeniedException( "Attempt to read/write folder file");
|
||||
}
|
||||
}
|
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
* Copyright (C) 2005 Alfresco, Inc.
|
||||
*
|
||||
* Licensed under the Mozilla Public License version 1.1
|
||||
* with a permitted attribution clause. You may obtain a
|
||||
* copy of the License at
|
||||
*
|
||||
* http://www.alfresco.org/legal/license.txt
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
||||
* either express or implied. See the License for the specific
|
||||
* language governing permissions and limitations under the
|
||||
* License.
|
||||
*/
|
||||
|
||||
package org.alfresco.filesys.server.pseudo;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
import org.alfresco.filesys.server.filesys.NetworkFile;
|
||||
import org.alfresco.filesys.smb.SeekType;
|
||||
|
||||
/**
|
||||
* Pseudo File Network File Class
|
||||
*
|
||||
* <p>Represents an open pseudo file and provides access to the file data.
|
||||
*
|
||||
* @author gkspencer
|
||||
*/
|
||||
public class PseudoNetworkFile extends NetworkFile
|
||||
{
|
||||
// File details
|
||||
|
||||
protected File m_file;
|
||||
|
||||
// Random access file used to read/write the actual file
|
||||
|
||||
protected RandomAccessFile m_io;
|
||||
|
||||
// End of file flag
|
||||
|
||||
protected boolean m_eof;
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* @param name String
|
||||
* @param localPath String
|
||||
* @param netPath String
|
||||
*/
|
||||
public PseudoNetworkFile(String name, String localPath, String netPath)
|
||||
{
|
||||
super( name);
|
||||
|
||||
// Set the file using the existing file object
|
||||
|
||||
m_file = new File( localPath);
|
||||
|
||||
// Set the file size
|
||||
|
||||
setFileSize(m_file.length());
|
||||
m_eof = false;
|
||||
|
||||
// Set the modification date/time, if available. Fake the creation date/time as it's not
|
||||
// available from the File class
|
||||
|
||||
long modDate = m_file.lastModified();
|
||||
setModifyDate(modDate);
|
||||
setCreationDate(modDate);
|
||||
|
||||
// Set the file id
|
||||
|
||||
setFileId(netPath.hashCode());
|
||||
|
||||
// Set the full relative path
|
||||
|
||||
setFullName( netPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the network file.
|
||||
*/
|
||||
public void closeFile() throws java.io.IOException
|
||||
{
|
||||
|
||||
// Close the file, if used
|
||||
|
||||
if (m_io != null)
|
||||
{
|
||||
|
||||
// Close the file
|
||||
|
||||
m_io.close();
|
||||
m_io = null;
|
||||
|
||||
// Set the last modified date/time for the file
|
||||
|
||||
if (this.getWriteCount() > 0)
|
||||
m_file.setLastModified(System.currentTimeMillis());
|
||||
|
||||
// Indicate that the file is closed
|
||||
|
||||
setClosed(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current file position.
|
||||
*
|
||||
* @return long
|
||||
*/
|
||||
public long currentPosition()
|
||||
{
|
||||
|
||||
// Check if the file is open
|
||||
|
||||
try
|
||||
{
|
||||
if (m_io != null)
|
||||
return m_io.getFilePointer();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the file.
|
||||
*
|
||||
* @exception IOException
|
||||
*/
|
||||
public void flushFile() throws IOException
|
||||
{
|
||||
// Flush all buffered data
|
||||
|
||||
if (m_io != null)
|
||||
m_io.getFD().sync();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the end of file has been reached.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isEndOfFile() throws java.io.IOException
|
||||
{
|
||||
// Check if we reached end of file
|
||||
|
||||
if (m_io != null && m_io.getFilePointer() == m_io.length())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the file.
|
||||
*
|
||||
* @param createFlag boolean
|
||||
* @exception IOException
|
||||
*/
|
||||
public void openFile(boolean createFlag) throws java.io.IOException
|
||||
{
|
||||
|
||||
synchronized (m_file)
|
||||
{
|
||||
// Check if the file is open
|
||||
|
||||
if (m_io == null)
|
||||
{
|
||||
|
||||
// Open the file, always read-only for now
|
||||
|
||||
m_io = new RandomAccessFile(m_file, "r");
|
||||
|
||||
// Indicate that the file is open
|
||||
|
||||
setClosed(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from the file.
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param len int
|
||||
* @param pos int
|
||||
* @param fileOff long
|
||||
* @return Length of data read.
|
||||
* @exception IOException
|
||||
*/
|
||||
public int readFile(byte[] buf, int len, int pos, long fileOff) throws java.io.IOException
|
||||
{
|
||||
|
||||
// Open the file, if not already open
|
||||
|
||||
if (m_io == null)
|
||||
openFile(false);
|
||||
|
||||
// Seek to the required file position
|
||||
|
||||
if (currentPosition() != fileOff)
|
||||
seekFile(fileOff, SeekType.StartOfFile);
|
||||
|
||||
// Read from the file
|
||||
|
||||
int rdlen = m_io.read(buf, pos, len);
|
||||
|
||||
// Return the actual length of data read
|
||||
|
||||
return rdlen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Seek to the specified file position.
|
||||
*
|
||||
* @param pos long
|
||||
* @param typ int
|
||||
* @return long
|
||||
* @exception IOException
|
||||
*/
|
||||
public long seekFile(long pos, int typ) throws IOException
|
||||
{
|
||||
|
||||
// Open the file, if not already open
|
||||
|
||||
if (m_io == null)
|
||||
openFile(false);
|
||||
|
||||
// Check if the current file position is the required file position
|
||||
|
||||
switch (typ)
|
||||
{
|
||||
|
||||
// From start of file
|
||||
|
||||
case SeekType.StartOfFile:
|
||||
if (currentPosition() != pos)
|
||||
m_io.seek(pos);
|
||||
break;
|
||||
|
||||
// From current position
|
||||
|
||||
case SeekType.CurrentPos:
|
||||
m_io.seek(currentPosition() + pos);
|
||||
break;
|
||||
|
||||
// From end of file
|
||||
|
||||
case SeekType.EndOfFile: {
|
||||
long newPos = m_io.length() + pos;
|
||||
m_io.seek(newPos);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Return the new file position
|
||||
|
||||
return currentPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate the file
|
||||
*
|
||||
* @param siz long
|
||||
* @exception IOException
|
||||
*/
|
||||
public void truncateFile(long siz) throws IOException
|
||||
{
|
||||
// Allow the truncate, just do not do anything
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a block of data to the file.
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param len int
|
||||
* @exception IOException
|
||||
*/
|
||||
public void writeFile(byte[] buf, int len, int pos) throws java.io.IOException
|
||||
{
|
||||
// Allow the write, just do not do anything
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a block of data to the file.
|
||||
*
|
||||
* @param buf byte[]
|
||||
* @param len int
|
||||
* @param pos int
|
||||
* @param offset long
|
||||
* @exception IOException
|
||||
*/
|
||||
public void writeFile(byte[] buf, int len, int pos, long offset) throws java.io.IOException
|
||||
{
|
||||
// Allow the write, just do not do anything
|
||||
}
|
||||
}
|
@@ -22,9 +22,9 @@ import org.alfresco.filesys.locking.LockConflictException;
|
||||
import org.alfresco.filesys.locking.NotLockedException;
|
||||
import org.alfresco.filesys.server.filesys.FileOpenParams;
|
||||
import org.alfresco.filesys.server.filesys.FileStatus;
|
||||
import org.alfresco.filesys.server.pseudo.PseudoFile;
|
||||
import org.alfresco.filesys.server.pseudo.PseudoFileList;
|
||||
import org.alfresco.filesys.smb.SharingMode;
|
||||
import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFile;
|
||||
import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFileList;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
Reference in New Issue
Block a user