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

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

/*******************************************************************************
* 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.io.IOException;

import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITypedRegion;

import de.innovationgate.eclipse.editors.Plugin;
import de.innovationgate.eclipse.editors.ResourceIDs;
import de.innovationgate.eclipse.editors.config.TMLTag;
import de.innovationgate.eclipse.editors.helpers.MarkerFactory;
import de.innovationgate.eclipse.editors.helpers.TMLTagValidator;
import de.innovationgate.eclipse.editors.tml.TMLRegion;
import de.innovationgate.eclipse.utils.wga.WGADesignStructureHelper;
import de.innovationgate.wga.common.beans.csconfig.v2.Shortcut;
import de.innovationgate.wga.model.WGADesignConfigurationModel;

/**
* validator for design db references on tml:include, tml:portlet
*
*
*/
public class DesignDBReferenceValidator extends TMLTagValidator {
 
  public String getMarkerID() {
    return ResourceIDs.MARKER_TML_DESIGNDB_REFERENCE;
  }

  public void validateAndMark(IFile file, IDocument document, ITypedRegion partition, TMLRegion tmlInfo, TMLTag tag) {
 
    
    int charStart = partition.getOffset();
    int charEnd = charStart + partition.getLength();
   
    String designDBValue = tmlInfo.getAttributeValue("designdb");
    if (tmlInfo.hasAttribute("designdb") && !tmlInfo.isDynamicAttributeValue("designdb") && designDBValue != null && designDBValue.startsWith("@")) {           
      WGADesignStructureHelper helper = new WGADesignStructureHelper(file);   
      try {
        WGADesignConfigurationModel model  = helper.createModel();
        boolean designDBReferenceFound = false;
        if (model.isFeatureSupported(WGADesignConfigurationModel.FEATURE_SHORTCUTS)) {
          for (Shortcut shortCut : model.getShortcuts()) {
            if (shortCut.getType() == Shortcut.TYPE_PLUGIN) {
              if (shortCut.getShortcut().equals(designDBValue.substring(1))) {
                designDBReferenceFound = true;
                break;
              }
            }
          }
        }
        if (!designDBReferenceFound) {
          IRegion designDBValueRegion;
          try {
            designDBValueRegion = tmlInfo.getAttributeValueRegion("designdb");
            charStart = designDBValueRegion.getOffset();
            charEnd = charStart + designDBValueRegion.getLength();
          } catch (BadLocationException e) {
            // ignore just mark the whole line
          }
          MarkerFactory.createErrorMarker(getMarkerID(), file, charStart, charEnd, "Unsatisfied design db reference '" + designDBValue + "'.");
        }
      } catch (IOException e) {
        Plugin.getDefault().logError("Unable to create design configuration model for design db reference validation.", e);
      }
    }
  }
}
TOP

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

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.