KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > xdm > xam > XDMAccessProvider


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.xdm.xam;
20
21 import java.io.BufferedReader JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.io.InputStreamReader JavaDoc;
25 import javax.swing.text.BadLocationException JavaDoc;
26 import javax.swing.text.Document JavaDoc;
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 /**
36  *
37  * @author Nam Nguyen
38  */

39 public class XDMAccessProvider implements DocumentModelAccessProvider {
40     
41     /** Creates a new instance of XDMAccessProvider */
42     public XDMAccessProvider() {
43     }
44
45     public DocumentModelAccess createModelAccess(AbstractDocumentModel model) {
46         return new XDMAccess(model);
47     }
48     
49     public Document JavaDoc loadSwingDocument(InputStream JavaDoc in) throws IOException JavaDoc, BadLocationException JavaDoc {
50         Document JavaDoc sd = new BaseDocument(XMLKit.class, false);
51         BufferedReader JavaDoc br = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(in));
52         try {
53             String JavaDoc line = null;
54             while ((line = br.readLine()) != null) {
55                 sd.insertString(sd.getLength(), line+System.getProperty("line.separator"), null); // NOI18N
56
}
57         } finally {
58             br.close();
59         }
60         return sd;
61     }
62
63     public Object JavaDoc getModelSourceKey(ModelSource source) {
64         return source.getLookup().lookup(DataObject.class);
65     }
66 }
67
Popular Tags