KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > nls > changes > CreateTextFileChange


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 JavaDoc;
14 import java.io.InputStream JavaDoc;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IPath;
19 import org.eclipse.core.runtime.NullProgressMonitor;
20
21 import org.eclipse.jdt.core.IJavaModelStatusConstants;
22 import org.eclipse.jdt.core.JavaModelException;
23
24 import org.eclipse.jdt.internal.corext.refactoring.nls.NLSUtil;
25
26 public class CreateTextFileChange extends CreateFileChange {
27     
28     private final String JavaDoc fTextType;
29     
30     public CreateTextFileChange(IPath path, String JavaDoc source, String JavaDoc encoding, String JavaDoc textType) {
31         super(path, source, encoding);
32         fTextType= textType;
33     }
34     
35     public String JavaDoc getTextType() {
36         return fTextType;
37     }
38     
39     public String JavaDoc getCurrentContent() throws JavaModelException {
40         IFile file= getOldFile(new NullProgressMonitor());
41         if (! file.exists())
42             return ""; //$NON-NLS-1$
43
InputStream JavaDoc stream= null;
44         try{
45             stream= file.getContents();
46             String JavaDoc encoding= file.getCharset();
47             String JavaDoc c= NLSUtil.readString(stream, encoding);
48             return (c == null) ? "": c; //$NON-NLS-1$
49
} catch (CoreException e){
50             throw new JavaModelException(e, IJavaModelStatusConstants.CORE_EXCEPTION);
51         } finally {
52             try {
53                 if (stream != null)
54                     stream.close();
55             } catch (IOException JavaDoc x) {
56             }
57         }
58     }
59     
60     public String JavaDoc getPreview() {
61         return getSource();
62     }
63 }
64
65
Popular Tags