how can I get the position (line, column) from an XPath?

<oXygen/> general issues.
sebastienlavandier
Posts: 124
Joined: Tue May 29, 2012 5:42 pm

how can I get the position (line, column) from an XPath?

Post by sebastienlavandier » Mon Aug 27, 2012 11:57 am

Hello,

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

Radu
Posts: 6788
Joined: Fri Jul 09, 2004 5:18 pm

Re: how can I get the position (line, column) from an XPath?

Post by Radu » Mon Aug 27, 2012 12:33 pm

Hi,

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)
Otherwise you will have to locate the node yourself looking in the AuthorNode hierarchical structure.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

sebastienlavandier
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 » Mon Aug 27, 2012 1:15 pm

Hi,
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

sebastienlavandier
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 » Mon Aug 27, 2012 1:15 pm

Hi,
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

Radu
Posts: 6788
Joined: Fri Jul 09, 2004 5:18 pm

Re: how can I get the position (line, column) from an XPath?

Post by Radu » Tue Aug 28, 2012 10:30 am

Hi Sebastien,

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()
Such a highlight is constructed over the content of the Author page.
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)
The returned intervals give you directly line and column intervals.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

sebastienlavandier
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 » Wed Oct 10, 2012 4:01 pm

Thanks you Radu.

Radu
Posts: 6788
Joined: Fri Jul 09, 2004 5:18 pm

Re: how can I get the position (line, column) from an XPath?

Post by Radu » Fri Oct 19, 2012 2:27 pm

Hi Sebastien,

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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com

sebastienlavandier
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 » Wed Nov 14, 2012 4:52 pm

Hi Radu,

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.

alex_jitianu
Posts: 741
Joined: Wed Nov 16, 2005 11:11 am

Re: how can I get the position (line, column) from an XPath?

Post by alex_jitianu » Wed Nov 14, 2012 5:28 pm

Hi Sebastien,

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)
Best regards,
Alex

sebastienlavandier
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 » Wed Nov 14, 2012 5:47 pm

Hi Radu,
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.

sebastienlavandier
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 » Wed Nov 14, 2012 6:19 pm

Just I want to set the line and the column number in AuthorDocumentPositionedInfo.
But how I can obtain those informations from an AuthorNode object ?

Thanks in advance for your answer.
Regards.

alex_jitianu
Posts: 741
Joined: Wed Nov 16, 2005 11:11 am

Re: how can I get the position (line, column) from an XPath?

Post by alex_jitianu » Wed Nov 14, 2012 6:30 pm

Hi Sebastien,

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

sebastienlavandier
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 » Thu Nov 15, 2012 1:30 pm

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?
Hi Alex,
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

alex_jitianu
Posts: 741
Joined: Wed Nov 16, 2005 11:11 am

Re: how can I get the position (line, column) from an XPath?

Post by alex_jitianu » Fri Nov 16, 2012 11:28 am

Hi Sebastien,

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);
Best regards,
Alex

sebastienlavandier
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 » Mon Nov 19, 2012 3:51 pm

Thanks you Alex.

Post Reply