how can I get the position (line, column) from an XPath?
-
- Posts: 124
- Joined: Tue May 29, 2012 5:42 pm
how can I get the position (line, column) from an XPath?
Post by sebastienlavandier »
I'm using a customized java service for the xml validation (MyClass extends ValidationProblemsFilter).
I need to identify the position (line, column) from an XPath for underline the error to the screen.
I have already got the text length with this code :
WSAuthorEditorPage authorPageAccess = (WSAuthorEditorPage) editorAccess.getCurrentPage();
AuthorDocumentController controller = authorPageAccess.getDocumentController();
int offsetLocation = controller.getXPathLocationOffset(location, AuthorConstants.POSITION_INSIDE_FIRST)
AuthorNode authorNode = controller.getNodeAtOffset(offsetLocation)
textLength = authorNode.getTextContent().length()
But how I can do for have the line and column from an xpath ?
Do you have an idea ?
Thanks in advance for your help.
Bye
-
- Posts: 9445
- Joined: Fri Jul 09, 2004 5:18 pm
Re: how can I get the position (line, column) from an XPath?
I do not quite understand.
What exactly does the web service validation return? An XPath expression? How does it look like?
If the XPath expression is valid we already have API like:
Code: Select all
ro.sync.ecss.extensions.api.AuthorDocumentController.findNodesByXPath(String, boolean, boolean, boolean)
Regards,
Radu
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 124
- Joined: Tue May 29, 2012 5:42 pm
Re: how can I get the position (line, column) from an XPath?
Post by sebastienlavandier »
The web service return an error message and an XPath.
With the informations, I create a DocumentPositionedInfo(ErrorMessage), and now I want to recover the line number, the column number and the length of the content for underline the error in the text mode or in the Author mode.
I hope that is most clear for you ?
My problem is :
1 / In the author mode I can recover the AuthorNode with getXPathLocationOffset
and recover the length but I can't recover the line number and the column number.
2 / In the text mode, I can recover a document controler for do the same things. But, some methods exiting for recover the line and column number.
I hope that you can help me.
Regards
-
- Posts: 124
- Joined: Tue May 29, 2012 5:42 pm
Re: how can I get the position (line, column) from an XPath?
Post by sebastienlavandier »
The web service return an error message and an XPath.
With the informations, I create a DocumentPositionedInfo(ErrorMessage), and now I want to recover the line number, the column number and the length of the content for underline the error in the text mode or in the Author mode.
I hope that is most clear for you ?
My problem is :
1 / In the author mode I can recover the AuthorNode with getXPathLocationOffset
and recover the length but I can't recover the line number and the column number.
2 / In the text mode, I can recover a document controler for do the same things. But, some methods exiting for recover the line and column number.
I hope that you can help me.
Regards
-
- Posts: 9445
- Joined: Fri Jul 09, 2004 5:18 pm
Re: how can I get the position (line, column) from an XPath?
I understand the difficulty.
Unfortunately right now there is no API to easily create a DocumentPositionInfo over an AuthorNode (or for a certain offset in the Author document). We will try to add the API.
A workaround for the Author page would be to add your own highlights using the API:
Code: Select all
ro.sync.exml.workspace.api.editor.page.author.WSAuthorEditorPageBase.getHighlighter()
I think there are some samples for adding highlights in the Author SDK-> Simple Documentation Framework project.
So basically when the filter gets called you could remove all Author highlights, add new ones and leave the list of DocumentPositionInfo objects unchanged.
For the Text page you have this newer API (which was added in version 14.0):
Code: Select all
ro.sync.exml.workspace.api.editor.page.text.xml.WSXMLTextEditorPage.findElementsByXPath(String)
Regards,
Radu
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 124
- Joined: Tue May 29, 2012 5:42 pm
Re: how can I get the position (line, column) from an XPath?
Post by sebastienlavandier »
-
- Posts: 9445
- Joined: Fri Jul 09, 2004 5:18 pm
Re: how can I get the position (line, column) from an XPath?
We just released Oxygen 14.1 which contains a new API class ro.sync.ecss.component.validation.AuthorDocumentPositionedInfo which would help you add custom errors to Author Nodes.
Regards,
Radu
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 124
- Joined: Tue May 29, 2012 5:42 pm
Re: how can I get the position (line, column) from an XPath?
Post by sebastienlavandier »
Thanks for your answer.
But the new class "AuthorDocumentPositionedInfo" isn't registered in the Oxygen javadoc.
That is difficult to implement without him.
Do you have more informations for me about the constructor ?
Regards.
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: how can I get the position (line, column) from an XPath?
Post by alex_jitianu »
I've just corrected the missing Java Doc entries. Until a new build is available here are the signatures for the two available constructors:
Code: Select all
/**
* Constructor.
*
* @param severity Severity. One of the severity constants form class DocumentPositionedInfo:
* SEVERITY_ERROR, SEVERITY_FATAL, SEVERITY_INFO , SEVERITY_WARN.
* @param message Error message.
* @param systemID System ID
* @param node The author node.
*/
public AuthorDocumentPositionedInfo(
int severity,
String message,
String systemID,
AuthorNode node)
/**
* Constructor.
*
* @param severity Severity. One of the severity constants form class DocumentPositionedInfo:
* SEVERITY_ERROR, SEVERITY_FATAL, SEVERITY_INFO , SEVERITY_WARN.
* @param message Error message.
* @param systemID System ID
* @param startOffset The start offset of the problem, mapped in the Author content.
* @param length The length of the problem, mapped in the Author content.
*/
public AuthorDocumentPositionedInfo(
int severity,
String message,
String systemID,
int startOffset,
int length)
Alex
-
- Posts: 124
- Joined: Tue May 29, 2012 5:42 pm
Re: how can I get the position (line, column) from an XPath?
Post by sebastienlavandier »
Thanks for your answer.
It's implemented and it's works well !
And now, how I can underline the error in the author page ?
Do you have an idea ?
thanks in advance for your answer.
-
- Posts: 124
- Joined: Tue May 29, 2012 5:42 pm
Re: how can I get the position (line, column) from an XPath?
Post by sebastienlavandier »
But how I can obtain those informations from an AuthorNode object ?
Thanks in advance for your answer.
Regards.
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: how can I get the position (line, column) from an XPath?
Post by alex_jitianu »
If you create an AuthorDocumentPositionedInfo over an AuthorNode then the given node will be automatically underlined in the author page. Why do you need to map that node into a line and column?
Best regards,
Alex
-
- Posts: 124
- Joined: Tue May 29, 2012 5:42 pm
Re: how can I get the position (line, column) from an XPath?
Post by sebastienlavandier »
Hi Alex,alex_jitianu wrote:If you create an AuthorDocumentPositionedInfo over an AuthorNode then the given node will be automatically underlined in the author page. Why do you need to map that node into a line and column?
But unfortunately, the node is not automatically underlined !
For do that, the line, column and length of the authorDocumentPositionedInfo object must be setted.
But how I can recover this informations ?
Thanks in advance for your help.
Regards
-
- Posts: 1016
- Joined: Wed Nov 16, 2005 11:11 am
Re: how can I get the position (line, column) from an XPath?
Post by alex_jitianu »
There should be no need for you to set the line and column, the node should be highlighted automatically. But as you already noticed the node isn't highlighted. We will add an issue and see what the problem is.
Regarding the possible workarounds, there is no API to obtain a line and column information for that node. One workaround would be that after adding the AuthorDocumentPositionedInfo in ValidationProblemsFilter, to add a highlight yourself for the node, something like this:
Code: Select all
AuthorDocumentPositionedInfo dpi = new AuthorDocumentPositionedInfo(...);
newProblemsList.add(dpi);
authorPage.getHighlighter().removeAllHighlights();
authorPage.getHighlighter().addHighlight(node.getStartOffset(), node.getEndOffset(), new ColorHighlightPainter(), null);
Alex
-
- Posts: 124
- Joined: Tue May 29, 2012 5:42 pm
Re: how can I get the position (line, column) from an XPath?
Post by sebastienlavandier »
- 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