Java tutorial
/** * PureInfo Command * @(#)ReportParser.java 1.0 2006-11-22 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srm.report.report.digital.parser; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.dom4j.Document; import org.dom4j.Element; import com.pureinfo.srm.report.report.digital.DigitalReport; import com.pureinfo.srm.report.report.digital.elements.Display; import com.pureinfo.srm.report.report.digital.elements.Grouper; /** * <P> * Created on 2006-11-22 11:16:40<BR> * Last modified on 2006-11-22 * </P> * TODO describe ReportParser here ... * * @author elmar.chen * @version 1.0, 2006-11-22 * @since Command 1.0 */ public class ReportParser { public static DigitalReport parse(Document _script) { DigitalReport report = new DigitalReport(); report.setQueries(parseQueries(_script)); report.setGroupers(parseGroupers(_script)); report.setDisplay(parseDisplay(_script)); return report; } private static Display parseDisplay(Document _sScript) { Element xDisplay = _sScript.getRootElement().element("display"); return DisplayParser.parse(xDisplay); } private static Map parseGroupers(Document _script) { List xGroupers = _script.getRootElement().element("groupers").elements("grouper"); Map groupers = new HashMap(xGroupers.size()); for (Iterator iter = xGroupers.iterator(); iter.hasNext();) { Element xQuery = (Element) iter.next(); String sId = xQuery.attributeValue("id"); Grouper grouper = new Grouper(); String sType = xQuery.attributeValue("type"); List xParams = xQuery.elements("param"); Map params = new HashMap(xParams.size()); for (Iterator iterInner = xGroupers.iterator(); iterInner.hasNext();) { Element xParam = (Element) iterInner.next(); params.put(xParam.attributeValue("name"), xParam.getText().trim()); } grouper.setType(sType); grouper.setPamrams(params); groupers.put(sId, grouper); } return groupers; } private static Map parseQueries(Document _script) { List xQueries = _script.getRootElement().element("queries").elements("query"); Map queries = new HashMap(xQueries.size()); for (Iterator iter = xQueries.iterator(); iter.hasNext();) { Element xQuery = (Element) iter.next(); queries.put(xQuery.attributeValue("id"), xQuery.getTextTrim()); } return queries; } }