use of org.talend.xml.sax.simpleparser.model.XMLNode in project tdi-studio-se by Talend.
the class SimpleSAXLoopHandler method startElement.
/*
* (non-Javadoc)
*
* @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String,
* org.xml.sax.Attributes)
*/
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
this.currentPath = this.currentPath + "/" + qName;
for (XMLNode node : nodes.getNodesCollection()) {
node.outputText = false;
if (this.currentPath.equals(node.loopPath)) {
node.isLooping = true;
}
if (node.isLooping) {
if (node.isAsXML && (this.currentPath.equals(node.nodePath) || this.currentPath.startsWith(node.nodePath + "/"))) {
node.addTextValue("<");
node.addTextValue(qName);
if (attributes.getLength() > 0) {
for (int m = 0; m < attributes.getLength(); m++) {
node.addTextValue(" ");
node.addTextValue(attributes.getQName(m));
node.addTextValue("=");
node.addTextValue("\"");
node.addTextValue(escapeEntityHelper.escapeAttributeEntities(attributes.getValue(m)));
node.addTextValue("\"");
}
}
node.outputText = true;
node.hasValue = false;
node.addTextValue(">");
} else if (node.isDot && (this.currentPath.equals(node.nodePath) || this.currentPath.startsWith(node.nodePath + "/"))) {
node.outputText = true;
node.hasValue = false;
} else {
int index = node.nodePath.lastIndexOf("@");
if (index > 0) {
if (currentPath.equals(node.nodePath.substring(0, index - 1))) {
String attribute = attributes.getValue(node.nodePath.substring(index + 1));
if (attribute != null && false == node.hasValue) {
node.addTextValue(attribute);
node.hasValue = true;
}
}
} else {
if (currentPath.equals(node.nodePath)) {
node.outputText = true;
}
}
}
} else {
//process the attribute out of the loop
int index = node.nodePath.lastIndexOf("@");
if (index > 0) {
if (currentPath.equals(node.nodePath.substring(0, index - 1))) {
String attribute = attributes.getValue(node.nodePath.substring(index + 1));
if (attribute != null) {
node.addTextValue(attribute);
} else {
node.addTextValue("");
}
}
}
}
}
}
use of org.talend.xml.sax.simpleparser.model.XMLNode 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("/"));
}
use of org.talend.xml.sax.simpleparser.model.XMLNode in project tdi-studio-se by Talend.
the class SimpleSAXLooper method initLoopEntries.
private void initLoopEntries() {
multiCache = DataBufferCache2.getInstance();
for (XMLNodes ns : nodesList) {
for (XMLNode node : ns.getNodes().values()) {
String column = node.originPath;
String resultCol = node.loopPath;
String[] splits = column.split("/");
for (String tmp : splits) {
if (tmp.equals("..")) {
resultCol = resultCol.substring(0, resultCol.lastIndexOf("/"));
node.setAttrOutOfLoop(true);
} else if (tmp.equals(".")) {
node.isDot = true;
} else {
resultCol += "/" + tmp;
}
}
node.nodePath = resultCol;
}
}
}
use of org.talend.xml.sax.simpleparser.model.XMLNode in project tdi-studio-se by Talend.
the class SimpleSAXLooper method initLoopEntry.
private void initLoopEntry() {
bcache = DataBufferCache.getInstance();
// parse the node path to loopEntry
for (XMLNode node : nodes.getNodes().values()) {
String column = node.originPath;
String resultCol = node.loopPath;
String[] splits = column.split("/");
for (String tmp : splits) {
if (tmp.equals("..")) {
resultCol = resultCol.substring(0, resultCol.lastIndexOf("/"));
node.setAttrOutOfLoop(true);
} else if (tmp.equals(".")) {
node.isDot = true;
} else {
resultCol += "/" + tmp;
}
}
node.nodePath = resultCol;
}
}
Aggregations