get copied data in code and do paste operation web author
-
- Posts: 99
- Joined: Fri Jul 01, 2022 12:08 pm
get copied data in code and do paste operation web author
Post by shikhar_472 »
I wanted to get the copied data which holds by copy event CTRL+C and want to paste by button action whatever position I want i web author, could you please help me on this.
Thanks,
Shikhar.
-
- Posts: 513
- Joined: Thu Sep 04, 2014 4:22 pm
Re: get copied data in code and do paste operation web author
Post by cristi_talau »
In Web Author users can paste content in two ways:
- Using the Ctrl+V (or Cmd+V) shortcut.
- Using the "Paste special" action from the contextual menu which shows a dialog where the users need to paste the content.
Regarding the location of the paste, do you want to create some actions like "Paste after" or "Paste before"? Or just want to tweak the paste position in some cases where the default paste strategy does not meet user expectations? The second use-case can be solved by using the
Code: Select all
ro.sync.ecss.extensions.api.AuthorSchemaAwareEditingHandler.handlePasteFragment()
Best,
Cristian
-
- Posts: 99
- Joined: Fri Jul 01, 2022 12:08 pm
Re: get copied data in code and do paste operation web author
Post by shikhar_472 »
Thanks for the reply.
I have one more question i have created the new Fragment using seriliazed xml(createNewDocumentFragmentInContext using this method) and now i want access all the nodes of that fragment inside AuthorDocumentFragment there is getContentNodes method is there which is only returning the first level node but i want to access all the nodes which are present inside the fragment created. Could you please suggest the way to achieve that
Thanks,
Shikhar.
-
- Posts: 99
- Joined: Fri Jul 01, 2022 12:08 pm
-
- Site Admin
- Posts: 163
- Joined: Tue Mar 20, 2018 5:28 pm
Re: get copied data in code and do paste operation web author
Post by Bogdan Dumitru »
To access all the nodes which are present inside the created fragment you have to cast from AuthorNode to AuthorElement [0].
For a safe cast you can first check if the node type is NODE_TYPE_ELEMENT:
Code: Select all
if (node.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement element = (AuthorElement) node;
element.getContentNodes();
}
http://www.oxygenxml.com
-
- Posts: 99
- Joined: Fri Jul 01, 2022 12:08 pm
Re: get copied data in code and do paste operation web author
Post by shikhar_472 »
AuthorDocumentFragment docFragment = model.getAuthorAccess().getDocumentController()
.createNewDocumentFragmentInContext(cotentToPaste,
model.getAuthorAccess().getEditorAccess().getCaretOffset());
AuthorNode authorNode = (AuthorElement)docFragment.getContentNodes(); //here it can not cast because list is there
ArrayList<AuthorNode> listNodes =(ArrayList<AuthorNode>) docFragment.getContentNodes();
i tried looping listNodes still not able to access all the nodes
My task is from text xml i created a fragment eg. <a><b><c id ="2"> </c></b><a>
now inside this fragment i want to increment the id for that i want to access c node to setAttribute but using getContentNodes inside list i am getting only <a> node.
-
- Site Admin
- Posts: 163
- Joined: Tue Mar 20, 2018 5:28 pm
Re: get copied data in code and do paste operation web author
Post by Bogdan Dumitru »
Yes, you have to iterate on all nodes returned by the "getContentNodes()" method and cast them to AuthorElement, then you have to recursively iterate in order to find all nodes, not just the ones from the first level.
The code should look something like this:
Code: Select all
public void findElementsToUpdate(AuthorDocumentFragment fragment) {
List<AuthorElement> elementsWithId = new ArrayList<>();
for (AuthorNode firstLevelNode : fragment.getContentNodes()) {
if (firstLevelNode.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement firstLevelElement = (AuthorElement) firstLevelNode;
elementsWithId.addAll(recursivelyFindNodesWithId(firstLevelElement));
}
}
System.out.println("Elements to updated: " + elementsWithId);
}
private static List<AuthorElement> recursivelyFindNodesWithId(AuthorElement element) {
List<AuthorElement> toReturn = new ArrayList<>();
if (element.getAttribute("id") != null) {
toReturn.add(element);
}
for (AuthorNode childNode : element.getContentNodes()) {
if (childNode.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement childElement = (AuthorElement) childNode;
toReturn.addAll(recursivelyFindNodesWithId(childElement));
}
}
return toReturn;
}
http://www.oxygenxml.com
-
- Posts: 99
- Joined: Fri Jul 01, 2022 12:08 pm
Re: get copied data in code and do paste operation web author
Post by shikhar_472 »
-
- Site Admin
- Posts: 163
- Joined: Tue Mar 20, 2018 5:28 pm
Re: get copied data in code and do paste operation web author
Post by Bogdan Dumitru »
The AuthorDocumentController.createNewDocumentFragmentInContext() shouldn't take much time unless you have a DOCTYPE that refers to a remote DTD that leads to a remote connection being made.
Your performance problem might be caused actually to the fact that the fragment is recursively iterated or the "createNewDocumentFragmentInContext()" is called multiple times. It should be faster to insert the fragment and then find the elements with the "id" attribute using AuthorDocumentController.evaluateXPath(). Another solution would be to process the fragment using a RegExp like " id=\"[^"]+\"".
http://www.oxygenxml.com
-
- Posts: 99
- Joined: Fri Jul 01, 2022 12:08 pm
Re: get copied data in code and do paste operation web author
Post by shikhar_472 »
Instant start = Instant.now();
AuthorDocumentFragment docFragment = docControl.createNewDocumentFragmentInContext(cotentToPaste,
authorAccess.getEditorAccess().getCaretOffset(););
Instant end = Instant.now();
Duration timeElapsed1 = Duration.between(start, end);
logger.info("after created doc fragment " + timeElapsed1");
This single line itself is taking more than 2 seconds and recursive iteration is taking only 0.026 Second could you please help me on this.
-
- Site Admin
- Posts: 163
- Joined: Tue Mar 20, 2018 5:28 pm
Re: get copied data in code and do paste operation web author
Post by Bogdan Dumitru »
Curious that the "createNewDocumentFragmentInContext(cotentToPaste, [...])" call takes that long.
If all you want is id attribute auto-generation, see the "Configuring the Automatic ID Generation and Unique Attributes Recognizer" topic [0], it might be exactly what you need.
If that topic isn't exactly what you need, please consider offering more details about your use case so that we can guide you to a more efficient solution that may not require manually creating an AuthorDocumentFragment.
If you want to troubleshoot why it takes soo long to create the fragment, please do and answer the following:
1. check the length of the "cotentToPaste" string. If it's a huge string, it might justify a long time computing it.
2. enable debug logging [1] and check if server makes requests when calling "createNewDocumentFragmentInContext()". This way you'll check that no external DTD is fetched.
3. does it take 2s just the first time when the method is called or always?
4. does the problem reproduces in a fresh Web Author kit from the last released version, v24.1?
5. help us to reproduce the problem. Send us to "support@oxygenxml.com" all the necessary so we can reproduce the problem: the "cotentToPaste" string, your framework, and relevant custom plugins if present.
[0] https://www.oxygenxml.com/doc/versions/ ... nizer.html
[1] https://www.oxygenxml.com/doc/versions/ ... tgc_1wq_2v
http://www.oxygenxml.com
-
- Posts: 99
- Joined: Fri Jul 01, 2022 12:08 pm
Re: get copied data in code and do paste operation web author
Post by shikhar_472 »
For me navigator.clipboard is coming as undefined is there any way to read data from clipboard without using navigator.clipboard
-
- Posts: 78
- Joined: Wed Jul 20, 2016 8:22 am
Re: get copied data in code and do paste operation web author
Post by mihai_coanda »
This API has limitations as described in this StackOverflow post [1] and in the MDN documentation [2].
Best Regards,
Michael
1. https://stackoverflow.com/questions/518 ... -undefined.
2. https://developer.mozilla.org/en-US/doc ... /Clipboard
https://www.oxygenxml.com
Return to “General XML Questions”
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service