View Javadoc

1   package net.sf.jpkgmk.prototype;
2   
3   import java.io.File;
4   import java.io.IOException;
5   
6   import net.sf.jpkgmk.pkgmap.PkgMapEntry;
7   import net.sf.jpkgmk.pkgmap.PkgMapEntryFile;
8   import net.sf.jpkgmk.pkgmap.PkgMapEntryType;
9   import net.sf.jpkgmk.util.FileUtil;
10  
11  /**
12   * @author gommma (gommma AT users.sourceforge.net)
13   * @author Last changed by: $Author: gommma $
14   * @version $Revision: 2 $ $Date: 2008-08-20 21:14:19 +0200 (Mi, 20 Aug 2008) $
15   * @since 1.0
16   */
17  public class PrototypeEntryDirectory extends AbstractPrototypeEntry {
18  
19  	
20  	/**
21  	 * Minimum constructor
22  	 * @param entryPath path to the file or directory
23  	 * @param mode
24  	 * @param owner
25  	 * @param group
26  	 */
27  	public PrototypeEntryDirectory(String entryPath, String mode, String owner, String group)
28  	{
29  		this(null, null, entryPath, mode, owner, group, null);
30  		
31  	}
32  
33  	/**
34  	 * Full constructor taking all possible arguments
35  	 * @param part
36  	 * @param fileClass
37  	 * @param entryPath
38  	 * @param mode
39  	 * @param owner
40  	 * @param group
41  	 * @param entryCommandDefault
42  	 */
43  	public PrototypeEntryDirectory(Integer part, String fileClass, String entryPath, String mode, String owner, String group, PrototypeEntryCommandDefault entryCommandDefault)
44  	{
45  		this(part, PrototypeEntryType.D, fileClass, entryPath, null, mode, owner, group, entryCommandDefault);
46  	}
47  	
48  	protected PrototypeEntryDirectory(Integer part, PrototypeEntryType type, String fileClass, String entryPath, String entryPathSource, String mode, String owner, String group, PrototypeEntryCommandDefault entryCommandDefault)
49  	{
50  		super(part, type, fileClass, entryPath, entryPathSource, mode, owner, group, entryCommandDefault);
51  		validate();
52  	}
53  
54  
55  	private void validate() {
56  		// Mandatory parameter check
57  		if(getEntryPath() == null) {
58  			throw new NullPointerException("The parameter 'entryPath' must not be null");
59  		}
60  	}
61  
62  	@Override
63  	protected void create(File targetDir, String entryPathExpanded,
64  			String entryPathSourceExpanded) throws IOException {
65  		
66  		File target = buildAbsolutePath(targetDir, entryPathExpanded);
67  		
68  		// the entry path must be in the target dir
69  		if(!FileUtil.isSubdir(target, targetDir)) {
70  			throw new IllegalStateException("The target file " + target + " must be in the target dir '" + targetDir + "'");
71  		}
72  
73  		FileUtil.createDir(target, true);
74  	}
75  
76  	@Override
77  	protected PkgMapEntry createPkgMapEntry(Integer part,
78  			PkgMapEntryType resultType, String entryClass, String path, String entryPathSource,
79  			Integer major, Integer minor, String mode, String owner, String group, File basedir) {
80  		return new PkgMapEntryFile(part, resultType, entryClass, path, mode, owner, group);
81  	}
82  
83  	
84  	public static class PrototypeEntryDirectoryParser extends AbstractPrototypeEntryParser implements PrototypeEntryParser
85  	{
86  		public PrototypeEntryDirectoryParser()
87  		{
88  			super();
89  		}
90  
91  		@Override
92  		protected PrototypeEntry parseItems(String[] items, Integer part, PrototypeEntryType type, int currentIndex, PrototypeEntryCommandDefault entryCommandDefault)
93  		{
94  
95  //			System.out.println(Arrays.asList(items));
96  			
97  			String fileClass = items[currentIndex++];
98  			String path = items[currentIndex++];
99  
100 			String mode = getArrayValue(items, currentIndex++);
101 			String owner = getArrayValue(items, currentIndex++);
102 			String group = getArrayValue(items, currentIndex++);
103 			
104 			return createPrototypeEntry(part, fileClass, path, mode, owner, group, entryCommandDefault);
105 		}
106 
107 		protected PrototypeEntry createPrototypeEntry(Integer part, String fileClass,
108 				String path, String mode, String owner, String group,
109 				PrototypeEntryCommandDefault entryCommandDefault) {
110 			PrototypeEntryDirectory entry = new PrototypeEntryDirectory(part, fileClass, path, mode, owner, group, entryCommandDefault);
111 			return entry;
112 		}
113 
114 
115 	}
116 
117 
118 
119 }