2 * Created on 06.09.2003
5 package net.sourceforge.phpeclipse.builder;
7 import java.io.ByteArrayInputStream;
8 import java.io.IOException;
9 import java.io.InputStream;
11 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.core.runtime.Status;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.ui.editors.text.StorageDocumentProvider;
22 * @version 1.0, May 19, 2003
24 public class ExternalStorageDocumentProvider extends StorageDocumentProvider {
27 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doSaveDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
29 protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
30 throws CoreException {
31 if (element instanceof ExternalEditorInput) {
32 ExternalEditorInput external = (ExternalEditorInput) element;
33 FileStorage storage = (FileStorage)external.getStorage();
34 String encoding = getEncoding(element);
36 encoding = getDefaultEncoding();
38 InputStream stream = new ByteArrayInputStream(document.get().getBytes(encoding));
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, PHPeclipsePlugin.PLUGIN_ID, IStatus.OK, e.getMessage(), e);
50 throw new CoreException(s);
54 super.doSaveDocument(monitor, element, document, overwrite);