List of usage examples for org.dom4j Node getText
String getText();
Returns the text of this node.
From source file:bard.pubchem.xml.PubChemXMLParserFactory.java
License:Open Source License
protected String join(Collection<Node> nodes, String separator) { StringBuffer sb = new StringBuffer(); int count = 0; for (Node node : nodes) { sb.append(node.getText()); if (count++ < nodes.size() - 1) sb.append(separator);// w w w . j a v a 2 s.c om } return sb.toString(); }
From source file:bio2rdf.datahub_get_stats_0_1.datahub_get_stats.java
License:Apache License
public void tHttpRequest_1Process(final java.util.Map<String, Object> globalMap) throws TalendException { globalMap.put("tHttpRequest_1_SUBPROCESS_STATE", 0); final boolean execStat = this.execStat; String iterateId = ""; int iterateLoop = 0; String currentComponent = ""; java.util.Map<String, Object> resourceMap = new java.util.HashMap<String, Object>(); try {//www . j av a2 s . c o m String currentMethodName = new java.lang.Exception().getStackTrace()[0].getMethodName(); boolean resumeIt = currentMethodName.equals(resumeEntryMethodName); if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start // the // resume globalResumeTicket = true; row6Struct row6 = new row6Struct(); row7Struct row7 = new row7Struct(); row8Struct row8 = new row8Struct(); row9Struct row9 = new row9Struct(); row10Struct row10 = new row10Struct(); row10Struct row5 = row10; /** * [tBufferOutput_1 begin ] start */ ok_Hash.put("tBufferOutput_1", false); start_Hash.put("tBufferOutput_1", System.currentTimeMillis()); currentComponent = "tBufferOutput_1"; int tos_count_tBufferOutput_1 = 0; /** * [tBufferOutput_1 begin ] stop */ /** * [tLogRow_2 begin ] start */ ok_Hash.put("tLogRow_2", false); start_Hash.put("tLogRow_2", System.currentTimeMillis()); currentComponent = "tLogRow_2"; int tos_count_tLogRow_2 = 0; /** * [tLogRow_2 begin ] stop */ /** * [tFilterRow_1 begin ] start */ ok_Hash.put("tFilterRow_1", false); start_Hash.put("tFilterRow_1", System.currentTimeMillis()); currentComponent = "tFilterRow_1"; int tos_count_tFilterRow_1 = 0; int nb_line_tFilterRow_1 = 0; int nb_line_ok_tFilterRow_1 = 0; int nb_line_reject_tFilterRow_1 = 0; class Operator_tFilterRow_1 { private String sErrorMsg = ""; private boolean bMatchFlag = true; private String sUnionFlag = "&&"; public Operator_tFilterRow_1(String unionFlag) { sUnionFlag = unionFlag; bMatchFlag = "||".equals(unionFlag) ? false : true; } public String getErrorMsg() { if (sErrorMsg != null && sErrorMsg.length() > 1) return sErrorMsg.substring(1); else return null; } public boolean getMatchFlag() { return bMatchFlag; } public void matches(boolean partMatched, String reason) { // no need to care about the next judgement if ("||".equals(sUnionFlag) && bMatchFlag) { return; } if (!partMatched) { sErrorMsg += "|" + reason; } if ("||".equals(sUnionFlag)) bMatchFlag = bMatchFlag || partMatched; else bMatchFlag = bMatchFlag && partMatched; } } /** * [tFilterRow_1 begin ] stop */ /** * [tJavaRow_2 begin ] start */ ok_Hash.put("tJavaRow_2", false); start_Hash.put("tJavaRow_2", System.currentTimeMillis()); currentComponent = "tJavaRow_2"; int tos_count_tJavaRow_2 = 0; int nb_line_tJavaRow_2 = 0; /** * [tJavaRow_2 begin ] stop */ /** * [tExtractRegexFields_1 begin ] start */ ok_Hash.put("tExtractRegexFields_1", false); start_Hash.put("tExtractRegexFields_1", System.currentTimeMillis()); currentComponent = "tExtractRegexFields_1"; int tos_count_tExtractRegexFields_1 = 0; java.util.regex.Pattern pattern_tExtractRegexFields_1 = java.util.regex.Pattern .compile("http:\\/\\/bio2rdf.org\\/(.*)_vocabulary:Resource"); /** * [tExtractRegexFields_1 begin ] stop */ /** * [tExtractJSONFields_1 begin ] start */ ok_Hash.put("tExtractJSONFields_1", false); start_Hash.put("tExtractJSONFields_1", System.currentTimeMillis()); currentComponent = "tExtractJSONFields_1"; int tos_count_tExtractJSONFields_1 = 0; int nb_line_tExtractJSONFields_1 = 0; class ConvertJSONString_tExtractJSONFields_1 { final static int Brace = 0; // { final static int Bracket = 1; // [ private int barceType = -1; private String originalJsonString = ""; private String originalLoopString = ""; private String jsonString4XML = null; private String loopString4XML = null; private String additionRoot = null; public void barceType() { for (int c = 0; c < originalJsonString.length(); ++c) { if (originalJsonString.charAt(c) == '{') { barceType = Brace; break; } else if (originalJsonString.charAt(c) == '[') { barceType = Bracket; break; } } } public void setJsonString(String originalJsonString) { this.originalJsonString = originalJsonString; } public void setLoopString(String originalLoopString) { this.originalLoopString = originalLoopString; } public String getJsonString4XML() { return jsonString4XML; } public String getLoopString4XML() { if (loopString4XML.length() > 1 && loopString4XML.endsWith("/")) { loopString4XML = loopString4XML.substring(0, loopString4XML.length() - 1); } return loopString4XML; } public void setAdditionRoot(String additionRoot) { this.additionRoot = additionRoot; } public String getAdditionRoot() { return additionRoot; } public void generate() { barceType(); jsonString4XML = originalJsonString; loopString4XML = originalLoopString; if (Brace == barceType) { if (isNeedAddRoot(originalJsonString)) { jsonString4XML = "{ \"root\": " + originalJsonString + " }"; loopString4XML = "root" + originalLoopString; setAdditionRoot("root"); } } else if (Bracket == barceType) { jsonString4XML = "{ \"root\" : { \"object\": " + originalJsonString + " } }"; loopString4XML = "root/object" + originalLoopString; setAdditionRoot("object"); } } public boolean isNeedAddRoot(String originalJsonString) { boolean isNeedAddRoot = false; net.sf.json.JSONObject jso = net.sf.json.JSONObject.fromObject(originalJsonString); String jsonKey = ""; Object firstObject = null; if (jso.names().size() == 1) { jsonKey = jso.names().get(0).toString(); firstObject = jso.get(jsonKey); } if (jso.size() > 1 || (firstObject != null && firstObject instanceof net.sf.json.JSONArray && ((net.sf.json.JSONArray) firstObject).size() > 1)) { isNeedAddRoot = true; } return isNeedAddRoot; } } ConvertJSONString_tExtractJSONFields_1 cjs_tExtractJSONFields_1 = new ConvertJSONString_tExtractJSONFields_1(); de.odysseus.staxon.json.JsonXMLConfig config_tExtractJSONFields_1 = new de.odysseus.staxon.json.JsonXMLConfigBuilder() .multiplePI(false).build(); de.odysseus.staxon.json.JsonXMLInputFactory jsonXMLInputFactory_tExtractJSONFields_1 = new de.odysseus.staxon.json.JsonXMLInputFactory( config_tExtractJSONFields_1); javax.xml.stream.XMLOutputFactory xmlOutputFactory_tExtractJSONFields_1 = javax.xml.stream.XMLOutputFactory .newInstance(); boolean isGetWholeJson_tExtractJSONFields_1 = false; class OriginalJSONString_tExtractJSONFields_1 { } OriginalJSONString_tExtractJSONFields_1 originalJSONString_tExtractJSONFields_1 = new OriginalJSONString_tExtractJSONFields_1(); class XML_API_tExtractJSONFields_1 { public boolean isDefNull(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null && node instanceof org.dom4j.Element) { org.dom4j.Attribute attri = ((org.dom4j.Element) node).attribute("nil"); if (attri != null && ("true").equals(attri.getText())) { return true; } } return false; } public boolean isMissing(org.dom4j.Node node) throws javax.xml.transform.TransformerException { return node == null ? true : false; } public boolean isEmpty(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null) { return node.getText().length() == 0; } return false; } } String jsonStr_tExtractJSONFields_1 = ""; String xmlStr_tExtractJSONFields_1 = ""; XML_API_tExtractJSONFields_1 xml_api_tExtractJSONFields_1 = new XML_API_tExtractJSONFields_1(); /** * [tExtractJSONFields_1 begin ] stop */ /** * [tHttpRequest_1 begin ] start */ ok_Hash.put("tHttpRequest_1", false); start_Hash.put("tHttpRequest_1", System.currentTimeMillis()); currentComponent = "tHttpRequest_1"; int tos_count_tHttpRequest_1 = 0; /** * [tHttpRequest_1 begin ] stop */ /** * [tHttpRequest_1 main ] start */ currentComponent = "tHttpRequest_1"; java.net.URL url_tHttpRequest_1 = new java.net.URL("http://" + context.endpoint_namespace + ".bio2rdf.org/sparql?default-graph-uri=&query=PREFIX+void%3A+%3Chttp%3A%2F%2Frdfs.org%2Fns%2Fvoid%23%3E%0D%0APREFIX+ds%3A+%3Chttp%3A%2F%2Fbio2rdf.org%2Fbio2rdf.dataset_vocabulary%3A%3E%0D%0A%0D%0ASELECT+*%0D%0A+%7B+%5B%5D+void%3Asubset+%5B%0D%0A+++++++a+ds%3ADataset-Type-Count%3B%0D%0A+++++++void%3Aclass+%3Flink%3B%0D%0A+++++++void%3AdistinctEntities+%3FdistinctCount%3B%0D%0A+++%5D%0D%0A+++FILTER+regex%28str%28%3Flink%29%2C+%27.*bio2rdf.org%5C%5C%2F.*_vocabulary%3AResource%27%2C+%27i%27%29%0D%0A+%7D&format=application%2Fsparql-results%2Bjson&timeout=0&debug=on"); java.net.HttpURLConnection urlConn_tHttpRequest_1 = (java.net.HttpURLConnection) url_tHttpRequest_1 .openConnection(); urlConn_tHttpRequest_1.setRequestMethod("GET"); urlConn_tHttpRequest_1.setDoOutput(true); urlConn_tHttpRequest_1.setDoInput(true); urlConn_tHttpRequest_1.setUseCaches(false); urlConn_tHttpRequest_1.connect(); byte[] buffer_tHttpRequest_1 = new byte[1024]; int bos_buffer_tHttpRequest_1 = 0; StringBuilder sb_tHttpRequest_1 = new StringBuilder(); if (java.net.HttpURLConnection.HTTP_OK == (urlConn_tHttpRequest_1.getResponseCode())) { java.io.InputStream bis_tHttpRequest_1 = new java.io.BufferedInputStream( urlConn_tHttpRequest_1.getInputStream()); while ((bos_buffer_tHttpRequest_1 = bis_tHttpRequest_1.read(buffer_tHttpRequest_1)) != -1) { sb_tHttpRequest_1.append(new String(buffer_tHttpRequest_1, 0, bos_buffer_tHttpRequest_1)); } bis_tHttpRequest_1.close(); } else { System.err.println(urlConn_tHttpRequest_1.getResponseCode() + " " + urlConn_tHttpRequest_1.getResponseMessage()); } row6.ResponseContent = sb_tHttpRequest_1.toString(); urlConn_tHttpRequest_1.disconnect(); tos_count_tHttpRequest_1++; /** * [tHttpRequest_1 main ] stop */ /** * [tExtractJSONFields_1 main ] start */ currentComponent = "tExtractJSONFields_1"; if (row6.ResponseContent != null) {// C_01 jsonStr_tExtractJSONFields_1 = row6.ResponseContent.toString(); row7 = null; org.dom4j.io.SAXReader reader_tExtractJSONFields_1 = new org.dom4j.io.SAXReader(); org.dom4j.Document doc_tExtractJSONFields_1 = null; java.util.HashMap xmlNameSpaceMap_tExtractJSONFields_1 = new java.util.HashMap<String, String>(); org.dom4j.XPath x_tExtractJSONFields_1 = null; java.util.List<org.dom4j.tree.AbstractNode> nodeList_tExtractJSONFields_1 = null; boolean isStructError_tExtractJSONFields_1 = true; String loopQuery_tExtractJSONFields_1 = "/results/bindings"; String oraginalJsonStr_tExtractJSONFields_1 = jsonStr_tExtractJSONFields_1; cjs_tExtractJSONFields_1.setJsonString(jsonStr_tExtractJSONFields_1); cjs_tExtractJSONFields_1.setLoopString(loopQuery_tExtractJSONFields_1); java.io.ByteArrayInputStream bais_tExtractJSONFields_1 = null; java.io.ByteArrayOutputStream baos_tExtractJSONFields_1 = new java.io.ByteArrayOutputStream(); try { cjs_tExtractJSONFields_1.generate(); jsonStr_tExtractJSONFields_1 = cjs_tExtractJSONFields_1.getJsonString4XML(); loopQuery_tExtractJSONFields_1 = cjs_tExtractJSONFields_1.getLoopString4XML(); bais_tExtractJSONFields_1 = new ByteArrayInputStream( jsonStr_tExtractJSONFields_1.getBytes("UTF-8")); javax.xml.stream.XMLEventReader xmlEventReader_tExtractJSONFields_1 = jsonXMLInputFactory_tExtractJSONFields_1 .createXMLEventReader(bais_tExtractJSONFields_1); javax.xml.stream.XMLEventWriter xmLEventWriter_tExtractJSONFields_1 = xmlOutputFactory_tExtractJSONFields_1 .createXMLEventWriter(baos_tExtractJSONFields_1, "UTF-8"); xmLEventWriter_tExtractJSONFields_1.add(xmlEventReader_tExtractJSONFields_1); // convert json string to xml xmlStr_tExtractJSONFields_1 = baos_tExtractJSONFields_1.toString(); xmLEventWriter_tExtractJSONFields_1.close(); xmlEventReader_tExtractJSONFields_1.close(); doc_tExtractJSONFields_1 = reader_tExtractJSONFields_1 .read(new java.io.StringReader(xmlStr_tExtractJSONFields_1)); x_tExtractJSONFields_1 = doc_tExtractJSONFields_1 .createXPath(loopQuery_tExtractJSONFields_1); x_tExtractJSONFields_1.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_1); nodeList_tExtractJSONFields_1 = (java.util.List<org.dom4j.tree.AbstractNode>) x_tExtractJSONFields_1 .selectNodes(doc_tExtractJSONFields_1); isStructError_tExtractJSONFields_1 = false; } catch (java.lang.Exception ex_tExtractJSONFields_1) { System.err.println(ex_tExtractJSONFields_1.getMessage()); } finally { baos_tExtractJSONFields_1.close(); if (bais_tExtractJSONFields_1 != null) { bais_tExtractJSONFields_1.close(); } } org.dom4j.Node node_tExtractJSONFields_1 = null; String str_tExtractJSONFields_1 = ""; for (int i_tExtractJSONFields_1 = 0; isStructError_tExtractJSONFields_1 || (nodeList_tExtractJSONFields_1 != null && i_tExtractJSONFields_1 < nodeList_tExtractJSONFields_1 .size()); i_tExtractJSONFields_1++) { if (!isStructError_tExtractJSONFields_1) { row7 = null; row7 = new row7Struct(); org.dom4j.tree.AbstractNode temp_tExtractJSONFields_1 = nodeList_tExtractJSONFields_1 .get(i_tExtractJSONFields_1); nb_line_tExtractJSONFields_1++; try { org.dom4j.XPath xTmp0_tExtractJSONFields_1 = temp_tExtractJSONFields_1 .createXPath("link/value"); xTmp0_tExtractJSONFields_1.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_1); Object obj0_tExtractJSONFields_1 = xTmp0_tExtractJSONFields_1 .evaluate(temp_tExtractJSONFields_1); if (obj0_tExtractJSONFields_1 instanceof String || obj0_tExtractJSONFields_1 instanceof Number) { node_tExtractJSONFields_1 = temp_tExtractJSONFields_1; str_tExtractJSONFields_1 = String.valueOf(obj0_tExtractJSONFields_1); } else { node_tExtractJSONFields_1 = xTmp0_tExtractJSONFields_1 .selectSingleNode(temp_tExtractJSONFields_1); str_tExtractJSONFields_1 = xTmp0_tExtractJSONFields_1 .valueOf(temp_tExtractJSONFields_1); } if (xml_api_tExtractJSONFields_1.isDefNull(node_tExtractJSONFields_1)) { row7.link = null; } else if (xml_api_tExtractJSONFields_1.isEmpty(node_tExtractJSONFields_1)) { row7.link = ""; } else if (xml_api_tExtractJSONFields_1.isMissing(node_tExtractJSONFields_1)) { row7.link = null; } else { row7.link = str_tExtractJSONFields_1; } org.dom4j.XPath xTmp1_tExtractJSONFields_1 = temp_tExtractJSONFields_1 .createXPath("distinctCount/value"); xTmp1_tExtractJSONFields_1.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_1); Object obj1_tExtractJSONFields_1 = xTmp1_tExtractJSONFields_1 .evaluate(temp_tExtractJSONFields_1); if (obj1_tExtractJSONFields_1 instanceof String || obj1_tExtractJSONFields_1 instanceof Number) { node_tExtractJSONFields_1 = temp_tExtractJSONFields_1; str_tExtractJSONFields_1 = String.valueOf(obj1_tExtractJSONFields_1); } else { node_tExtractJSONFields_1 = xTmp1_tExtractJSONFields_1 .selectSingleNode(temp_tExtractJSONFields_1); str_tExtractJSONFields_1 = xTmp1_tExtractJSONFields_1 .valueOf(temp_tExtractJSONFields_1); } if (xml_api_tExtractJSONFields_1.isDefNull(node_tExtractJSONFields_1)) { row7.count = null; } else if (xml_api_tExtractJSONFields_1.isEmpty(node_tExtractJSONFields_1)) { row7.count = ""; } else if (xml_api_tExtractJSONFields_1.isMissing(node_tExtractJSONFields_1)) { row7.count = null; } else { row7.count = str_tExtractJSONFields_1; } } catch (java.lang.Exception ex_tExtractJSONFields_1) { System.err.println(ex_tExtractJSONFields_1.getMessage()); row7 = null; } } isStructError_tExtractJSONFields_1 = false; tos_count_tExtractJSONFields_1++; /** * [tExtractJSONFields_1 main ] stop */ // Start of branch "row7" if (row7 != null) { /** * [tExtractRegexFields_1 main ] start */ currentComponent = "tExtractRegexFields_1"; row8 = null; if (row7.link != null) {// C_01 java.util.regex.Matcher matcher_tExtractRegexFields_1 = pattern_tExtractRegexFields_1 .matcher(row7.link); int groupCount_tExtractRegexFields_1 = matcher_tExtractRegexFields_1.groupCount(); while (matcher_tExtractRegexFields_1.find()) { try { row8 = new row8Struct(); row8.count = row7.count; String temp_tExtractRegexFields_1 = null; row8.linkNamespace = groupCount_tExtractRegexFields_1 <= 0 ? "" : matcher_tExtractRegexFields_1.group(1); } catch (java.lang.Exception ex_tExtractRegexFields_1) { throw (ex_tExtractRegexFields_1); } tos_count_tExtractRegexFields_1++; /** * [tExtractRegexFields_1 main ] stop */ // Start of branch "row8" if (row8 != null) { /** * [tJavaRow_2 main ] start */ currentComponent = "tJavaRow_2"; // Code gnr selon le schmas d'entre // et de sortie row9.link = row8.linkNamespace; row9.stat = row8.count; nb_line_tJavaRow_2++; tos_count_tJavaRow_2++; /** * [tJavaRow_2 main ] stop */ /** * [tFilterRow_1 main ] start */ currentComponent = "tFilterRow_1"; row10 = null; Operator_tFilterRow_1 ope_tFilterRow_1 = new Operator_tFilterRow_1("&&"); ope_tFilterRow_1.matches((// code sample : use // row9 to define // the condition. // row9.columnName1.equals("foo") // ||!(row9.columnName2.equals("bar")) // replace the following // expression by your // own filter condition !row9.link.contains(".") && !row9.link.contains(" ") && !row9.link.equals(context.endpoint_namespace)), "advanced condition failed"); if (ope_tFilterRow_1.getMatchFlag()) { if (row10 == null) { row10 = new row10Struct(); } row10.link = row9.link; row10.stat = row9.stat; nb_line_ok_tFilterRow_1++; } else { nb_line_reject_tFilterRow_1++; } nb_line_tFilterRow_1++; tos_count_tFilterRow_1++; /** * [tFilterRow_1 main ] stop */ // Start of branch "row10" if (row10 != null) { /** * [tLogRow_2 main ] start */ currentComponent = "tLogRow_2"; row5 = row10; tos_count_tLogRow_2++; /** * [tLogRow_2 main ] stop */ /** * [tBufferOutput_1 main ] start */ currentComponent = "tBufferOutput_1"; String[] row_tBufferOutput_1 = new String[] { "", "", }; if (row5.link != null) { row_tBufferOutput_1[0] = row5.link; } else { row_tBufferOutput_1[0] = null; } if (row5.stat != null) { row_tBufferOutput_1[1] = row5.stat; } else { row_tBufferOutput_1[1] = null; } globalBuffer.add(row_tBufferOutput_1); tos_count_tBufferOutput_1++; /** * [tBufferOutput_1 main ] stop */ } // End of branch "row10" } // End of branch "row8" // end for } } // C_01 } // End of branch "row7" // end for } } // C_01 /** * [tHttpRequest_1 end ] start */ currentComponent = "tHttpRequest_1"; ok_Hash.put("tHttpRequest_1", true); end_Hash.put("tHttpRequest_1", System.currentTimeMillis()); /** * [tHttpRequest_1 end ] stop */ /** * [tExtractJSONFields_1 end ] start */ currentComponent = "tExtractJSONFields_1"; globalMap.put("tExtractJSONFields_1_NB_LINE", nb_line_tExtractJSONFields_1); ok_Hash.put("tExtractJSONFields_1", true); end_Hash.put("tExtractJSONFields_1", System.currentTimeMillis()); /** * [tExtractJSONFields_1 end ] stop */ /** * [tExtractRegexFields_1 end ] start */ currentComponent = "tExtractRegexFields_1"; ok_Hash.put("tExtractRegexFields_1", true); end_Hash.put("tExtractRegexFields_1", System.currentTimeMillis()); /** * [tExtractRegexFields_1 end ] stop */ /** * [tJavaRow_2 end ] start */ currentComponent = "tJavaRow_2"; globalMap.put("tJavaRow_2_NB_LINE", nb_line_tJavaRow_2); ok_Hash.put("tJavaRow_2", true); end_Hash.put("tJavaRow_2", System.currentTimeMillis()); /** * [tJavaRow_2 end ] stop */ /** * [tFilterRow_1 end ] start */ currentComponent = "tFilterRow_1"; globalMap.put("tFilterRow_1_NB_LINE", nb_line_tFilterRow_1); globalMap.put("tFilterRow_1_NB_LINE_OK", nb_line_ok_tFilterRow_1); globalMap.put("tFilterRow_1_NB_LINE_REJECT", nb_line_reject_tFilterRow_1); ok_Hash.put("tFilterRow_1", true); end_Hash.put("tFilterRow_1", System.currentTimeMillis()); /** * [tFilterRow_1 end ] stop */ /** * [tLogRow_2 end ] start */ currentComponent = "tLogRow_2"; ok_Hash.put("tLogRow_2", true); end_Hash.put("tLogRow_2", System.currentTimeMillis()); /** * [tLogRow_2 end ] stop */ /** * [tBufferOutput_1 end ] start */ currentComponent = "tBufferOutput_1"; ok_Hash.put("tBufferOutput_1", true); end_Hash.put("tBufferOutput_1", System.currentTimeMillis()); /** * [tBufferOutput_1 end ] stop */ } // end the resume } catch (java.lang.Exception e) { TalendException te = new TalendException(e, currentComponent, globalMap); throw te; } catch (java.lang.Error error) { throw error; } finally { try { /** * [tHttpRequest_1 finally ] start */ currentComponent = "tHttpRequest_1"; /** * [tHttpRequest_1 finally ] stop */ /** * [tExtractJSONFields_1 finally ] start */ currentComponent = "tExtractJSONFields_1"; /** * [tExtractJSONFields_1 finally ] stop */ /** * [tExtractRegexFields_1 finally ] start */ currentComponent = "tExtractRegexFields_1"; /** * [tExtractRegexFields_1 finally ] stop */ /** * [tJavaRow_2 finally ] start */ currentComponent = "tJavaRow_2"; /** * [tJavaRow_2 finally ] stop */ /** * [tFilterRow_1 finally ] start */ currentComponent = "tFilterRow_1"; /** * [tFilterRow_1 finally ] stop */ /** * [tLogRow_2 finally ] start */ currentComponent = "tLogRow_2"; /** * [tLogRow_2 finally ] stop */ /** * [tBufferOutput_1 finally ] start */ currentComponent = "tBufferOutput_1"; /** * [tBufferOutput_1 finally ] stop */ } catch (java.lang.Exception e) { // ignore } catch (java.lang.Error error) { // ignore } resourceMap = null; } globalMap.put("tHttpRequest_1_SUBPROCESS_STATE", 1); }
From source file:bio2rdf.upload_all_datasets_0_1.upload_all_datasets.java
License:Apache License
public void tFileList_3Process(final java.util.Map<String, Object> globalMap) throws TalendException { globalMap.put("tFileList_3_SUBPROCESS_STATE", 0); final boolean execStat = this.execStat; String iterateId = ""; int iterateLoop = 0; String currentComponent = ""; java.util.Map<String, Object> resourceMap = new java.util.HashMap<String, Object>(); try {/*from w w w . j a v a 2s . co m*/ String currentMethodName = new java.lang.Exception().getStackTrace()[0].getMethodName(); boolean resumeIt = currentMethodName.equals(resumeEntryMethodName); if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start // the // resume globalResumeTicket = true; row6Struct row6 = new row6Struct(); row4Struct row4 = new row4Struct(); row7Struct row7 = new row7Struct(); /** * [tFileList_3 begin ] start */ int NB_ITERATE_tHttpRequest_4 = 0; // for statistics ok_Hash.put("tFileList_3", false); start_Hash.put("tFileList_3", System.currentTimeMillis()); currentComponent = "tFileList_3"; int tos_count_tFileList_3 = 0; String directory_tFileList_3 = context.workspace; final java.util.List<String> maskList_tFileList_3 = new java.util.ArrayList<String>(); final java.util.List<java.util.regex.Pattern> patternList_tFileList_3 = new java.util.ArrayList<java.util.regex.Pattern>(); maskList_tFileList_3.add("datahub_import_*.json"); for (final String filemask_tFileList_3 : maskList_tFileList_3) { String filemask_compile_tFileList_3 = filemask_tFileList_3; filemask_compile_tFileList_3 = org.apache.oro.text.GlobCompiler.globToPerl5( filemask_tFileList_3.toCharArray(), org.apache.oro.text.GlobCompiler.DEFAULT_MASK); java.util.regex.Pattern fileNamePattern_tFileList_3 = java.util.regex.Pattern .compile(filemask_compile_tFileList_3); patternList_tFileList_3.add(fileNamePattern_tFileList_3); } int NB_FILEtFileList_3 = 0; final boolean case_sensitive_tFileList_3 = true; final java.util.List<java.io.File> list_tFileList_3 = new java.util.ArrayList<java.io.File>(); final java.util.List<String> filePath_tFileList_3 = new java.util.ArrayList<String>(); java.io.File file_tFileList_3 = new java.io.File(directory_tFileList_3); file_tFileList_3.listFiles(new java.io.FilenameFilter() { public boolean accept(java.io.File dir, String name) { java.io.File file = new java.io.File(dir, name); if (!file.isDirectory()) { String fileName_tFileList_3 = file.getName(); for (final java.util.regex.Pattern fileNamePattern_tFileList_3 : patternList_tFileList_3) { if (fileNamePattern_tFileList_3.matcher(fileName_tFileList_3).matches()) { if (!filePath_tFileList_3.contains(file.getAbsolutePath())) { list_tFileList_3.add(file); filePath_tFileList_3.add(file.getAbsolutePath()); } } } } return true; } }); java.util.Collections.sort(list_tFileList_3); for (int i_tFileList_3 = 0; i_tFileList_3 < list_tFileList_3.size(); i_tFileList_3++) { java.io.File files_tFileList_3 = list_tFileList_3.get(i_tFileList_3); String fileName_tFileList_3 = files_tFileList_3.getName(); String currentFileName_tFileList_3 = files_tFileList_3.getName(); String currentFilePath_tFileList_3 = files_tFileList_3.getAbsolutePath(); String currentFileDirectory_tFileList_3 = files_tFileList_3.getParent(); String currentFileExtension_tFileList_3 = null; if (files_tFileList_3.getName().contains(".") && files_tFileList_3.isFile()) { currentFileExtension_tFileList_3 = files_tFileList_3.getName() .substring(files_tFileList_3.getName().lastIndexOf(".") + 1); } else { currentFileExtension_tFileList_3 = ""; } NB_FILEtFileList_3++; globalMap.put("tFileList_3_CURRENT_FILE", currentFileName_tFileList_3); globalMap.put("tFileList_3_CURRENT_FILEPATH", currentFilePath_tFileList_3); globalMap.put("tFileList_3_CURRENT_FILEDIRECTORY", currentFileDirectory_tFileList_3); globalMap.put("tFileList_3_CURRENT_FILEEXTENSION", currentFileExtension_tFileList_3); globalMap.put("tFileList_3_NB_FILE", NB_FILEtFileList_3); /** * [tFileList_3 begin ] stop */ /** * [tFileList_3 main ] start */ currentComponent = "tFileList_3"; tos_count_tFileList_3++; /** * [tFileList_3 main ] stop */ NB_ITERATE_tHttpRequest_4++; iterateLoop++; /** * [tLogRow_4 begin ] start */ ok_Hash.put("tLogRow_4", false); start_Hash.put("tLogRow_4", System.currentTimeMillis()); currentComponent = "tLogRow_4"; int tos_count_tLogRow_4 = 0; // ///////////////////// final String OUTPUT_FIELD_SEPARATOR_tLogRow_4 = "|"; java.io.PrintStream consoleOut_tLogRow_4 = null; StringBuilder strBuffer_tLogRow_4 = null; int nb_line_tLogRow_4 = 0; // ///////////////////// /** * [tLogRow_4 begin ] stop */ /** * [tExtractJSONFields_3 begin ] start */ ok_Hash.put("tExtractJSONFields_3", false); start_Hash.put("tExtractJSONFields_3", System.currentTimeMillis()); currentComponent = "tExtractJSONFields_3"; int tos_count_tExtractJSONFields_3 = 0; int nb_line_tExtractJSONFields_3 = 0; class ConvertJSONString_tExtractJSONFields_3 { final static int Brace = 0; // { final static int Bracket = 1; // [ private int barceType = -1; private String originalJsonString = ""; private String originalLoopString = ""; private String jsonString4XML = null; private String loopString4XML = null; private String additionRoot = null; public void barceType() { for (int c = 0; c < originalJsonString.length(); ++c) { if (originalJsonString.charAt(c) == '{') { barceType = Brace; break; } else if (originalJsonString.charAt(c) == '[') { barceType = Bracket; break; } } } public void setJsonString(String originalJsonString) { this.originalJsonString = originalJsonString; } public void setLoopString(String originalLoopString) { this.originalLoopString = originalLoopString; } public String getJsonString4XML() { return jsonString4XML; } public String getLoopString4XML() { if (loopString4XML.length() > 1 && loopString4XML.endsWith("/")) { loopString4XML = loopString4XML.substring(0, loopString4XML.length() - 1); } return loopString4XML; } public void setAdditionRoot(String additionRoot) { this.additionRoot = additionRoot; } public String getAdditionRoot() { return additionRoot; } public void generate() { barceType(); jsonString4XML = originalJsonString; loopString4XML = originalLoopString; if (Brace == barceType) { if (isNeedAddRoot(originalJsonString)) { jsonString4XML = "{ \"root\": " + originalJsonString + " }"; loopString4XML = "root" + originalLoopString; setAdditionRoot("root"); } } else if (Bracket == barceType) { jsonString4XML = "{ \"root\" : { \"object\": " + originalJsonString + " } }"; loopString4XML = "root/object" + originalLoopString; setAdditionRoot("object"); } } public boolean isNeedAddRoot(String originalJsonString) { boolean isNeedAddRoot = false; net.sf.json.JSONObject jso = net.sf.json.JSONObject.fromObject(originalJsonString); String jsonKey = ""; Object firstObject = null; if (jso.names().size() == 1) { jsonKey = jso.names().get(0).toString(); firstObject = jso.get(jsonKey); } if (jso.size() > 1 || (firstObject != null && firstObject instanceof net.sf.json.JSONArray && ((net.sf.json.JSONArray) firstObject).size() > 1)) { isNeedAddRoot = true; } return isNeedAddRoot; } } ConvertJSONString_tExtractJSONFields_3 cjs_tExtractJSONFields_3 = new ConvertJSONString_tExtractJSONFields_3(); de.odysseus.staxon.json.JsonXMLConfig config_tExtractJSONFields_3 = new de.odysseus.staxon.json.JsonXMLConfigBuilder() .multiplePI(false).build(); de.odysseus.staxon.json.JsonXMLInputFactory jsonXMLInputFactory_tExtractJSONFields_3 = new de.odysseus.staxon.json.JsonXMLInputFactory( config_tExtractJSONFields_3); javax.xml.stream.XMLOutputFactory xmlOutputFactory_tExtractJSONFields_3 = javax.xml.stream.XMLOutputFactory .newInstance(); boolean isGetWholeJson_tExtractJSONFields_3 = false; class OriginalJSONString_tExtractJSONFields_3 { } OriginalJSONString_tExtractJSONFields_3 originalJSONString_tExtractJSONFields_3 = new OriginalJSONString_tExtractJSONFields_3(); class XML_API_tExtractJSONFields_3 { public boolean isDefNull(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null && node instanceof org.dom4j.Element) { org.dom4j.Attribute attri = ((org.dom4j.Element) node).attribute("nil"); if (attri != null && ("true").equals(attri.getText())) { return true; } } return false; } public boolean isMissing(org.dom4j.Node node) throws javax.xml.transform.TransformerException { return node == null ? true : false; } public boolean isEmpty(org.dom4j.Node node) throws javax.xml.transform.TransformerException { if (node != null) { return node.getText().length() == 0; } return false; } } String jsonStr_tExtractJSONFields_3 = ""; String xmlStr_tExtractJSONFields_3 = ""; XML_API_tExtractJSONFields_3 xml_api_tExtractJSONFields_3 = new XML_API_tExtractJSONFields_3(); /** * [tExtractJSONFields_3 begin ] stop */ /** * [tReplicate_1 begin ] start */ ok_Hash.put("tReplicate_1", false); start_Hash.put("tReplicate_1", System.currentTimeMillis()); currentComponent = "tReplicate_1"; int tos_count_tReplicate_1 = 0; /** * [tReplicate_1 begin ] stop */ /** * [tHttpRequest_4 begin ] start */ ok_Hash.put("tHttpRequest_4", false); start_Hash.put("tHttpRequest_4", System.currentTimeMillis()); currentComponent = "tHttpRequest_4"; int tos_count_tHttpRequest_4 = 0; /** * [tHttpRequest_4 begin ] stop */ /** * [tHttpRequest_4 main ] start */ currentComponent = "tHttpRequest_4"; java.net.URL url_tHttpRequest_4 = new java.net.URL( "http://datahub.io/api/action/package_update"); java.net.HttpURLConnection urlConn_tHttpRequest_4 = (java.net.HttpURLConnection) url_tHttpRequest_4 .openConnection(); urlConn_tHttpRequest_4.setRequestMethod("POST"); urlConn_tHttpRequest_4.setDoOutput(true); urlConn_tHttpRequest_4.setDoInput(true); urlConn_tHttpRequest_4.setUseCaches(false); urlConn_tHttpRequest_4.setRequestProperty("Authorization", context.authorizationKey); urlConn_tHttpRequest_4.connect(); byte[] buffer_tHttpRequest_4 = new byte[1024]; int bos_buffer_tHttpRequest_4 = 0; StringBuilder sb_tHttpRequest_4 = new StringBuilder(); java.io.InputStream bisParam_tHttpRequest_4 = new java.io.BufferedInputStream( new java.io.FileInputStream(((String) globalMap.get("tFileList_3_CURRENT_FILEPATH")))); java.io.OutputStream bosParam_tHttpRequest_4 = new java.io.BufferedOutputStream( urlConn_tHttpRequest_4.getOutputStream()); while ((bos_buffer_tHttpRequest_4 = bisParam_tHttpRequest_4 .read(buffer_tHttpRequest_4)) != -1) { bosParam_tHttpRequest_4.write(buffer_tHttpRequest_4, 0, bos_buffer_tHttpRequest_4); } bosParam_tHttpRequest_4.flush(); bosParam_tHttpRequest_4.close(); bisParam_tHttpRequest_4.close(); if (java.net.HttpURLConnection.HTTP_OK == (urlConn_tHttpRequest_4.getResponseCode())) { java.io.InputStream bis_tHttpRequest_4 = new java.io.BufferedInputStream( urlConn_tHttpRequest_4.getInputStream()); while ((bos_buffer_tHttpRequest_4 = bis_tHttpRequest_4.read(buffer_tHttpRequest_4)) != -1) { sb_tHttpRequest_4 .append(new String(buffer_tHttpRequest_4, 0, bos_buffer_tHttpRequest_4)); } bis_tHttpRequest_4.close(); } else { System.err.println(urlConn_tHttpRequest_4.getResponseCode() + " " + urlConn_tHttpRequest_4.getResponseMessage()); } row6.ResponseContent = sb_tHttpRequest_4.toString(); urlConn_tHttpRequest_4.disconnect(); tos_count_tHttpRequest_4++; /** * [tHttpRequest_4 main ] stop */ /** * [tReplicate_1 main ] start */ currentComponent = "tReplicate_1"; row4 = new row4Struct(); row4.ResponseContent = row6.ResponseContent; tos_count_tReplicate_1++; /** * [tReplicate_1 main ] stop */ /** * [tExtractJSONFields_3 main ] start */ currentComponent = "tExtractJSONFields_3"; if (row4.ResponseContent != null) {// C_01 jsonStr_tExtractJSONFields_3 = row4.ResponseContent.toString(); row7 = null; org.dom4j.io.SAXReader reader_tExtractJSONFields_3 = new org.dom4j.io.SAXReader(); org.dom4j.Document doc_tExtractJSONFields_3 = null; java.util.HashMap xmlNameSpaceMap_tExtractJSONFields_3 = new java.util.HashMap<String, String>(); org.dom4j.XPath x_tExtractJSONFields_3 = null; java.util.List<org.dom4j.tree.AbstractNode> nodeList_tExtractJSONFields_3 = null; boolean isStructError_tExtractJSONFields_3 = true; String loopQuery_tExtractJSONFields_3 = "/result"; String oraginalJsonStr_tExtractJSONFields_3 = jsonStr_tExtractJSONFields_3; cjs_tExtractJSONFields_3.setJsonString(jsonStr_tExtractJSONFields_3); cjs_tExtractJSONFields_3.setLoopString(loopQuery_tExtractJSONFields_3); java.io.ByteArrayInputStream bais_tExtractJSONFields_3 = null; java.io.ByteArrayOutputStream baos_tExtractJSONFields_3 = new java.io.ByteArrayOutputStream(); try { cjs_tExtractJSONFields_3.generate(); jsonStr_tExtractJSONFields_3 = cjs_tExtractJSONFields_3.getJsonString4XML(); loopQuery_tExtractJSONFields_3 = cjs_tExtractJSONFields_3.getLoopString4XML(); bais_tExtractJSONFields_3 = new ByteArrayInputStream( jsonStr_tExtractJSONFields_3.getBytes("UTF-8")); javax.xml.stream.XMLEventReader xmlEventReader_tExtractJSONFields_3 = jsonXMLInputFactory_tExtractJSONFields_3 .createXMLEventReader(bais_tExtractJSONFields_3); javax.xml.stream.XMLEventWriter xmLEventWriter_tExtractJSONFields_3 = xmlOutputFactory_tExtractJSONFields_3 .createXMLEventWriter(baos_tExtractJSONFields_3, "UTF-8"); xmLEventWriter_tExtractJSONFields_3.add(xmlEventReader_tExtractJSONFields_3); // convert json string to xml xmlStr_tExtractJSONFields_3 = baos_tExtractJSONFields_3.toString(); xmLEventWriter_tExtractJSONFields_3.close(); xmlEventReader_tExtractJSONFields_3.close(); doc_tExtractJSONFields_3 = reader_tExtractJSONFields_3 .read(new java.io.StringReader(xmlStr_tExtractJSONFields_3)); x_tExtractJSONFields_3 = doc_tExtractJSONFields_3 .createXPath(loopQuery_tExtractJSONFields_3); x_tExtractJSONFields_3.setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_3); nodeList_tExtractJSONFields_3 = (java.util.List<org.dom4j.tree.AbstractNode>) x_tExtractJSONFields_3 .selectNodes(doc_tExtractJSONFields_3); isStructError_tExtractJSONFields_3 = false; } catch (java.lang.Exception ex_tExtractJSONFields_3) { System.err.println(ex_tExtractJSONFields_3.getMessage()); } finally { baos_tExtractJSONFields_3.close(); if (bais_tExtractJSONFields_3 != null) { bais_tExtractJSONFields_3.close(); } } org.dom4j.Node node_tExtractJSONFields_3 = null; String str_tExtractJSONFields_3 = ""; for (int i_tExtractJSONFields_3 = 0; isStructError_tExtractJSONFields_3 || (nodeList_tExtractJSONFields_3 != null && i_tExtractJSONFields_3 < nodeList_tExtractJSONFields_3 .size()); i_tExtractJSONFields_3++) { if (!isStructError_tExtractJSONFields_3) { row7 = null; row7 = new row7Struct(); org.dom4j.tree.AbstractNode temp_tExtractJSONFields_3 = nodeList_tExtractJSONFields_3 .get(i_tExtractJSONFields_3); nb_line_tExtractJSONFields_3++; try { org.dom4j.XPath xTmp0_tExtractJSONFields_3 = temp_tExtractJSONFields_3 .createXPath("name"); xTmp0_tExtractJSONFields_3 .setNamespaceURIs(xmlNameSpaceMap_tExtractJSONFields_3); Object obj0_tExtractJSONFields_3 = xTmp0_tExtractJSONFields_3 .evaluate(temp_tExtractJSONFields_3); if (obj0_tExtractJSONFields_3 instanceof String || obj0_tExtractJSONFields_3 instanceof Number) { node_tExtractJSONFields_3 = temp_tExtractJSONFields_3; str_tExtractJSONFields_3 = String.valueOf(obj0_tExtractJSONFields_3); } else { node_tExtractJSONFields_3 = xTmp0_tExtractJSONFields_3 .selectSingleNode(temp_tExtractJSONFields_3); str_tExtractJSONFields_3 = xTmp0_tExtractJSONFields_3 .valueOf(temp_tExtractJSONFields_3); } if (xml_api_tExtractJSONFields_3.isDefNull(node_tExtractJSONFields_3)) { row7.ResponseContent = null; } else if (xml_api_tExtractJSONFields_3.isEmpty(node_tExtractJSONFields_3)) { row7.ResponseContent = ""; } else if (xml_api_tExtractJSONFields_3.isMissing(node_tExtractJSONFields_3)) { row7.ResponseContent = null; } else { row7.ResponseContent = str_tExtractJSONFields_3; } } catch (java.lang.Exception ex_tExtractJSONFields_3) { System.err.println(ex_tExtractJSONFields_3.getMessage()); row7 = null; } } isStructError_tExtractJSONFields_3 = false; tos_count_tExtractJSONFields_3++; /** * [tExtractJSONFields_3 main ] stop */ // Start of branch "row7" if (row7 != null) { /** * [tLogRow_4 main ] start */ currentComponent = "tLogRow_4"; // ///////////////////// strBuffer_tLogRow_4 = new StringBuilder(); if (row7.ResponseContent != null) { // strBuffer_tLogRow_4.append(String.valueOf(row7.ResponseContent)); } // if (globalMap.get("tLogRow_CONSOLE") != null) { consoleOut_tLogRow_4 = (java.io.PrintStream) globalMap.get("tLogRow_CONSOLE"); } else { consoleOut_tLogRow_4 = new java.io.PrintStream( new java.io.BufferedOutputStream(System.out)); globalMap.put("tLogRow_CONSOLE", consoleOut_tLogRow_4); } consoleOut_tLogRow_4.println(strBuffer_tLogRow_4.toString()); consoleOut_tLogRow_4.flush(); nb_line_tLogRow_4++; // //// // //// // ///////////////////// tos_count_tLogRow_4++; /** * [tLogRow_4 main ] stop */ } // End of branch "row7" // end for } } // C_01 /** * [tHttpRequest_4 end ] start */ currentComponent = "tHttpRequest_4"; ok_Hash.put("tHttpRequest_4", true); end_Hash.put("tHttpRequest_4", System.currentTimeMillis()); /** * [tHttpRequest_4 end ] stop */ /** * [tReplicate_1 end ] start */ currentComponent = "tReplicate_1"; ok_Hash.put("tReplicate_1", true); end_Hash.put("tReplicate_1", System.currentTimeMillis()); /** * [tReplicate_1 end ] stop */ /** * [tExtractJSONFields_3 end ] start */ currentComponent = "tExtractJSONFields_3"; globalMap.put("tExtractJSONFields_1_NB_LINE", nb_line_tExtractJSONFields_3); ok_Hash.put("tExtractJSONFields_3", true); end_Hash.put("tExtractJSONFields_3", System.currentTimeMillis()); /** * [tExtractJSONFields_3 end ] stop */ /** * [tLogRow_4 end ] start */ currentComponent = "tLogRow_4"; // //// // //// globalMap.put("tLogRow_4_NB_LINE", nb_line_tLogRow_4); // ///////////////////// ok_Hash.put("tLogRow_4", true); end_Hash.put("tLogRow_4", System.currentTimeMillis()); /** * [tLogRow_4 end ] stop */ /** * [tFileList_3 end ] start */ currentComponent = "tFileList_3"; } globalMap.put("tFileList_3_NB_FILE", NB_FILEtFileList_3); ok_Hash.put("tFileList_3", true); end_Hash.put("tFileList_3", System.currentTimeMillis()); /** * [tFileList_3 end ] stop */ } // end the resume } catch (java.lang.Exception e) { TalendException te = new TalendException(e, currentComponent, globalMap); throw te; } catch (java.lang.Error error) { throw error; } finally { try { /** * [tFileList_3 finally ] start */ currentComponent = "tFileList_3"; /** * [tFileList_3 finally ] stop */ /** * [tHttpRequest_4 finally ] start */ currentComponent = "tHttpRequest_4"; /** * [tHttpRequest_4 finally ] stop */ /** * [tReplicate_1 finally ] start */ currentComponent = "tReplicate_1"; /** * [tReplicate_1 finally ] stop */ /** * [tExtractJSONFields_3 finally ] start */ currentComponent = "tExtractJSONFields_3"; /** * [tExtractJSONFields_3 finally ] stop */ /** * [tLogRow_4 finally ] start */ currentComponent = "tLogRow_4"; /** * [tLogRow_4 finally ] stop */ } catch (java.lang.Exception e) { // ignore } catch (java.lang.Error error) { // ignore } resourceMap = null; } globalMap.put("tFileList_3_SUBPROCESS_STATE", 1); }
From source file:ch.epfl.codimsd.qep.QEPFactory.java
License:Open Source License
/** * Build a hashtable containing operator opNode structures, according to what is defined * in the query execution plan./*from w w w . j a v a 2 s. co m*/ * * @param document dom4j document of the QEP. * @return the opnode hashtable. * * @throws QEPInitializationException */ private static Hashtable<String, OpNode> buildOpNodeTable(Document document) throws QEPInitializationException { Hashtable<String, OpNode> operatorList = new Hashtable<String, OpNode>(); /*List listMod = document.selectNodes( "//qep:Module" ); Element modElement = (Element)listMod; String[] stringType = modElement.attributeValue("type").split(","); int numberOfIterations = Integer.parseInt(modElement.attributeValue("numberOfIterations")); */ List list = document.selectNodes("//op:Operator"); Iterator itt = list.iterator(); while (itt.hasNext()) { Element opElement = (Element) itt.next(); // Get operator ID from xml QEP int opID = Integer.parseInt(opElement.attributeValue("id")); // Build producers from xml QEP String[] stringProducers = opElement.attributeValue("prod").split(","); int[] producers = new int[stringProducers.length]; for (int i = 0; i < stringProducers.length; i++) producers[i] = Integer.parseInt(stringProducers[i]); // Get operator type String type = opElement.attributeValue("type"); // Get parallelizable information String parallelAtt = opElement.attributeValue("parallelizable"); boolean parallelizable = false; if (parallelAtt != null) { if (parallelAtt.equalsIgnoreCase("true")) parallelizable = true; } // Get operator name from xml QEP Iterator opItt = opElement.elementIterator(); Node xmlOpNode = (Node) opItt.next(); String opName = xmlOpNode.getText(); // Build operator parameters int i = 0; String paramString = ""; String[] params = null; if (opItt.hasNext()) { Element parameterList = (Element) opItt.next(); Iterator paramItt = parameterList.elementIterator(); while (paramItt.hasNext()) { Node parameter = (Node) paramItt.next(); paramString = paramString + parameter.getText() + ";"; i++; } params = new String[i]; params = paramString.split(";"); } // Build operator timeStamp long idTimeStamp = System.currentTimeMillis(); // Build OpNode object for this operator OpNode opNode = new OpNode(opID, opName, producers, params, idTimeStamp + "", type, parallelizable); // Build DataSources if necessary if (opNode.getType() != null) { if (opNode.getType().equalsIgnoreCase("Scan")) { // Write the number of tuples in the BlackBoard as specified in the QEP // This operation is not done in remote nodes as G2N has already been called String numberOfTuples = opElement.attributeValue(Constants.QEP_SCAN_NUMBER_TUPLES); // In remote QEP this parameter is null, so we dont write again the field numberOfTuples // used in the DiscoveryOptimizer when it calls G2N if (numberOfTuples != null) { if (!numberOfTuples.equalsIgnoreCase("?")) { BlackBoard bl = BlackBoard.getBlackBoard(); bl.put(Constants.QEP_SCAN_NUMBER_TUPLES, numberOfTuples); } } try { DataSourceManager dsManager = DataSourceManager.getDataSourceManager(); dsManager.createDataSources(opNode); } catch (Exception ex) { throw new QEPInitializationException( "Error creating the " + "datasource : " + ex.getMessage()); } } } // Put OpNode in the QEP operatorList.put(opID + "", opNode); } return operatorList; }
From source file:ch.javasoft.xml.config.XmlPrint.java
License:BSD License
/** * Print the given element using the given print writer and initial * indention//from w ww . j a v a2 s .com * @param elem the xml element * @param indention the initial indention * @param writer the print writer to use for the output */ @SuppressWarnings("unchecked") public void print(Element elem, String indention, PrintWriter writer) { writer.print(indention + "<" + elem.getName()); Iterator<Attribute> itAtt = elem.attributeIterator(); Iterator<Element> itElem = elem.elementIterator(); if (elem.hasMixedContent() || (elem.hasContent() && !itElem.hasNext())) { Iterator<Node> it = elem.nodeIterator(); while (it.hasNext()) { Node node = it.next(); if (node instanceof CharacterData) { if (!(node instanceof Comment) && node.getText().trim().length() != 0) { throw new IllegalArgumentException( "text content not supported: \"" + node.getText() + "\""); } } else if (!(node instanceof Element || node instanceof Attribute)) { throw new IllegalArgumentException("only attributes and elements are supported"); } } } while (itAtt.hasNext()) { Attribute att = itAtt.next(); final String attName = att.getName(); final String attValue = att.getValue(); writer.print(" " + attName + "=\"" + escapeAttributeValue(attValue) + "\""); } if (!itElem.hasNext()) { writer.println("/>"); } else { writer.println(">"); while (itElem.hasNext()) { print(itElem.next(), indention + getIndention(), writer); } writer.println(indention + "</" + elem.getName() + ">"); } writer.flush(); }
From source file:cinnamon.global.Conf.java
License:Open Source License
@SuppressWarnings("unchecked") public List<String> getApiClasses(String repository) { Node repo = xml.selectSingleNode("//repository[name='" + repository + "']/apiClasses"); List<Node> apiNodes = repo.selectNodes("apiClass"); List<String> apiClasses = new ArrayList<>(); for (Node n : apiNodes) { apiClasses.add(n.getText()); }/*from w w w . j a va 2s . co m*/ return apiClasses; }
From source file:cms.service.util.ItemUtility.java
License:Open Source License
public String getElementValueByXpath(String xml, String xpath, String index) { String val = ""; int idx = Integer.parseInt(index); int count = 0; //System.out.println(xml); List<Node> nodes = this.getDocument(xml).selectNodes(xpath); for (Node n : nodes) { if (count == idx) { val = n.getText(); break; }/* www . j a v a 2s.co m*/ count++; } return (val); }
From source file:cn.com.sunjiesh.wechat.service.AbstractWechatMessageReceiveService.java
/** * ??//from w w w .j a v a 2s. co m * * @param message ? * @param queryParams querystring? * @return * @throws ServiceException ServiceException * @throws AesException AesException */ public String messageReceive(String message, Map<String, String> queryParams) throws ServiceException, AesException { try { // ??XML Document doc4j = DocumentHelper.parseText(message); Node encryptEle = doc4j.selectSingleNode("/xml/Encrypt"); if (encryptEle != null) { LOGGER.debug("???"); String token = WeChatProperties.getProperty(WeChatProperties.TOKEN); String encodingAesKey = WeChatProperties.getProperty(WeChatProperties.ENCODING_AES_KEY); String appId = WeChatProperties.getProperty(WeChatProperties.APPID); String timeStamp = queryParams.get("timestamp"); String nonce = queryParams.get("nonce"); String msgSignature = queryParams.get("msg_signature"); WXBizMsgCrypt pc = new WXBizMsgCrypt(token, encodingAesKey, appId); String format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%1$s]]></Encrypt></xml>"; String fromXML = String.format(format, encryptEle.getText()); String decryptStr = pc.decryptMsg(msgSignature, timeStamp, nonce, fromXML); LOGGER.debug("" + decryptStr); Document decryptDoc = DocumentHelper.parseText(decryptStr); Document resultDoc = messageReceive(decryptDoc); String resultStr = resultDoc.asXML(); String encryptResultStr = pc.encryptMsg(resultStr, timeStamp, nonce); return encryptResultStr; } Document resultDoc = messageReceive(doc4j); if (resultDoc == null) { //???Success return "success"; } return resultDoc.asXML(); } catch (DocumentException ex) { throw new ServiceException("?XML", ex); } }
From source file:cn.com.sunjiesh.wechat.service.AbstractWechatMessageReceiveService.java
/** * ??/*from ww w .ja v a2s . c o m*/ * * @param doc4j ??Dom * @return XML * @throws ServiceException ServiceException */ protected Document messageReceive(Document doc4j) throws ServiceException { // ?? Node toUserNameNode = doc4j.selectSingleNode("/xml/ToUserName"); Node fromUserNameNode = doc4j.selectSingleNode("/xml/FromUserName"); Node createTimeNode = doc4j.selectSingleNode("/xml/CreateTime"); Node msgTypeNode = doc4j.selectSingleNode("/xml/MsgType"); String toUserName = toUserNameNode == null ? "" : toUserNameNode.getText(); String fromUserName = fromUserNameNode == null ? "" : fromUserNameNode.getText(); String createTime = createTimeNode == null ? "" : createTimeNode.getText(); String msgType = msgTypeNode == null ? "" : msgTypeNode.getText(); Calendar createTimeCal = Calendar.getInstance(); createTimeCal.setTimeInMillis(Long.valueOf(createTime)); Date createTimeDate = createTimeCal.getTime(); WechatMessage wechatMessage = new WechatMessage(); wechatMessage.setToUserName(toUserName); wechatMessage.setFromUserName(fromUserName); wechatMessage.setCreateTime(createTimeDate); wechatMessage.setMsgType(msgType); WechatMessageBaseRequest wechatMessageBaseRequest = new WechatMessageBaseRequest(); wechatMessageBaseRequest.setToUserName(toUserName); wechatMessageBaseRequest.setFromUserName(fromUserName); wechatMessageBaseRequest.setCreateTime(createTimeDate); wechatMessageBaseRequest.setMsgType(msgType); Document respDoc4j = null; // MsgType???WechatMessage WechatReceiveMessageMsgTypeEnum msgTypeEnum = WechatReceiveMessageMsgTypeEnum .valueOf(msgType.toUpperCase().replace("_", "")); switch (msgTypeEnum) { case TEXT: respDoc4j = textMessageReceive(doc4j, wechatMessageBaseRequest); break; case IMAGE: respDoc4j = imageMessageReceive(doc4j, wechatMessage); break; case VOICE: respDoc4j = voiceMessageReceive(doc4j, wechatMessage); break; case VIDEO: respDoc4j = videoMessageReceive(doc4j, wechatMessage); break; case SHORTVIDEO: respDoc4j = shortvideoMessageReceive(doc4j, wechatMessage); break; case LOCATION: respDoc4j = locationMessageReceive(doc4j, wechatMessage); break; case LINK: respDoc4j = linkMessageReceive(doc4j, wechatMessage); break; case EVENT: respDoc4j = eventReceive(doc4j, wechatMessage); break; default: break; } return respDoc4j; }
From source file:cn.com.sunjiesh.wechat.service.AbstractWechatMessageReceiveService.java
/** * ??//w ww. j av a 2 s .c o m * * @param doc4j ??Dom * @param wechatMessage * @return ? * @throws ServiceException ServiceException */ protected Document eventReceive(Document doc4j, WechatMessage wechatMessage) throws ServiceException { // ?? // ?? Node eventNode = doc4j.selectSingleNode("/xml/Event"); Node eventKeyNode = doc4j.selectSingleNode("/xml/EventKey"); String event = eventNode == null ? "" : eventNode.getText(); String eventKey = eventKeyNode == null ? "" : eventKeyNode.getText(); String toUserName = wechatMessage.getToUserName(); String fromUserName = wechatMessage.getFromUserName(); Document respDoc4j = null; WechatReceiveMessageEventEnum eventEnum = WechatReceiveMessageEventEnum.valueOf(event.toUpperCase()); switch (eventEnum) { case CLICK: respDoc4j = clickEventReceive(toUserName, fromUserName, eventKey); break; case LOCATION: respDoc4j = locationEventReceive(doc4j, toUserName, fromUserName, eventKey); break; case SCAN: respDoc4j = scanEventReceive(doc4j, toUserName, fromUserName, eventKey); break; case SUBSCRIBE: respDoc4j = subscribeEventReceive(doc4j, toUserName, fromUserName, eventKey); break; case UNSUBSCRIBE: respDoc4j = unSubscribeEventReceive(doc4j, toUserName, fromUserName, eventKey); break; case VIEW: respDoc4j = viewEventReceive(doc4j, toUserName, fromUserName, eventKey); break; case SCANCODE_PUSH: respDoc4j = scanCodeEventReceive(doc4j, toUserName, fromUserName, eventKey); break; case SCANCODE_WAITMSG: respDoc4j = scanCodeEventReceive(doc4j, toUserName, fromUserName, eventKey); break; case PIC_SYSPHOTO: respDoc4j = picSysphotoEventReceive(doc4j, toUserName, fromUserName, eventKey); break; case PIC_PHOTO_OR_ALBUM: respDoc4j = picPhotoOrAlbumEventReceive(doc4j, toUserName, fromUserName, eventKey); break; case PIC_WEIXIN: respDoc4j = picWeixinEventReceive(doc4j, toUserName, fromUserName, eventKey); break; case LOCATION_SELECT: respDoc4j = locationSelectEventReceive(doc4j, toUserName, fromUserName, eventKey); break; default: break; } return respDoc4j; }