View Javadoc

1   package org.catacomb.druid.manifest;
2   
3   import org.catacomb.report.E;
4   import org.catacomb.util.FileUtil;
5   
6   import java.io.File;
7   
8   
9   public class DecFile {
10  
11      public String directory;
12      public String name;
13      public String extension;
14  
15      public static final int CLASSPATH = 0;
16      public static final int FILE_SYSTEM = 1;
17      private int p_accessMethod;
18      private File p_rootFolder;
19  
20      private String p_fullID;
21      private String p_cachedText;
22      private Object p_cachedObject;
23  
24  
25  
26      public DecFile() {
27      }
28  
29  
30      public DecFile(String psf, String nm) {
31          directory = psf;
32          name = nm;
33          cutName();
34      }
35  
36  
37      public DecFile(File f, File rtFolder) {
38          p_accessMethod = FILE_SYSTEM;
39          p_rootFolder = rtFolder;
40  
41          name= f.getName();
42          directory = FileUtil.getRelativeDirectory(f, rtFolder);
43  
44          cutName();
45      }
46  
47  
48  
49  
50      public DecFile(String fullPath) {
51          if (fullPath.startsWith("file:")) {
52              String sp = fullPath.substring(5, fullPath.length());
53              File f = new File(sp);
54              directory = f.getParentFile().getAbsolutePath();
55              name = f.getName();
56              cutName();
57              setFileSystemAccess(new File("/"), "");
58          } else {
59              E.missing();
60          }
61      }
62  
63  
64      public String toString() {
65          return "decFile dir=" + directory + " name=" + name + " ext=" + extension +
66                 " access=" + p_accessMethod;
67  
68      }
69  
70  
71      private void cutName() {
72          if (name.endsWith(".xml")) {
73              name = name.substring(0, name.length() - 4);
74              extension = "xml";
75          } else {
76              extension = "";
77              E.error(" - DecFile in DecManifest only handles " + "extension .xml  so far");
78          }
79      }
80  
81  
82      public String getName() {
83          return name;
84      }
85  
86  
87      public String getDirectory() {
88          return directory;
89      }
90  
91  
92      public String getFullID() {
93          if (p_fullID == null) {
94              p_fullID = makeFullID();
95          }
96          return p_fullID;
97      }
98  
99  
100     private String makeFullID() {
101         if (directory == null) {
102             directory = "";
103             E.error("null directory in DecFile");
104         }
105         String sret = null;
106         if (directory.length() > 0) {
107             if (directory.endsWith("/")) {
108                 sret = directory + name;
109             } else {
110                 sret = directory + "/" + name;
111             }
112         } else {
113             sret = name;
114         }
115         sret = sret.replaceAll("/", ".");
116         return sret;
117     }
118 
119 
120     public void setFileSystemAccess(File fdir, String cproot) {
121         directory = cproot + directory;
122         p_accessMethod = FILE_SYSTEM;
123         p_rootFolder = fdir;
124     }
125 
126 
127     public void setClasspathAccess() {
128         p_accessMethod = CLASSPATH;
129     }
130 
131 
132     public boolean inClasspath() {
133         return (p_accessMethod == CLASSPATH);
134     }
135 
136 
137     public boolean inFileSystem() {
138         return (p_accessMethod == FILE_SYSTEM);
139     }
140 
141 
142     public void setCachedObject(Object obj) {
143         p_cachedObject = obj;
144     }
145 
146 
147     public boolean hasCachedObject() {
148         return (p_cachedObject != null);
149     }
150 
151 
152     public Object getCachedObject() {
153         return p_cachedObject;
154     }
155 
156 
157     public void setCachedText(String s) {
158         p_cachedText = s;
159     }
160 
161 
162     public boolean hasCachedText() {
163         return (p_cachedText != null);
164     }
165 
166 
167     public String getCachedText() {
168         return p_cachedText;
169     }
170 
171 
172     public void clearObjectCache() {
173         p_cachedObject = null;
174     }
175 
176 
177     public void clearTextCache() {
178         p_cachedText = null;
179     }
180 
181 
182     public File getSourceFile() {
183         String fnm = name + "." + extension;
184 
185         File fdir = null;
186         if (p_rootFolder != null) {
187             fdir = new File(p_rootFolder, directory);
188         } else {
189             fdir = new File(directory);
190         }
191         return new File(fdir, fnm);
192     }
193 
194 
195     public String getPath() {
196         String sd = directory;
197         if (sd == null || sd.length() == 0) {
198             sd = "";
199         } else {
200             sd = directory + "/'";
201         }
202         return sd + name + "." + extension;
203 
204     }
205 
206 
207 
208 }