/*
* Enhydra Java Application Server Project
*
* The contents of this file are subject to the Enhydra Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License on
* the Enhydra web site ( http://www.enhydra.org/ ).
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific terms governing rights and limitations
* under the License.
*
* The Initial Developer of the Enhydra Application Server is Lutris
* Technologies, Inc. The Enhydra Application Server and portions created
* by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
* All Rights Reserved.
*
* Contributor(s):
* Paul Mahar
*
*/
//
package org.enhydra.tool.codegen;
//
import org.enhydra.tool.ToolBoxInfo;
import org.enhydra.tool.common.Template;
import org.enhydra.tool.common.TemplateTool;
import org.enhydra.tool.common.TemplateFilter;
import org.enhydra.tool.common.PathHandle;
//
public class ProjectTemplateFilter implements TemplateFilter, Constants {
private TemplateTool tool = null;
private String destPath = null;
private String[] includes = new String[0];
private String[] excludes = new String[0];
private boolean tempIn = true;
public ProjectTemplateFilter(TemplateTool t, String dest) {
final String[] initExts = {
TYPE_TEMPLATE
};
tool = t;
tool.setInitExtensions(initExts);
tool.setInitDestination(dest);
}
public String getDestination() {
return tool.getInitDestination();
}
public boolean isIncludeTemplate() {
return tempIn;
}
public void setIncludeTemplate(boolean b) {
tempIn = b;
}
public TemplateTool getTemplateTool() {
return tool;
}
public String[] getOutputExcludes() {
return excludes;
}
public void setOutputExcludes(String[] ex) {
excludes = ex;
}
public void setInputIncludes(String[] in) {
includes = in;
}
public String[] getInputIncludes() {
return includes;
}
public boolean accept(Template template) {
int index = -1;
boolean include = false;
boolean dir = false;
PathHandle path = null;
String ext = new String();
if (template.isDirectory()) {
include = tempIn;
dir = true;
} else {
path = PathHandle.createPathHandle(template.toString());
ext = path.getExtension();
if (tempIn) {
include = ext.startsWith(TYPE_TEMPLATE) && includeInput(ext);
} else {
include = (!ext.startsWith(TYPE_TEMPLATE))
&& includeInput(ext);
}
}
if (include) {
path = PathHandle.createPathHandle(template.getOutput());
if (path.getPath() == null) {
tool.initOutput(template);
path = PathHandle.createPathHandle(template.getOutput());
}
ext = path.getExtension();
index = ext.indexOf('-');
if (index > -1) {
path.setExtension(ext.substring(0, index));
template.setOutput(path.getFile());
}
include = (!path.endsWith(getOutputExcludes()));
}
return include;
}
private boolean includeInput(String input) {
boolean include = false;
int index = -1;
String suffix = new String();
if (input == null) {
include = false;
} else {
index = input.indexOf('-');
if (index > 0) {
suffix = input.substring(index);
for (int i = 0; i < getInputIncludes().length; i++) {
if (suffix.equalsIgnoreCase('-'
+ getInputIncludes()[i])) {
include = true;
break;
}
}
} else {
include = true;
}
}
return include;
}
}
|