report.builder.TextBuilder.java Source code

Java tutorial

Introduction

Here is the source code for report.builder.TextBuilder.java

Source

/**
 * Copyright (C) 2013 Benjamin Bouguet
 *
 * ReportGenerator is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * ReportGenerator is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package report.builder;

import java.util.Iterator;
import java.util.Map;

import org.json.simple.JSONObject;

import fr.opensagres.xdocreport.template.IContext;
import fr.opensagres.xdocreport.template.formatter.FieldsMetadata;

/**
 * @author Benjamin Bouguet
 *
 */
public class TextBuilder implements IContextBuilder {

    /**
     * Adds the text data from the JSON to the report's context.
     */
    @Override
    public void build(JSONObject json, FieldsMetadata metadata, IContext context) {
        // iterate on all the simple text
        Iterator<?> iter = json.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry<?, ?> entry = (Map.Entry<?, ?>) iter.next();
            // add the text to the report's context
            context.put(entry.getKey().toString(), entry.getValue().toString());
        }
    }

}