All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.template.base.impl.SearchExtensionsStrategy Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.template.base.impl;

import java.util.List;

import org.zodiac.sdk.toolkit.util.AssertUtil;
import org.zodiac.sdk.toolkit.util.collection.CollAndMapUtil;

/**
 * 假如当前模板名后缀无法找到模板,试着以其它后缀寻找。
 * 

* 例如:模板test.vm不存在,那么就尝试一下test.jsptest.ftl等。 *

*/ public class SearchExtensionsStrategy implements TemplateSearchingStrategy { private final String[] availableExtensions; public SearchExtensionsStrategy(String[] extensions) { this.availableExtensions = AssertUtil.assertNotNull(extensions, "extensions"); } public Object getKey(String templateName) { return null; } public boolean findTemplate(TemplateMatcher matcher) { List testedExtensions = CollAndMapUtil.list(availableExtensions.length); boolean found = false; String ext = matcher.getExtension(); if (ext != null) { testedExtensions.add(ext); found = matcher.findTemplate(); } for (int i = 0; !found && i < availableExtensions.length; i++) { ext = availableExtensions[i]; if (!testedExtensions.contains(ext)) { testedExtensions.add(ext); matcher.setExtension(ext); found = matcher.findTemplate(); } } return found; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy