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 40 public class XMLDataObjectLifeLock68934Test extends LoggingTestCaseHid 41 implements Node.Cookie { 42 43 private ErrorManager err; 44 45 public XMLDataObjectLifeLock68934Test(String s) { 46 super(s); 47 } 48 protected void setUp() throws Exception { 49 clearWorkDir(); 50 51 err = ErrorManager.getDefault().getInstance("TEST-" + getName()); 52 } 53 54 public void testQueryFromInsideTheQuery() throws IOException { 55 FileObject res = FileUtil.createData( 56 Repository.getDefault().getDefaultFileSystem().getRoot(), 57 getName() + "/R.xml" 58 ); 59 60 err.log("file created: " + res); 61 org.openide.filesystems.FileLock l = res.lock(); 62 OutputStream os = res.getOutputStream(l); 63 err.log("stream opened"); 64 PrintStream ps = new PrintStream (os); 65 66 ps.println("<?xml version='1.0' encoding='UTF-8'?>"); 67 ps.println("<!DOCTYPE MIME-resolver PUBLIC '-//NetBeans//DTD MIME Resolver 1.0//EN' 'http://www.netbeans.org/dtds/mime-resolver-1_0.dtd'>"); 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 class EP implements Environment.Provider, Node.Cookie { 85 public EP query = this; 86 87 public Lookup getEnvironment(DataObject obj) { 88 89 if (query == this) { 90 query = null; 91 query = (EP)obj.getCookie(EP.class); 92 93 assertEquals("Right object: ", XMLDataObject.class, obj.getClass()); 94 XMLDataObject xml = (XMLDataObject)obj; 95 String id = null; 96 try { 97 id = xml.getDocument().getDoctype().getPublicId(); 98 } catch (IOException ex) { 99 ex.printStackTrace(); 100 fail("No exception"); 101 } catch (SAXException ex) { 102 ex.printStackTrace(); 103 fail("No exception"); 104 } 105 assertEquals("-//NetBeans//DTD MIME Resolver 1.0//EN", id); 106 } 107 108 109 return Lookups.singleton(this); 110 } 111 }; 112 113 EP environmentProvider = new EP(); 114 registerIntoLookup(environmentProvider); 115 116 117 EP mine = (EP)obj.getCookie(EP.class); 118 119 assertEquals("provider is objects cookie", environmentProvider, mine); 120 assertEquals("query inside works as well", environmentProvider, environmentProvider.query); 121 } 122 123 124 } 125 | Popular Tags |