Implementing a simple Validator for HTML Files [message #227158] |
Sat, 24 January 2009 14:39 |
Dominik Raymann Messages: 37 Registered: July 2009 |
Member |
|
|
Hi there,
I try to implement a (batch) validator to validate HTML files. These
HTML files contain some special attributes for a template engine and I
want to check whether these attributes are set to reasonable values. I
think that this is a quite common validator type. However, I was not
able to easily find information about how to proceed.
So my problems breaks down to:
1. registering an additional validator
2. in the validateInJob method get the DOM for the document
I was able to solve 1. by registering my validator at the extension points:
<extension point="org.eclipse.wst.validation.validator" id="Test"
name="%Validator.Name">
<validator>
<filter
objectClass="org.eclipse.core.resources.IFile"
caseSensitive="false"
nameFilter="*.html">
</filter>
<helper
class=" org.eclipse.wst.xml.validation.internal.operations.Workbench Context ">
</helper>
<run
class="ch.raymi.plugin.coder.validator.TemplateValidator"
enabled="true"
fullBuild="true"
incremental="true">
</run>
</validator>
</extension>
I think that I should change the helper class to something HTML
specific, but I was unable to figure out what the appropriate HTML
helper class would be (and do I have to use these internal classes?).
Can anyone help me here?
I am then able to get the file in the validateInJob with:
Object[] params = { filename };
IFile file = (IFile)helper.loadModel("getFile", params);
However, I would really appreciate having a DOM tree instead of parsing
the file on my own. How do I get a DOM model, if I use the appropriate
HTML helper?
Is it also possible to get the DOM model when using source validation
(org.eclipse.wst.sse.ui.sourcevalidation)?
Sorry for the newbies questions, but it's really hard to find useful
information about this topic in the internet (well, maybe I just looked
in the wrong places). Maybe someone knows some good resources regarding
this topic?
Thanks in advance for your help.
Cheers,
Dominik
|
|
|
Re: Implementing a simple Validator for HTML Files [message #227180 is a reply to message #227158] |
Sat, 24 January 2009 22:44 |
Dominik Raymann Messages: 37 Registered: July 2009 |
Member |
|
|
Dominik Raymann schrieb:
> Hi there,
>
> I try to implement a (batch) validator to validate HTML files. These
> HTML files contain some special attributes for a template engine and I
> want to check whether these attributes are set to reasonable values. I
> think that this is a quite common validator type. However, I was not
> able to easily find information about how to proceed.
>
> So my problems breaks down to:
> 1. registering an additional validator
> 2. in the validateInJob method get the DOM for the document
>
> I was able to solve 1. by registering my validator at the extension points:
>
> <extension point="org.eclipse.wst.validation.validator" id="Test"
> name="%Validator.Name">
> <validator>
> <filter
> objectClass="org.eclipse.core.resources.IFile"
> caseSensitive="false"
> nameFilter="*.html">
> </filter>
> <helper
> class=" org.eclipse.wst.xml.validation.internal.operations.Workbench Context ">
> </helper>
> <run
> class="ch.raymi.plugin.coder.validator.TemplateValidator"
> enabled="true"
> fullBuild="true"
> incremental="true">
> </run>
> </validator>
> </extension>
>
>
> I think that I should change the helper class to something HTML
> specific, but I was unable to figure out what the appropriate HTML
> helper class would be (and do I have to use these internal classes?).
> Can anyone help me here?
>
> I am then able to get the file in the validateInJob with:
> Object[] params = { filename };
> IFile file = (IFile)helper.loadModel("getFile", params);
>
> However, I would really appreciate having a DOM tree instead of parsing
> the file on my own. How do I get a DOM model, if I use the appropriate
> HTML helper?
>
> Is it also possible to get the DOM model when using source validation
> (org.eclipse.wst.sse.ui.sourcevalidation)?
>
> Sorry for the newbies questions, but it's really hard to find useful
> information about this topic in the internet (well, maybe I just looked
> in the wrong places). Maybe someone knows some good resources regarding
> this topic?
>
> Thanks in advance for your help.
> Cheers,
>
> Dominik
After a little research and a peek in the HTMLValidator source code I
found a way to get the DOM, namely by using:
IStructuredModel ism =
StructuredModelManager.getModelManager().getModelForRead(fil e);
DOMStyleModelImpl dm = (DOMStyleModelImpl)ism;
IDOMDocument domdoc = dm.getDocument();
Would it be better to extend HTMLValidator (instead of implementing the
interfaces)? Is it possible to hook in the HTMLValidator (so that I only
have to write a validate method)?
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04236 seconds