[373442] [TCP/IP Monitor] Improper handling of national characters
diff --git a/plugins/org.eclipse.wst.internet.monitor.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.wst.internet.monitor.ui/META-INF/MANIFEST.MF
index 47073cc..e95b978 100644
--- a/plugins/org.eclipse.wst.internet.monitor.ui/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.wst.internet.monitor.ui/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.wst.internet.monitor.ui; singleton:=true
-Bundle-Version: 1.0.507.qualifier
+Bundle-Version: 1.0.508.qualifier
Bundle-Activator: org.eclipse.wst.internet.monitor.ui.internal.MonitorUIPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
diff --git a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/Messages.java b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/Messages.java
index 29bd204..e95c439 100644
--- a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/Messages.java
+++ b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/Messages.java
@@ -1,5 +1,5 @@
/**********************************************************************
- * Copyright (c) 2007, 2008 IBM Corporation and others.
+ * Copyright (c) 2007, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -51,6 +51,7 @@
public static String viewType;
public static String viewResponseTimeFormat;
public static String viewSize;
+ public static String viewEncoding;
public static String viewResponse;
public static String viewRequest;
public static String actionSortByResponseTime;
@@ -61,6 +62,7 @@
public static String actionProperties;
public static String yes;
public static String no;
+ public static String defaultEncodingOption;
static {
NLS.initializeMessages(MonitorUIPlugin.PLUGIN_ID + ".internal.Messages", Messages.class);
diff --git a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/Messages.properties b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/Messages.properties
index 601417d..09c7175 100644
--- a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/Messages.properties
+++ b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/Messages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2005, 2008 IBM Corporation and others.
+# Copyright (c) 2005, 2012 IBM Corporation and others.
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License v1.0
# which accompanies this distribution, and is available at
@@ -21,6 +21,7 @@
viewSize=Size: {0}
viewResponseTimeFormat={0} ms
viewSizeFormat={0} ({1}) bytes
+viewEncoding=Encoding:
# The following string allows you to change the time format of the TCP/IP monitor
# view. It uses the formatting options found in java.text.SimpleDateFormat:
@@ -75,4 +76,6 @@
connectionTimeout=T&imeout (in milliseconds):
preferenceDescription=Configure TCP/IP monitors on local and remote ports.
-prefShowView=S&how the TCP/IP Monitor view when there is activity
\ No newline at end of file
+prefShowView=S&how the TCP/IP Monitor view when there is activity
+
+defaultEncodingOption=<None>
\ No newline at end of file
diff --git a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/provisional/ContentViewer.java b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/provisional/ContentViewer.java
index db500ab..704c0f9 100644
--- a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/provisional/ContentViewer.java
+++ b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/provisional/ContentViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -129,4 +129,17 @@
public boolean getEditable() {
return false;
}
+
+ /**
+ * Sets the encoding of the viewer for views that encode content.
+ * <p>
+ * The default implementation of this method does nothing.
+ * Subclasses should override this method to allows instances
+ * to set the encoding.
+ * </p>
+ * @param str an array of encodings
+ */
+ public void setEncodings(String[] str){
+ // do nothing
+ }
}
diff --git a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/view/Viewer.java b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/view/Viewer.java
index 00e313f..26d823b 100644
--- a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/view/Viewer.java
+++ b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/view/Viewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2011 IBM Corporation and others.
+ * Copyright (c) 2003, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -19,6 +19,8 @@
public class Viewer {
private IConfigurationElement element;
+ protected String[] encodings = null;
+
/**
* Create a new content viewer.
*
@@ -40,6 +42,31 @@
return label;
}
+ public String[] getEncodings(){
+ // Cache the encoding
+ if (encodings == null){
+ String encodingString = element.getAttribute("encodings");
+
+ if (Trace.FINEST) {
+ Trace.trace(Trace.STRING_FINEST, "encodingString from extension point : " + encodingString);
+ }
+
+ if (encodingString != null){
+ encodings = encodingString.split(",");
+ int size= encodings.length;
+ for (int i=0;i<size;i++){
+ // Clean up input
+ encodings[i] = encodings[i].trim();
+ }
+ }
+ }
+
+ if (Trace.FINEST) {
+ Trace.trace(Trace.STRING_FINEST, "Get encodings : " + encodings);
+ }
+ return encodings;
+ }
+
/**
* Create an instance of the viewer.
*
diff --git a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/view/ViewerManager.java b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/view/ViewerManager.java
index 974faa5..c0d76b5 100644
--- a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/view/ViewerManager.java
+++ b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/view/ViewerManager.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2011 IBM Corporation and others.
+ * Copyright (c) 2003, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -13,7 +13,10 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import org.eclipse.core.runtime.*;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionRegistry;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@@ -265,8 +268,10 @@
reqViewer.dispose();
requestViewer = viewer;
- if (viewer != null)
+ if (viewer != null){
reqViewer = viewer.createViewer();
+ reqViewer.setEncodings(viewer.getEncodings());
+ }
else
reqViewer = null;
if (reqViewer == null)
@@ -298,8 +303,10 @@
respViewer.dispose();
responseViewer = viewer;
- if (viewer != null)
+ if (viewer != null){
respViewer = viewer.createViewer();
+ respViewer.setEncodings(viewer.getEncodings());
+ }
else
respViewer = null;
if (respViewer == null)
diff --git a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/viewers/ByteViewer.java b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/viewers/ByteViewer.java
index 3082e7c..e561cc5 100644
--- a/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/viewers/ByteViewer.java
+++ b/plugins/org.eclipse.wst.internet.monitor.ui/monitorui/org/eclipse/wst/internet/monitor/ui/internal/viewers/ByteViewer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2007 IBM Corporation and others.
+ * Copyright (c) 2003, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,27 +10,96 @@
*******************************************************************************/
package org.eclipse.wst.internet.monitor.ui.internal.viewers;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+
import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.internet.monitor.ui.internal.ContextIds;
+import org.eclipse.wst.internet.monitor.ui.internal.Messages;
import org.eclipse.wst.internet.monitor.ui.internal.MonitorUIPlugin;
+import org.eclipse.wst.internet.monitor.ui.internal.Trace;
import org.eclipse.wst.internet.monitor.ui.internal.provisional.ContentViewer;
/**
* A basic byte viewer.
*/
public class ByteViewer extends ContentViewer {
protected Text text;
-
+ protected Label encodingLabel;
+ protected Combo encodingCombo;
+ protected Composite byteViewerBodyComposite;
+ protected String encodingType = null;
+
+ // Cache the content in order to encode the content when the user changes
+ // the content
+ protected byte[] contentArray;
+
+ // copied from MonitorUI
+ private static final String lineSeparator = System.getProperty("line.separator");
+
+ protected String[] encodings = null;
+
/** (non-Javadoc)
* @see ContentViewer#init(Composite)
*/
- public void init(Composite parent) {
- text = new Text(parent, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
- Display display = parent.getDisplay();
+ public void init(Composite parent) {
+ byteViewerBodyComposite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ layout.marginHeight = 0;
+ layout.marginWidth = 0;
+
+ GridData data = new GridData(GridData.FILL_HORIZONTAL
+ | GridData.FILL_VERTICAL
+ | GridData.VERTICAL_ALIGN_BEGINNING);
+ data.horizontalSpan = 2;
+
+ byteViewerBodyComposite.setLayoutData(data);
+ byteViewerBodyComposite.setLayout(layout);
+
+ encodingLabel = new Label(byteViewerBodyComposite, SWT.NONE);
+
+ encodingLabel.setText(NLS.bind(Messages.viewEncoding,""));
+ encodingCombo = new Combo(byteViewerBodyComposite, SWT.RIGHT);
+
+ // Add the default option
+ encodingCombo.add(NLS.bind(Messages.defaultEncodingOption,""));
+ // Select the default option
+ encodingCombo.select(0);
+
+ if (encodings != null){
+ int size = encodings.length;
+ for (int i=0;i<size;i++){
+ encodingCombo.add(encodings[i]);
+ }
+ }
+
+ encodingCombo.addModifyListener(new ModifyListener(){
+ public void modifyText(ModifyEvent me) {
+ encodingType = encodingCombo.getText();
+ if (contentArray != null){
+ setContent(contentArray);
+ }
+ }
+
+ });
+
+ text = new Text(byteViewerBodyComposite, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL);
+ Display display = byteViewerBodyComposite.getDisplay();
+ text.setLayoutData(data);
text.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
text.setForeground(display.getSystemColor(SWT.COLOR_LIST_FOREGROUND));
text.setFont(JFaceResources.getTextFont());
@@ -71,11 +140,11 @@
public void setContent(byte[] b) {
String out = "";
if (b != null) {
+ contentArray = b;
b = MonitorUIPlugin.unzip(b);
- out = MonitorUIPlugin.parse(b);
+ out = parseEncoded(b);
}
- String lineSeparator = System.getProperty("line.separator");
int ls = lineSeparator.length();
if (out.length() > ls) {
while (out.substring(0, ls).indexOf(lineSeparator) >= 0)
@@ -84,6 +153,57 @@
text.setText(out);
}
+
+ /**
+ * Convenience method to parse the given bytes into String form. The bytes
+ * are parsed into a line delimited string. The byte array must not be null.
+ *
+ * @param b a byte array
+ * @return the string after the conversion
+ */
+ public String parseEncoded(byte[] b) {
+ if (b == null)
+ throw new IllegalArgumentException();
+
+ ByteArrayInputStream bin = new ByteArrayInputStream(b);
+ BufferedReader br = null;
+ if (encodingType != null){
+ try {
+ br = new BufferedReader(new InputStreamReader(bin,encodingType));
+ } catch (UnsupportedEncodingException e) {
+ if (Trace.FINEST) {
+ Trace.trace(Trace.STRING_FINEST,
+ "An unsupported encoding exception when using encodingType="
+ + encodingType, e);
+ }
+
+ // If it is unsupported, use default. No prompt is given to the user
+ br = new BufferedReader(new InputStreamReader(bin));
+ }
+ }
+ else {
+ br = new BufferedReader(new InputStreamReader(bin));
+ }
+
+ StringBuffer sb = new StringBuffer();
+ try {
+ String s = br.readLine();
+
+ while (s != null) {
+ sb.append(s);
+ s = br.readLine();
+ if (s != null)
+ sb.append(lineSeparator);
+ }
+ } catch (Exception e) {
+ if (Trace.SEVERE) {
+ Trace.trace(Trace.STRING_SEVERE, "Error parsing input", e);
+ }
+ }
+
+ return sb.toString();
+ }
+
/** (non-Javadoc)
* @see ContentViewer#dispose()
@@ -91,5 +211,24 @@
public void dispose() {
text.dispose();
text = null;
+
+ encodingCombo.dispose();
+ encodingCombo = null;
+
+ encodingLabel.dispose();
+ encodingLabel = null;
+
+ byteViewerBodyComposite.dispose();
+ byteViewerBodyComposite = null;
}
+
+ /** (non-Javadoc)
+ *
+ * Sets the encodings to show in the encodings combo box
+ *
+ */
+ public void setEncodings(String[] str){
+ this.encodings = str;
+ }
+
}
diff --git a/plugins/org.eclipse.wst.internet.monitor.ui/plugin.xml b/plugins/org.eclipse.wst.internet.monitor.ui/plugin.xml
index 383610e..8f85473 100644
--- a/plugins/org.eclipse.wst.internet.monitor.ui/plugin.xml
+++ b/plugins/org.eclipse.wst.internet.monitor.ui/plugin.xml
@@ -42,6 +42,7 @@
id="org.eclipse.wst.internet.monitor.viewers.byte"
class="org.eclipse.wst.internet.monitor.ui.internal.viewers.ByteViewer"
type="requestresponse"
+ encodings="UTF-8,UTF-16,ASCII,Cp1250,Cp1251,Cp1252,Cp1253,Cp1254,Cp1257,ISO8859_1,ISO8859_2,ISO8859_4,ISO8859_5,ISO8859_7,ISO8859_9,ISO8859_13,ISO8859_15,KOI8_R,UnicodeBigUnmarked,UnicodeLittleUnmarked,UnicodeBig,UnicodeLittle"
label="%byteView"/>
<viewer
id="org.eclipse.wst.internet.monitor.viewers.image"
diff --git a/plugins/org.eclipse.wst.internet.monitor.ui/schema/viewers.exsd b/plugins/org.eclipse.wst.internet.monitor.ui/schema/viewers.exsd
index 6d76378..96b4c1a 100644
--- a/plugins/org.eclipse.wst.internet.monitor.ui/schema/viewers.exsd
+++ b/plugins/org.eclipse.wst.internet.monitor.ui/schema/viewers.exsd
@@ -1,6 +1,6 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.wst.internet.monitor.ui">
+<schema targetNamespace="org.eclipse.wst.internet.monitor.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.wst.internet.monitor.ui" id="viewers" name="Content Viewers"/>
@@ -11,6 +11,11 @@
</annotation>
<element name="extension">
+ <annotation>
+ <appInfo>
+ <meta.element />
+ </appInfo>
+ </annotation>
<complexType>
<sequence>
<element ref="viewer" minOccurs="1" maxOccurs="unbounded"/>
@@ -77,6 +82,13 @@
</documentation>
</annotation>
</attribute>
+ <attribute name="encodings" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
</complexType>
</element>
@@ -118,14 +130,6 @@
</documentation>
</annotation>
- <annotation>
- <appInfo>
- <meta.section type="implementation"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
<annotation>
<appInfo>