Package com.intellij.struts2

Source Code of com.intellij.struts2.StrutsFileTemplateProvider

/*
* Copyright 2013 The authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.struts2;

import com.intellij.ide.fileTemplates.FileTemplate;
import com.intellij.ide.fileTemplates.FileTemplateManager;
import com.intellij.openapi.module.Module;
import com.intellij.struts2.facet.ui.StrutsVersionDetector;
import com.intellij.util.text.VersionComparatorUtil;
import org.jetbrains.annotations.NotNull;

/**
* @author Yann Cébron
*/
public class StrutsFileTemplateProvider {

  private final String myVersionName;
  private final boolean my21orNewer;

  public StrutsFileTemplateProvider(Module module) {
    myVersionName = StrutsVersionDetector.detectStrutsVersion(module);
    my21orNewer = isNewerThan("2.1");
  }

  @NotNull
  public FileTemplate determineFileTemplate() {
    String template;
    if (isNewerThan("2.3")) {
      template = StrutsFileTemplateGroupDescriptorFactory.STRUTS_2_3_XML;
    }
    else if (my21orNewer) {
      template = isNewerThan("2.1.7") ?
                 StrutsFileTemplateGroupDescriptorFactory.STRUTS_2_1_7_XML :
                 StrutsFileTemplateGroupDescriptorFactory.STRUTS_2_1_XML;
    }
    else {
      template = StrutsFileTemplateGroupDescriptorFactory.STRUTS_2_0_XML;
    }

    final FileTemplateManager fileTemplateManager = FileTemplateManager.getInstance();
    return fileTemplateManager.getJ2eeTemplate(template);
  }

  public boolean is21orNewer() {
    return my21orNewer;
  }

  private boolean isNewerThan(String versionName) {
    return VersionComparatorUtil.compare(myVersionName, versionName) > 0;
  }
}
TOP

Related Classes of com.intellij.struts2.StrutsFileTemplateProvider

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.