Copy paste strips xml:id

Oxygen general issues.
xsaero00
Posts: 58
Joined: Sat Aug 01, 2009 12:57 am

Copy paste strips xml:id

Post by xsaero00 »

When I copy/paste from one file to other in Author view it strips the xml:id. How do I modify that behavior?
xsaero00
Posts: 58
Joined: Sat Aug 01, 2009 12:57 am

Re: Copy paste strips xml:id

Post by xsaero00 »

I found the code responsible for this. I want to override it but still keep some of the behaviour. Basically, if I am copying from the same file I want ids to be stripped but if I copy from other file then I want to keep IDs. I got something working but its not quite what I want.

Code: Select all


@Override
public ClipboardFragmentProcessor getClipboardFragmentProcessor() {
final ClipboardFragmentProcessor originalImplementation = super.getClipboardFragmentProcessor();

return new Docbook5UniqueAttributesRecognizer()
{
/**
* @see ro.sync.ecss.extensions.api.content.ClipboardFragmentProcessor#process(ro.sync.ecss.extensions.api.content.ClipboardFragmentInformation)
*/
@Override
public void process(ClipboardFragmentInformation fragmentInformation) {
if(!fragmentInformation.getFragment().isEmpty() &&
fragmentInformation.getFragment().getContentNodes().size() > 0 &&
fragmentInformation.getFragment().getContentNodes().get(0).getName() == "table") {
// do not strip ids for tables
}
else
originalImplementation.process(fragmentInformation);
}

};
}
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Copy paste strips xml:id

Post by Radu »

Hi Mike,

You are on the right path.
Maybe you can look at the Java code (which is available in the SDK) for the:

ro/sync/ecss/extensions/commons/id/DefaultUniqueAttributesRecognizer.java

and see how the method:

public void process(ClipboardFragmentInformation fragmentInformation)

is implemented.

The code which decides the IDs will be stripped in the target file is this:

Code: Select all


.................
if(fragmentInformation.getFragmentOriginalLocation() != null
&& ! fragmentInformation.getFragmentOriginalLocation().equals(authorAccess.getEditorAccess().getEditorLocation().toString())) {
//Paste from another document. Remove the IDs
removeUniqueIDs = true;
}
................
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
xsaero00
Posts: 58
Joined: Sat Aug 01, 2009 12:57 am

Re: Copy paste strips xml:id

Post by xsaero00 »

Thanks. Yes I saw that code. What I don't know is how do I change the condition

Code: Select all


fragmentInformation.getFragmentOriginalLocation().equals(authorAccess.getEditorAccess().getEditorLocation().toString())
in such a way so it returns true when copying from the same file and false when copying from another file opened in the same Editor.
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: Copy paste strips xml:id

Post by Radu »

Hi Mike,

The fragmentInformation.getFragmentOriginalLocation() represents the URL from where the fragment was cut/copied or dragged.
And authorAccess.getEditorAccess().getEditorLocation() represents the URL of the current editor in which the fragment is pasted or dropped.

So just reverse the condition like:

Code: Select all


.................
if(fragmentInformation.getFragmentOriginalLocation() != null
&& ! fragmentInformation.getFragmentOriginalLocation().equals(authorAccess.getEditorAccess().getEditorLocation().toString())) {
//Paste from another document. Do not remove the IDs
removeUniqueIDs = false;
}
................
Actually we've discussed and in the next version we'll also change the default implementation bundled with Oxygen not to remove IDs when pasting to other files.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
xsaero00
Posts: 58
Joined: Sat Aug 01, 2009 12:57 am

Re: Copy paste strips xml:id

Post by xsaero00 »

Thank you very much. That was easier than I expected. :oops:
Post Reply