Search in sources :

Example 1 with EnoughDataException

use of org.talend.xml.sax.exception.EnoughDataException in project tdi-studio-se by Talend.

the class SimpleSAXLoopHandler method endElement.

/*
     * (non-Javadoc)
     * 
     * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
     */
public void endElement(String uri, String localName, String qName) throws SAXException {
    for (XMLNode node : nodes.getNodesCollection()) {
        if (node.isLooping) {
            if (node.outputText) {
                if (node.hasValue == false) {
                    node.addTextValue("");
                }
                node.hasValue = true;
            }
            if ((node.isAsXML || node.isDot) && (this.currentPath.equals(node.nodePath) || this.currentPath.startsWith(node.nodePath + "/"))) {
                if (node.isAsXML) {
                    node.addTextValue("</");
                    node.addTextValue(qName);
                    node.addTextValue(">");
                }
                if (this.currentPath.equals(node.nodePath)) {
                    node.hasValue = true;
                }
            }
        }
        node.outputText = false;
    }
    if (this.currentPath.equals(nodes.getLoopPath())) {
        if (isNotNull(nodes.getNodesCollection(), nodes.size())) {
            Map<String, String> map = new HashMap<String, String>();
            for (XMLNode node : nodes.getNodesCollection()) {
                map.put(node.originPath, node.getTextValue());
            }
            if (multiCache != null) {
                HashMap<String, Map<String, String>> row = new HashMap<String, Map<String, String>>(1);
                row.put(nodes.getOriginalLoopPath(), map);
                multiCache.writeData(row);
            } else {
                bufferCache.writeData(map);
            }
            if (stop) {
                throw new EnoughDataException("Get enough data,now stop the xml parse action");
            }
        }
        nodes.resetAll();
    }
    this.currentPath = this.currentPath.substring(0, this.currentPath.lastIndexOf("/"));
}
Also used : XMLNode(org.talend.xml.sax.simpleparser.model.XMLNode) HashMap(java.util.HashMap) EnoughDataException(org.talend.xml.sax.exception.EnoughDataException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 EnoughDataException (org.talend.xml.sax.exception.EnoughDataException)1 XMLNode (org.talend.xml.sax.simpleparser.model.XMLNode)1