Bug 4378 - IMemento#getString(String) removes formatting
Summary: IMemento#getString(String) removes formatting
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows NT
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Ryan Cooper CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 4937
  Show dependency tree
 
Reported: 2001-10-11 10:27 EDT by Darin Swanson CLA
Modified: 2002-02-28 13:54 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Darin Swanson CLA 2001-10-11 10:27:42 EDT
If a String with formatting (tabs, new lines) is stored into an IMemento using
putString(String, String), when the String is retrieved during IViewPart#init
(IViewSite, IMemento), the "control" characters have been replaced with spaces.
Currently impacts the Debugger DisplayView
Comment 1 Simon Arsenault CLA 2002-02-06 15:41:29 EST
It seems to keep the newline characters - from my simple test of opening the 
debug perspective, typing the following in the Display view:
   int i = 0;
   int j = 0;
   i = j;
Exit and restart Eclipse, and the Display view still shows the three lines but 
not the leading tabs. Is that what you've noticed too? Since IMemento is simply 
making use of xerces plug-in, I'll have to check what can be done.
Comment 2 Darin Swanson CLA 2002-02-06 15:50:07 EST
We have coded a major workaround in the DisplayView...not a good place to 
test ;-)  See DisplayView#saveState() and DisplayView#getRestoredDocument()
See bug 4937.
Comment 3 Simon Arsenault CLA 2002-02-07 15:59:14 EST
Can you look at what it takes to get xerces plug-in to keep the tab and new 
line characters? I'll forward you an e-mail with links to docs for this stuff.
Comment 4 Ryan Cooper CLA 2002-02-11 14:14:03 EST
Build: 20020205

As a simple test, I changeded the XMLMemento#putString(String, String) method 
to the following:

public void putString(String key, String value) {
	if(value==null) return;
	String m,n;
	m = value;
	element.setAttribute(key, value);
	n = element.getAttribute(key);
	boolean x = m.equals(n);
}

I tested this by writing a few lines of code including tabs and newlines in the 
display view and shutting down Eclipse. Since DisplayView#saveState(IMemento) 
calls XMLMemento#putString(String, String) without first modifying the value 
String (other than trmming leading and trailing whitespace), putString takes as 
input the original contents of the view, including the tabs and newlines 
(except leading and trailing tabs and newlines).

It turns out that the String fed to setAttribute and the String retrieved from 
getAttribute are equal (x is always true). All of the tabs and newline 
characters which are present in the input String are retrieved, so the xerces 
plug-in is not eliminating tab or newline characters.
Comment 5 Simon Arsenault CLA 2002-02-11 14:22:12 EST
There is one missing step to your test...the element's attribute was never 
written to a file and read again. Your test is succeeding probably because 
xerces has not applied some "filter" yet and probably does not until it writes 
it out to a file.

For a simple test, hack the workbench save state code to add an attribute to an 
element which has tabs and newlines. In the restore state method, read this 
attribute and notice the tabs and newlines are gone now.
Comment 6 Ryan Cooper CLA 2002-02-28 13:54:44 EST
Date: 20020228

API released to stream:

Added to IMemento in package org.eclipse.ui:
public String getTextData()
public void putTextData(String data)

These methods are used to store Text (also known as Character Data) to an 
IMemento. Unlike the getString/putString methods of IMemento, these methods 
cause white space to be persisted.

Each IMemento is allowed only one Text node. When putTextData(String data) is 
called, data replaces the previous value of the Text node of the IMemento. For 
example, if the following code was executed, then getTextData would 
return "World" afterwards.

IMemento memento = new IMemento();
memento.putTextData("Hello");
memento.putTextData("World");

To use these methods, call putTextData(String value) and getTextData() where 
you would previously call putString(String key, String value) and getString
(String key).