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 {
23 * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doSaveDocument(org.eclipse.core.runtime.IProgressMonitor, java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
25 protected void doSaveDocument(IProgressMonitor monitor, Object element, IDocument document, boolean overwrite)
26 throws CoreException {
27 if (element instanceof ExternalEditorInput) {
28 ExternalEditorInput external = (ExternalEditorInput) element;
29 FileStorage storage = (FileStorage)external.getStorage();
30 String encoding = getEncoding(element);
32 encoding = getDefaultEncoding();
34 InputStream stream = new ByteArrayInputStream(document.get().getBytes(encoding));
36 // inform about the upcoming content change
37 fireElementStateChanging(element);
38 storage.setContents(stream, overwrite, true, monitor);
39 } catch (RuntimeException e) {
40 // inform about failure
41 fireElementStateChangeFailed(element);
44 } catch (IOException e) {
45 IStatus s = new Status(IStatus.ERROR, PHPeclipsePlugin.PLUGIN_ID, IStatus.OK, e.getMessage(), e);
46 throw new CoreException(s);
50 super.doSaveDocument(monitor, element, document, overwrite);