1 9 package org.jboss.portal.test.setup; 10 11 import junit.framework.TestCase; 12 13 import java.io.File ; 14 import java.io.IOException ; 15 16 17 18 19 20 26 public class ContentLoaderTestCase extends TestCase 27 { 28 public ContentLoaderTestCase (String name) 29 { 30 super(name); 31 } 32 33 public void test1() throws Exception 34 { 35 String file = Thread.currentThread().getContextClassLoader().getResource("content").getFile(); 36 File content = new File (file); 37 if(content.isDirectory()) { 38 loadDirectory(content, null, false); 39 } 40 else { 41 loadFile(content, "content"); 42 } 43 } 44 48 public boolean loadDirectory(File dir, String parentUri, boolean add) throws IOException { 49 50 String nodeUri = null; 52 if(add) { 53 nodeUri = parentUri == null ? File.separatorChar + dir.getName() : parentUri + File.separator + dir.getName(); 54 } else { 55 nodeUri = parentUri; 56 } 57 58 File [] files = dir.listFiles(); 59 for ( int i=0; i<files.length; i++ ) { 60 if ( files[i].isDirectory() ) { 61 loadDirectory( files[i], nodeUri, true); 62 } 63 else { 64 loadFile( files[i], nodeUri); 65 } 66 } 67 return true; 68 } 69 70 private boolean loadFile(File file, String parentUri) throws IOException 71 { 72 73 74 if(parentUri == null) { 75 parentUri = "/files"; 76 } 77 String name = file.getName(); 78 String fileUri = parentUri + File.separatorChar + name; 79 80 String extension = name.substring(name.lastIndexOf('.')); 81 82 return true; 83 84 } 85 86 } 87 | Popular Tags |