Lines 104-110
Link Here
|
104 |
file = FileUtil.normalizeFile(file); |
104 |
file = FileUtil.normalizeFile(file); |
105 |
FileObject fo = FileUtil.toFileObject(file); |
105 |
FileObject fo = FileUtil.toFileObject(file); |
106 |
if (fo != null) { |
106 |
if (fo != null) { |
107 |
r = getReaderFromEditorSupport(fo); |
107 |
r = getReaderFromEditorSupport(fo, fo); |
108 |
} |
108 |
} |
109 |
} catch (IllegalArgumentException iaex) { |
109 |
} catch (IllegalArgumentException iaex) { |
110 |
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, iaex); |
110 |
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, iaex); |
Lines 121-126
Link Here
|
121 |
} |
121 |
} |
122 |
|
122 |
|
123 |
public Reader getReader(FileObject fo, String encoding) throws FileNotFoundException { |
123 |
public Reader getReader(FileObject fo, String encoding) throws FileNotFoundException { |
|
|
124 |
return getReader(fo, encoding, fo.getExt()); |
125 |
} |
126 |
|
127 |
public Reader getReader(FileObject fo, String encoding, String secondFileExt) throws FileNotFoundException { |
128 |
return getReader(fo, encoding, fo, secondFileExt); |
129 |
} |
130 |
|
131 |
public Reader getReader(FileObject fo, String encoding, FileObject type) throws FileNotFoundException { |
132 |
return getReader(fo, encoding, type, type.getExt()); |
133 |
} |
134 |
|
135 |
private Reader getReader(FileObject fo, String encoding, FileObject type, String secondFileExt) throws FileNotFoundException { |
124 |
if (encoding != null) { |
136 |
if (encoding != null) { |
125 |
try { |
137 |
try { |
126 |
return new InputStreamReader(fo.getInputStream(), encoding); |
138 |
return new InputStreamReader(fo.getInputStream(), encoding); |
Lines 129-140
Link Here
|
129 |
} |
141 |
} |
130 |
} |
142 |
} |
131 |
Reader r = null; |
143 |
Reader r = null; |
132 |
String ext = fo.getExt(); |
144 |
String ext = type.getExt(); |
133 |
if (!"java".equalsIgnoreCase(ext)) {// We read the encoding for Java files explicitely |
145 |
if (!"java".equalsIgnoreCase(ext) || !ext.equals(secondFileExt)) {// We read the encoding for Java files explicitely |
134 |
// If it's not defined, read with default encoding from stream (because of guarded blocks) |
146 |
// If it's not defined, read with default encoding from stream (because of guarded blocks) |
135 |
r = getReaderFromEditorSupport(fo); |
147 |
// But when the extensions of the two files are different (comparing Java files with something else), |
|
|
148 |
// we have to use the Document approach for both due to possible different line-endings. |
149 |
r = getReaderFromEditorSupport(fo, type); |
136 |
if (r == null) { |
150 |
if (r == null) { |
137 |
r = getReaderFromKit(null, fo, fo.getMIMEType()); |
151 |
r = getReaderFromKit(null, fo, type.getMIMEType()); |
138 |
} |
152 |
} |
139 |
} |
153 |
} |
140 |
if (r == null) { |
154 |
if (r == null) { |
Lines 145-159
Link Here
|
145 |
} |
159 |
} |
146 |
|
160 |
|
147 |
/** @return The reader or <code>null</code>. */ |
161 |
/** @return The reader or <code>null</code>. */ |
148 |
private Reader getReaderFromEditorSupport(FileObject fo) throws FileNotFoundException { |
162 |
private Reader getReaderFromEditorSupport(FileObject fo, FileObject type) throws FileNotFoundException { |
149 |
//System.out.println("getReaderFromEditorSupport("+fo+")"); |
163 |
//System.out.println("getReaderFromEditorSupport("+fo+")"); |
150 |
DataObject dobj; |
164 |
DataObject dobj; |
151 |
try { |
165 |
try { |
152 |
dobj = DataObject.find(fo); |
166 |
dobj = DataObject.find(type); |
153 |
} catch (DataObjectNotFoundException donfex) { |
167 |
} catch (DataObjectNotFoundException donfex) { |
154 |
return null; |
168 |
return null; |
155 |
} |
169 |
} |
156 |
if (!fo.equals(dobj.getPrimaryFile())) { |
170 |
if (!type.equals(dobj.getPrimaryFile())) { |
157 |
return null; |
171 |
return null; |
158 |
} |
172 |
} |
159 |
EditCookie edit = (EditCookie) dobj.getCookie(EditCookie.class); |
173 |
EditCookie edit = (EditCookie) dobj.getCookie(EditCookie.class); |