Adding phpdoc tags to String[] array so the code scanner will pick them up and do...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / builder / ExternalStorageDocumentProvider.java
1 package net.sourceforge.phpeclipse.builder;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6
7 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
8
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;
15
16 /**
17  * @author ed
18  * @version 1.0, May 19, 2003
19  */
20 public class ExternalStorageDocumentProvider extends StorageDocumentProvider {
21
22         /*
23          * (non-Javadoc)
24          * 
25          * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doSaveDocument(org.eclipse.core.runtime.IProgressMonitor,
26          *      java.lang.Object, org.eclipse.jface.text.IDocument, boolean)
27          */
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);
34                         if (encoding == null)
35                                 encoding = getDefaultEncoding();
36                         try {
37                                 InputStream stream = new ByteArrayInputStream(document.get()
38                                                 .getBytes(encoding));
39                                 try {
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);
46                                         throw e;
47                                 }
48                         } catch (IOException e) {
49                                 IStatus s = new Status(IStatus.ERROR,
50                                                 PHPeclipsePlugin.PLUGIN_ID, IStatus.OK, e.getMessage(),
51                                                 e);
52                                 throw new CoreException(s);
53                         }
54
55                 } else {
56                         super.doSaveDocument(monitor, element, document, overwrite);
57                 }
58         }
59
60 }