Custom Validation of custom content type [message #891938] |
Tue, 26 June 2012 15:58 |
rohit chawla Messages: 19 Registered: June 2012 |
Junior Member |
|
|
Hi guys,
I want to validate a custom content type document(xml kind), with an custom validator. Want to validate it with a xsd, but only after certain preprocessing of main document.
Normal xml validator can't be used because-
1.) The schema location(xsd) & namespaces are not defined in the main document file.
2.) And bcz of first reason & many more, want to do some preprocessing to the document file, before applying xsd validation.
So I want to use the xml validator, but only after preprocessing of my file.
My plugin.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.core.runtime.contentTypes">
<content-type
id="com.xyz.ide.core.contentType.dummy"
base-type="org.eclipse.core.runtime.xml"
file-extensions="blabla"
/>
</extension>
<extension
point="org.eclipse.wst.sse.ui.sourcevalidation">
<validator
scope="total"
class="mc.CustomValidator"
id="com.xyz.myValidator">
<contentTypeIdentifier
id="com.xyz.ide.core.contentType.dummy">
<partitionType
id="org.eclipse.wst.xml.XML_DEFAULT">
</partitionType>
</contentTypeIdentifier>
</validator>
</extension>
</plugin>
CustomValidator.java
public class CustomValidator implements ISourceValidator, IValidator {
XMLValidator validator = new XMLValidator();
IDocument document;
public void validate(IValidationContext helper, IReporter reporter) {
String fileContent = this.document.get();
final InputStream is = new ByteArrayInputStream(fileContent.toLowerCase().getBytes());
// Whats the problem in this line???
XMLValidationReport report = validator.validate("/home/rchawla/xmlWorkspace/abc.xsd", is);
ValidationMessage[] messages = report.getValidationMessages();
for(ValidationMessage message:messages){
System.out.println(message.getMessage());
}
}
I can hit the validate method on running the plugin in debug mode, but
the document is not getting validated with the xsd.
What is wrong in the above method as,
ValidationMessage[] messages = report.getValidationMessages(); is giving zero messages, even though the there are errors in the main document file.
[Updated on: Tue, 26 June 2012 16:03] Report message to a moderator
|
|
|
Re: Custom Validation of custom content type [message #891983 is a reply to message #891938] |
Tue, 26 June 2012 18:23 |
|
On 6/26/2012 11:58 AM, rohit chawla wrote:
> I want to validate a custom content type document(xml kind), with an
> custom validator. Want to validate it with a xsd, but only after certain
> preprocessing of main document.
> Normal xml validator can't be used because-
> 1.) The schema location(xsd) & namespaces are not defined in the main
> document file.
> 2.) And bcz of first reason & many more, want to do some preprocessing
> to the document file, before applying xsd validation.
>
> So I want to use the xml validator, but only after preprocessing of my
> file.
Then you can not use the XML Validator. The plug-in extension point you
have cited is for as-you-type validation only. It does not make your
validator callable by the Validation Framework. Also, the call you are
making to the internal XMLValidator class does not use the string
argument as a URI for a XML Schema to validate against, it is for the
document being validated itself.
---
Nitin Dahyabhai
Eclipse WTP Source Editing and JSDT
IBM Rational
_
Nitin Dahyabhai
Eclipse Web Tools Platform
|
|
|
|
Powered by
FUDForum. Page generated in 0.03437 seconds