]> git.uio.no Git - ifi-stolz-refaktor.git/blob - case-study/jdt-before/core refactoring/org/eclipse/jdt/internal/corext/refactoring/nls/changes/CreateTextFileChange.java
Some talks, mostly identical.
[ifi-stolz-refaktor.git] / case-study / jdt-before / core refactoring / org / eclipse / jdt / internal / corext / refactoring / nls / changes / CreateTextFileChange.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2008 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.corext.refactoring.nls.changes;
12
13 import java.io.IOException;
14 import java.io.InputStream;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.NullProgressMonitor;
19
20 import org.eclipse.core.resources.IFile;
21
22 import org.eclipse.jdt.core.IJavaModelStatusConstants;
23 import org.eclipse.jdt.core.JavaModelException;
24
25 import org.eclipse.jdt.internal.corext.refactoring.nls.NLSUtil;
26
27 public class CreateTextFileChange extends CreateFileChange {
28
29         private final String fTextType;
30
31         public CreateTextFileChange(IPath path, String source, String encoding, String textType) {
32                 super(path, source, encoding);
33                 fTextType= textType;
34         }
35
36         public String getTextType() {
37                 return fTextType;
38         }
39
40         public String getCurrentContent() throws JavaModelException {
41                 IFile file= getOldFile(new NullProgressMonitor());
42                 if (! file.exists())
43                         return ""; //$NON-NLS-1$
44                 InputStream stream= null;
45                 try{
46                         stream= file.getContents();
47                         String encoding= file.getCharset();
48                         String c= NLSUtil.readString(stream, encoding);
49                         return (c == null) ? "": c; //$NON-NLS-1$
50                 } catch (CoreException e){
51                         throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION);
52                 } finally {
53                         try {
54                                 if (stream != null)
55                                         stream.close();
56                         } catch (IOException x) {
57                         }
58                 }
59         }
60
61         public String getPreview() {
62                 return getSource();
63         }
64 }
65