Package de.innovationgate.eclipse.editors.tml.markers

Source Code of de.innovationgate.eclipse.editors.tml.markers.TMLFileValidator

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.tml.markers;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.part.FileEditorInput;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.ResourceIDs;
import de.innovationgate.eclipse.editors.helpers.MarkingHandler;
import de.innovationgate.eclipse.editors.tml.TMLDocumentProvider;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.wga.model.VersionCompliance;

/**
* validator for tml files
* - provide methods for validating tml files
* - extends incremental project builder to perform revalidation of existing markers on resource changes
*
*
*/
public class TMLFileValidator extends IncrementalProjectBuilder {
 
  private static Set<MarkingHandler> allHandlers = new HashSet<MarkingHandler>();
  static {
    allHandlers = new HashSet<MarkingHandler>();
    allHandlers.add(new UnknownTMLTagMarkingHandler());
    allHandlers.add(new UnknownTMLAttributeMarkingHandler());
    allHandlers.add(new UnclosedTMLTagMarkingHandler());
    allHandlers.add(new TMLTagValidationMarkingHandler());
  }

   
  public static void validateTMLFile(IFile file) { 
    try {
      TMLDocumentProvider provider = new TMLDocumentProvider();   
      IFileEditorInput input = new FileEditorInput(file);     
      provider.connect(input);
     
      VersionCompliance versionCompliance = WGADesignStructureHelper.getWGAVersionCompliance(file);
     
      Iterator<MarkingHandler> it = allHandlers.iterator();
      while (it.hasNext()) {
        MarkingHandler handler = it.next()
        handler.setWGAVersionCompliance(versionCompliance);
        handler.setDocumentProvider(provider);
        handler.createMarkers(file, provider.getDocument(input));       
      }     
      provider.disconnect(input);
    } catch (CoreException e) {
      Plugin.getDefault().logError("Unable to validate tml file '" + file.getLocation().toString() + "'.", e);
    }
  }

  @SuppressWarnings("unchecked")
  @Override
  protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {   
    IProject project = getProject();
    if (project != null && project.isAccessible()) {
      IMarker[] markers = project.findMarkers(ResourceIDs.MARKER_TML_REFERENCES, false, IResource.DEPTH_INFINITE);
      for (IMarker marker : markers) {
        if (marker.getResource() != null && marker.getResource() instanceof IFile) {
          TMLFileValidator.validateTMLFile((IFile)marker.getResource());
        }
      }
    }
    return null;
  }
 
 
}
TOP

Related Classes of de.innovationgate.eclipse.editors.tml.markers.TMLFileValidator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.