1 19 package org.openide.loaders; 20 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 import java.io.PrintStream ; 24 import org.openide.ErrorManager; 25 import org.openide.filesystems.FileObject; 26 import org.openide.filesystems.FileUtil; 27 import org.openide.filesystems.Repository; 28 import org.openide.loaders.Environment.Provider; 29 import org.openide.nodes.Node; 30 import org.openide.util.Lookup; 31 import org.openide.util.RequestProcessor; 32 import org.openide.util.lookup.Lookups; 33 import org.xml.sax.SAXException ; 34 35 39 public class XMLDataObjectGetNoCookieTest extends LoggingTestCaseHid 40 implements Node.Cookie { 41 42 private ErrorManager err; 43 44 public XMLDataObjectGetNoCookieTest(String s) { 45 super(s); 46 } 47 protected void setUp() throws Exception { 48 clearWorkDir(); 49 50 err = ErrorManager.getDefault().getInstance("TEST-" + getName()); 51 52 registerIntoLookup(ENV); 53 } 54 55 public void testNoDTD() throws IOException { 56 FileObject res = FileUtil.createData( 57 Repository.getDefault().getDefaultFileSystem().getRoot(), 58 getName() + "/R.xml" 59 ); 60 61 err.log("file created: " + res); 62 org.openide.filesystems.FileLock l = res.lock(); 63 OutputStream os = res.getOutputStream(l); 64 err.log("stream opened"); 65 PrintStream ps = new PrintStream (os); 66 67 ps.println("<?xml version='1.0' encoding='UTF-8'?>"); 68 ps.println("<MIME-resolver>"); 69 ps.println(" <file>"); 70 ps.println(" <ext name='lenka'/>"); 71 ps.println(" <resolver mime='hodna/lenka'/>"); 72 ps.println(" </file>"); 73 ps.println("</MIME-resolver>"); 74 75 err.log("Content written"); 76 os.close(); 77 err.log("Stream closed"); 78 l.releaseLock(); 79 err.log("releaseLock"); 80 81 82 final DataObject obj = DataObject.find(res); 83 84 EP cookie = (EP) obj.getCookie(EP.class); 85 86 assertEquals("But cookie is returned correctly", ENV, cookie); 87 } 88 89 90 private static Object ENV = new EP(); 91 92 private static final class EP implements Environment.Provider, Node.Cookie { 93 public Lookup getEnvironment(DataObject obj) { 94 assertEquals("Right object: ", XMLDataObject.class, obj.getClass()); 95 XMLDataObject xml = (XMLDataObject)obj; 96 String id = null; 97 try { 98 id = xml.getDocument().getDoctype().getPublicId(); 99 } catch (IOException ex) { 100 ex.printStackTrace(); 101 fail("No exception"); 102 } catch (SAXException ex) { 103 ex.printStackTrace(); 104 fail("No exception"); 105 } 106 assertEquals("No DTD means no ID", null, id); 107 return Lookups.singleton(this); 108 } 109 }; 110 } 111 | Popular Tags |