栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

FreeMarker代码分析第二篇

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

FreeMarker代码分析第二篇

2021SC@SDUSC

FreeMarker代码分析第二篇
  • ant包
    • FreemarkerXmlTask.java
      • 代码分析
        • execute()方法
    • JythonAntTask.java
    • UnlinkedJythonOperations.java
    • UnlinkedJythonOperationsImpl.java

ant包 FreemarkerXmlTask.java 代码分析 execute()方法
@Override
    public void execute() throws BuildException {
//初始化文件夹扫描器和文件名数组
        DirectoryScanner scanner;
        String[]         list;
//查找可用目录
        if (baseDir == null) {
            baseDir = getProject().getbaseDir();
        }
        if (destDir == null ) {
            String msg = "destdir attribute must be set!";
            throw new BuildException(msg, getLocation());
        }
//初始化文件
        File templateFile = null;

        if (templateDir == null) {
            if (templateName != null) {
                templateFile = new File(templateName);
                if (!templateFile.isAbsolute()) {
                    templateFile = new File(getProject().getbaseDir(), templateName);
                }
                templateDir = templateFile.getParentFile();
                templateName = templateFile.getName();
            } else {
                templateDir = baseDir;
            }
            setTemplateDir(templateDir);
        } else if (templateName != null) {
            if (new File(templateName).isAbsolute()) {
                throw new BuildException("Do not specify an absolute location for the template as well as a templateDir");
            }
            templateFile = new File(templateDir, templateName);
        }
        if (templateFile != null) {
            templateFileLastModified = templateFile.lastModified();
        }

        try {
            if (templateName != null) {
                parsedTemplate = cfg.getTemplate(templateName, templateEncoding);
            }
        } catch (IOException ioe) {
            throw new BuildException(ioe.toString());
        }
        // get the last modification of the template
        log("Transforming into: " + destDir.getAbsolutePath(), Project.MSG_INFO);

        // projectFile relative to baseDir
        if (projectAttribute != null && projectAttribute.length() > 0) {
            projectFile = new File(baseDir, projectAttribute);
            if (projectFile.isFile())
                projectFileLastModified = projectFile.lastModified();
            else {
                log ("Project file is defined, but could not be located: " +
                     projectFile.getAbsolutePath(), Project.MSG_INFO );
                projectFile = null;
            }
        }

        generateModels();
        
        // find the files/directories
        scanner = getDirectoryScanner(baseDir);

        propertiesTemplate = wrapMap(project.getProperties());
        userPropertiesTemplate = wrapMap(project.getUserProperties());

        builderFactory.setValidating(validation);
        try {
            builder = builderFactory.newdocumentBuilder();
        } catch (ParserConfigurationException e) {
            throw new BuildException("Could not create document builder", e, getLocation());
        }

        // get a list of files to work on
        list = scanner.getIncludedFiles();
        
        
        for (int i = 0; i < list.length; ++i) {
            process(baseDir, list[i], destDir);
        }
    }
JythonAntTask.java UnlinkedJythonOperations.java UnlinkedJythonOperationsImpl.java
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/292569.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号