Hello Hussein, between lines:

On 15/05/2013 19:09, Hussein Shafie wrote:
> On 05/15/2013 06:26 PM, Maxime Bégnis wrote:
>> Hello,
>>
>> We finally solve the problem by using a Java applet accessed through
>> javascript to copy the xml content to the clipboard with a mime type of
>> "text/xml". It works fine when using it under linux, but not under
>> windows and I can't figure out why. Here is the very simple code I use
>> for the applet:
>>
>> public class ClipboardApplet extends Applet implements ClipboardOwner {
>>
>>      private Clipboard clipboard;
>>
>>      @Override
>>      public void init() {
>>          clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
>>      }
>>
>>      public boolean copy(final String mimeType, final String content) {
>>          clipboard.setContents(new DataHandler(content, mimeType),
>> this);
>>          return true;
>>      }
>>
>>      @Override
>>      public void lostOwnership(Clipboard clipboard, Transferable
>> contents) {
>>          // Nothing
>>      }
>>
>> }
>>
>> The "copy" method is used by javascript:
>> ClipboardApplet.copy('text/xml', xmlCode);
>>
>> xmlCode being for example:
>>
>> <?xml version="1.0"?><ns:clipboard
>> ns2:inclusion="com.xmlmind.xml.xinclude.XInclude:href=&quot;&quot;
>> xpointer=&quot;lorem-ipsum&quot;" ns2:readOnly="true"
>> ns2:sourceURL=""
>> xmlns:ns2="http://www.xmlmind.com/xmleditor/namespace/property";
>> xmlns:ns="http://www.xmlmind.com/xmleditor/namespace/clipboard";><para
>> xmlns="http://docbook.org/ns/docbook"; xml:id="lorem-ipsum" vendor=""
>> role="check">Lorem ipsum dolor sit amet, consectetur adipisicing elit,
>> sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut
>> enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
>> aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
>> in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
>> Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
>> officia deserunt mollit anim id est laborum.</para></ns:clipboard>
>>
>> Am I doing something wrong here?
>
> I don't see, but please note that I don't know what is DataHandler.
> (If it is:
>
> http://docs.oracle.com/javaee/1.4/api/javax/activation/DataHandler.html
It is.

>
> then I've never used this class. Internally, XXE uses
> com.xmlmind.xmledit.edit.XMLTransferable, whose thoroughly commented
> source code is attached to this email.)
Thanks to that source code I managed to make it work under Windows and
Linux. I used the same classes in the same way, got rid of DataHandler.

>
> May be there is nothing wrong at all. May be you are simply facing one
> of the many problems documented here:
>
> http://www.xmlmind.com/xmleditor/known_problems.html#platform_independent
>
> (Search for "Known problems related to the clipboard:")
It doesn't look like it.

>
> As explained in my answer below, I did not recommend to follow this
> path. Therefore, I'm sorry but I don't see how I could help you solve
> your problem.
We were in a hurry for this. We would prefer in the end to use the
solution you suggested and I'm sorry we didn't answer earlier:

>
>
>
>>
>> Thanks for your help.
>>
>> Maxime Bégnis
>>
>> On 04/05/2013 10:13, Hussein Shafie wrote:
>>> On 05/03/2013 04:57 PM, Fabián Mandelbaum wrote:
>>>> Hussein, thanks for your answers, my remarks between lines:
>>>>
>>>>     An external application copying some XML to the clipboard for
>>>> use by
>>>>     XXE must now declare the copied data as being "application/xml"
>>>> (or
>>>>     "text/xml").
>>>>
>>>>     In a nutshell, XXE 5.6.0 makes a difference between
>>>> "text/plain" and
>>>>     "application/xml", while XXE 5.4.0 ignored "application/xml" and
>>>>     ``sniffed'' the "text/plain" in order the detect the case where
>>>> this
>>>>     text was actually XML (starts with "<?xml ").
>>>>
>>>>
>>>> So, we're kind of stuck... because it's not easy (or even possible?)
>>>> from Javascript to copy stuff to the clipboard, much less being
>>>> able to
>>>> specify the media type (text/xml, for example) of the copied object...
>>>>
>>>> I'm sure there's a very valid and well thought rationale behind this
>>>> change, but this is a feature breaker for us...
>>>>
>>>> We're currently investigating the possibility to implement a small
>>>> java
>>>> applet that will perform this copy-to-clipboard function to replace
>>>> the
>>>> JavaScript implemented feature on our UI, but having an applet (on an
>>>> otherwise html+css+javascript-ONLY UI) just for this is not a very
>>>> elegant solution.
>>>>
>>>> Will keep investigating about JavaScript and the clipboard (which
>>>> seems
>>>> rather dead because, mainly, security constraints).
>>>>
>>>
>>> Don't worry, I'm sure we'll manage to solve this problem *cleanly*. So
>>> please forget about hacks, at least for the moment.
>>>
>>> I suggest to simply add a new scriptable method to the XXE applet.
>>>
>>> References:
>>>
>>> *
>>> http://www.xmlmind.com/xmleditor/_distrib/doc/configure/integrating_the_applet.html#applet_scripting
>>>
>>>
>>> *
>>> http://www.xmlmind.com/xmleditor/_distrib/doc/api/com/xmlmind/xmleditapp/applet/Applet.html
>>>
>>>
>>> This new scriptable method would allow to execute any command on the
>>> active document view by passing to the applet a command name and a
>>> command parameter. This mechanism can be used to copy an XML fragment
>>> to the clipboard or to directly paste something into the active
>>> document view.
>>>
>>> On your JavaScript side:
>>>
>>> 1) Do you currently use Scriptable methods?
Yes, to close documents when the browser's tab is closed.

>>>
>>> 2) If the answer is no, why no?
>>>
>>> 3) If the answer is yes, do you currently have any  problem (e.g.
>>> JavaScript security) with this?
No, it works quite well. Note that under Chrome, the tab is closed
immediately no matter if there is some pending changes or not, so the
user has no chance to say if he wants to save the changes or not. The
changes are not saved in this case. But the document is unlocked
correctly. I still don't know if we can do anything about that, but I
don't think so.

To use the solution you suggest, we would have to call the XXE applet
(or a javascript function on the XXE applet page) from another
tab/window of the browser. I must say that we still don't know if we can
do that and if it will work for any browser.

Thanks for everything.

>
>

-- 
-- 
*NeoDoc*
*Maxime Bégnis*
[email protected]
Tél: +33 (0)4.42.52.24.20
5, rue de la Touloubre
13770 Venelles
France
http://www.neodoc.fr/
--
XMLmind XML Editor Support List
[email protected]
http://www.xmlmind.com/mailman/listinfo/xmleditor-support

Reply via email to