/** * 获取模板引擎实例 * * @param pTemplateType 引擎类型 * @return 返回模板引擎实例 */ public static TemplateEngine getTemplateEngine(TemplateType pType) { if (pType == null) { return null; } if (ENGINES.containsKey(pType) == false) { throw new IllegalArgumentException( G4Constants.Exception_Head + "不支持的模板类别:" + pType.getType()); } return (TemplateEngine) ENGINES.get(pType); }
public TNode parse(Path path) { try { final TNode root = parse(Files.readAllBytes(path), TemplateType.fromPath(path)); root.setUnparsedSize(Files.size(path)); return root; } catch (IOException e) { throw new TemplateException(e); } catch (TemplateException e) { if (e.getCause() != null) { throw new TemplateException( "Error when parsing " + path + ":" + e.getCause().getMessage(), e.getCause()); } else { throw new TemplateException("Error when parsing " + path + ":" + e.getMessage(), e); } } }
public static Template createTemplate( String format, InputStream in, Map<String, Object> options) { TemplateType type = TemplateType.getByFormat(format); Template template; switch (type) { case EXCEL: template = new ExcelTemplate(in, options); break; case WORD: template = new WordTemplate(in, options); break; case WORD_PDF: template = new WordPdfTemplate(in, options); break; default: throw new IllegalArgumentException("Unknown template type for " + format); } return template; }
public static Template fromJson(final JsonCommand command) { final String name = command.stringValueOfParameterNamed("name"); final String text = command.stringValueOfParameterNamed("text"); final TemplateEntity entity = TemplateEntity.values()[command.integerValueSansLocaleOfParameterNamed("entity")]; final TemplateType type = TemplateType.values()[command.integerValueSansLocaleOfParameterNamed("type")]; final JsonArray array = command.arrayOfParameterNamed("mappers"); final List<TemplateMapper> mappersList = new ArrayList<>(); for (final JsonElement element : array) { mappersList.add( new TemplateMapper( element.getAsJsonObject().get("mappersorder").getAsInt(), element.getAsJsonObject().get("mapperskey").getAsString(), element.getAsJsonObject().get("mappersvalue").getAsString())); } return new Template(name, text, entity, type, mappersList); }
public String getTemplateExtension() { if (template != null) { return template.getExtension(); } return null; }
public String[] getTemplateRenamings() { if (template != null) { return template.getSourceRenamings(); } return null; }
public boolean[] getTemplateGenerates() { if (template != null) { return template.getSourceGenerates(); } return null; }
public String[] getTemplateLocations() { if (template != null) { return template.getSourceLocations(); } return null; }
public String[] getTemplateNames() { if (template != null) { return template.getSourceNames(); } return null; }
public String getTemplateLocation() { if (template != null) { return template.getLocation(); } return null; }