1 19 package org.netbeans.modules.xml.schema.completion; 20 21 import java.io.BufferedReader ; 22 import java.io.File ; 23 import java.io.InputStream ; 24 import java.io.InputStreamReader ; 25 import java.net.URL ; 26 import javax.swing.text.Document ; 27 import org.netbeans.editor.BaseDocument; 28 import org.netbeans.modules.xml.text.syntax.XMLKit; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileUtil; 31 32 36 public class Util { 37 38 private Util() { 39 } 40 41 public static FileObject getResourceAsFileObject(String path) throws Exception { 42 URL url = Util.class.getResource(path); 43 File file = new File (url.toURI()); 44 file = FileUtil.normalizeFile(file); 45 FileObject fileObj = FileUtil.toFileObject(file); 46 return fileObj; 47 } 48 49 public static Document getResourceAsDocument(String path) throws Exception { 50 InputStream in = Util.class.getResourceAsStream(path); 51 Document sd = new BaseDocument(XMLKit.class, false); 52 BufferedReader br = new BufferedReader (new InputStreamReader (in,"UTF-8")); 53 StringBuffer sbuf = new StringBuffer (); 54 try { 55 String line = null; 56 while ((line = br.readLine()) != null) { 57 sbuf.append(line); 58 sbuf.append(System.getProperty("line.separator")); 59 } 60 } finally { 61 br.close(); 62 } 63 sd.insertString(0,sbuf.toString(),null); 64 return sd; 65 } 66 67 } 68 | Popular Tags |