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