Page 1 of 1

AuthorSchemaManager for validating AuthorDocumentFragments

Posted: Thu Nov 08, 2012 9:31 pm
by SSC
Hello,

I want to check, if a certain XML String can be inserted at a certain location.
To insert a XML String schema aware you can easily use ro.sync.ecss.extensions.api.AuthorDocumentController.insertXMLFragmentSchemaAware(String, int);

But how can I just check if a certain XML String may be inserted according to schema rules?
I tried to use the ro.sync.ecss.extensions.api.AuthorSchemaManager.canInsertDocumentFragment(AuthorDocumentFragment, int, short)
method, but I cannot figure out how to create an ro.sync.ecss.extensions.api.node.AuthorDocumentFragment from a XML String.
When I use the ro.sync.ecss.extensions.api.AuthorDocumentController.createNewDocumentTextFragment(String) method to create an AuthorDocumentFragment the canInsertDocumentFragment always returns true, even thought if the element actually is not allowed.

Can you please give me a hint how I can check if a certain xml string is allowed at a certain offset?

With xml String I mean something like this : <image href="test.jpg" />

Best regards,

Simon

Re: AuthorSchemaManager for validating AuthorDocumentFragments

Posted: Fri Nov 09, 2012 9:49 am
by alex_jitianu
Hi Simon,

The ro.sync.ecss.extensions.api.AuthorDocumentController.createNewDocumentTextFragment(String) method creates a text fragment, even if the string you provide represents an XMl content.
What you can do is to use the following method that creates an AuthorDocumentFragment representing an XML content:

Code: Select all


  /**
* Create a new {@link AuthorDocumentFragment} from an XML string in a specified context.
* <br/>
* The author content contains the entire XML document text and special marker characters.
* Each author node points in the content to the start and end marker characters which are used to
* delimit it's range.
* The start and end offsets pointed to by the AuthorNode can be retrieved using the
* AuthorNode.getStartOffset() and AuthorNode.getEndOffset()
*
* @param xmlFragment The XML Fragment.
* @param contentOffset The offset where the XML fragment should be inserted.
* @return The newly created {@link AuthorDocumentFragment}.
* It does not return a <code>null</code> fragment.
* @throws AuthorOperationException If the new fragment creation fails.
*/
AuthorDocumentFragment createNewDocumentFragmentInContext(String xmlFragment, int contentOffset)
throws AuthorOperationException;
Then you can check if this document fragment can be inserted at a specific offset by using the method you already discovered: ro.sync.ecss.extensions.api.AuthorSchemaManager.canInsertDocumentFragment(AuthorDocumentFragment, int, short)

Please let us know if you need further assistance.

Best regards,
Alex

Re: AuthorSchemaManager for validating AuthorDocumentFragments

Posted: Fri Nov 09, 2012 1:13 pm
by SSC
Hello Alex,

The name createNewDocumentFragmentInContext and having a parameter, which specifies the offset(@param contentOffset The offset where the XML fragment should be inserted.) leaded me to the conclusion that this method would directly insert the xml fragment into the document, which was not desired at that point.

But with the createNewDocumentFragmentInContext everything works fine.
Thanks for the hint.
Maybe you could mention in your JavaDoc that the resulting AuthorDocumentFragment is not directly inserted to the document and that the insertFragmentSchemaAware method does it.

Best regards,

Simon

Re: AuthorSchemaManager for validating AuthorDocumentFragments

Posted: Fri Nov 09, 2012 1:47 pm
by alex_jitianu
Hi Simon,

This is a good opportunity to review a little our documentation. I've already added an issue to correct the JavaDoc as well as providing more information about the two methods. Method createNewDocumentTextFragment's documentation is also extremely vague.

Best regards,
Alex