Search in sources :

Example 6 with FileTypeMap

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;
}
Also used : ClassPath(com.kyj.fx.voeditor.visual.main.model.vo.ClassPath) InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) InputStreamReader(java.io.InputStreamReader) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Document(org.w3c.dom.Document) FileInputStream(java.io.FileInputStream) ClassPathEntry(com.kyj.fx.voeditor.visual.main.model.vo.ClassPathEntry) DocumentBuilder(javax.xml.parsers.DocumentBuilder) MimetypesFileTypeMap(javax.activation.MimetypesFileTypeMap) FileTypeMap(javax.activation.FileTypeMap) File(java.io.File)

Aggregations

FileTypeMap (javax.activation.FileTypeMap)6 MimetypesFileTypeMap (javax.activation.MimetypesFileTypeMap)4 ClassPath (com.kyj.fx.voeditor.visual.main.model.vo.ClassPath)1 ClassPathEntry (com.kyj.fx.voeditor.visual.main.model.vo.ClassPathEntry)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 HashMap (java.util.HashMap)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1 InputSource (org.xml.sax.InputSource)1