Custom Validation Issues [message #891817] |
Tue, 26 June 2012 06:51 |
rohit chawla Messages: 19 Registered: June 2012 |
Junior Member |
|
|
Hi guys,
I want to validate a document, with an custom validator. Want to validate it with a xsd, but only aftter certain preprocessing of main document.
Custom validator is required instead of normal xml validator, because the schema location is not defined in the main file & also I want to do some preprocessing to the file, before applying xsd validation.
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.ide.ui.editors.page.validator">
<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());
XMLValidationReport report = validator.validate("/home/rchawla/xmlWorkspace/abc.xsd", is);
ValidationMessage[] messages = report.getValidationMessages();
for(ValidationMessage message:messages){
System.out.println(message.getMessage());
}
}
The problem is that the execution point does come to the above validate method, but
How can I associate xsd to the xmlvalidator object and validate it. Write now, ValidationMessage[] messages = report.getValidationMessages(); is giving zero messages, even though the there are errors in the main file.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03298 seconds