Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsImplementing a simple Validator for HTML Files
https://www.eclipse.org/forums/index.php/mv/msg/72654/227158/#msg_227158
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:
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]]>Dominik Raymann2009-01-24T14:39:52-00:00Re: Implementing a simple Validator for HTML Files
https://www.eclipse.org/forums/index.php/mv/msg/72654/227180/#msg_227180
> 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:
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)?]]>Dominik Raymann2009-01-24T22:44:46-00:00Re: Implementing a simple Validator for HTML Files
https://www.eclipse.org/forums/index.php/mv/msg/72654/227336/#msg_227336
> 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)?
The short answer is "no".
The longer answer is based on the HTMLValidator having migrated from
the V1 extension point and interface to the newer framework, leaving
a lot of extra scaffolding code in place. This makes it less
efficient at runtime and harder to learn from as a developer, but we
just didn't have a lot of time to spend in the migration, nor a
desire to risk breakage. The new
org.eclipse.wst.validation.validatorV2 extension point is far easier
to work with, and the implementation of the new-in-M5
org.eclipse.jst.jsp.core.internal.validation.TLDValidator class is
exactly as it should be, with the bulk of the code doing the actual
validation instead of interacting with the framework.
--
---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational]]>Nitin Dahyabhai2009-01-27T16:24:04-00:00Re: Implementing a simple Validator for HTML Files
https://www.eclipse.org/forums/index.php/mv/msg/72654/1857558/#msg_1857558
The above two links cannot be opened
I'm also looking for a way to check HTML syntax
I can't find any documents,Are there any documents or examples