Content creation/generation with the AuthorSchemaManager

Post here questions and problems related to oXygen frameworks/document types.
SSC
Posts: 206
Location: Hamburg, Germany

Content creation/generation with the AuthorSchemaManager

Mon Aug 04, 2014 7:01 pm

Hello,

we are using the Eclipse Oxygen Author in Version 15.2.

You have certain preferences, which can be set for "Content Completion" like "Add first Choice particle" and "Insert the fixed attributes".

When I insert XML content programmatically I´d also like to set a boolean flag for those preferences I just mentioned.

In my code I do want to insert a certain XML Element schema aware:

Code: Select all

        AuthorSchemaManager schemaManager = authorAccess
                .getDocumentController().getAuthorSchemaManager();

// method which finds the desired node in the global elements
        CIElement ciElementByElementName = getCIElementByElementName(
                schemaManager.getGlobalElements(), {elementName});

// this fragment should contain also the first choice particle and all the required attributes
        AuthorDocumentFragment documentFragment = schemaManager
                    .createAuthorDocumentFragment(ciElementByElementName);

        authorAccess.getDocumentController().insertFragmentSchemaAware(offset,
                documentFragment);


I hope this piece of code demonstrates what my intention is.

Actually I´d like to have something like that :

Code: Select all


schemaManager.createAuthorDocumentFragment(ciElementByElementName, {boolean for "first choice particle"}, {boolean for "inserting required attributes"});



Is there a way how I can achieve that with existing API?
I hope so, because you already do it somehow with the preferences for content completion.

As an aside, I only want to do this in order to generate the content nodes of an element, which contains a conref attribute. So actually the generated content will not be shown anyway, because it will be replaced by the conref, but it is of cause still required due to the schema contraints.

Best regards,

Simon
Simon Scholz
vogella GmbH
http://www.vogella.com
alex_jitianu
Posts: 653

Re: Content creation/generation with the AuthorSchemaManager

Tue Aug 05, 2014 10:22 am

Hello,

You can make sure the options are set to the required value before executing the code:

Code: Select all

PluginWorkspaceProvider.getPluginWorkspace().setGlobalObjectProperty("code.insight.add.first.choice", true);    PluginWorkspaceProvider.getPluginWorkspace().setGlobalObjectProperty("code.insight.insert.required.attributes", true);


Unfortunately you can't get the current value for the options so that you can restore it at the end of the operation. But chances are you already know the default values for these options in your editing environment so you can explicitly set them to those values after inserting the element.

Best regards,
Alex
SSC
Posts: 206
Location: Hamburg, Germany

Re: Content creation/generation with the AuthorSchemaManager

Tue Aug 05, 2014 11:24 am

Hello Alex,

as you can imagine this solution is not really satisfying.

Could you please consider to offer also a method, where such operationmodes can be added without modifying these global options?
Maybe something like:

Code: Select all

OperationModes opermationModes = new OperationModes();
opermationModes.add(IOperationModeConstants.ADD_FIRST_CHOICE);
opermationModes.add(IOperationModeConstants.INSERT_REQUIRED_ATTRIBUTES);

AuthorDocumentFragment documentFragment = schemaManager
                    .createAuthorDocumentFragment(ciElementByElementName, opermationModes);


A second thing that sounds weird to me is the fact that I am able to modify certain preferences, but cannot read those preferences in order to reset them.

Do you offer a class or an interface, where those global properties keys like "code.insight.add.first.choice" are defined?

Best regards,

Simon
Simon Scholz
vogella GmbH
http://www.vogella.com
alex_jitianu
Posts: 653

Re: Content creation/generation with the AuthorSchemaManager

Tue Aug 05, 2014 2:08 pm

Hello Simon,

I agree that the solution is by far the most elegant one... but unfortunately it's all you can do with the current API... I've added an issue regarding a dedicated API as you suggested.

We don't have an API for getting the existing value of an option because of security reasons (the values might contain sensitive information). We also don't have an API class with all option keys. If you need to find out the key of an option you can either ask us or export the options with and without the option being set, and compare the two versions.

Best regards,
Alex

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 2 guests