1 package net.sourceforge.phpeclipse.builder;
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
7 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
9 import org.eclipse.core.runtime.CoreException;
10 import org.eclipse.core.runtime.IProgressMonitor;
11 import org.eclipse.core.runtime.IStatus;
12 import org.eclipse.core.runtime.Status;
13 import org.eclipse.jface.text.IDocument;
14 import org.eclipse.ui.editors.text.StorageDocumentProvider;
18 * @version 1.0, May 19, 2003
20 public class ExternalStorageDocumentProvider extends StorageDocumentProvider {
25 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doSaveDocument(org.eclipse.core.runtime.IProgressMonitor,
26 * java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
28 protected void doSaveDocument(IProgressMonitor monitor, Object element,
29 IDocument document, boolean overwrite) throws CoreException {
30 if (element instanceof ExternalEditorInput) {
31 ExternalEditorInput external = (ExternalEditorInput) element;
32 FileStorage storage = (FileStorage) external.getStorage();
33 String encoding = getEncoding(element);
35 encoding = getDefaultEncoding();
37 InputStream stream = new ByteArrayInputStream(document.get()
40 // inform about the upcoming content change
41 fireElementStateChanging(element);
42 storage.setContents(stream, overwrite, true, monitor);
43 } catch (RuntimeException e) {
44 // inform about failure
45 fireElementStateChangeFailed(element);
48 } catch (IOException e) {
49 IStatus s = new Status(IStatus.ERROR,
50 PHPeclipsePlugin.PLUGIN_ID, IStatus.OK, e.getMessage(),
52 throw new CoreException(s);
56 super.doSaveDocument(monitor, element, document, overwrite);