Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Weinand2003-11-17 22:22:38 +0000
committerAndre Weinand2003-11-17 22:22:38 +0000
commitd91d3838a7add970857502e584f2ae20b0a28ceb (patch)
tree30ab1f1d60fdb3fccc0add9031d3110c646faef8 /bundles/org.eclipse.compare/compare
parentf278bbbfd5f05a40f395e6b65a27e23ddca55d8c (diff)
downloadeclipse.platform.team-d91d3838a7add970857502e584f2ae20b0a28ceb.tar.gz
eclipse.platform.team-d91d3838a7add970857502e584f2ae20b0a28ceb.tar.xz
eclipse.platform.team-d91d3838a7add970857502e584f2ae20b0a28ceb.zip
fixed #46805
Diffstat (limited to 'bundles/org.eclipse.compare/compare')
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java5
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/HistoryItem.java10
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamContentAccessorExtension2.java29
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/ResourceNode.java8
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/ZipFileStructureCreator.java9
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java21
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/AddFromHistoryDialog.java6
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java8
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/EditionAction.java15
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/SimpleTextViewer.java3
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java4
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java9
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java17
13 files changed, 101 insertions, 43 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java
index 5a9f494d9..bbc9b6aff 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/EditionSelectionDialog.java
@@ -18,7 +18,6 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.HashSet;
import java.util.Calendar;
-import java.io.InputStream;
import java.text.*;
import org.eclipse.swt.SWT;
@@ -120,9 +119,7 @@ public class EditionSelectionDialog extends ResizableDialog {
if (fItem instanceof IStreamContentAccessor) {
IStreamContentAccessor sca= (IStreamContentAccessor) fItem;
try {
- InputStream is= sca.getContents();
- if (is != null)
- fContent= Utilities.readString(is);
+ fContent= Utilities.readString(sca);
} catch (CoreException ex) {
// NeedWork
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/HistoryItem.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/HistoryItem.java
index cc521e14e..1d5071c1b 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/HistoryItem.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/HistoryItem.java
@@ -15,6 +15,7 @@ import java.io.BufferedInputStream;
import org.eclipse.swt.graphics.Image;
+import org.eclipse.compare.internal.Utilities;
import org.eclipse.core.resources.IFileState;
import org.eclipse.core.runtime.CoreException;
@@ -27,7 +28,7 @@ import org.eclipse.core.runtime.CoreException;
* Clients may instantiate this class; it is not intended to be subclassed.
* </p>
*/
-public class HistoryItem implements IStreamContentAccessor, ITypedElement, IModificationDate {
+public class HistoryItem implements IStreamContentAccessorExtension2, ITypedElement, IModificationDate {
private ITypedElement fBase;
private IFileState fFileState;
@@ -79,5 +80,12 @@ public class HistoryItem implements IStreamContentAccessor, ITypedElement, IModi
public InputStream getContents() throws CoreException {
return new BufferedInputStream(fFileState.getContents());
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.IStreamContentAccessor#getEncoding()
+ */
+ public String getCharset() {
+ return Utilities.guessCharset(getName());
+ }
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamContentAccessorExtension2.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamContentAccessorExtension2.java
new file mode 100644
index 000000000..8b5a9aef8
--- /dev/null
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/IStreamContentAccessorExtension2.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.compare;
+
+import org.eclipse.core.runtime.CoreException;
+
+/**
+ * Extension interface for <code>IStreamContentAccessor</code>. Extends the original
+ * concept of a <code>IStreamContentAccessor</code> to answer the Charset (encoding) used for the stream.
+ *
+ * @since 3.0
+ */
+public interface IStreamContentAccessorExtension2 extends IStreamContentAccessor {
+
+ /**
+ * @return The character encoding of the stream returned by <code>getContents()</code>.
+ * @exception CoreException if the contents of this object could not be accessed
+ * @since 3.0
+ */
+ String getCharset() throws CoreException;
+}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/ResourceNode.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/ResourceNode.java
index b06fe6c31..7029a4ff6 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/ResourceNode.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/ResourceNode.java
@@ -20,6 +20,7 @@ import org.eclipse.jface.util.Assert;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.compare.internal.Utilities;
import org.eclipse.compare.structuremergeviewer.IStructureComparator;
/**
@@ -193,5 +194,12 @@ public class ResourceNode extends BufferedContent
public ITypedElement replace(ITypedElement child, ITypedElement other) {
return child;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.IStreamContentAccessor#getEncoding()
+ */
+ public String getCharset() {
+ return Utilities.getCharset(fResource);
+ }
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/ZipFileStructureCreator.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/ZipFileStructureCreator.java
index 853568cfd..151295d71 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/ZipFileStructureCreator.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/ZipFileStructureCreator.java
@@ -121,7 +121,7 @@ public class ZipFileStructureCreator implements IStructureCreator {
}
}
- static class ZipFile extends ZipResource implements IStreamContentAccessor {
+ static class ZipFile extends ZipResource implements IStreamContentAccessorExtension2 {
private byte[] fContents;
@@ -167,6 +167,13 @@ public class ZipFileStructureCreator implements IStructureCreator {
fContents= newBuf;
}
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.IStreamContentAccessor#getCharset()
+ */
+ public String getCharset() {
+ return Utilities.guessCharset(getName());
+ }
}
private String fTitle;
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index ff19da227..2db1b6cb7 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -17,7 +17,6 @@ import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
import java.util.ResourceBundle;
-import java.io.UnsupportedEncodingException;
import java.text.MessageFormat;
import java.lang.reflect.InvocationTargetException;
@@ -43,7 +42,6 @@ import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.CoreException;
@@ -1777,9 +1775,9 @@ public class TextMergeViewer extends ContentMergeViewer {
if (newDoc == null) {
IStreamContentAccessor sca= (IStreamContentAccessor) o;
String s= null;
-
+
try {
- s= Utilities.readString(sca.getContents());
+ s= Utilities.readString(sca);
} catch (CoreException ex) {
// NeedWork
}
@@ -1932,19 +1930,8 @@ public class TextMergeViewer extends ContentMergeViewer {
MergeSourceViewer v= left ? fLeft : fRight;
if (v != null) {
IDocument d= v.getDocument();
- if (d != null) {
- String contents= d.get();
- if (contents != null) {
- byte[] bytes;
- try {
- bytes= contents.getBytes(ResourcesPlugin.getEncoding());
- } catch(UnsupportedEncodingException ex) {
- // use default encoding
- bytes= contents.getBytes();
- }
- return bytes;
- }
- }
+ if (d != null)
+ return Utilities.getBytes(d.get(), "UTF-16"); //$NON-NLS-1$
}
return null;
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/AddFromHistoryDialog.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/AddFromHistoryDialog.java
index bb4f590a6..3fd546aef 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/AddFromHistoryDialog.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/AddFromHistoryDialog.java
@@ -32,7 +32,7 @@ import org.eclipse.compare.*;
public class AddFromHistoryDialog extends ResizableDialog {
- static class HistoryInput implements ITypedElement, IStreamContentAccessor, IModificationDate {
+ static class HistoryInput implements ITypedElement, IStreamContentAccessorExtension2, IModificationDate {
IFile fFile;
IFileState fFileState;
@@ -43,6 +43,10 @@ public class AddFromHistoryDialog extends ResizableDialog {
public InputStream getContents() throws CoreException {
return new BufferedInputStream(fFileState.getContents());
}
+ public String getCharset() {
+ Utilities.guessCharset(fFile.getName());
+ return Utilities.getCharset(fFile);
+ }
public String getName() {
return fFile.getName();
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
index 8e779009f..f8ba07487 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/ComparePreferencePage.java
@@ -35,7 +35,8 @@ import org.eclipse.compare.structuremergeviewer.*;
public class ComparePreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
- class FakeInput implements ITypedElement, IStreamContentAccessor {
+ class FakeInput implements ITypedElement, IStreamContentAccessorExtension2 {
+ static final String UTF_16= "UTF-16"; //$NON-NLS-1$
String fContent;
FakeInput(String name) {
@@ -51,7 +52,10 @@ public class ComparePreferencePage extends PreferencePage implements IWorkbenchP
return "no type"; //$NON-NLS-1$
}
public InputStream getContents() {
- return new ByteArrayInputStream(fContent.getBytes());
+ return new ByteArrayInputStream(Utilities.getBytes(fContent, UTF_16));
+ }
+ public String getCharset() {
+ return UTF_16;
}
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/EditionAction.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/EditionAction.java
index 4d91d0526..80bde7777 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/EditionAction.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/EditionAction.java
@@ -10,8 +10,8 @@
*******************************************************************************/
package org.eclipse.compare.internal;
-import java.io.InputStream;
import java.io.ByteArrayInputStream;
+import java.io.InputStream;
import java.util.ResourceBundle;
import java.lang.reflect.InvocationTargetException;
@@ -44,8 +44,8 @@ public class EditionAction extends BaseCompareAction {
* Implements the IStreamContentAccessor and ITypedElement protocols
* for a Document.
*/
- class DocumentBufferNode implements ITypedElement, IStreamContentAccessor {
-
+ class DocumentBufferNode implements ITypedElement, IStreamContentAccessorExtension2 {
+ private static final String UTF_16= "UTF-16"; //$NON-NLS-1$
private IDocument fDocument;
private IFile fFile;
@@ -67,7 +67,11 @@ public class EditionAction extends BaseCompareAction {
}
public InputStream getContents() {
- return new ByteArrayInputStream(fDocument.get().getBytes());
+ return new ByteArrayInputStream(Utilities.getBytes(fDocument.get(), UTF_16));
+ }
+
+ public String getCharset() {
+ return UTF_16;
}
}
@@ -189,8 +193,7 @@ public class EditionAction extends BaseCompareAction {
private void updateDocument(IDocument document, IStreamContentAccessor sa) throws InvocationTargetException {
try {
- InputStream is= sa.getContents();
- String text= Utilities.readString(is);
+ String text= Utilities.readString(sa);
document.replace(0, document.getLength(), text);
} catch (CoreException e) {
throw new InvocationTargetException(e);
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/SimpleTextViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/SimpleTextViewer.java
index 3ebdd4382..a28339bfb 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/SimpleTextViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/SimpleTextViewer.java
@@ -54,9 +54,8 @@ public class SimpleTextViewer extends AbstractViewer {
private String getString(Object input) {
if (input instanceof IStreamContentAccessor) {
- IStreamContentAccessor sca= (IStreamContentAccessor) input;
try {
- return Utilities.readString(sca.getContents());
+ return Utilities.readString((IStreamContentAccessor) input);
} catch (CoreException ex) {
// NeedWork
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
index e05816c4a..d5d2d1dad 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/Patcher.java
@@ -860,7 +860,7 @@ public class Patcher {
Reader streamReader= null;
try {
- streamReader= new InputStreamReader(is, ResourcesPlugin.getEncoding());
+ streamReader= new InputStreamReader(is, Utilities.getCharset(file));
} catch (UnsupportedEncodingException x) {
// use default encoding
streamReader= new InputStreamReader(is);
@@ -901,7 +901,7 @@ public class Patcher {
byte[] bytes;
try {
- bytes= contents.getBytes(ResourcesPlugin.getEncoding());
+ bytes= contents.getBytes(Utilities.getCharset(file));
} catch (UnsupportedEncodingException x) {
// uses default encoding
bytes= contents.getBytes();
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
index 30141e0d2..380a8422b 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/PreviewPatchPage.java
@@ -38,6 +38,7 @@ import org.eclipse.compare.internal.CompareUIPlugin;
import org.eclipse.compare.internal.DiffImage;
import org.eclipse.compare.internal.ICompareContextIds;
import org.eclipse.compare.internal.TimeoutContext;
+import org.eclipse.compare.internal.Utilities;
import org.eclipse.compare.structuremergeviewer.*;
@@ -53,7 +54,8 @@ import org.eclipse.compare.structuremergeviewer.*;
/**
* Used with CompareInput
*/
- static class HunkInput implements ITypedElement, IStreamContentAccessor {
+ static class HunkInput implements ITypedElement, IStreamContentAccessorExtension2 {
+ static final String UTF_16= "UTF-16"; //$NON-NLS-1$
String fContent;
String fType;
@@ -71,7 +73,10 @@ import org.eclipse.compare.structuremergeviewer.*;
return fType;
}
public InputStream getContents() {
- return new ByteArrayInputStream(fContent.getBytes());
+ return new ByteArrayInputStream(Utilities.getBytes(fContent, UTF_16));
+ }
+ public String getCharset() {
+ return UTF_16;
}
}
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java
index 800c4d49f..f50d08836 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/structuremergeviewer/DocumentRangeNode.java
@@ -41,9 +41,10 @@ import org.eclipse.compare.contentmergeviewer.IDocumentRange;
* @see Differencer
*/
public class DocumentRangeNode
- implements IDocumentRange, IStructureComparator, IEditableContent, IStreamContentAccessor {
+ implements IDocumentRange, IStructureComparator, IEditableContent, IStreamContentAccessorExtension2 {
private static final boolean POS_UPDATE= true;
+ private static final String UTF_16= "UTF-16"; //$NON-NLS-1$
private IDocument fBaseDocument;
private Position fRange; // the range in the base document
@@ -300,8 +301,8 @@ public class DocumentRangeNode
s= fBaseDocument.get(fRange.getOffset(), fRange.getLength());
} catch (BadLocationException ex) {
s= ""; //$NON-NLS-1$
- }
- return new ByteArrayInputStream(Utilities.getBytes(s));
+ }
+ return new ByteArrayInputStream(Utilities.getBytes(s, UTF_16));
}
/* (non Javadoc)
@@ -324,8 +325,7 @@ public class DocumentRangeNode
if (other instanceof IStreamContentAccessor) {
try {
- InputStream is= ((IStreamContentAccessor)other).getContents();
- srcContents= Utilities.readString(is);
+ srcContents= Utilities.readString((IStreamContentAccessor)other);
} catch(CoreException ex) {
// NeedWork
}
@@ -343,5 +343,12 @@ public class DocumentRangeNode
*/
public void setContent(byte[] content) {
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.compare.IStreamContentAccessor#getEncoding()
+ */
+ public String getCharset() {
+ return UTF_16;
+ }
}

Back to the top