1 19 package org.netbeans.modules.xml.xdm.xam; 20 21 import java.io.BufferedReader ; 22 import java.io.IOException ; 23 import java.io.InputStream ; 24 import java.io.InputStreamReader ; 25 import javax.swing.text.BadLocationException ; 26 import javax.swing.text.Document ; 27 import org.netbeans.editor.BaseDocument; 28 import org.netbeans.modules.xml.text.syntax.XMLKit; 29 import org.netbeans.modules.xml.xam.ModelSource; 30 import org.netbeans.modules.xml.xam.dom.AbstractDocumentModel; 31 import org.netbeans.modules.xml.xam.dom.DocumentModelAccess; 32 import org.netbeans.modules.xml.xam.spi.DocumentModelAccessProvider; 33 import org.openide.loaders.DataObject; 34 35 39 public class XDMAccessProvider implements DocumentModelAccessProvider { 40 41 42 public XDMAccessProvider() { 43 } 44 45 public DocumentModelAccess createModelAccess(AbstractDocumentModel model) { 46 return new XDMAccess(model); 47 } 48 49 public Document loadSwingDocument(InputStream in) throws IOException , BadLocationException { 50 Document sd = new BaseDocument(XMLKit.class, false); 51 BufferedReader br = new BufferedReader (new InputStreamReader (in)); 52 try { 53 String line = null; 54 while ((line = br.readLine()) != null) { 55 sd.insertString(sd.getLength(), line+System.getProperty("line.separator"), null); } 57 } finally { 58 br.close(); 59 } 60 return sd; 61 } 62 63 public Object getModelSourceKey(ModelSource source) { 64 return source.getLookup().lookup(DataObject.class); 65 } 66 } 67 | Popular Tags |