Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » Implementing a simple Validator for HTML Files
Implementing a simple Validator for HTML Files [message #227158] Sat, 24 January 2009 14:39 Go to next message
Dominik Raymann is currently offline Dominik RaymannFriend
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 Go to previous messageGo to next message
Dominik Raymann is currently offline Dominik RaymannFriend
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)?
Re: Implementing a simple Validator for HTML Files [message #227336 is a reply to message #227180] Tue, 27 January 2009 16:24 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4425
Registered: July 2009
Senior Member

Dominik Raymann wrote:
> 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.

http://dev.eclipse.org/viewcvs/index.cgi/sourceediting/plugi ns/org.eclipse.jst.jsp.core/plugin.xml?root=WebTools_Project &view=markup
and
http://dev.eclipse.org/viewcvs/index.cgi/sourceediting/plugi ns/org.eclipse.jst.jsp.core/src/org/eclipse/jst/jsp/core/int ernal/validation/TLDValidator.java?root=WebTools_Project& ;view=markup

--
---
Nitin Dahyabhai
Eclipse WTP Source Editing
IBM Rational


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Implementing a simple Validator for HTML Files [message #1857558 is a reply to message #227336] Wed, 15 February 2023 07:56 Go to previous message
panda mkk is currently offline panda mkkFriend
Messages: 38
Registered: April 2022
Member
Hi,Nitin Dahyabhai
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


Previous Topic:Debugging JSPs (breakpoints) does not work
Next Topic:org.apache.cxf.cxf-core and jetty plugins giving issue missing constraint import package java.awt
Goto Forum:
  


Current Time: Tue Mar 19 05:11:00 GMT 2024

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

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

Back to the top