View Javadoc

1   /**
2    * 
3    */
4   package net.sf.jpkgmk;
5   
6   import java.io.File;
7   
8   /**
9    * @author gommma (gommma AT users.sourceforge.net)
10   * @author Last changed by: $Author: gommma $
11   * @version $Revision: 2 $ $Date: 2008-08-20 21:14:19 +0200 (Mi, 20 Aug 2008) $
12   * @since 1.0
13   */
14  public class DefaultPermissionProvider implements PermissionProvider
15  {
16  	private String defaultDirectoryMode = "0550";
17  	private String defaultExecutableMode = "0550";
18  	private String defaultFileMode = "0440";
19  	
20  	/**
21  	 * @return Returns the 4 bit permissions to be set for the given file in the prototype
22  	 */
23  	public String getMode(File file){
24  		if(file.isDirectory()) {
25  			return defaultDirectoryMode;
26  		}
27  		else {
28  			String filename = file.getName();
29  			// Try to guess whether the file should be executable
30  			if(filename.endsWith(".sh") || filename.endsWith(".bat")) {
31  				return defaultExecutableMode;
32  			}
33  			// Default is just read for user and group
34  			return defaultFileMode;
35  		}
36  	}
37  	
38  	@Override
39  	public String toString()
40  	{
41  		StringBuffer sb = new StringBuffer();
42  		sb.append(getClass().getName()).append("[");
43  		sb.append("defaultDirectoryMode=").append(defaultDirectoryMode);
44  		sb.append(",defaultExecutableMode=").append(defaultExecutableMode);
45  		sb.append(",defaultFileMode=").append(defaultFileMode);
46  		sb.append("]");
47  		return sb.toString();
48  	}
49  
50  }