Search in sources :

Example 16 with Message

use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.

the class AbstractNestedValidator method validate.

/**
 * Validate the given file and use the reporter for the validation messages.
 * This method does not perform the validation logic but rather delegates to
 * the validate method in subclasses to validate. This method is responsible
 * for reporting the messages that result from validation.
 *
 * @param file
 *            An IFile to validate.
 * @param inputstream
 *            An InputStream that represents the file. The InputStream may
 *            be null in which case the files should be validated from the
 *            IFile.
 * @param result
 *            - The validation result
 * @param reporter
 *            The reporter with which to report validation messages.
 * @param context
 *            The context of the current validation.
 */
private void validate(IFile file, InputStream inputstream, ValidationResult result, IReporter reporter, NestedValidatorContext context) {
    Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, file.getFullPath().toString());
    reporter.displaySubtask(this, message);
    String locationString = null;
    if (file.getLocation() != null) {
        locationString = file.getLocation().toString();
    }
    if (locationString == null && file.getLocationURI() != null) {
        locationString = file.getLocationURI().toString();
    }
    if (locationString == null) {
        locationString = file.getFullPath().toString();
    }
    String uri = createURIForFilePath(locationString);
    clearMarkers(file, this, reporter);
    ValidationReport valreport = null;
    if (result == null)
        valreport = validate(uri, inputstream, context);
    else
        valreport = validate(uri, inputstream, context, result);
    createMarkers(file, valreport.getValidationMessages(), reporter);
    try {
        file.setSessionProperty(ValidationMessage.ERROR_MESSAGE_MAP_QUALIFIED_NAME, valreport.getNestedMessages());
    } catch (CoreException e) {
        // $NON-NLS-1$
        System.out.println("Unable to set nested messages property.");
    }
}
Also used : IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) CoreException(org.eclipse.core.runtime.CoreException)

Example 17 with Message

use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.

the class HTMLSourceValidator 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)
        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;
        }
        IPath filePath = null;
        IFile file = null;
        ITextFileBuffer fb = FileBufferModelManager.getInstance().getBuffer(fDocument);
        if (fb != null) {
            filePath = fb.getLocation();
            if (filePath.segmentCount() > 1) {
                file = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath);
                if (!file.isAccessible()) {
                    file = null;
                }
            }
        } else {
            filePath = new Path(model.getId());
        }
        // 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, filePath.toString().substring(1));
                reporter.displaySubtask(this, mess);
            }
            adapter.validate(ir);
        }
    } finally {
        releaseModel(model);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) LocalizedMessage(org.eclipse.wst.html.core.internal.validation.LocalizedMessage) 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) HTMLValidationReporter(org.eclipse.wst.html.core.internal.validation.HTMLValidationReporter) 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) LocalizedMessage(org.eclipse.wst.html.core.internal.validation.LocalizedMessage)

Example 18 with Message

use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.

the class HTMLValidator method validateContainer.

/**
 */
private void validateContainer(IValidationContext helper, IReporter reporter, IContainer container) {
    try {
        IResource[] resourceArray = container.members(false);
        for (int i = 0; i < resourceArray.length; i++) {
            IResource resource = resourceArray[i];
            if (resource == null || reporter.isCancelled())
                continue;
            if (resource instanceof IFile) {
                Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, resource.getFullPath().toString().substring(1));
                reporter.displaySubtask(this, message);
                validateFile(helper, reporter, (IFile) resource, null);
            } else if (resource instanceof IContainer) {
                validateContainer(helper, reporter, (IContainer) resource);
            }
        }
    } catch (CoreException ex) {
    }
}
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) CoreException(org.eclipse.core.runtime.CoreException) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource)

Example 19 with Message

use of org.eclipse.wst.validation.internal.core.Message in project webtools.sourceediting by eclipse.

the class HTMLValidator method validateDelta.

/**
 */
private void validateDelta(IValidationContext helper, IReporter reporter) {
    String[] deltaArray = helper.getURIs();
    for (int i = 0; i < deltaArray.length; i++) {
        String delta = deltaArray[i];
        if (delta == null)
            continue;
        if (reporter != null) {
            Message message = new LocalizedMessage(IMessage.LOW_SEVERITY, delta.substring(1));
            reporter.displaySubtask(this, message);
        }
        IResource resource = getResource(delta);
        if (resource == null || !(resource instanceof IFile))
            continue;
        validateFile(helper, reporter, (IFile) resource, null);
    }
}
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) IResource(org.eclipse.core.resources.IResource)

Aggregations

Message (org.eclipse.wst.validation.internal.core.Message)19 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)17 CoreException (org.eclipse.core.runtime.CoreException)10 IFile (org.eclipse.core.resources.IFile)8 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)5 IResource (org.eclipse.core.resources.IResource)4 LocalizedMessage (org.eclipse.wst.validation.internal.operations.LocalizedMessage)4 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)3 Path (org.eclipse.core.runtime.Path)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)2 IContainer (org.eclipse.core.resources.IContainer)2 IProject (org.eclipse.core.resources.IProject)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 IPath (org.eclipse.core.runtime.IPath)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 JSPELParser (org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParser)2