com.pureinfo.srm.report.report.digital.parser.DisplayParser.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.report.report.digital.parser.DisplayParser.java

Source

/**
 * PureInfo Command
 * @(#)DisplayParser.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.Iterator;

import org.dom4j.Element;

import com.pureinfo.srm.report.report.digital.elements.Display;
import com.pureinfo.srm.report.report.digital.elements.DisplayItem;
import com.pureinfo.srm.report.report.digital.elements.Line;
import com.pureinfo.srm.report.report.digital.elements.LineGroup;

/**
 * <P>
 * Created on 2006-11-22 16:14:35 <BR>
 * Last modified on 2006-11-22
 * </P>
 * TODO describe DisplayParser here ...
 * 
 * @author elmar.chen
 * @version 1.0, 2006-11-22
 * @since Command 1.0
 */
public class DisplayParser {
    public static Display parse(Element _xDisplay) {
        Display display = new Display();
        DisplayItem cols = parseLineGroup(_xDisplay.element("cols"));
        DisplayItem rows = parseLineGroup(_xDisplay.element("rows"));
        display.setCols(cols);
        display.setRows(rows);
        return display;
    }

    private static DisplayItem parseItem(Element _xItem) {
        String sType = _xItem.getName();
        if (sType.equals("line"))
            return parseLine(_xItem);
        if (sType.equals("line-group"))
            return parseLineGroup(_xItem);
        return null;
    }

    private static Line parseLine(Element _sItem) {
        Line line = new Line();
        line.setBy(_sItem.attributeValue("by"));
        line.setId(_sItem.attributeValue("id"));
        line.setSource(_sItem.attributeValue("source"));
        line.setName(_sItem.attributeValue("name"));
        return line;
    }

    private static LineGroup parseLineGroup(Element _sItem) {
        LineGroup group = new LineGroup();
        group.setGrouper(_sItem.attributeValue("grouper"));
        group.setId(_sItem.attributeValue("id"));
        group.setOther(_sItem.attributeValue("auto"));
        group.setTotal(_sItem.attributeValue("total"));
        for (Iterator iter = _sItem.elementIterator(); iter.hasNext();) {
            Element xItem = (Element) iter.next();
            DisplayItem item = parseItem(xItem);
            if (item != null) {
                group.addItem(item);
            }
        }
        return group;
    }
}