Plugin development - currentFileURL

Having trouble installing Oxygen? Got a bug to report? Post it all here.
calvados
Posts: 22
Joined: Wed Jul 30, 2008 12:46 am

Plugin development - currentFileURL

Post by calvados »

Hi there...

I'm in the process of writing some custom transformation plugins for author mode, and I'm trying to access the currently open document. Is there a way to access the current document like ${currentFileURL} does in the oxygen transformation scenario, but from a plugin that functions in author mode?

Thanks for your help..

Cal.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Plugin development - currentFileURL

Post by sorin_ristache »

Hello,

In your custom extension for the Author mode which you set up in the Classpath tab of the document type editing dialog you find the URL of the current document with the method getEditorLocation() of interface AuthorAccess. The interface which your custom Author operation must implement, that is AuthorOperation has a method doOperation which receives a parameter of type AuthorAccess.

Also you can access the content of the current document through the interface AuthorDocumentController which you obtain from AuthorOperation with the method AuthorAccess.getDocumentController().


Regards,
Sorin
calvados
Posts: 22
Joined: Wed Jul 30, 2008 12:46 am

Re: Plugin development - currentFileURL

Post by calvados »

Thanks Sorin, getEditorLocation() worked perfectly, except that if the file currently being edited hasn't been saved, the unsaved changes are not brought across. This differs from the behavior experienced when using ${currentFileURL}, where unsaved changes are captured.

Is there a way to either: a) capture the unsaved changes along with the rest of the document, or b) to determine if the current document has not been saved, and prompt the user to do so before the author plugin continues?

Also...maybe I'm not understanding completely, but do you know of a way to retrieve the current location of the frameworks directory? ie. ${frameworks}?

Thanks again for your help with these matters...

Cal.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Plugin development - currentFileURL

Post by sorin_ristache »

Hello,
calvados wrote:if the file currently being edited hasn't been saved, the unsaved changes are not brought across. This differs from the behavior experienced when using ${currentFileURL}, where unsaved changes are captured.
An Author extension attached to a document type and executed by pressing a toolbar button or by selecting a menu item when a document of that type is currently edited works on the current content of the editor panel. It does not read the file content from disk, it uses the edited content which means it works on the unsaved changes.
calvados wrote:do you know of a way to retrieve the current location of the frameworks directory? ie. ${frameworks}?
No, there is no way to find the location of the frameworks directory from an Author extension. Please give more details about how you want to use this location. It seems that normally you do not need the disk location of the frameworks directory because all the files of a document type (the schema, the CSS stylesheet, the custom Author extensions, the document templates) are stored in the same subdirectory of the frameworks directory and using relative paths should be what you need for finding other files of the same document type. Using relative paths enables sharing the document type with other users who may store it in a different location on disk without modifying anything in the document type from Options -> Preferences -> Document Type Association.


Regards,
Sorin
calvados
Posts: 22
Joined: Wed Jul 30, 2008 12:46 am

Re: Plugin development - currentFileURL

Post by calvados »

An Author extension attached to a document type and executed by pressing a toolbar button or by selecting a menu item when a document of that type is currently edited works on the current content of the editor panel. It does not read the file content from disk, it uses the edited content which means it works on the unsaved changes.
Hey Sorin, I'm sorry to say but this differs from my experience. Unsaved changes are not brought across into my custom extension. authorAccess.getEditorLocation() returns a path to the file that's currently being edited on the file system. This is evidenced by executing authorAccess.showErrorMessage(authorAccess.getEditorLocation());

The way in which I'm using getEditorLocation to get the content of the document currently being edited is as follows...
InputStream is = authorAccess.getEditorLocation().openStream();

My extension is registered with the document type association for the type of document being edited. The rest of the content is captured, but not the unsaved changes.

Am I doing something wrong?

Cal.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Plugin development - currentFileURL

Post by sorin_ristache »

calvados wrote:The way in which I'm using getEditorLocation to get the content of the document currently being edited is as follows...
InputStream is = authorAccess.getEditorLocation().openStream();
authorAccess.getEditorLocation() returns the URL of the edited file so openStream() will read the content of the file from the URL, that is the content saved on disk or on a remote server (HTTP server, FTP server, etc).

What I said about accessing the unsaved changes that the user applied in the Author mode is about the usual Author API methods for accessing the edited content, that is authorAccess.getSelectedText(), authorAccess.deleteSelection(), authorAccess.getWordAtCaret(), authorAccess.insertText(), authorAccess.insertXMLFragment(), authorAccess.multipleDelete(), authorAccess.getDocumentController().getText(), etc.


Regards,
Sorin
calvados
Posts: 22
Joined: Wed Jul 30, 2008 12:46 am

Re: Plugin development - currentFileURL

Post by calvados »

Hey Sorin,

I was wondering if in the new 10.0 version if there's a way to select the entire xml document as it is presented to the user with any unsaved changes?

Thanks,

Cal.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Plugin development - currentFileURL

Post by sorin_ristache »

Hello,

You can select the entire content of the current XML document edited in the Author mode with:

Code: Select all

authorAccess.select(0, authorAccess.getDocumentController().getTextContentLength() - 1)
These calls were also available in the Author API in the previous versions of Oxygen.


Regards,
Sorin
calvados
Posts: 22
Joined: Wed Jul 30, 2008 12:46 am

Re: Plugin development - currentFileURL

Post by calvados »

Unfortunately this only provides me with the content of the text nodes of the xml document, as opposed to the entire xml document itself including all nodes, attributes, and content. Is there a way to retrieve the entire xml document? Like what what the user seeing in text mode as opposed to author mode including all changes that have not yet been saved?

Also...I was under the impression that authorAccess.select(startOffset, endOffset) was a new implementation of 10.0 It is not listed in the 9.3 SDK.

Thanks,

Cal.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Plugin development - currentFileURL

Post by sorin_ristache »

Hello,

Yes, authorAccess.select(startOffset, endOffset) was added in version 10.0.

There is no method for getting the serialized form of the Author document, that is a text string that includes both the content edited in the Author mode and the XML markup available in Text mode. Can you give more details about why or how you need to use the serialized form of the document?


Regards,
Sorin
calvados
Posts: 22
Joined: Wed Jul 30, 2008 12:46 am

Re: Plugin development - currentFileURL

Post by calvados »

I'm trying to gain access to the serialized document so that I can run xPath queries from my java author extension. It's extremely frustrating to have such a powerful GUI XML editor such as oxygen's author mode, and the flexibility to develop java plugins, but yet not have access to something as basic as the ability to perform an xPath query on the document. My options now seem to rely on the offsets of the nodes to determine where in the document I am, and write extremely long methods to achieve what could easily be returned by a single xPath expression.

After developing author mode plugins for 9.3 and now 10.0, I can easily say the lack of xPath queries, and access to the unsaved XML document are the two most critical lacking features.

Do you have any other ideas as to how I may achieve the same results with the calls that are currently available?

Are there plans in the works to allow access to the currently unsaved document? Are there plans to allow xPath queries?

Thanks,

Cal.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Plugin development - currentFileURL

Post by sorin_ristache »

Hello,
calvados wrote:I'm trying to gain access to the serialized document so that I can run xPath queries from my java author extension.

...

Are there plans in the works to allow access to the currently unsaved document? Are there plans to allow xPath queries?
Yes, we plan to add support for running an XPath expression from an Author extension in a future version (one of the 10.x versions).

I assume you want to access the complete (as in Text mode - the document content including the XML markup) and unsaved XML document for running an XPath query on it. That will not be needed after the Author API will allow running XPath queries on the XML document.


Regards,
Sorin
calvados
Posts: 22
Joined: Wed Jul 30, 2008 12:46 am

Re: Plugin development - currentFileURL

Post by calvados »

In the meanwhile, I'm attempting to serialize the XML document by traversing the document and creating an in memory XML document. I've now run into a problem where I'm unable to retrieve the text node of and element, without retrieving all of the descendants text as well.

For example:

Code: Select all

<?xml version="1.0"?>
<root>
<content>
<speech>
<text>I would like to talk about the <actName>election act</actName> as it pertains to the upcoming election.</text>
</speech>
</content>
</root>
If I'm on the 'root' element, I'd like to determine if one of the children of that node is a text element. In this case the answer would be no. Then I move to 'content', and look for a child text node. Again the answer would be no. Then to again to 'speech', until I reach 'text', where finally the answer would be yes...but there is another node ('actName') nested in there with text as well.

I'm stuck trying to serialize this part of the document with a nested node in the middle of some text content. Also, determining if a node contains text at all, and retrieving it without retrieving all descendants text as well.

Thanks for your ongoing help.

Cal.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Plugin development - currentFileURL

Post by sorin_ristache »

Hello,

I am sorry, you cannot get only the text child nodes of an element. The method for getting the text content of an element used in an Author extension returns the complete text from all the child nodes of that element. We will add the possibility to run an XPath query in an Author extension in a future version.


Regards,
Sorin
calvados
Posts: 22
Joined: Wed Jul 30, 2008 12:46 am

Re: Plugin development - currentFileURL

Post by calvados »

Hmm...That's dissapointing.

Thanks very much for your patience and help with these matters.

I know you're very busy, but any idea when a version of oxygen that contains this xPath functionality might be expected?

Thanks again...

Cal.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Plugin development - currentFileURL

Post by sorin_ristache »

Hello,

This feature is not included in a detailed plan so I cannot give you an exact date but it will be implemented in one of the 10.x versions, probably not later than the next 6 months.


Regards,
Sorin
Post Reply