Saving Layouts in XML

This forum is used by users to request and discuss new product features. Please do not use this forum for technical support including bug reports.

Moderator: JIDE Support

Forum rules
Product suggestions only. Please do not use this forum for technical support including bug reports.

Saving Layouts in XML

Postby Fairall » Mon Nov 01, 2004 6:50 am

8) Hi All

We are developing a product based on Jide Dockable Framework which
employs a number of (Eclipse-like) perspectives.
Each perspective is a DockableHolder.
When we do a SaveLayout, we have to save each Layout file separately
using the perspective names to identify the layouts.

We would really like to have the option of saving the Layouts to file in
XML format and combine all the perspective layouts. If this is too much then perhaps access to the classes and information on what is saved in the binary files.
'Twould be marvellous !
Thanks

Rich Fairall
Fairall
 
Posts: 5
Joined: Mon May 10, 2004 10:16 pm

Postby JIDE Support » Mon Nov 01, 2004 9:36 am

You don't need to always save layout to a file. There are many ways to save a layout. One method you can use is getLayoutData(). It will get the layout data as a String. Later on, you can use setLayoutData(String layout) to restore the layout. Once you have the layout string, you can do whatever you want to it including save the string as part of an xml file which has all the perspective layouts you want.

Let me know if this solution works.

Thanks.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby Fairall » Thu Nov 04, 2004 12:58 am

Thanks for the reply.
I invoked dockingManager.getLayoutData() and see that the string
is non-readable (lots of hieroglyphics), is this to be expected?
XML files are always readable, and I had expected something readable here.
I could stuff it into an attribute in one lump I suppose.
Rich
Fairall
 
Posts: 5
Joined: Mon May 10, 2004 10:16 pm

Postby JIDE Support » Thu Nov 04, 2004 1:05 am

I guess it depends how you define readable. It's readable (pure ASCII) but not understandable because it is encoded. However you have no problem dump it into XML using CDATA.

Thanks.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby m.bruni » Thu Sep 29, 2005 4:22 am

JIDE Support wrote:However you have no problem dump it into XML using CDATA.


Since CDATA sections accept only unicode chars
http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char wrote:#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */

and the layoutString contains 0x0, parsing the XML file would result in a SAXParseException...
I think I will encode it using Base64 before putting it in an XML node...

--
Matteo Bruni
m.bruni
 
Posts: 125
Joined: Tue Sep 20, 2005 7:13 am

Postby JIDE Support » Thu Sep 29, 2005 8:11 am

That's correct. There are several Base64 encoder out there on the web. You can use them.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby Jii » Fri Oct 21, 2005 3:42 am

How do i go about encoding the layout string?

There is a method which takes in the specified encoding also as string (getLayoutData(String encode)). What should i hand it as the param to get base64?


edit:
Also i just noticed this:
The most exciting feature is probably the new Visual Designer. Visual Designer allows you to use drag-n-drop to visually design the layout of dockable frames and command bars, and save it as an xml file. In your application, instead of calling setInitXxx method to hard code the initial side, mode and index of each dockable frame, you just call loadInitialLayout to load the layout xml file you created. Both JIDE Docking Framework and JIDE Action Framework now support to load initial layouts.


If you're going to let people save layouts to xml from the visual designer anyway, why not make that possible in persistence saving?


edit2:
Additionally, Base64 encoding it doesn't seem to work. Tyring to decode ends up in:
org.apache.commons.codec.DecoderException: RFC 1522 violation: malformed encoded content

What the christ are you putting into this stuff? :)
Jii
 
Posts: 42
Joined: Tue Jul 05, 2005 1:43 am

Postby JIDE Support » Fri Oct 21, 2005 8:24 am

Base64 should work. I heard one customer used Base64 encoding/decoding at http://iharder.sourceforge.net/base64/.

Initial layout saved by Visual Designer is much simpler. After user drag-n-drop to rearrange the layout, the actual layout saved using saveLayoutData() is much more complex. One reason we don't want to save it as xml because we don't want to other people find out what information we saved by looking at the layout file.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby Jii » Mon Oct 24, 2005 11:21 pm

JIDE Support wrote:Base64 should work. I heard one customer used Base64 encoding/decoding at http://iharder.sourceforge.net/base64/.

Initial layout saved by Visual Designer is much simpler. After user drag-n-drop to rearrange the layout, the actual layout saved using saveLayoutData() is much more complex. One reason we don't want to save it as xml because we don't want to other people find out what information we saved by looking at the layout file.



What about is more complex? Suppose we wanted to just save the very basic stuff about dockable frames (location, size, docking status etc)? Would this be possible using xml?
Jii
 
Posts: 42
Joined: Tue Jul 05, 2005 1:43 am

Postby JIDE Support » Tue Oct 25, 2005 8:43 am

Even the basic stuff is beyond the cability of initial layout xml. Initial layout only allows one level of hierarchy. In the other word, you can only define one level of dockable frames on each dock side. However docking framework supports any level of nested dockable frames which initial layout can't support.

Any reason you can't use Base64 to save layout as string into your own xml format?

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby Jii » Tue Oct 25, 2005 10:50 pm

JIDE Support wrote:Any reason you can't use Base64 to save layout as string into your own xml format?

Thanks,



Just that it doesn't seem to work at all. DockingManager.getLayoutData() encoded to base64 and then decoded and applied with setLayoutData(String) doesn't work. Also the two strings look slightly different after the operation, which is probably why :)
Last edited by Jii on Tue Oct 25, 2005 11:20 pm, edited 1 time in total.
Jii
 
Posts: 42
Joined: Tue Jul 05, 2005 1:43 am

Postby JIDE Support » Tue Oct 25, 2005 11:11 pm

It absolutely should work. Here is what I tried in DockingFrameworkDemo.

Code: Select all
String layoutData = _frame.getDockingManager().getLayoutData();
byte[] layout = Base64.encode(layoutData.getBytes());
String newLayoutData = new String(Base64.decode(layout));
if(newLayoutData.equals(layoutData)) {
    System.out.println("equal");
}


I simply used the Base64 class in xerces since I happen to have xerces.jar in my class path.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby Jii » Tue Oct 25, 2005 11:29 pm

JIDE Support wrote:It absolutely should work. Here is what I tried in DockingFrameworkDemo.

Code: Select all
String layoutData = _frame.getDockingManager().getLayoutData();
byte[] layout = Base64.encode(layoutData.getBytes());
String newLayoutData = new String(Base64.decode(layout));
if(newLayoutData.equals(layoutData)) {
    System.out.println("equal");
}


I simply used the Base64 class in xerces since I happen to have xerces.jar in my class path.

Thanks,


Any chance that hashing the string mid-way might mess this up?

Because i just tried in a simple tester program and it worked, yet it doesn't in my application.
Jii
 
Posts: 42
Joined: Tue Jul 05, 2005 1:43 am

Postby m.bruni » Wed Oct 26, 2005 6:53 am

Any chance that hashing the string mid-way might mess this up?


I'm actually using this method to save my layouts and works fine (using Base64 library from apache commons codec project

--
Matteo Bruni
m.bruni
 
Posts: 125
Joined: Tue Sep 20, 2005 7:13 am

Postby Jii » Thu Oct 27, 2005 12:58 am

Ok now i tried this:

Code: Select all
         FileWriter writer = new FileWriter(new File("layout"));
         String layoutData = getDockingManager().getLayoutData();
         layoutData = Base64.encode(layoutData.getBytes());
         writer.write(layoutData);


And then this:

Code: Select all
         BufferedReader reader = new BufferedReader(new FileReader("layout"));
         String layoutData = reader.readLine();
         System.out.println(layoutData);
         layoutData = new String(Base64.decode(layoutData));


The system.out doesnt indicate that the String is null, yet i get a nullpointerexception on the next line.

Suggestions?
Jii
 
Posts: 42
Joined: Tue Jul 05, 2005 1:43 am

Postby Jii » Thu Oct 27, 2005 3:04 am

Ditching the xml thing, i tried to keep it simple:

Code: Select all
getDockingManager().saveLayoutDataToFile("backup.layout");


and

Code: Select all
getDockingManager().loadLayoutDataFromFile("backup.layout");


... after creating the components.

The layout still doesn't work, looks nothing like the one i saved.


edit: an update on this, it seems to work if i first save the layout, then move some components and then load it again.

However, if i do:
Code: Select all
layoutData = getDockingManager().getLayoutData("utf-8");


, move a component and then do:

Code: Select all
getDockingManager().setLayoutData(layoutData, "utf-8");


it doesn't work, the layout reverts to default. Even though the two strings are identical according to equals :/
Jii
 
Posts: 42
Joined: Tue Jul 05, 2005 1:43 am

Postby Jii » Thu Oct 27, 2005 11:08 pm

Just an update to say this issue is resolved now, thanks for all the swift help :)
Jii
 
Posts: 42
Joined: Tue Jul 05, 2005 1:43 am

Postby JIDE Support » Fri Oct 28, 2005 5:08 pm

So how do you resolve it? I want to know in case someone gets the same error?

BTW, our initial test found out getLayoutData("utf-8")/setLayoutData(layoutData, "utf-8") pair doesn't work. We will try to fix it. getLayoutData()/setLayoutData() works all the time even I don't rearrange component in between.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Postby Jii » Tue Nov 01, 2005 5:52 am

JIDE Support wrote:So how do you resolve it? I want to know in case someone gets the same error?

BTW, our initial test found out getLayoutData("utf-8")/setLayoutData(layoutData, "utf-8") pair doesn't work. We will try to fix it. getLayoutData()/setLayoutData() works all the time even I don't rearrange component in between.

Thanks,



Well it was a doozy. Here's how we do it now:

Code: Select all
   private String getLayout(DockingManager manager) {
      ByteArrayOutputStream bout = new ByteArrayOutputStream();
      bout.reset();
      try {
         manager.saveLayoutTo(bout);
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
      BASE64Encoder b64 = new BASE64Encoder();
      return b64.encode(bout.toByteArray());
   }


and

Code: Select all
   private void setLayout(DockingManager manager, String layout) {
      BASE64Decoder d64 = new BASE64Decoder();
      try {
         if(layout == null){
            manager.loadLayoutData();
         }
         else{
            manager.loadLayoutFrom(new ByteArrayInputStream(d64.decodeBuffer(layout)));
         }
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }


and those seem to do the trick. The layout is still saved as a String in the xml, it was just some weird bytearray/String/encoding problem.
Jii
 
Posts: 42
Joined: Tue Jul 05, 2005 1:43 am

Postby JIDE Support » Tue Nov 01, 2005 9:17 am

Thanks for the code. I think it will be very helpful for other people who wants to do the same thing.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to Product Suggestions

Who is online

Users browsing this forum: No registered users and 80 guests