1 22 package org.enhydra.kelp.common.importer; 23 24 import org.enhydra.tool.ToolBoxInfo; 26 import org.enhydra.tool.common.PathHandle; 27 28 import java.io.File ; 30 import java.util.Vector ; 31 32 public class MakefileData { 34 private Vector docVector = new Vector (); 35 private Vector itemVector = new Vector (); 36 private String xmlcOptionFilePath = new String (); 37 private String xmlcParams = new String (); 38 39 private String packPath = new String (); 41 private String docPath = new String (); 42 private String makeParentPath = new String (); 43 private String sourcePath = new String (); 44 private String rootPath = new String (); 45 46 protected MakefileData(String makeParent, String source) { 47 makeParentPath = PathHandle.createPathString(makeParent); 48 sourcePath = PathHandle.createPathString(source); 49 rootPath = sourcePath; } 51 52 protected String getMakeParentPath() { 53 return makeParentPath; 54 } 55 56 protected String getSourcePath() { 57 return sourcePath; 58 } 59 60 protected void readRootPath(String p) { 61 rootPath = PathHandle.createPathString(getMakeParentPath() 62 + File.separator + p); 63 } 64 65 protected String getRootPath() { 66 return rootPath; 67 } 68 69 protected void readXMLCOptionFilePath(String p) { 70 xmlcOptionFilePath = PathHandle.createPathString(getMakeParentPath() 71 + File.separator + p); 72 } 73 74 protected String getXMLCOptionFilePath() { 75 return xmlcOptionFilePath; 76 } 77 78 protected void readPackagePath(String d) { 79 packPath = PathHandle.createPathString(sourcePath + File.separator 80 + d); 81 } 82 83 protected String getPackagePath() { 84 return packPath; 85 } 86 87 protected String getJavaPackage() { 88 String javaPack = new String (); 89 PathHandle sourceHandle = null; 90 PathHandle packHandle = null; 91 int index = -1; 92 93 sourceHandle = PathHandle.createPathHandle(getSourcePath()); 94 packHandle = PathHandle.createPathHandle(getPackagePath()); 95 if (sourceHandle.parentOf(packHandle)) { 96 index = packHandle.getPath().indexOf(sourceHandle.getPath()); 97 if (index > -1) { 98 javaPack = 99 packHandle.getPath().substring(sourceHandle.getPath().length() 100 + 1); 101 javaPack = javaPack.replace('/', '.'); 102 } 103 } 104 return javaPack; 105 } 106 107 protected void readDocPath(String p) { 108 int index = -1; 109 110 index = p.indexOf(')'); 111 if (index > 0) { 112 p = getRootPath() + p.substring(index + 1); 113 } else { 114 p = getMakeParentPath() + File.separator + p; 115 } 116 docPath = PathHandle.createPathString(p); 117 } 118 119 protected String getDocPath() { 120 return docPath; 121 } 122 123 protected void setXMLCParameters(String p) { 124 if (p == null) { 125 xmlcParams = new String (); 126 } else { 127 xmlcParams = p.trim(); 128 } 129 } 130 131 protected String getXMLCParameters() { 132 return xmlcParams; 133 } 134 135 protected void addSourceDocPath(String className) { 136 String docResourcePath = new String (); 137 String docSourcePath = new String (); 138 139 if ((className != null) && (className.trim().length() > 0)) { 140 docResourcePath = createSourceDocPath(getMakeParentPath(), 141 className); 142 docSourcePath = createSourceDocPath(getDocPath(), className); 143 File f = new File (docResourcePath); 144 145 if (f.exists()) { 146 docVector.addElement(docResourcePath); 147 } else { 148 f = new File (docSourcePath); 149 if (f.exists()) { 150 docVector.addElement(docSourcePath); 151 } 152 } 153 } 154 } 155 156 private String createSourceDocPath(String parentPath, String className) { 157 PathHandle handle = null; 158 String path = null; 159 String [] docTypes = ToolBoxInfo.getSupportedDocTypes(); 160 StringBuffer newPath = new StringBuffer (); 161 int extLength = 3; 162 163 handle = PathHandle.createPathHandle(parentPath + File.separator 164 + className); 165 path = handle.getPath(); 166 for (int i = 0; i < docTypes.length; i++) { 167 if (handle.endsWith(docTypes[i])) { 168 if (docTypes[i].length() > extLength) { 169 extLength = docTypes[i].length(); 170 } 171 } 172 } 173 newPath.append(path.substring(0, path.length() - extLength)); 174 newPath.append('.'); 175 newPath.append(path.substring(path.length() 176 - extLength).toLowerCase()); 177 return newPath.toString(); 178 } 179 180 protected String [] getSourceDocPaths() { 181 String [] paths = new String [docVector.size()]; 182 183 paths = (String []) docVector.toArray(paths); 184 return paths; 185 } 186 187 protected boolean containSourceDoc(String inPath) { 188 String [] docs = new String [0]; 189 PathHandle handle = null; 190 boolean contains = false; 191 192 docs = getSourceDocPaths(); 193 handle = PathHandle.createPathHandle(inPath); 194 for (int i = 0; i < docs.length; i++) { 195 if (handle.equals(docs[i])) { 196 contains = true; 197 break; 198 } 199 } 200 return contains; 201 } 202 203 protected void addItem(String i, String o) { 204 MakeItemData data = new MakeItemData(i, o); 205 206 itemVector.addElement(data); 207 } 208 209 protected MakeItemData[] getItems() { 210 MakeItemData[] items = new MakeItemData[itemVector.size()]; 211 212 items = (MakeItemData[]) itemVector.toArray(items); 213 return items; 214 } 215 216 protected boolean isSymbolic() { 217 boolean sym = false; 218 219 if (isXMLC()) { 220 PathHandle packHandle = null; 221 222 packHandle = PathHandle.createPathHandle(getPackagePath()); 223 if (packHandle.equals(getMakeParentPath())) { 224 225 } else { 227 sym = true; 228 } 229 } 230 return sym; 231 } 232 233 protected boolean isXMLC() { 234 boolean is = false; 235 StringBuffer buf = new StringBuffer (); 236 237 buf.append(getXMLCOptionFilePath()); 238 buf.append(getXMLCParameters()); 239 buf.append(getDocPath()); 240 if (buf.toString().trim().length() > 0) { 241 is = true; 242 } else if (getSourceDocPaths().length >= 1) { 243 is = true; 244 } else if (getItems().length >= 1) { 245 is = true; 246 } 247 return is; 248 } 249 250 public String toString() { 251 StringBuffer buf = new StringBuffer (); 252 253 buf.append("makeParentPath: " + getMakeParentPath() + '\n'); buf.append("sourcePath: " + getSourcePath() + '\n'); buf.append("rootPath: " + getRootPath() + '\n'); buf.append("packagePath: " + getPackagePath() + '\n'); buf.append("xmlcOptionFilePath: " + getXMLCOptionFilePath() + '\n'); buf.append("xmlcParameters: " + getXMLCParameters() + '\n'); buf.append("DocPath: " + getDocPath() + '\n'); String [] paths = getSourceDocPaths(); 261 262 for (int i = 0; i < paths.length; i++) { 263 buf.append("Class doc path: " + paths[i] + '\n'); } 265 MakeItemData[] ids = getItems(); 266 267 for (int i = 0; i < ids.length; i++) { 268 buf.append(ids[i].toString()); 269 buf.append('\n'); 270 } 271 return buf.toString(); 272 } 273 274 } 275 | Popular Tags |