ValidationScenario fails when opening XML from Workspace Plu
Oxygen general issues.
-
- Posts: 2
- Joined: Wed Jul 02, 2014 9:22 pm
ValidationScenario fails when opening XML from Workspace Plu
Post by dale.lancaster »
Hello,
I'm writing a workspace plugin to automatically traverse and validate all referenced XML documents from a single "root" document. I have a custom validation scenario setup that automatically runs when an applicable XML file is opened normally, but when I open the file through the PluginWorkspace, like this:
The validation scenario does not trigger correctly. It does work if I select the Editor window and hit F5 to refresh, so I even tried adding the following:
But it still does not help. Am I missing something in the documentation? I've searched the forums, but everyone seems to be using this method.
The unique aspect of my Validation Scenario is simply that I'm redirecting to a controlled copy of a schema (as opposed to the relative path that is used in the XML by default), and there is schematron validation performed. It seemed excessive to recreate these steps in the plugin when I could simply open an Editor window and check the ValidationProblems.
Thanks,
Dale
I'm writing a workspace plugin to automatically traverse and validate all referenced XML documents from a single "root" document. I have a custom validation scenario setup that automatically runs when an applicable XML file is opened normally, but when I open the file through the PluginWorkspace, like this:
Code: Select all
PluginWorkspace ws = PluginWorkspaceProvider.getPluginWorkspace();
ws.open(url, EditorPageConstants.PAGE_AUTHOR);
Code: Select all
WSEditor ed = ws.getEditorAccess(url, PluginWorkspace.MAIN_EDITING_AREA);
WSAuthorEditorPage page = (WSAuthorEditorPage) ed.getCurrentPage();
page.refresh();
The unique aspect of my Validation Scenario is simply that I'm redirecting to a controlled copy of a schema (as opposed to the relative path that is used in the XML by default), and there is schematron validation performed. It seemed excessive to recreate these steps in the plugin when I could simply open an Editor window and check the ValidationProblems.
Thanks,
Dale
-
- Posts: 9472
- Joined: Fri Jul 09, 2004 5:18 pm
Re: ValidationScenario fails when opening XML from Workspace
Hi Dale,
I need to know more details about your use case.
1) How exactly is the validation scenario associated to the opened XML documents? Is it set as a default validation scenario in the associated document type configuration? Or did you associate it in another way?
2) Do you try to detect from the API side that validation errors occurred when opening the XML document using the ro.sync.exml.workspace.api.editor.validation.ValidationProblemsFilter API? Or do you visually inspect the opened XML document?
3) Why don't you link in the Oxygen project view the XML documents and batch validate them from there?
4) Could you paste more sample Java code from your plugin? Just for me to get a general idea of your intentions.
Regards,
Radu
I need to know more details about your use case.
1) How exactly is the validation scenario associated to the opened XML documents? Is it set as a default validation scenario in the associated document type configuration? Or did you associate it in another way?
2) Do you try to detect from the API side that validation errors occurred when opening the XML document using the ro.sync.exml.workspace.api.editor.validation.ValidationProblemsFilter API? Or do you visually inspect the opened XML document?
3) Why don't you link in the Oxygen project view the XML documents and batch validate them from there?
4) Could you paste more sample Java code from your plugin? Just for me to get a general idea of your intentions.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 2
- Joined: Wed Jul 02, 2014 9:22 pm
Re: ValidationScenario fails when opening XML from Workspace
Post by dale.lancaster »
Hi Radu,
The validation scenario is setup as the default validation scenario in the document type configuration.
I didn't actually get to the ValidationProblemsFilter yet (although that's something else I'm trying to figure out now). The process I'm walking through is identifying all of the references to external documents, building an array of URLs, then opening an editor tab for each URL (eventually, if there are no errors detected, the window will automatically close again). The problem is that the validation scenario did not associate at this point, so I was trying to solve that first.
Just a note on that point, I was adding in some debugging steps into my code yesterday, and when I added the following line:
The association works correctly and the XML validates. I'm not sure if that's a timing issue when opening through the API?
Here is my function:
Without the DocumentTypeInformation test in there, the validation scenario does not pickup. I had added it in to test that the correct framework was being detected (it was), and the validation started working.
I haven't really figured out the ValidationProblemsFilter part of the code yet, so that part is a little hacky.
The general intent of the code is that a user can load the root XML document and scan the entire collection for any schema or schematron validation errors and automatically open those XML files to be fixed (as opposed to just building a report).
Regarding your question #3, we haven't been using the project view at all, so I was trying to avoid adding in a new requirement to build and maintain the XPR file.
Thanks,
Dale
The validation scenario is setup as the default validation scenario in the document type configuration.
I didn't actually get to the ValidationProblemsFilter yet (although that's something else I'm trying to figure out now). The process I'm walking through is identifying all of the references to external documents, building an array of URLs, then opening an editor tab for each URL (eventually, if there are no errors detected, the window will automatically close again). The problem is that the validation scenario did not associate at this point, so I was trying to solve that first.
Just a note on that point, I was adding in some debugging steps into my code yesterday, and when I added the following line:
Code: Select all
DocumentTypeInformation framework = ed.getDocumentTypeInformation();
Here is my function:
Code: Select all
public void doOperation(AuthorAccess authorAccess, ArgumentsMap argumentsMap) throws IllegalArgumentException, AuthorOperationException {
AuthorDocumentController adc = authorAccess.getDocumentController();
AuthorDocument doc = adc.getAuthorDocumentNode();
AuthorNode[] refs = adc.findNodesByXPath("//content//refdm", true, true, true);
ArrayList<URL> refList = scanDataModules(refs);
PluginWorkspace ws = PluginWorkspaceProvider.getPluginWorkspace();
for (URL url : refList) {
ws.open(url, EditorPageConstants.PAGE_AUTHOR);
WSEditor ed = ws.getEditorAccess(url, PluginWorkspace.MAIN_EDITING_AREA);
DocumentTypeInformation framework = ed.getDocumentTypeInformation();
ProblemCache test = new ProblemCache();
ed.addValidationProblemsFilter(test);
WSAuthorEditorPage page = (WSAuthorEditorPage) ed.getCurrentPage();
page.refresh();
if (test.getProblems()==null) {
ws.close(url);
}
}
}
I haven't really figured out the ValidationProblemsFilter part of the code yet, so that part is a little hacky.
The general intent of the code is that a user can load the root XML document and scan the entire collection for any schema or schematron validation errors and automatically open those XML files to be fixed (as opposed to just building a report).
Regarding your question #3, we haven't been using the project view at all, so I was trying to avoid adding in a new requirement to build and maintain the XPR file.
Thanks,
Dale
-
- Posts: 9472
- Joined: Fri Jul 09, 2004 5:18 pm
Re: ValidationScenario fails when opening XML from Workspace
Hi Dale,
The problem is that the automatic validation which is performed when an XML document is opened is done on a thread so the open operation does not block until the validation thread has performed the validation. So after an editor was opened you have to wait a little bit for the automatic validation thread to kick in and report problems in the filter for it.
So after you add the validation problems filter the validation thread will take some time to validate and report the problems. Invoking ed.getDocumentTypeInformation() induces a bit of delay on the code and this is maybe why this works for you.
Again, the editors should be opened on a different thread in order not to block the main AWT thread which runs the operation's code.
Anyway, here's some code I tested and which seems to work better for what you need:
The problem is that the automatic validation which is performed when an XML document is opened is done on a thread so the open operation does not block until the validation thread has performed the validation. So after an editor was opened you have to wait a little bit for the automatic validation thread to kick in and report problems in the filter for it.
So after you add the validation problems filter the validation thread will take some time to validate and report the problems. Invoking ed.getDocumentTypeInformation() induces a bit of delay on the code and this is maybe why this works for you.
Again, the editors should be opened on a different thread in order not to block the main AWT thread which runs the operation's code.
Anyway, here's some code I tested and which seems to work better for what you need:
Code: Select all
/**
* @see ro.sync.ecss.extensions.api.AuthorOperation#doOperation(ro.sync.ecss.extensions.api.AuthorAccess, ro.sync.ecss.extensions.api.ArgumentsMap)
*/
@Override
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws IllegalArgumentException, AuthorOperationException {
final PluginWorkspace ws = PluginWorkspaceProvider.getPluginWorkspace();
//Run this on thread in order not to block the AWT thread on which the operation runs
new Thread("Main Editors Opener"){
@Override
public void run() {
try {
//The list will be reused for all sequential opened topics.
final List<DocumentPositionedInfo> dpis = new ArrayList<DocumentPositionedInfo>();
//The filter will also be reused.
final ValidationProblemsFilter filter = new ValidationProblemsFilter(){
@Override
public void filterValidationProblems(ValidationProblems validationProblems) {
if(validationProblems.getProblemsList() != null){
dpis.addAll(validationProblems.getProblemsList());
}
}
};
//For each of the URLs to open.
for (int i = 0; i < urls.length; i++) {
URL url = .......;
//Keep a link to the opened editor, we will close it and we'll remove the filter from it if all goes well.
final WSEditor[] currentEditorToCheck = new WSEditor[1];
dpis.clear();
new Thread("Check validation in " + url){
public void run() {
try {
ws.open(url, EditorPageConstants.PAGE_AUTHOR);
currentEditorToCheck[0] = ws.getEditorAccess(url, PluginWorkspace.MAIN_EDITING_AREA);
currentEditorToCheck[0].addValidationProblemsFilter(filter);
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}.start();
//Wait for the automatic validation thread to report problems.
Thread.sleep(2000);
//Now remove the filter
currentEditorToCheck[0].removeValidationProblemsFilter(filter);
//Check what errors were reported on the filter.
if(dpis.isEmpty()){
//Close it, successfull validation
currentEditorToCheck[0].close(false);
} else {
//We have problems, leave the editor opened
System.err.println("PROBLEMS " + dpis);
}
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
}
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ Artificial Intelligence (AI Positron Assistant add-on)
- ↳ 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