Last modified 15 years ago
Last modified on 05/31/10 09:45:26
Analysis
Overview
The purpose of this task is to fix some of the bugs related to working with text on the server. Since real text collaboration will be hard to achieve, focus at this revision should be on the following things:
- Character encoding
- Caret position update
Task requirements
The following three bugs should be fixed as part of this task:
- Books on server cannot contain text - exceptions are thrown (background) and changes are seen only by the author that made them. Fix this
- Currently special characters on the server coming from a Windows machine are encoded as cp1251 or cp1252 instead of Unicode. Thus a strange symbol appears on a Unix client instead of a new line for example.
- When two people work collaboratively on the server, text is updated, but caret position is not. Same is true when two views share the same model (e.g. save a book and reopen it). Last caret position should be updated together with the text.
Task result
Source code
Implementation idea
- Unicode encoding on the server should fix the first problem.
- The resource's raw text should be tracked and the TextChange should be extracted from the last AutoAction applied, so that the caret will be updated.
Related
None
How to demo
Run the scenarios that describe the bugs (see the task requirements) and show they are no longer present.
Design
- Books on server cannot contain text
- ImmTextIntervalPersister is not registered as extension in BaseModelTextModule, so it cannot be used by the server. Registering the persister enables texts on server.
- Windows encoding.
- The problem is not in the server, it is in the way the client posts and reads data. OutputStreamWriter and InputStreamReader use the default system charset if nothing is specified. And their usage in MultiPartRequest must be as follows:
OutputStreamWriter writer = new OutputStreamWriter( this.connection.getOutputStream(), Charset.forName("UTF-8"));
and
InputStreamReader input = new InputStreamReader( this.connection.getInputStream(), Charset.forName("UTF-8"));
- Offline collaboration:
- Create resource property named "<Your ad here!>" in ResourceTextModel. It will get the current resource revision of the associated text resource and its causing Change.
- If the change is a ModelChange, search the action fields for a TextChange. If found, call update with it. If not, do nothing.
- If the change is a MetaChange, create a TextStyleChange (interval - the whole text, style : HotStyleDef.empty()). update the model with it. The result is that the caret and selection are not changed. If the current caret index is in the text, it will stay there. If not, it will automatically be displayed in the text end.
- Create resource property named "<Your ad here!>" in ResourceTextModel. It will get the current resource revision of the associated text resource and its causing Change.
- Online collaboration:
- Extend the property in ResourceTextModel. Keep internally the last processed resourceRevision. All the incoming revisions should be put on the place of the last one. Together with them, make a hash map, mapping revision ids to imm texts. In the case when the access to the text resource is a DelegatingServerAccess one, write a new logic for the property - when a change occurs:
- Find the last resource revision id which is common for the last revision history and the current history.
- In the last revision history, create a reverse change for every change after the found id (if change C is applied to text A and the result is text B, the reverse is the change that applied to text B would create text A).
- In the current revision history, just get all the text changes after the found revision id.
- Get the reversed list of the first changes, then add the list of the second changes. Update the view model with all of them.
- Extend the property in ResourceTextModel. Keep internally the last processed resourceRevision. All the incoming revisions should be put on the place of the last one. Together with them, make a hash map, mapping revision ids to imm texts. In the case when the access to the text resource is a DelegatingServerAccess one, write a new logic for the property - when a change occurs:
Implementation
Done in branches/private/kyli/2425 according to the design, of course problems appeared:
- The TextLinkProcessor.applyChange() generates wrong results sometimes, so I had to replace it with full text processing. Unfortunately, the time is not enough to try to debug it.
- Synchronization between client and server replaces horizontal tabs and line breaks in the hot text with spaces. The problem is in XMLPersister, but I didn't succeed to find out more.
Testing
Place the testing results here.
Comments
Write comments for this or later revisions here.