Page 1 of 1

Workspace access to Map Manager and validation console?

Posted: Fri Oct 14, 2022 11:36 pm
by wmaclean
Hello,
If I have a WorkspaceAccessPluginExtension object, are there APIs to access the following?
1. The current root map select in Map Manager and it's values.
2. The values in the validation console.
Please see the screenshot below for clarification.
Thank you,
Will
image.png

Re: Workspace access to Map Manager and validation console?

Posted: Mon Oct 17, 2022 7:12 am
by Radu
Hi Will,
1. The current root map select in Map Manager and it's values.
We have a static access using the method "ro.sync.ecss.dita.DITAAccess.getRootMapURL();" to retrieve the root map URL. But we do not have API to retrieve all values from the root map combo box. Could you elaborate? Why are you interested in those values?
2. The values in the validation console.
We have API to add a validation problems filter to each opened document:
https://www.oxygenxml.com/InstData/Edit ... emsFilter-
For example you can use this filter to receive notifications when the document is validated and to even add more validation problems or filter out existing validation problems before they are shown to the end user. Like in this Javascript-based Oxygen plugin:
https://github.com/oxygenxml/wsaccess-j ... sAccess.js

Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Tue Oct 18, 2022 3:50 pm
by wmaclean
Hi Radu,
Thanks for your response.

ValidationProblemsFilter looks good - thanks!

ro.sync.ecss.dita.DITAAccess.getRootMapURL(); looks like a good place to start. Is this the correct Javadoc?
https://www.oxygenxml.com/InstData/Edit ... ccess.html

Our use case - we are maintaining, separately from the maps, a list of all files in a rootmap and it's submaps, and modify that list as writers edit a publication, like adding topics and map and images. We have a way to do this with one root map at a time.

But, we want writers to be able to have multiple root maps open at one time, but be able to identify specifically the current root map in:
image.png
If we know the current root map, then we can assume they are looking specifically at that map, then we can modify the correct list based on that root map.

They would be able to switch between maps, and we would be able to maintain two or more separate lists using the GUID of the root map to identify the correct list.
  • There is no way to get the current map in Map Manager?
  • Is there some other way to identify a list of current root maps, and designate one as current?
Thanks again for your help,
Will

Re: Workspace access to Map Manager and validation console?

Posted: Wed Oct 19, 2022 7:25 am
by Radu
Hi Will,

Let's say you have multiple DITA Maps opened in the DITA Maps Manager view. We have API to know which one of them is selected, or which one is opened/closed/saved:

Code: Select all

    public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
      pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
        public void editorSelected(URL editorLocation) {
          //The map identified by the "editorLocation" URL was selected in the DITA Maps Manager view
        };
      }, PluginWorkspace.DITA_MAPS_EDITING_AREA);
    }
https://www.oxygenxml.com/InstData/Edit ... tener.html

If the "Root map" combo box is set to <Current map> then indeed the current selected map in the DITA Maps Manager view is the root map. But it may be set to another value, in which case the "DITAAccess.getRootMapURL()" is a better way to get that reference to the root map.
For example for the Oxygen User's manual we have one root map "Userguide.ditamap" and about 20 submaps. We always set the "Root map" combo box to "Userguide.ditamap" so that whatever submaps are currently edited in the DITA Maps Manager view the keys are always gathered from the "Userguide.ditamap" by Oxygen.

Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Wed Oct 19, 2022 9:57 pm
by wmaclean
Hi Radu,
This looks very promising.
Thanks a ton!
Will

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 11, 2023 10:09 am
by vishwavaranasi
Hi Radu , in continuation of what Will asked above , we have implemented a custom method as below , and this method we are calling from one of our ActionListener -actionPerformed method to get as List if there any validation problems

but this never printing the problems list ,

would you suggest us , is there anything we are doing wrong here?

Code: Select all

public static List<DocumentPositionedInfo> CustomValidationProblemsFilter(StandalonePluginWorkspace pluginWorkspaceAccess)
	{		
		 URL[] allOpenedEditorLocations = pluginWorkspaceAccess.getAllEditorLocations(pluginWorkspaceAccess.MAIN_EDITING_AREA);
		    for (int i = 0; i < allOpenedEditorLocations.length; i++) {
		    	
		    	System.out.println("this got printed" + allOpenedEditorLocations[i].getFile());
		      WSEditor openedEditor = pluginWorkspaceAccess.getEditorAccess(allOpenedEditorLocations[i], pluginWorkspaceAccess.MAIN_EDITING_AREA);		     
		    				
				 /*Add validation problems filter*/
				if(openedEditor!=null)
				{   System.out.println("THIS GOT PRINTED ---1------ValidationProblemsFilter" +openedEditor.getEditorLocation().getPath());
					openedEditor.addValidationProblemsFilter(new ValidationProblemsFilter() {
			            public void filterValidationProblems(ValidationProblems validationProblems) {
			            	validationProblems.getProblemsList().stream().forEach(problem->System.out.println("----printing validationProblems----"+problem.getMessage()));  [b][u]// never reached here , it's not printing the problems list[/u][/b]
			            	

			                
			            }
			        });
					
				}else {
					
					System.out.println("editorAccess is null");
				}	  
		    }
		
		
		return validationProblemsWithErrorSeverity;
		
	}
}

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 11, 2023 10:49 am
by Radu
Hi,

So when is the "CustomValidationProblemsFilter" class instantiated?
If it's instantiated on the "WorkspaceAccessPluginExtension.applicationStarted(StandalonePluginWorkspace)" callback, this callback is received when Oxygen is started, there are no files opened in Oxygen at that time so the method "pluginWorkspaceAccess.getAllEditorLocations" returns an empty array.
Also while Oxygen is running, other files may be opened by the end user, you need to add the filter on those files as well.
So this is why you should add the filter like this (add a listener to be notified when a file is opened and add the filter to it):

Code: Select all

void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
    pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
      @Override
      public void editorOpened(URL editorLocation) {
        pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA).addValidationProblemsFilter(...);
      }
    }, PluginWorkspace.MAIN_EDITING_AREA);
  }
Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 11, 2023 11:22 am
by vishwavaranasi
Here
"CustomValidationProblemsFilter" class is NOT instantiated inside WorkspaceAccessPluginExtension.applicationStarted(StandalonePluginWorkspace)"

instead

we are instantiating inside actionPerforemd method of one of our custom ActionListner class

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 11, 2023 11:49 am
by Radu
Hi,

I need more details, what is the purpose of that custom action which creates the "CustomValidationProblemsFilter" object?
Is it called by the end user? Can it be called multiple times? If it's called multiple times, it's implementation will add a filter to the opened documents each time so this is a bad idea.
Also if you add a filter does not mean that the validation will be called immediately after you add it. Validation of an opened document is usually called when editing the document or when using the "Validate" toolbar action.
Or you can call programmatically "openedEditor.checkValid()" to force validation to be done on an opened "WSEditor".

Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 11, 2023 12:40 pm
by vishwavaranasi
if we add ValidationProblemsFilter to WorkspaceAccessPluginExtension.applicationStarted(StandalonePluginWorkspace)"

Code: Select all

addValidationProblemsFilter(new ValidationProblemsFilter() {
		            public void filterValidationProblems(ValidationProblems validationProblems) {
		            	validationProblems.getProblemsList().stream().forEach(problem->System.out.println("----printing validationProblems----"+problem.getMessage()));
		            }
this is listing the problems

but we have a requirement when we wanted the topic file to be checked in to a DB having the validation problems should not allowed.
for that reason we wanted to put this inside a action listener of DB action.

if we put the ValidationProblemsFilter inside WorkspaceAccessPluginExtension.applicationStarted() , here is the question how can i access the problem list from my custom action listener?

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 11, 2023 1:22 pm
by Radu
Hi,

So when the "Check in" action is pressed you want to reject checking in topics if one or more of the current opened topics are invalid, right?
I see two possible ways:

1)

Code: Select all

    
    private HashMap<URL, List> lastValidationErrors = new HashMap();
    
    @Override
    public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
      pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
        @Override
        public void editorOpened(URL editorLocation) {
          WSEditor ed = pluginWorkspaceAccess.getEditorAccess(editorLocation, StandalonePluginWorkspace.MAIN_EDITING_AREA);
          ed.addValidationProblemsFilter(new ValidationProblemsFilter() {
            @Override
            public void filterValidationProblems(
                ro.sync.exml.workspace.api.editor.validation.ValidationProblems validationProblems) {
              lastValidationErrors.put(ed.getEditorLocation(), validationProblems.getProblemsList());
            };
          });
        };
      }, StandalonePluginWorkspace.MAIN_EDITING_AREA);
      
      AbstractAction checkout = new AbstractAction() {
        
        @Override
        public void actionPerformed(ActionEvent e) {
         URL[] locations = pluginWorkspaceAccess.getAllEditorLocations(StandalonePluginWorkspace.MAIN_EDITING_AREA);
         for (int i = 0; i < locations.length; i++) {
           List problems = lastValidationErrors.get(locations[i]);
           if(problems != null && ! problems.isEmpty()) {
             //We had a validation problem for this editor location...
           }
         }
        }
      };
    }
2)

Code: Select all

    @Override
    public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
      AbstractAction checkout = new AbstractAction() {
        
        @Override
        public void actionPerformed(ActionEvent e) {
         URL[] locations = pluginWorkspaceAccess.getAllEditorLocations(StandalonePluginWorkspace.MAIN_EDITING_AREA);
         for (int i = 0; i < locations.length; i++) {
           WSEditor editor = pluginWorkspaceAccess.getEditorAccess(locations[i], StandalonePluginWorkspace.MAIN_EDITING_AREA);
           boolean valid = editor.checkValid();
           if(! valid) {
             //Reject the action
           }
         }
        }
      };
    }
Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 11, 2023 4:08 pm
by vishwavaranasi
Thanks Radu.

Since my Custom Action outside of WorkspaceAccessPluginExtension.applicationStarted(StandalonePluginWorkspace)"

i am planning to do this - inside applicationStarted()
javax.swing.UIManager.put("DOCS_VALIDATIONS", lastValidationErrors);

and at the other end
HashMap<URL, List> lastValidationErrors = (HashMap<URL, List>) UIManager.get("DOCS_VALIDATIONS");
am checking if the lastValidationErrors size is not zero before check in file to DB action will show error.

is this a good approach ?

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 11, 2023 6:13 pm
by Radu
Hi,

I do not know anything about how your code is structured, where the custom action is created... if you give me enough small code snippets to understand how the action is created, in what part of the code, I can give you better advice, otherwise... what you did is not elegant but probably works.


Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Thu Jan 12, 2023 1:27 pm
by vishwavaranasi
Sorry Radu making you confused.
the checkin action what we are doing outside of WorkspaceAccessPluginExtension class , from there we have launched another Jframe , and this JFrame has some checkin action.

from previous reply I did do this , this am calling from checkin action listener class every time when user clicks checkin button on a file, here we know the file opened in oxygen editor , and i need to see this is a valid file by calling the below method.

Code: Select all

public static boolean CustomValidationProblemsFilter(StandalonePluginWorkspace pluginWorkspaceAccess)
	{	
		logger.info("CustomValidationProblemsFilter Called..");
		boolean isxmlDocumentValid=false;
		URL[] locations = pluginWorkspaceAccess.getAllEditorLocations(StandalonePluginWorkspace.MAIN_EDITING_AREA);
        for (int i = 0; i < locations.length; i++) {
          WSEditor editor = pluginWorkspaceAccess.getEditorAccess(locations[i], StandalonePluginWorkspace.MAIN_EDITING_AREA);
          if(editor.checkValid())
          {
        	  isxmlDocumentValid=true;
            }  
			}
        return isxmlDocumentValid;
	}

this method works fine for the first time i have errors then its not allowed checkin , but next time i have fixed errors to a file and saved , and then try checkin the above still returns that it is invalid file.

Re: Workspace access to Map Manager and validation console?

Posted: Thu Jan 12, 2023 2:59 pm
by Radu
Hi,

Your implementation has various problems, if for example the files F1 and F2 are opened in the editor and the file F1 is invalid and F2 is valid, your method returns "valid" although it should return invalid as F1 is invalid.

In my opinion the method should look like this:

Code: Select all

  public static boolean checkAllOpenedEditorsValid(
      StandalonePluginWorkspace pluginWorkspaceAccess) {
    boolean allOpenedEditorsAreValid = true;
    URL[] locations = pluginWorkspaceAccess
        .getAllEditorLocations(StandalonePluginWorkspace.MAIN_EDITING_AREA);
    for (int i = 0; i < locations.length; i++) {
      WSEditor editor = pluginWorkspaceAccess.getEditorAccess(locations[i],
          StandalonePluginWorkspace.MAIN_EDITING_AREA);
      allOpenedEditorsAreValid = allOpenedEditorsAreValid && editor.checkValid();
      if (!allOpenedEditorsAreValid) {
        //At least one file is invalid
        break;
      }
    }
    return allOpenedEditorsAreValid;
  }
and you can call it every time your "Check in" action is invoked. You can call it like this for example using our singleton access to the StandalonePluginWorkspace:

Code: Select all

booleanAllOpenedFilesAreValid = checkAllOpenedEditorsValid((StandalonePluginWorkspace) ro.sync.exml.workspace.api.PluginWorkspaceProvider.getPluginWorkspace());
Other than that you can add System.err messages in the code and if you start Oxygen using the "OXYGEN_INSTALL_DIR\oxygen.bat" script you will see your messages in the console. This will help you debug your problems.

You should also try to have a more clear perspective about how you should check if invalid files are about to be checked in.
For example you have files F1, F2 and F3 opened. File F3 is opened from the local disk, it's not opened from the CMS, the fact that it's valid or not should not influence the check in operation. Or you open file F1 from the CMS, make it invalid, save it and close it. The file is no longer opened but you still need to check it in.

Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Fri Jan 13, 2023 9:49 am
by vishwavaranasi
Thanks Radu , the solution from last reply looks working.
here editor.checkValid(); is also considering WARNINGS. is that expected?
I have observed only file with below in GREEN are valid?
image.png

Re: Workspace access to Map Manager and validation console?

Posted: Fri Jan 13, 2023 10:43 am
by Radu
Hi,

Yes, the Javadoc is available here:
https://www.oxygenxml.com/InstData/Edit ... eckValid--
Check if the current editor is valid, performs manual validation and returns true if the last validation was finished without errors or warnings.
Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Fri Jan 13, 2023 1:00 pm
by vishwavaranasi
Thanks Radu , is there anyways that we can make checkValid() considering only errors to treat file as valid xml file or not?

Re: Workspace access to Map Manager and validation console?

Posted: Fri Jan 13, 2023 1:26 pm
by Radu
Hi,

The "checkValid() " cannot make this distinction.
If you want this distinction between errors and warnings, you would need to go back to using the "ValidationProblemsFilter" API as the list of problems that you receive "validationProblems.getProblemsList()" can be iterated and each problem has a "ro.sync.document.DocumentPositionedInfo.getSeverity()" method which can be used to find out the severity of the problem (info/warning/error).

Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Tue Jan 17, 2023 9:03 pm
by vishwavaranasi
Thanks Radu, I am trying the below code and getting confused how can my method returns the problem list with SeverityAs error or fatal error.

here not able to declare the correct place for
List<DocumentPositionedInfo> validationProblemsWithErrorSeverity=new ArrayList<DocumentPositionedInfo>();

as i defined in the below method
but the last 2 lines showing me error
//error here variable validationProblemsWithErrorSeverity not accessable


NOTE : as i mentioned previous replies my custom checkin action has to invoking this after a call checkValid() , here the problem list with SeverityAs error or fatal error where the sysout below printing fine.

System.out.println("----printing ERROR and Fatal validationProblems----"
+ problem.getMessage() + " " + problem.getSeverityAsString()));

Code: Select all

public int CustomValidationProblemsFilter() {

		URL[] locations1 = ro.sync.exml.workspace.api.PluginWorkspaceProvider.getPluginWorkspace().getAllEditorLocations(StandalonePluginWorkspace.MAIN_EDITING_AREA);
		
		for (int i = 0; i < locations1.length; i++) {
			
			ro.sync.exml.workspace.api.PluginWorkspaceProvider.getPluginWorkspace().getEditorAccess(locations1[i], StandalonePluginWorkspace.MAIN_EDITING_AREA)
			.addValidationProblemsFilter(new ValidationProblemsFilter() {
				
				public void filterValidationProblems(ValidationProblems validationProblems) {
				
				List<DocumentPositionedInfo> validationProblemsWithErrorSeverity=new ArrayList<DocumentPositionedInfo>();
					if (validationProblems.getProblemsList() != null) {
						validationProblemsWithErrorSeverity = validationProblems.getProblemsList().stream()
								.filter(problem -> problem.getSeverityAsString().equals("error")
										|| problem.getSeverityAsString().equals("fatal error"))
								.collect(Collectors.toList());
						
						
						validationProblemsWithErrorSeverity.stream().forEach(
								problem -> System.out.println("----printing ERROR and Fatal validationProblems----"
										+ problem.getMessage() + "  " + problem.getSeverityAsString()));

					} 

				}
			});

			
		}

				

	
		System.out.println("2---printing validationProblemsWithErrorSeverity.size()" + validationProblemsWithErrorSeverity.size()); //error here  variable validationProblemsWithErrorSeverity not accessable


		return validationProblemsWithErrorSeverity.size();      //error here  variable validationProblemsWithErrorSeverity not accessable

	}

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 18, 2023 8:33 am
by Radu
Hi,

I proposed to you previously at some point to keep a hash map between editor location and problems.
So the code would look something like this:

Code: Select all

    private Map<URL, List<DocumentPositionedInfo>> locationToErrorsMap = new HashMap<>();
    
    @Override
    public void applicationStarted(StandalonePluginWorkspace pluginWorkspaceAccess) {
      pluginWorkspaceAccess.addEditorChangeListener(new WSEditorChangeListener() {
        @Override
        public void editorOpened(URL editorLocation) {
          pluginWorkspaceAccess.getEditorAccess(editorLocation, PluginWorkspace.MAIN_EDITING_AREA)
          .addValidationProblemsFilter(new ValidationProblemsFilter() {
            @Override
            public void filterValidationProblems(ValidationProblems validationProblems) {
              List<DocumentPositionedInfo> validationProblemsWithErrorSeverity = new ArrayList<DocumentPositionedInfo>();
              if (validationProblems.getProblemsList() != null) {
                validationProblemsWithErrorSeverity = validationProblems.getProblemsList().stream()
                    .filter(problem -> problem.getSeverity() == DocumentPositionedInfo.SEVERITY_ERROR
                        || problem.getSeverity() == DocumentPositionedInfo.SEVERITY_FATAL)
                    .collect(Collectors.toList());
              } 
              locationToErrorsMap.put(editorLocation, validationProblemsWithErrorSeverity);
            }
          });
        }
      }, PluginWorkspace.MAIN_EDITING_AREA);
    }
    
    public int getNumberOfErrorsFromAllOpenedDocuments() {
      URL[] locations = ro.sync.exml.workspace.api.PluginWorkspaceProvider.getPluginWorkspace().getAllEditorLocations(StandalonePluginWorkspace.MAIN_EDITING_AREA);
      int counterWithAllErrorsFromAllOpenedDocuments = 0;
      for (int i = 0; i < locations.length; i++) {
        List<DocumentPositionedInfo> problems = locationToErrorsMap.get(locations[i]);
        if(problems != null) {
          counterWithAllErrorsFromAllOpenedDocuments += problems.size();
        }
      }
      return counterWithAllErrorsFromAllOpenedDocuments;
    }
Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 18, 2023 1:27 pm
by vishwavaranasi
is that possible to call this method getNumberOfErrorsFromAllOpenedDocuments() outside of CustomWorkspaceAccessPluginExtension implements WorkspaceAccessPluginExtension

Re: Workspace access to Map Manager and validation console?

Posted: Wed Jan 18, 2023 1:41 pm
by Radu
Hi,

You could try for example to make the map "locationToErrorsMap" static and also make the method "getNumberOfErrorsFromAllOpenedDocuments" static so that you can call it like CustomWorkspaceAccessPluginExtension.getNumberOfErrorsFromAllOpenedDocuments().

Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Fri Feb 17, 2023 9:17 am
by vishwavaranasi
Thanks Radu it's worked for us.

Re: Workspace access to Map Manager and validation console?

Posted: Fri Feb 17, 2023 9:34 am
by vishwavaranasi
just asking another question
would it possible to check the validations problems even in case of file not opened inside a editor?

Thanks,
vishwa

Re: Workspace access to Map Manager and validation console?

Posted: Fri Feb 17, 2023 9:43 am
by Radu
Hi,

We have an API for this as well but it works only with Oxygen 25.0 and newer:

ro.sync.exml.workspace.api.PluginWorkspace.getValidationUtilAccess()

https://www.oxygenxml.com/InstData/Edit ... ccess.html

For older versions of Oxygen you would need to open the XML file in Oxygen using our APis and validate it.

Regards,
Radu

Re: Workspace access to Map Manager and validation console?

Posted: Mon Feb 20, 2023 2:34 pm
by vishwavaranasi
is that Oxygen 25.0 available bundled with only java 17?

Re: Workspace access to Map Manager and validation console?

Posted: Tue Feb 21, 2023 10:29 am
by adrian
Hi,

What are you looking for, exactly? A distribution of Oxygen with a different version of Java, or a distribution with no Java bundle?

Officially Oxygen 25.0 only supports Java 11 and Java 17. The officially supported distribution bundles Java 17.
Unofficially there are also some distributions of v25.0 with Java 8 (Windows and macOS), but they are unsupported (a warning appears at startup). Please contact us on support@oxygenxml.com, if you require these (Java 8 ). Starting with v26.0 these will no longer be available, Java 17 only.

If you want a distribution with no Java bundle, please download the Other > All platforms distribution, or the Windows ZIP and remove the jre folder.

Regards,
Adrian

Re: Workspace access to Map Manager and validation console?

Posted: Thu Feb 23, 2023 1:53 pm
by vishwavaranasi
Thanks Adrian , we will think about this and will get back you.