Package com.google.refine.templating

Examples of com.google.refine.templating.Template


        String templateString = options.getProperty("template");
        String prefixString = options.getProperty("prefix");
        String suffixString = options.getProperty("suffix");
        String separatorString = options.getProperty("separator");
       
        Template template;
        try {
            template = Parser.parse(templateString);
        } catch (ParsingException e) {
            throw new IOException("Missing or bad template", e);
        }
       
        template.setPrefix(prefixString);
        template.setSuffix(suffixString);
        template.setSeparator(separatorString);
       
        if (!"true".equals(options.getProperty("preview"))) {
            StringWriter stringWriter = new StringWriter();
            JSONWriter jsonWriter = new JSONWriter(stringWriter);
            try {
                jsonWriter.object();
                jsonWriter.key("template"); jsonWriter.value(templateString);
                jsonWriter.key("prefix"); jsonWriter.value(prefixString);
                jsonWriter.key("suffix"); jsonWriter.value(suffixString);
                jsonWriter.key("separator"); jsonWriter.value(separatorString);
                jsonWriter.endObject();
            } catch (JSONException e) {
                // ignore
            }
           
            project.getMetadata().getPreferenceStore().put("exporters.templating.template", stringWriter.toString());
        }
       
        if (engine.getMode() == Mode.RowBased) {
            FilteredRows filteredRows = engine.getAllFilteredRows();
            RowVisitor visitor = template.getRowVisitor(writer, limit);
           
            if (sortingJson != null) {
                try {
                    SortingRowVisitor srv = new SortingRowVisitor(visitor);
                    srv.initializeFromJSON(project, sortingJson);
                   
                    if (srv.hasCriteria()) {
                        visitor = srv;
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
           
            filteredRows.accept(project, visitor);
        } else {
            FilteredRecords filteredRecords = engine.getFilteredRecords();
            RecordVisitor visitor = template.getRecordVisitor(writer, limit);
           
            if (sortingJson != null) {
                try {
                    SortingRecordVisitor srv = new SortingRecordVisitor(visitor);
                    srv.initializeFromJSON(project, sortingJson);
View Full Code Here

TOP

Related Classes of com.google.refine.templating.Template

Copyright © 2018 www.massapicom. 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.