use of javax.activation.FileTypeMap in project Gargoyle by callakrsos.
the class FileSearcher method parsingClassPath.
// static class RuntimeJarLoader {
//
// public static void loadJarIndDir(String dir) {
// final URLClassLoader loader = (URLClassLoader)
// ClassLoader.getSystemClassLoader();
// loadJarIndDir(loader, dir);
// }
//
// public static void loadJarIndDir(ClassLoader loader, String dir) {
// try {
// final Method method = URLClassLoader.class.getDeclaredMethod("addURL",
// new Class[] { URL.class });
// method.setAccessible(true);
//
// new File(dir).listFiles(new FileFilter() {
// public boolean accept(File jar) {
// // jar 파일인 경우만 로딩
// if (jar.toString().toLowerCase().contains(".jar")) {
// try {
// // URLClassLoader.addURL(URL url) 메소드 호출
// method.invoke(loader, new Object[] { jar.toURI().toURL() });
// System.out.println(jar.getName() + " is loaded.");
// } catch (Exception e) {
// System.out.println(jar.getName() + " can't load.");
// }
// }
// return false;
// }
// });
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// }
// }
/**
* classPath의 정보를 파싱하여 데이터셋으로 반환
*
* @작성자 : KYJ
* @작성일 : 2015. 10. 26.
* @param filePathName
* @return
* @throws Exception
*/
public static ClassPath parsingClassPath(String filePathName) throws Exception {
DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = newInstance.newDocumentBuilder();
{
FileTypeMap defaultFileTypeMap = MimetypesFileTypeMap.getDefaultFileTypeMap();
String contentType = defaultFileTypeMap.getContentType(filePathName);
LOGGER.debug(String.format("File path Name : %s Content type : %s ", filePathName, contentType));
}
Reader reader = new InputStreamReader(new FileInputStream(new File(filePathName)), ENCODING);
InputSource is = new InputSource(reader);
Document parse = builder.parse(is);
ClassPath classPath = new ClassPath();
classPath.setFilePathName(filePathName);
classPath.setApplyedEncoding(ENCODING);
NodeList elementsByTagName2 = parse.getElementsByTagName("classpath");
int length = elementsByTagName2.getLength();
for (int i = 0; i < length; i++) {
Node classPathNode = elementsByTagName2.item(i);
NodeList childNodes = classPathNode.getChildNodes();
int classEntrySize = childNodes.getLength();
for (int e = 0; e < classEntrySize; e++) {
Node classEntryNode = childNodes.item(e);
NamedNodeMap attributes = classEntryNode.getAttributes();
if (attributes == null)
continue;
// 코드에서 필요로하는 부분만 XML을 파싱해서 데이터셋에 담는다.
String kind = emptyThan(attributes.getNamedItem("kind"));
String output = emptyThan(attributes.getNamedItem("output"));
String path = emptyThan(attributes.getNamedItem("path"));
ClassPathEntry classPathEntry = new ClassPathEntry(kind, output, path);
classPath.addEntry(classPathEntry);
}
}
return classPath;
}
Aggregations