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:
Gary Spencer
2006-11-27 09:39:49 +00:00
parent 0eda95cc5f
commit a2a543684b
39 changed files with 2153 additions and 871 deletions

View File

@@ -16,13 +16,9 @@
*/
package org.alfresco.filesys.smb.server.repo;
import java.util.Enumeration;
import org.alfresco.filesys.alfresco.AlfrescoContext;
import org.alfresco.filesys.alfresco.IOControlHandler;
import org.alfresco.filesys.server.filesys.*;
import org.alfresco.filesys.server.state.FileStateReaper;
import org.alfresco.filesys.server.state.FileStateTable;
import org.alfresco.filesys.smb.server.repo.pseudo.ContentPseudoFileImpl;
import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFileInterface;
import org.alfresco.service.cmr.repository.*;
/**
@@ -32,7 +28,7 @@ import org.alfresco.service.cmr.repository.*;
*
* @author GKSpencer
*/
public class ContentContext extends DiskDeviceContext
public class ContentContext extends AlfrescoContext
{
// Store and root path
@@ -43,28 +39,6 @@ public class ContentContext extends DiskDeviceContext
private NodeRef m_rootNodeRef;
// File state table and associated file state reaper
private FileStateTable m_stateTable;
private FileStateReaper m_stateReaper;
// URL pseudo file web path prefix (server/port/webapp) and link file name
private String m_urlPathPrefix;
private String m_urlFileName;
// Pseudo file interface
private PseudoFileInterface m_pseudoFileInterface;
// Desktop actions
private DesktopActionTable m_desktopActions;
// I/O control handler
private IOControlHandler m_ioHandler;
/**
* Class constructor
*
@@ -81,10 +55,6 @@ public class ContentContext extends DiskDeviceContext
m_rootPath = rootPath;
m_rootNodeRef = rootNodeRef;
// Create the file state table
m_stateTable = new FileStateTable();
}
/**
@@ -127,263 +97,24 @@ public class ContentContext extends DiskDeviceContext
return m_rootNodeRef;
}
/**
* Determine if the file state table is enabled
*
* @return boolean
*/
public final boolean hasStateTable()
{
return m_stateTable != null ? true : false;
}
/**
* Return the file state table
*
* @return FileStateTable
*/
public final FileStateTable getStateTable()
{
return m_stateTable;
}
/**
* Enable/disable the file state table
*
* @param ena boolean
* @param stateReaper FileStateReaper
*/
public final void enableStateTable(boolean ena, FileStateReaper stateReaper)
{
if ( ena == false)
{
// Remove the state table from the reaper
stateReaper.removeStateTable( getFilesystemName());
m_stateTable = null;
}
else if ( m_stateTable == null)
{
// Create the file state table
m_stateTable = new FileStateTable();
// Register with the file state reaper
stateReaper.addStateTable( getFilesystemName(), m_stateTable);
}
// Save the reaper, for deregistering when the filesystem is closed
m_stateReaper = stateReaper;
}
/**
* Determine if the pseudo file interface is enabled
*
* @return boolean
*/
public final boolean hasPseudoFileInterface()
{
return m_pseudoFileInterface != null ? true : false;
}
/**
* Return the pseudo file interface
*
* @return PseudoFileInterface
*/
public final PseudoFileInterface getPseudoFileInterface()
{
return m_pseudoFileInterface;
}
/**
* Enable the pseudo file interface for this filesystem
*/
public final void enabledPseudoFileInterface()
{
if ( m_pseudoFileInterface == null)
m_pseudoFileInterface = new ContentPseudoFileImpl();
}
/**
* Determine if there are desktop actins configured
*
* @return boolean
*/
public final boolean hasDesktopActions()
{
return m_desktopActions != null ? true : false;
}
/**
* Return the desktop actions table
*
* @return DesktopActionTable
*/
public final DesktopActionTable getDesktopActions()
{
return m_desktopActions;
}
/**
* Return the count of desktop actions
*
* @return int
*/
public final int numberOfDesktopActions()
{
return m_desktopActions != null ? m_desktopActions.numberOfActions() : 0;
}
/**
* Add a desktop action
*
* @param action DesktopAction
* @return boolean
*/
public final boolean addDesktopAction(DesktopAction action)
{
// Check if the desktop actions table has been created
if ( m_desktopActions == null)
{
m_desktopActions = new DesktopActionTable();
// Enable pseudo files
enabledPseudoFileInterface();
}
// Add the action
return m_desktopActions.addAction(action);
}
/**
* Determine if custom I/O control handling is enabled for this filesystem
*
* @return boolean
*/
public final boolean hasIOHandler()
{
return m_ioHandler != null ? true : false;
}
/**
* Return the custom I/O control handler
*
* @return IOControlHandler
*/
public final IOControlHandler getIOHandler()
{
return m_ioHandler;
}
/**
* Determine if the URL pseudo file is enabled
*
* @return boolean
*/
public final boolean hasURLFile()
{
if ( m_urlPathPrefix != null && m_urlFileName != null)
return true;
return false;
}
/**
* Return the URL pseudo file path prefix
*
* @return String
*/
public final String getURLPrefix()
{
return m_urlPathPrefix;
}
/**
* Return the URL pseudo file name
*
* @return String
*/
public final String getURLFileName()
{
return m_urlFileName;
}
/**
* Set the URL path prefix
*
* @param urlPrefix String
*/
public final void setURLPrefix(String urlPrefix)
{
m_urlPathPrefix = urlPrefix;
if ( urlPrefix != null)
enabledPseudoFileInterface();
}
/**
* Set the URL pseudo file name
*
* @param urlFileName String
*/
public final void setURLFileName(String urlFileName)
{
m_urlFileName = urlFileName;
if ( urlFileName != null)
enabledPseudoFileInterface();
}
/**
* Set the desktop actions
*
* @param desktopActions DesktopActionTable
* @param filesysDriver DiskInterface
*/
public final void setDesktopActions(DesktopActionTable desktopActions, DiskInterface filesysDriver)
{
// Enumerate the desktop actions and add to this filesystem
Enumeration<String> names = desktopActions.enumerateActionNames();
while ( names.hasMoreElements())
{
addDesktopAction( desktopActions.getAction(names.nextElement()));
}
// If there are desktop actions then create the custom I/O control handler
if ( numberOfDesktopActions() > 0)
{
// Access the filesystem driver
ContentDiskDriver contentDriver = (ContentDiskDriver) filesysDriver;
// Create the custom I/O control handler
m_ioHandler = new ContentIOControlHandler();
m_ioHandler.initialize(contentDriver, this);
}
}
/**
* Close the filesystem context
*/
public void CloseContext() {
// Deregister the file state table from the reaper
if ( m_stateTable != null)
enableStateTable( false, m_stateReaper);
// Call the base class
super.CloseContext();
}
/**
* Create the I/O control handler for this filesystem type
*
* @param filesysDriver DiskInterface
* @return IOControlHandler
*/
protected IOControlHandler createIOHandler( DiskInterface filesysDriver)
{
return new ContentIOControlHandler();
}
}

View File

@@ -25,6 +25,7 @@ import javax.transaction.UserTransaction;
import org.alfresco.config.ConfigElement;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.filesys.alfresco.AlfrescoDiskDriver;
import org.alfresco.filesys.server.SrvSession;
import org.alfresco.filesys.server.core.DeviceContext;
import org.alfresco.filesys.server.core.DeviceContextException;
@@ -38,30 +39,21 @@ import org.alfresco.filesys.server.filesys.FileName;
import org.alfresco.filesys.server.filesys.FileOpenParams;
import org.alfresco.filesys.server.filesys.FileSharingException;
import org.alfresco.filesys.server.filesys.FileStatus;
import org.alfresco.filesys.server.filesys.FileSystem;
import org.alfresco.filesys.server.filesys.IOControlNotImplementedException;
import org.alfresco.filesys.server.filesys.IOCtlInterface;
import org.alfresco.filesys.server.filesys.NetworkFile;
import org.alfresco.filesys.server.filesys.SearchContext;
import org.alfresco.filesys.server.filesys.SrvDiskInfo;
import org.alfresco.filesys.server.filesys.TreeConnection;
import org.alfresco.filesys.server.pseudo.MemoryNetworkFile;
import org.alfresco.filesys.server.pseudo.PseudoFile;
import org.alfresco.filesys.server.pseudo.PseudoFileInterface;
import org.alfresco.filesys.server.pseudo.PseudoFileList;
import org.alfresco.filesys.server.pseudo.PseudoNetworkFile;
import org.alfresco.filesys.server.state.FileState;
import org.alfresco.filesys.server.state.FileStateReaper;
import org.alfresco.filesys.server.state.FileState.FileStateStatus;
import org.alfresco.filesys.smb.SMBException;
import org.alfresco.filesys.smb.SMBStatus;
import org.alfresco.filesys.smb.SharingMode;
import org.alfresco.filesys.smb.server.SMBSrvSession;
import org.alfresco.filesys.smb.server.repo.pseudo.MemoryNetworkFile;
import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFile;
import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFileInterface;
import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFileList;
import org.alfresco.filesys.smb.server.repo.pseudo.PseudoNetworkFile;
import org.alfresco.filesys.util.DataBuffer;
import org.alfresco.filesys.util.WildCard;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.lock.NodeLockedException;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -83,7 +75,7 @@ import org.apache.commons.logging.LogFactory;
*
* @author Derek Hulley
*/
public class ContentDiskDriver implements DiskInterface, IOCtlInterface
public class ContentDiskDriver extends AlfrescoDiskDriver implements DiskInterface
{
// Logging
@@ -112,14 +104,6 @@ public class ContentDiskDriver implements DiskInterface, IOCtlInterface
private AuthenticationComponent authComponent;
private AuthenticationService authService;
// Service registry for desktop actions
private ServiceRegistry serviceRegistry;
// File state reaper
private FileStateReaper m_stateReaper;
/**
* Class constructor
*
@@ -199,26 +183,6 @@ public class ContentDiskDriver implements DiskInterface, IOCtlInterface
return this.searchService;
}
/**
* Return the service registry
*
* @return ServiceRegistry
*/
public final ServiceRegistry getServiceRegistry()
{
return this.serviceRegistry;
}
/**
* Return the file state reaper
*
* @return FileStateReaper
*/
public final FileStateReaper getStateReaper()
{
return m_stateReaper;
}
/**
* @param contentService the content service
*/
@@ -269,16 +233,6 @@ public class ContentDiskDriver implements DiskInterface, IOCtlInterface
this.permissionService = permissionService;
}
/**
* Set the service registry
*
* @param serviceRegistry
*/
public void setServiceRegistry(ServiceRegistry serviceRegistry)
{
this.serviceRegistry = serviceRegistry;
}
/**
* Set the authentication component
*
@@ -299,16 +253,6 @@ public class ContentDiskDriver implements DiskInterface, IOCtlInterface
this.authService = authService;
}
/**
* Set the file state reaper
*
* @param stateReaper FileStateReaper
*/
public final void setStateReaper(FileStateReaper stateReaper)
{
m_stateReaper = stateReaper;
}
/**
* Parse and validate the parameter string and create a device context object for this instance
* of the shared device. The same DeviceInterface implementation may be used for multiple
@@ -419,15 +363,6 @@ public class ContentDiskDriver implements DiskInterface, IOCtlInterface
// Create the context
context = new ContentContext(name, storeValue, rootPath, rootNodeRef);
// Default the filesystem to look like an 80Gb sized disk with 90% free space
context.setDiskInformation(new SrvDiskInfo(2560000, 64, 512, 2304000));
// Set parameters
context.setFilesystemAttributes(FileSystem.CasePreservedNames + FileSystem.UnicodeOnDisk +
FileSystem.CaseSensitiveSearch);
}
catch (Exception ex)
{
@@ -2198,37 +2133,4 @@ public class ContentDiskDriver implements DiskInterface, IOCtlInterface
{
// Nothing to do
}
/**
* Process a filesystem I/O control request
*
* @param sess Server session
* @param tree Tree connection.
* @param ctrlCode I/O control code
* @param fid File id
* @param dataBuf I/O control specific input data
* @param isFSCtrl true if this is a filesystem control, or false for a device control
* @param filter if bit0 is set indicates that the control applies to the share root handle
* @return DataBuffer
* @exception IOControlNotImplementedException
* @exception SMBException
*/
public DataBuffer processIOControl(SrvSession sess, TreeConnection tree, int ctrlCode, int fid, DataBuffer dataBuf,
boolean isFSCtrl, int filter)
throws IOControlNotImplementedException, SMBException
{
// Validate the file id
NetworkFile netFile = tree.findFile(fid);
if ( netFile == null || netFile.isDirectory() == false)
throw new SMBException(SMBStatus.NTErr, SMBStatus.NTInvalidParameter);
// Check if the I/O control handler is enabled
ContentContext ctx = (ContentContext) tree.getContext();
if ( ctx.hasIOHandler())
return ctx.getIOHandler().processIOControl( sess, tree, ctrlCode, fid, dataBuf, isFSCtrl, filter);
else
throw new IOControlNotImplementedException();
}
}

View File

@@ -18,6 +18,15 @@ package org.alfresco.filesys.smb.server.repo;
import java.io.FileNotFoundException;
import org.alfresco.filesys.alfresco.AlfrescoContext;
import org.alfresco.filesys.alfresco.AlfrescoDiskDriver;
import org.alfresco.filesys.alfresco.DesktopAction;
import org.alfresco.filesys.alfresco.DesktopActionTable;
import org.alfresco.filesys.alfresco.DesktopParams;
import org.alfresco.filesys.alfresco.DesktopResponse;
import org.alfresco.filesys.alfresco.DesktopTarget;
import org.alfresco.filesys.alfresco.IOControl;
import org.alfresco.filesys.alfresco.IOControlHandler;
import org.alfresco.filesys.server.SrvSession;
import org.alfresco.filesys.server.auth.ClientInfo;
import org.alfresco.filesys.server.filesys.IOControlNotImplementedException;
@@ -28,7 +37,6 @@ import org.alfresco.filesys.smb.SMBException;
import org.alfresco.filesys.smb.SMBStatus;
import org.alfresco.filesys.smb.server.repo.CifsHelper;
import org.alfresco.filesys.smb.server.repo.ContentDiskDriver;
import org.alfresco.filesys.smb.server.repo.IOControlHandler;
import org.alfresco.filesys.util.DataBuffer;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationException;
@@ -69,13 +77,13 @@ public class ContentIOControlHandler implements IOControlHandler
/**
* Initalize the I/O control handler
*
* @param contentDriver ContentDiskDriver
* @param contentContext ContentContext
* @param filesysDriver AlfrescoDiskDriver
* @param context AlfrescoContext
*/
public void initialize( ContentDiskDriver contentDriver, ContentContext contentContext)
public void initialize( AlfrescoDiskDriver filesysDriver, AlfrescoContext context)
{
this.contentDriver = contentDriver;
this.contentContext = contentContext;
this.contentDriver = (ContentDiskDriver) filesysDriver;
this.contentContext = (ContentContext) context;
}
/**

View File

@@ -21,8 +21,8 @@ import java.util.List;
import org.alfresco.filesys.server.filesys.FileInfo;
import org.alfresco.filesys.server.filesys.SearchContext;
import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFile;
import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFileList;
import org.alfresco.filesys.server.pseudo.PseudoFile;
import org.alfresco.filesys.server.pseudo.PseudoFileList;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

View File

@@ -1,639 +0,0 @@
/*
* 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.smb.server.repo;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLDecoder;
import org.alfresco.config.ConfigElement;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.filesys.server.filesys.DiskSharedDevice;
import org.alfresco.filesys.smb.server.repo.pseudo.LocalPseudoFile;
import org.alfresco.filesys.smb.server.repo.pseudo.PseudoFile;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.transaction.TransactionService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Desktop Action Class
*
* @author gkspencer
*
*/
public abstract class DesktopAction {
// Logging
protected static final Log logger = LogFactory.getLog(DesktopAction.class);
// Constants
//
// Action attributes
public static final int AttrTargetFiles = 0x0001; // allow files from the same folder
public static final int AttrTargetFolders = 0x0002; // allow sub-folders from the same folder
public static final int AttrClientFiles = 0x0004; // allow files from a client drive
// File(s) will be copied to the target folder
public static final int AttrClientFolders = 0x0008; // allow folders from a client drive
// Folder(s) will be copied to the target folder
public static final int AttrAlfrescoFiles = 0x0010; // allow files from another path within the Alfresco share
public static final int AttrAlfrescoFolders = 0x0020; // allow folders from another path within the Alfresco share
public static final int AttrMultiplePaths = 0x0040; // run action using multiple paths
// default is to run the action against a single path with the client app calling the action
// multiple times
public static final int AttrAllowNoParams = 0x0080; // allow action to run without parameters
// used when files/folder parameters are optional
public static final int AttrAnyFiles = AttrTargetFiles + AttrClientFiles + AttrAlfrescoFiles;
public static final int AttrAnyFolders = AttrTargetFolders + AttrClientFolders + AttrAlfrescoFolders;
public static final int AttrAnyFilesFolders = AttrAnyFiles + AttrAnyFolders;
// Client side pre-processing actions
public static final int PreCopyToTarget = 0x0001; // copy files/folders from another Alfresco folder to the target folder
public static final int PreConfirmAction = 0x0002; // confirm action, allow user to abort
public static final int PreLocalToWorkingCopy = 0x0004; // local files must match a working copy in the target folder
// Desktop action status codes
public static final int StsSuccess = 0;
public static final int StsError = 1;
public static final int StsFileNotFound = 2;
public static final int StsAccessDenied = 3;
public static final int StsBadParameter = 4;
public static final int StsNotWorkingCopy = 5;
public static final int StsNoSuchAction = 6;
public static final int StsLaunchURL = 7;
public static final int StsCommandLine = 8;
// Token name to substitute current servers DNS name or TCP/IP address into the webapp URL
private static final String TokenLocalName = "${localname}";
// Action name
private String m_name;
// Pseudo file details
private PseudoFile m_pseudoFile;
// Desktop action attributes
private int m_attributes;
// Desktop action client side pre-processing control
private int m_clientPreActions;
// Filesystem driver and context
private ContentDiskDriver m_contentDriver;
private ContentContext m_contentContext;
// Webapp URL
private String m_webappURL;
// Debug enable flag
private boolean m_debug;
/**
* Default constructor
*/
protected DesktopAction()
{
}
/**
* Class constructor
*
* @param attr int
* @param preActions int
*/
protected DesktopAction(int attr, int preActions)
{
setAttributes(attr);
setPreProcessActions(preActions);
}
/**
* Class constructor
*
* @param name String
*/
protected DesktopAction(String name)
{
m_name = name;
}
/**
* Return the desktop action attributes
*
* @return int
*/
public final int getAttributes()
{
return m_attributes;
}
/**
* Check for a specified action attribute
*
* @param attr int
* @return boolean
*/
public final boolean hasAttribute(int attr)
{
return ( m_attributes & attr) != 0 ? true : false;
}
/**
* Return the desktop action pore-processing actions
*
* @return int
*/
public final int getPreProcessActions()
{
return m_clientPreActions;
}
/**
* Check for the specified pre-process action
*
* @param pre int
* @return boolean
*/
public final boolean hasPreProcessAction(int pre)
{
return (m_clientPreActions & pre) != 0 ? true : false;
}
/**
* Return the action name
*
* @return String
*/
public final String getName()
{
return m_name;
}
/**
* Check if the action has an associated pseudo file
*
* @return boolean
*/
public final boolean hasPseudoFile()
{
return m_pseudoFile != null ? true : false;
}
/**
* Return the associated pseudo file
*
* @return PseudoFile
*/
public final PseudoFile getPseudoFile()
{
return m_pseudoFile;
}
/**
* Return the content filesystem driver
*
* @return ContentDiskDriver
*/
public final ContentDiskDriver getDriver()
{
return m_contentDriver;
}
/**
* Return the filesystem context
*
* @return ContentContext
*/
public final ContentContext getContext()
{
return m_contentContext;
}
/**
* Return the action confirmation string to be displayed by the client application
*
* @return String
*/
public String getConfirmationString()
{
return null;
}
/**
* Check if debug output is enabled
*
* @return boolean
*/
public final boolean hasDebug()
{
return m_debug;
}
/**
* Check if the webapp URL is set
*
* @return boolean
*/
public final boolean hasWebappURL()
{
return m_webappURL != null ? true : false;
}
/**
* Return the webapp URL
*
* @return String
*/
public final String getWebappURL()
{
return m_webappURL;
}
/**
* Initialize the desktop action
*
* @param global ConfigElement
* @param config ConfigElement
* @param fileSys DiskSharedDevice
* @exception DesktopActionException
*/
public void initializeAction(ConfigElement global, ConfigElement config, DiskSharedDevice fileSys)
throws DesktopActionException
{
// Perform standard initialization
standardInitialize(global, config, fileSys);
}
/**
* Perform standard desktop action initialization
*
* @param global ConfigElement
* @param config ConfigElement
* @param fileSys DiskSharedDevice
* @exception DesktopActionException
*/
public void standardInitialize(ConfigElement global, ConfigElement config, DiskSharedDevice fileSys)
throws DesktopActionException
{
// Save the filesystem device and I/O handler
if ( fileSys.getDiskInterface() instanceof ContentDiskDriver)
{
m_contentDriver = (ContentDiskDriver) fileSys.getDiskInterface();
m_contentContext = (ContentContext) fileSys.getDiskContext();
}
else
throw new DesktopActionException("Desktop action requires content filesystem driver");
// Check for standard config values
ConfigElement elem = config.getChild("name");
if ( elem != null && elem.getValue().length() > 0)
{
// Set the action name
setName(elem.getValue());
}
else
throw new DesktopActionException("Desktop action name not specified");
// Get the pseudo file name
ConfigElement name = config.getChild("filename");
if ( name == null || name.getValue() == null || name.getValue().length() == 0)
throw new DesktopActionException("Desktop action pseudo name not specified");
// Get the local path to the executable
ConfigElement path = findConfigElement("path", global, config);
if ( path == null || path.getValue() == null || path.getValue().length() == 0)
throw new DesktopActionException("Desktop action executable path not specified");
// Check that the application exists on the local filesystem
URL appURL = this.getClass().getClassLoader().getResource(path.getValue());
if ( appURL == null)
throw new DesktopActionException("Failed to find drag and drop application, " + path.getValue());
// Decode the URL path, it might contain escaped characters
String appURLPath = null;
try
{
appURLPath = URLDecoder.decode( appURL.getFile(), "UTF-8");
}
catch ( UnsupportedEncodingException ex)
{
throw new DesktopActionException("Failed to decode drag/drop path, " + ex.getMessage());
}
// Check that the drag/drop file exists
File appFile = new File(appURLPath);
if ( appFile.exists() == false)
throw new DesktopActionException("Drag and drop application not found, " + path.getValue());
// Create the pseudo file for the action
PseudoFile pseudoFile = new LocalPseudoFile(name.getValue(), appFile.getAbsolutePath());
setPseudoFile(pseudoFile);
// Check if confirmations should be switched off for the action
if ( findConfigElement("noConfirm", global, config) != null && hasPreProcessAction(PreConfirmAction))
setPreProcessActions(getPreProcessActions() - PreConfirmAction);
// Check if the webapp URL has been specified
ConfigElement webURL = findConfigElement("webpath", global, config);
if ( webURL != null)
{
// Check if the path name contains the local name token
String webPath = webURL.getValue();
if ( webPath.endsWith("/") == false)
webPath = webPath + "/";
int pos = webPath.indexOf(TokenLocalName);
if (pos != -1)
{
// Get the local server name
String srvName = "localhost";
try
{
srvName = InetAddress.getLocalHost().getHostName();
}
catch ( Exception ex)
{
}
// Rebuild the host name substituting the token with the local server name
StringBuilder hostStr = new StringBuilder();
hostStr.append(webPath.substring(0, pos));
hostStr.append(srvName);
pos += TokenLocalName.length();
if (pos < webPath.length())
hostStr.append(webPath.substring(pos));
webPath = hostStr.toString();
setWebappURL( webPath);
}
}
// Check if debug output is enabled for the action
ConfigElement debug = findConfigElement("debug", global, config);
if ( debug != null)
setDebug(true);
// DEBUG
if ( logger.isDebugEnabled() && hasDebug())
logger.debug("Initialized desktop action " + getName() + ", pseudo name " + name.getValue());
}
/**
* Find the required configuration element in the local or global config
*
* @param name String
* @param global ConfigElement
* @param local configElement
* @return ConfigElement
*/
private final ConfigElement findConfigElement(String name, ConfigElement global, ConfigElement local)
{
// Check if the required setting is in the local config
ConfigElement elem = local.getChild(name);
if ( elem == null && global != null)
elem = global.getChild(name);
return elem;
}
/**
* Run the desktop action
*
* @param params DesktopParams
* @return DesktopResponse
* @exception
*/
public abstract DesktopResponse runAction(DesktopParams params)
throws DesktopActionException;
/**
* Return the CIFS helper
*
* @return CifsHelper
*/
protected final CifsHelper getCifsHelper()
{
return m_contentDriver.getCifsHelper();
}
/**
* Return the transaction service
*
* @return TransactionService
*/
protected final TransactionService getTransactionService()
{
return m_contentDriver.getTransactionService();
}
/**
* Return the node service
*
* @return NodeService
*/
protected final NodeService getNodeService()
{
return m_contentDriver.getNodeService();
}
/**
* Return the content service
*
* @return ContentService
*/
public final ContentService getContentService()
{
return m_contentDriver.getContentService();
}
/**
* Return the namespace service
*
* @return NamespaceService
*/
public final NamespaceService getNamespaceService()
{
return m_contentDriver.getNamespaceService();
}
/**
* Return the search service
*
* @return SearchService
*/
public final SearchService getSearchService()
{
return m_contentDriver.getSearchService();
}
/**
* Return the service registry
*
* @return ServiceRegistry
*/
public final ServiceRegistry getServiceRegistry()
{
return m_contentDriver.getServiceRegistry();
}
/**
* Set the action attributes
*
* @param attr int
*/
protected final void setAttributes(int attr)
{
m_attributes = attr;
}
/**
* Set the client side pre-processing actions
*
* @param pre int
*/
protected final void setPreProcessActions(int pre)
{
m_clientPreActions = pre;
}
/**
* Set the action name
*
* @param name String
*/
protected final void setName(String name)
{
m_name = name;
}
/**
* Set the associated pseudo file
*
* @param pseudoFile PseudoFile
*/
protected final void setPseudoFile(PseudoFile pseudoFile)
{
m_pseudoFile = pseudoFile;
}
/**
* Enable debug output
*
* @param ena boolean
*/
protected final void setDebug(boolean ena)
{
m_debug = ena;
}
/**
* Set the webapp URL
*
* @param urlStr String
*/
public final void setWebappURL(String urlStr)
{
m_webappURL = urlStr;
}
/**
* Equality check
*
* @param obj Object
* @return boolean
*/
@Override
public boolean equals(Object obj)
{
if ( obj instanceof DesktopAction)
{
DesktopAction action = (DesktopAction) obj;
return action.getName().equals(getName());
}
return false;
}
/**
* Return the desktop action details as a string
*
* @return String
*/
public String toString()
{
StringBuilder str = new StringBuilder();
str.append("[");
str.append(getName());
str.append(":Attr=0x");
str.append(Integer.toHexString(getAttributes()));
str.append(":Pre=0x");
str.append(Integer.toHexString(getPreProcessActions()));
if ( hasPseudoFile())
{
str.append(":Pseudo=");
str.append(getPseudoFile().getFileName());
}
str.append("]");
return str.toString();
}
}

View File

@@ -1,75 +0,0 @@
/*
* 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.smb.server.repo;
/**
* Desktop Action Exception Class
*
* @author gkspencer
*/
public class DesktopActionException extends Exception {
private static final long serialVersionUID = 1006648817889605047L;
// Status code
private int m_stsCode;
/**
* Class constructor
*
* @param sts int
* @param msg String
*/
public DesktopActionException(int sts, String msg)
{
super(msg);
m_stsCode = sts;
}
/**
* Class constructor
*
* @param s String
*/
public DesktopActionException(String s)
{
super(s);
}
/**
* Class constructor
*
* @param s String
* @param ex Exception
*/
public DesktopActionException(String s, Throwable ex)
{
super(s, ex);
}
/**
* Return the status code
*
* @return int
*/
public final int getStatusCode()
{
return m_stsCode;
}
}

View File

@@ -1,118 +0,0 @@
/*
* 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.smb.server.repo;
import java.util.Enumeration;
import java.util.Hashtable;
/**
* Desktop Action Table Class
*
* <p>Contains a list of desktop actions indexed by action name.
*
* @author gkspencer
*/
public class DesktopActionTable {
// Table of actions, indexed by action name and pseudo file name
private Hashtable<String, DesktopAction> m_actions;
private Hashtable<String, DesktopAction> m_actionsPseudo;
/**
* Default constructor
*/
public DesktopActionTable()
{
m_actions = new Hashtable<String, DesktopAction>();
m_actionsPseudo = new Hashtable<String, DesktopAction>();
}
/**
* Find a named action
*
* @param name String
* @return DesktopAction
*/
public final DesktopAction getAction(String name)
{
return m_actions.get(name);
}
/**
* Find an action via the pseudo file name
*
* @param pseudoName String
* @return DesktopAction
*/
public final DesktopAction getActionViaPseudoName(String pseudoName)
{
return m_actionsPseudo.get(pseudoName.toUpperCase());
}
/**
* Return the count of actions
*
* @return int
*/
public final int numberOfActions()
{
return m_actions.size();
}
/**
* Add an action
*
* @param action DesktopAction
* @return boolean
*/
public final boolean addAction(DesktopAction action)
{
if ( m_actions.get( action.getName()) == null)
{
m_actions.put(action.getName(), action);
m_actionsPseudo.put(action.getPseudoFile().getFileName().toUpperCase(), action);
return true;
}
return false;
}
/**
* Enumerate the action names
*
* @return Enumeration<String>
*/
public final Enumeration<String> enumerateActionNames()
{
return m_actions.keys();
}
/**
* Remove an action
*
* @param name String
* @return DesktopAction
*/
public final DesktopAction removeAction(String name)
{
DesktopAction action = m_actions.remove(name);
if ( action != null)
m_actionsPseudo.remove(action.getPseudoFile().getFileName().toUpperCase());
return action;
}
}

View File

@@ -1,180 +0,0 @@
/*
* 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.smb.server.repo;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.filesys.server.SrvSession;
import org.alfresco.filesys.server.auth.ClientInfo;
import org.alfresco.filesys.server.filesys.NetworkFile;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Desktop Parameters Class
*
* <p>Contains the parameters for a desktop action request from the client side application.
*
* @author gkspencer
*/
public class DesktopParams {
// File server session
private SrvSession m_session;
// Folder node that the actions are working in
private NodeRef m_folderNode;
// Network file for the folder node
private NetworkFile m_folderFile;
// List of file/folder/node targets for the action
private List<DesktopTarget> m_targets;
/**
* Default constructor
*/
public DesktopParams()
{
}
/**
* Class constructor
*
* @param sess SrvSession
* @param folderNode NodeRef
* @param folderFile NetworkFile
*/
public DesktopParams(SrvSession sess, NodeRef folderNode, NetworkFile folderFile)
{
m_session = sess;
m_folderNode = folderNode;
m_folderFile = folderFile;
}
/**
* Return the count of target nodes for the action
*
* @return int
*/
public final int numberOfTargetNodes()
{
return m_targets != null ? m_targets.size() : 0;
}
/**
* Return the file server session
*
* @return SrvSession
*/
public final SrvSession getSession()
{
return m_session;
}
/**
* Return the authentication ticket for the user/session
*
* @return String
*/
public final String getTicket()
{
ClientInfo cInfo = m_session.getClientInformation();
if ( cInfo != null)
return cInfo.getAuthenticationTicket();
return null;
}
/**
* Return the working directory node
*
* @return NodeRef
*/
public final NodeRef getFolderNode()
{
return m_folderNode;
}
/**
* Return the folder network file
*
* @return NetworkFile
*/
public final NetworkFile getFolder()
{
return m_folderFile;
}
/**
* Set the folder network file
*
* @param netFile NetworkFile
*/
public final void setFolder(NetworkFile netFile)
{
m_folderFile = netFile;
}
/**
* Return the required target
*
* @param idx int
* @return DesktopTarget
*/
public final DesktopTarget getTarget(int idx)
{
DesktopTarget deskTarget = null;
if ( m_targets != null && idx >= 0 && idx < m_targets.size())
deskTarget = m_targets.get(idx);
return deskTarget;
}
/**
* Add a target node for the action
*
* @param target DesktopTarget
*/
public final void addTarget(DesktopTarget target)
{
if ( m_targets == null)
m_targets = new ArrayList<DesktopTarget>();
m_targets.add(target);
}
/**
* Return the desktop parameters as a string
*
* @return String
*/
public String toString()
{
StringBuilder str = new StringBuilder();
str.append("[");
str.append("Targets=");
str.append(numberOfTargetNodes());
str.append("]");
return str.toString();
}
}

View File

@@ -1,237 +0,0 @@
/*
* 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.smb.server.repo;
import java.util.ArrayList;
import java.util.List;
import org.mozilla.javascript.ScriptableObject;
/**
* Desktop Response Class
*
* <p>Holds the status code, optional status message and optional values returned by a desktop action.
*
* @author gkspencer
*/
public class DesktopResponse extends ScriptableObject {
// Version id
private static final long serialVersionUID = 6421278986221629296L;
// Desktop action status and optional status message
private int m_status;
private String m_statusMsg;
// Optional return values
private List<Object> m_responseValues;
/**
* Class constructor
*
* @param sts int
*/
public DesktopResponse(int sts)
{
m_status = sts;
}
/**
* Class constructor
*
* @param sts int
* @param msg String
*/
public DesktopResponse(int sts, String msg)
{
m_status = sts;
m_statusMsg = msg;
}
/**
* Javascript constructor
*
* @param sts int
* @param msg String
*/
public void jsConstructor(int sts, String msg)
{
m_status = sts;
m_statusMsg = msg;
}
/**
* Return the class name
*
* @return String
*/
@Override
public String getClassName() {
return "DesktopResponse";
}
/**
* Return the status code
*
* @return int
*/
public final int getStatus()
{
return m_status;
}
/**
* Return the status property
*
* @return int
*/
public int jsGet_status()
{
return m_status;
}
/**
* Determine if there is an optional status message
*
* @return boolean
*/
public final boolean hasStatusMessage()
{
return m_statusMsg != null ? true : false;
}
/**
* Return the status message
*
* @return String
*/
public final String getStatusMessage()
{
return m_statusMsg;
}
/**
* Return the status message property
*
* @return String
*/
public String jsGet_message()
{
return m_statusMsg != null ? m_statusMsg : "";
}
/**
* Determine if there are optional response values
*
* @return boolean
*/
public final boolean hasResponseValues()
{
return m_responseValues != null ? true : false;
}
/**
* Return the count of response values
*
* @return int
*/
public final int numberOfResponseValues()
{
return m_responseValues != null ? m_responseValues.size() : 0;
}
/**
* Get the response value list
*
* @return List<Object>
*/
public final List<Object> getResponseValues()
{
return m_responseValues;
}
/**
* Add a response value
*
* @param respObj Object
*/
public final void addResponseValue(Object respObj)
{
if ( m_responseValues == null)
m_responseValues = new ArrayList<Object>();
m_responseValues.add(respObj);
}
/**
* Set the status code and message
*
* @param sts int
* @param msg String
*/
public final void setStatus(int sts, String msg)
{
m_status = sts;
m_statusMsg = msg;
}
/**
* Set the status property
*
* @param sts int
*/
public void jsSet_status(int sts)
{
m_status = sts;
}
/**
* Set the status message property
*
* @param msg String
*/
public void jsSet_message(String msg)
{
m_statusMsg = msg;
}
/**
* Return the desktop response as a string
*
* @return String
*/
public String toString()
{
StringBuilder str = new StringBuilder();
str.append("[");
str.append(getStatus());
str.append(":");
if ( hasStatusMessage())
str.append(getStatusMessage());
else
str.append("<NoMsg>");
str.append(":Values=");
str.append(numberOfResponseValues());
str.append("]");
return str.toString();
}
}

View File

@@ -1,166 +0,0 @@
/*
* 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.smb.server.repo;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Desktop Target Class
*
* <p>Contains the details of a target file/folder/node for a desktop action.
*
* @author gkspencer
*/
public class DesktopTarget {
// Desktop target types
public static final int TargetFile = 0;
public static final int TargetFolder = 1;
public static final int TargetCopiedFile = 2;
public static final int TargetCopiedFolder = 3;
public static final int TargetNodeRef = 4;
// Target type
private int m_type;
// Target path/id
private String m_target;
// Associated noderef
private NodeRef m_noderef;
/**
* class constructor
*
* @param typ int
* @param path String
*/
public DesktopTarget(int typ, String path)
{
m_type = typ;
m_target = path;
}
/**
* Return the target type
*
* @return int
*/
public final int isType()
{
return m_type;
}
/**
* Return the target path/id
*
* @return String
*/
public final String getTarget()
{
return m_target;
}
/**
* Check if the associated node is valid
*
* @return boolean
*/
public final boolean hasNodeRef()
{
return m_noderef != null ? true : false;
}
/**
* Return the associated node
*
* @return NodeRef
*/
public final NodeRef getNode()
{
return m_noderef;
}
/**
* Return the target type as a string
*
* @return String
*/
public final String getTypeAsString()
{
String str = null;
switch( isType())
{
case TargetFile:
str = "File";
break;
case TargetFolder:
str = "Folder";
break;
case TargetCopiedFile:
str = "File Copy";
break;
case TargetCopiedFolder:
str = "Folder Copy";
break;
case TargetNodeRef:
str = "NodeRef";
break;
}
return str;
}
/**
* Set the associated node
*
* @param node NodeRef
*/
public final void setNode(NodeRef node)
{
m_noderef = node;
}
/**
* Return the desktop target as a string
*
* @return String
*/
public String toString()
{
StringBuilder str = new StringBuilder();
str.append("[");
str.append(getTypeAsString());
str.append(":");
str.append(getTarget());
if ( hasNodeRef())
{
str.append(":");
str.append(getNode());
}
str.append("]");
return str.toString();
}
}

View File

@@ -1,65 +0,0 @@
/*
* 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.smb.server.repo;
import org.alfresco.filesys.smb.NTIOCtl;
/**
* Content Disk Driver I/O Control Codes Class
*
* <p>Contains I/O control codes and status codes used by the content disk driver I/O control
* implementation.
*
* @author gkspencer
*/
public class IOControl
{
// Custom I/O control codes
public static final int CmdProbe = NTIOCtl.FsCtlCustom;
public static final int CmdFileStatus = NTIOCtl.FsCtlCustom + 1;
// Version 1 CmdCheckOut = NTIOCtl.FsCtlCustom + 2
// Version 1 CmdCheckIn = NTIOCtl.FsCtlCustom + 3
public static final int CmdGetActionInfo = NTIOCtl.FsCtlCustom + 4;
public static final int CmdRunAction = NTIOCtl.FsCtlCustom + 5;
// I/O control request/response signature
public static final String Signature = "ALFRESCO";
// I/O control interface version id
public static final int Version = 2;
// Boolean field values
public static final int True = 1;
public static final int False = 0;
// File status field values
//
// Node type
public static final int TypeFile = 0;
public static final int TypeFolder = 1;
// Lock status
public static final int LockNone = 0;
public static final int LockRead = 1;
public static final int LockWrite = 2;
}

View File

@@ -1,39 +0,0 @@
/*
* 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.smb.server.repo;
import org.alfresco.filesys.server.filesys.IOCtlInterface;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.transaction.TransactionService;
/**
* I/O Control Handler Interface
*
* @author gkspencer
*/
public interface IOControlHandler extends IOCtlInterface
{
/**
* Initialize the I/O control handler
*
*
* @param contentDriver ContentDiskDriver
* @param contentContext ContentContext
*/
public void initialize( ContentDiskDriver contentDriver, ContentContext contentContext);
}

View File

@@ -20,15 +20,17 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.filesys.alfresco.DesktopAction;
import org.alfresco.filesys.alfresco.DesktopParams;
import org.alfresco.filesys.alfresco.DesktopResponse;
import org.alfresco.filesys.alfresco.DesktopTarget;
import org.alfresco.filesys.server.filesys.FileName;
import org.alfresco.filesys.server.filesys.NotifyChange;
import org.alfresco.filesys.smb.server.repo.DesktopAction;
import org.alfresco.filesys.smb.server.repo.DesktopParams;
import org.alfresco.filesys.smb.server.repo.DesktopResponse;
import org.alfresco.filesys.smb.server.repo.DesktopTarget;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.transaction.TransactionService;
/**
* Check In/Out Desktop Action Class
@@ -75,9 +77,14 @@ public class CheckInOutDesktopAction extends DesktopAction {
if ( params.numberOfTargetNodes() == 0)
return new DesktopResponse(StsSuccess);
// Get required services
TransactionService transService = getServiceRegistry().getTransactionService();
NodeService nodeService = getServiceRegistry().getNodeService();
// Start a transaction
params.getSession().beginTransaction(getTransactionService(), false);
params.getSession().beginTransaction( transService, false);
// Process the list of target nodes
@@ -91,7 +98,7 @@ public class CheckInOutDesktopAction extends DesktopAction {
// Check if the node is a working copy
if ( getNodeService().hasAspect( target.getNode(), ContentModel.ASPECT_WORKING_COPY))
if ( nodeService.hasAspect( target.getNode(), ContentModel.ASPECT_WORKING_COPY))
{
try
{
@@ -144,11 +151,11 @@ public class CheckInOutDesktopAction extends DesktopAction {
{
// Check if the file is locked
if ( getNodeService().hasAspect( target.getNode(), ContentModel.ASPECT_LOCKABLE)) {
if ( nodeService.hasAspect( target.getNode(), ContentModel.ASPECT_LOCKABLE)) {
// Get the lock type
String lockTypeStr = (String) getNodeService().getProperty( target.getNode(), ContentModel.PROP_LOCK_TYPE);
String lockTypeStr = (String) nodeService.getProperty( target.getNode(), ContentModel.PROP_LOCK_TYPE);
if ( lockTypeStr != null) {
response.setStatus(StsError, "Checkout failed, file is locked");
return response;
@@ -161,7 +168,7 @@ public class CheckInOutDesktopAction extends DesktopAction {
// Get the working copy file name
String workingCopyName = (String) getNodeService().getProperty( workingCopyNode, ContentModel.PROP_NAME);
String workingCopyName = (String) nodeService.getProperty( workingCopyNode, ContentModel.PROP_NAME);
// Check out was successful, pack the working copy name

View File

@@ -16,9 +16,9 @@
*/
package org.alfresco.filesys.smb.server.repo.desk;
import org.alfresco.filesys.smb.server.repo.DesktopAction;
import org.alfresco.filesys.smb.server.repo.DesktopParams;
import org.alfresco.filesys.smb.server.repo.DesktopResponse;
import org.alfresco.filesys.alfresco.DesktopAction;
import org.alfresco.filesys.alfresco.DesktopParams;
import org.alfresco.filesys.alfresco.DesktopResponse;
/**
* Command Line Desktop Action Class

View File

@@ -18,9 +18,9 @@ package org.alfresco.filesys.smb.server.repo.desk;
import java.util.Date;
import org.alfresco.filesys.smb.server.repo.DesktopAction;
import org.alfresco.filesys.smb.server.repo.DesktopParams;
import org.alfresco.filesys.smb.server.repo.DesktopResponse;
import org.alfresco.filesys.alfresco.DesktopAction;
import org.alfresco.filesys.alfresco.DesktopParams;
import org.alfresco.filesys.alfresco.DesktopResponse;
/**
* Echo Desktop Action Class

View File

@@ -29,13 +29,14 @@ import java.util.Map;
import java.util.StringTokenizer;
import org.alfresco.config.ConfigElement;
import org.alfresco.filesys.alfresco.DesktopAction;
import org.alfresco.filesys.alfresco.DesktopActionException;
import org.alfresco.filesys.alfresco.DesktopParams;
import org.alfresco.filesys.alfresco.DesktopResponse;
import org.alfresco.filesys.server.filesys.DiskSharedDevice;
import org.alfresco.filesys.smb.server.repo.DesktopAction;
import org.alfresco.filesys.smb.server.repo.DesktopActionException;
import org.alfresco.filesys.smb.server.repo.DesktopParams;
import org.alfresco.filesys.smb.server.repo.DesktopResponse;
import org.alfresco.service.cmr.repository.ScriptException;
import org.alfresco.service.cmr.repository.ScriptService;
import org.alfresco.service.transaction.TransactionService;
/**
* Javascript Desktop Action Class
@@ -272,7 +273,8 @@ public class JavaScriptDesktopAction extends DesktopAction {
// Start a transaction
params.getSession().beginTransaction(getTransactionService(), false);
TransactionService transService = getServiceRegistry().getTransactionService();
params.getSession().beginTransaction( transService, false);
// Access the script service
@@ -291,7 +293,7 @@ public class JavaScriptDesktopAction extends DesktopAction {
// Start a transaction
params.getSession().beginTransaction(getTransactionService(), false);
params.getSession().beginTransaction( transService, false);
// Run the script

View File

@@ -19,9 +19,10 @@ package org.alfresco.filesys.smb.server.repo.desk;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.alfresco.filesys.smb.server.repo.DesktopAction;
import org.alfresco.filesys.smb.server.repo.DesktopParams;
import org.alfresco.filesys.smb.server.repo.DesktopResponse;
import org.alfresco.filesys.alfresco.DesktopAction;
import org.alfresco.filesys.alfresco.DesktopParams;
import org.alfresco.filesys.alfresco.DesktopResponse;
/**
* URL Desktop Action Class

View File

@@ -1,284 +0,0 @@
/*
* 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.smb.server.repo.pseudo;
import java.util.Enumeration;
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.state.FileState;
import org.alfresco.filesys.smb.server.SMBSrvSession;
import org.alfresco.filesys.smb.server.repo.ContentContext;
import org.alfresco.filesys.smb.server.repo.DesktopAction;
import org.alfresco.filesys.smb.server.repo.DesktopActionTable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Content Filesystem Driver Pseudo File Implementation
*
* <p>Pseudo file implementation for the content disk driver.
*
* @author gkspencer
*/
public class ContentPseudoFileImpl implements PseudoFileInterface
{
// Logging
private static final Log logger = LogFactory.getLog(ContentPseudoFileImpl.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;
}
}

View File

@@ -1,110 +0,0 @@
/*
* 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.smb.server.repo.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 ( m_fileInfo == null) {
// Get the file details
File localFile = new File( getFilePath());
if ( localFile.exists())
{
// Create the file information
m_fileInfo = new FileInfo( getFileName(), localFile.length(), getAttributes());
// Set the file creation/modification times
m_fileInfo.setModifyDateTime( localFile.lastModified());
m_fileInfo.setCreationDateTime( _creationDateTime);
m_fileInfo.setChangeDateTime( _creationDateTime);
// Set the allocation size, round up the actual length
m_fileInfo.setAllocationSize(( localFile.length() + 512L) & 0xFFFFFFFFFFFFFE00L);
}
}
// Return the file information
return m_fileInfo;
}
/**
* 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);
}
}

View File

@@ -1,252 +0,0 @@
/*
* 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.smb.server.repo.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;
// End of file flag
private boolean m_eof;
/**
* 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);
m_eof = false;
// 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
}
}

View File

@@ -1,95 +0,0 @@
/*
* 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.smb.server.repo.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 ( m_fileInfo == null) {
// Create the file information
m_fileInfo = new FileInfo( getFileName(), m_data != null ? m_data.length : 0, getAttributes());
// Set the file creation/modification times
m_fileInfo.setCreationDateTime( _creationDateTime);
m_fileInfo.setModifyDateTime( _creationDateTime);
m_fileInfo.setChangeDateTime( _creationDateTime);
// Set the allocation size, round up the actual length
m_fileInfo.setAllocationSize(( m_fileInfo.getSize() + 512L) & 0xFFFFFFFFFFFFFE00L);
}
// Return the file information
return m_fileInfo;
}
/**
* 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);
}
}

View File

@@ -1,126 +0,0 @@
/*
* 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.smb.server.repo.pseudo;
import java.io.File;
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
protected 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;
}
/**
* 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);
/**
* 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();
}
}

View File

@@ -1,70 +0,0 @@
/*
* 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.smb.server.repo.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);
}

View File

@@ -1,147 +0,0 @@
/*
* 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.smb.server.repo.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;
}
}

View File

@@ -1,302 +0,0 @@
/*
* 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.smb.server.repo.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
}
}