Search in sources :

Example 1 with ValidationAdapter

use of org.eclipse.wst.sse.core.internal.validate.ValidationAdapter in project webtools.sourceediting by eclipse.

the class HTMLValidator method validate.

private HTMLValidationResult validate(IReporter reporter, IFile file, IDOMModel model) {
    if (file == null || model == null)
        // error
        return null;
    IDOMDocument document = model.getDocument();
    if (document == null)
        // error
        return null;
    if (!hasHTMLFeature(document))
        // ignore
        return null;
    INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
    ValidationAdapter adapter = (ValidationAdapter) factory.adapt(document);
    if (adapter == null)
        // error
        return null;
    HTMLValidationReporter rep = getReporter(reporter, file, model);
    rep.clear();
    adapter.setReporter(rep);
    adapter.validate(document);
    return rep.getResult();
}
Also used : ValidationAdapter(org.eclipse.wst.sse.core.internal.validate.ValidationAdapter) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) INodeAdapterFactory(org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory)

Example 2 with ValidationAdapter

use of org.eclipse.wst.sse.core.internal.validate.ValidationAdapter in project webtools.sourceediting by eclipse.

the class CompositeValidator method setReporter.

/**
 */
public void setReporter(ValidationReporter reporter) {
    super.setReporter(reporter);
    Iterator i = components.iterator();
    while (i.hasNext()) {
        ValidationAdapter component = (ValidationAdapter) i.next();
        if (component == null)
            continue;
        component.setReporter(reporter);
    }
}
Also used : Iterator(java.util.Iterator) ValidationAdapter(org.eclipse.wst.sse.core.internal.validate.ValidationAdapter)

Example 3 with ValidationAdapter

use of org.eclipse.wst.sse.core.internal.validate.ValidationAdapter in project webtools.sourceediting by eclipse.

the class JSPContentValidator method validate.

/*
	 * Mostly copied from HTMLValidator
	 */
private void validate(IReporter reporter, IFile file, IDOMModel model) {
    if (file == null || model == null)
        // error
        return;
    IDOMDocument document = model.getDocument();
    if (document == null)
        // error
        return;
    // This validator currently only handles validating HTML content in
    // JSP
    boolean hasXMLFeature = isXMLJSP(document);
    boolean hasHTMLFeature = hasHTMLFeature(document);
    if (hasHTMLFeature && !hasXMLFeature) {
        INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
        ValidationAdapter adapter = (ValidationAdapter) factory.adapt(document);
        if (adapter == null)
            // error
            return;
        HTMLValidationReporter rep = getReporter(reporter, file, model);
        rep.clear();
        adapter.setReporter(rep);
        adapter.validate(document);
    }
}
Also used : ValidationAdapter(org.eclipse.wst.sse.core.internal.validate.ValidationAdapter) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) INodeAdapterFactory(org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory)

Example 4 with ValidationAdapter

use of org.eclipse.wst.sse.core.internal.validate.ValidationAdapter in project webtools.sourceediting by eclipse.

the class JSPContentValidator method validate.

private void validate(IFile file, int kind, ValidationState state, IProgressMonitor monitor, IDOMModel model, IReporter reporter) {
    IDOMDocument document = model.getDocument();
    if (document == null)
        // error
        return;
    boolean isXMLJSP = isXMLJSP(document);
    boolean hasHTMLFeature = hasHTMLFeature(document);
    if (hasHTMLFeature && !isXMLJSP) {
        INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
        ValidationAdapter adapter = (ValidationAdapter) factory.adapt(document);
        if (adapter != null) {
            HTMLValidationReporter rep = getReporter(reporter, file, model);
            rep.clear();
            adapter.setReporter(rep);
            adapter.validate(document);
        }
    }
    if (!hasHTMLFeature && isXMLJSP) {
        Validator xmlValidator = new Validator();
        xmlValidator.validate(file, kind, state, monitor);
    }
}
Also used : ValidationAdapter(org.eclipse.wst.sse.core.internal.validate.ValidationAdapter) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Validator(org.eclipse.wst.xml.core.internal.validation.eclipse.Validator) INodeAdapterFactory(org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory)

Example 5 with ValidationAdapter

use of org.eclipse.wst.sse.core.internal.validate.ValidationAdapter in project webtools.sourceediting by eclipse.

the class JSPContentSourceValidator method validate.

/**
 * This validate call is for the ISourceValidator partial document
 * validation approach
 *
 * @param dirtyRegion
 * @param helper
 * @param reporter
 * @see org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator
 */
public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) {
    if (helper == null || fDocument == null || !fEnableSourceValidation)
        return;
    if ((reporter != null) && (reporter.isCancelled() == true)) {
        throw new OperationCanceledException();
    }
    IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument);
    if (model == null)
        // error
        return;
    try {
        IDOMDocument document = null;
        if (model instanceof IDOMModel) {
            document = ((IDOMModel) model).getDocument();
        }
        if (document == null || !hasHTMLFeature(document))
            // ignore
            return;
        ITextFileBuffer fb = FileBufferModelManager.getInstance().getBuffer(fDocument);
        if (fb == null)
            return;
        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(fb.getLocation());
        if (file == null || !file.exists())
            return;
        // this will be the wrong region if it's Text (instead of Element)
        // we don't know how to validate Text
        // model.getIndexedRegion(dirtyRegion.getOffset());
        IndexedRegion ir = getCoveringNode(dirtyRegion);
        if (ir instanceof Text) {
            while (ir != null && ir instanceof Text) {
                // it's assumed that this gets the IndexedRegion to
                // the right of the end offset
                ir = model.getIndexedRegion(ir.getEndOffset());
            }
        }
        if (ir instanceof INodeNotifier) {
            INodeAdapterFactory factory = HTMLValidationAdapterFactory.getInstance();
            ValidationAdapter adapter = (ValidationAdapter) factory.adapt((INodeNotifier) ir);
            if (adapter == null)
                // error
                return;
            if (reporter != null) {
                HTMLValidationReporter rep = null;
                rep = getReporter(reporter, file, (IDOMModel) model);
                rep.clear();
                adapter.setReporter(rep);
                Message mess = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString().substring(1));
                reporter.displaySubtask(this, mess);
            }
            adapter.validate(ir);
        }
    } finally {
        if (model != null)
            model.releaseFromRead();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) Text(org.w3c.dom.Text) IndexedRegion(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion) INodeAdapterFactory(org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) ValidationAdapter(org.eclipse.wst.sse.core.internal.validate.ValidationAdapter) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) INodeNotifier(org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)

Aggregations

ValidationAdapter (org.eclipse.wst.sse.core.internal.validate.ValidationAdapter)8 INodeAdapterFactory (org.eclipse.wst.sse.core.internal.provisional.INodeAdapterFactory)5 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)5 INodeNotifier (org.eclipse.wst.sse.core.internal.provisional.INodeNotifier)4 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)2 IFile (org.eclipse.core.resources.IFile)2 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)2 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)2 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)2 Message (org.eclipse.wst.validation.internal.core.Message)2 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)2 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)2 Node (org.w3c.dom.Node)2 Text (org.w3c.dom.Text)2 Iterator (java.util.Iterator)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 HTMLValidationReporter (org.eclipse.wst.html.core.internal.validation.HTMLValidationReporter)1 LocalizedMessage (org.eclipse.wst.html.core.internal.validation.LocalizedMessage)1 Validator (org.eclipse.wst.xml.core.internal.validation.eclipse.Validator)1