Lines 41-50
Link Here
|
41 |
import org.netbeans.api.lexer.Language; |
41 |
import org.netbeans.api.lexer.Language; |
42 |
import org.netbeans.api.lexer.LanguagePath; |
42 |
import org.netbeans.api.lexer.LanguagePath; |
43 |
import org.netbeans.api.queries.FileEncodingQuery; |
43 |
import org.netbeans.api.queries.FileEncodingQuery; |
|
|
44 |
import org.netbeans.modules.editor.NbEditorUtilities; |
44 |
import org.netbeans.modules.parsing.api.Embedding; |
45 |
import org.netbeans.modules.parsing.api.Embedding; |
45 |
import org.netbeans.modules.parsing.api.Snapshot; |
46 |
import org.netbeans.modules.parsing.api.Snapshot; |
46 |
import org.netbeans.modules.parsing.spi.EmbeddingProvider; |
47 |
import org.netbeans.modules.parsing.spi.EmbeddingProvider; |
47 |
import org.netbeans.modules.parsing.spi.Scheduler; |
|
|
48 |
import org.netbeans.modules.parsing.spi.SchedulerTask; |
48 |
import org.netbeans.modules.parsing.spi.SchedulerTask; |
49 |
import org.netbeans.modules.parsing.spi.TaskFactory; |
49 |
import org.netbeans.modules.parsing.spi.TaskFactory; |
50 |
import org.openide.filesystems.FileObject; |
50 |
import org.openide.filesystems.FileObject; |
Lines 61-89
Link Here
|
61 |
try { |
61 |
try { |
62 |
LanguagePath path = LanguagePath.get(MimeLookup.getLookup(snapshot.getMimeType()).lookup(Language.class)); |
62 |
LanguagePath path = LanguagePath.get(MimeLookup.getLookup(snapshot.getMimeType()).lookup(Language.class)); |
63 |
InputAttributes attributes = (InputAttributes) doc.getProperty(InputAttributes.class); |
63 |
InputAttributes attributes = (InputAttributes) doc.getProperty(InputAttributes.class); |
64 |
FileObject fileObject = (FileObject) attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N |
|
|
65 |
int offset = (Integer)attributes.getValue(path, "dialogBinding.offset"); //NOI18N |
64 |
int offset = (Integer)attributes.getValue(path, "dialogBinding.offset"); //NOI18N |
66 |
int length = (Integer)attributes.getValue(path, "dialogBinding.length"); //NOI18N |
65 |
int length = (Integer)attributes.getValue(path, "dialogBinding.length"); //NOI18N |
67 |
String mimeType = fileObject.getMIMEType(); |
66 |
Document d = (Document) attributes.getValue(path, "dialogBinding.document"); //NOI18N |
68 |
InputStream inputStream = fileObject.getInputStream(); |
67 |
if (d != null) { |
69 |
try { |
68 |
String mimeType = NbEditorUtilities.getMimeType(d); |
70 |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, FileEncodingQuery.getEncoding(fileObject))); |
69 |
ArrayList<Embedding> ret = new ArrayList<Embedding>(3); |
71 |
CharBuffer charBuffer = CharBuffer.allocate(4096); |
70 |
ret.add(snapshot.create(d.getText(0, offset), mimeType)); |
72 |
StringBuilder sb = new StringBuilder(); |
71 |
ret.add(snapshot.create(0, snapshot.getText().length(), mimeType)); |
73 |
int i = bufferedReader.read(charBuffer); |
72 |
ret.add(snapshot.create(d.getText(offset + length, d.getLength() - offset - length), mimeType)); |
74 |
while (i > 0) { |
73 |
return Collections.singletonList(Embedding.create(ret)); |
75 |
charBuffer.flip(); |
74 |
} else { |
76 |
sb.append(charBuffer); |
75 |
FileObject fileObject = (FileObject) attributes.getValue(path, "dialogBinding.fileObject"); //NOI18N |
77 |
charBuffer.clear(); |
76 |
String mimeType = fileObject.getMIMEType(); |
78 |
i = bufferedReader.read(charBuffer); |
77 |
InputStream inputStream = fileObject.getInputStream(); |
|
|
78 |
try { |
79 |
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, FileEncodingQuery.getEncoding(fileObject))); |
80 |
CharBuffer charBuffer = CharBuffer.allocate(4096); |
81 |
StringBuilder sb = new StringBuilder(); |
82 |
int i = bufferedReader.read(charBuffer); |
83 |
while (i > 0) { |
84 |
charBuffer.flip(); |
85 |
sb.append(charBuffer); |
86 |
charBuffer.clear(); |
87 |
i = bufferedReader.read(charBuffer); |
88 |
} |
89 |
ArrayList<Embedding> ret = new ArrayList<Embedding>(3); |
90 |
ret.add(snapshot.create(sb.subSequence(0, offset), mimeType)); |
91 |
ret.add(snapshot.create(0, snapshot.getText().length(), mimeType)); |
92 |
ret.add(snapshot.create(sb.subSequence(offset + length, sb.length()), mimeType)); |
93 |
return Collections.singletonList(Embedding.create(ret)); |
94 |
} finally { |
95 |
inputStream.close(); |
79 |
} |
96 |
} |
80 |
ArrayList<Embedding> ret = new ArrayList<Embedding>(3); |
|
|
81 |
ret.add(snapshot.create(sb.subSequence(0, offset), mimeType)); |
82 |
ret.add(snapshot.create(0, snapshot.getText().length(), mimeType)); |
83 |
ret.add(snapshot.create(sb.subSequence(offset + length, sb.length()), mimeType)); |
84 |
return Collections.singletonList(Embedding.create(ret)); |
85 |
} finally { |
86 |
inputStream.close(); |
87 |
} |
97 |
} |
88 |
} catch (Exception e) { |
98 |
} catch (Exception e) { |
89 |
e.printStackTrace(); |
99 |
e.printStackTrace(); |