Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Custom Validation of custom content type
Custom Validation of custom content type [message #891938] Tue, 26 June 2012 15:58 Go to next message
rohit chawla is currently offline rohit chawlaFriend
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 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

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
Re: Custom Validation of custom content type [message #891990 is a reply to message #891983] Tue, 26 June 2012 18:52 Go to previous message
rohit chawla is currently offline rohit chawlaFriend
Messages: 19
Registered: June 2012
Junior Member
Thanks Nitin. Then can you give any suggestions on how can I achieve this inside eclipse?

I want to prerocess the xml document, before validating it with some XML schema.
How can I achieve this?
Previous Topic:Web-servise
Next Topic:based on Eclipse 4.2 of WTP plan release date?
Goto Forum:
  


Current Time: Tue Apr 23 09:03:26 GMT 2024

Powered by FUDForum. Page generated in 0.03437 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top