Java 类net.sf.jasperreports.engine.util.xml.JRXPathExecuter 实例源码

项目:PDFReporter-Studio    文件:XMLDataAdapterDescriptor.java   
/**
 * Returns the list of fields provided by an XML document and the related
 * query.
 * 
 * @param doc
 *          the W3C XML document
 * @param jConfig
 *          the JasperReports configuration instance
 * @param jDataset
 *          the current dataset
 * @return the list of fields
 * @throws JRException
 */
protected List<JRDesignField> getFieldsFromDocument(Document doc, JasperReportsConfiguration jConfig, JRDataset jDataset) throws JRException {
    JRXPathExecuterFactory xPathExecuterFactory = JRXPathExecuterUtils.getXPathExecuterFactory(jConfig);
    JRXPathExecuter xPathExecuter = xPathExecuterFactory.getXPathExecuter();
    NodeList nodes = xPathExecuter.selectNodeList(doc, jDataset.getQuery().getText());
    LinkedHashMap<String, JRDesignField> fieldsMap = new LinkedHashMap<String, JRDesignField>();
    for (int nIdx = 0; nIdx < nodes.getLength(); nIdx++) {
        Node currNode = nodes.item(nIdx);
        findDirectChildrenAttributes(currNode,fieldsMap,"");
        if(currNode.getNodeType() == Node.ELEMENT_NODE) {
            NodeList childNodes = currNode.getChildNodes();
            findChildFields(childNodes, fieldsMap,"");
        }
    }
    return new ArrayList<JRDesignField>(fieldsMap.values());
}